lundi 8 avril 2013

Compilation via Maven et UTF-8

Pour forcer la compilation via maven en prenant en charge l'UTF-8, définir les propriétés suivantes :

<properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-compiler-plugin</artifactId>
    <configuration>
        <source>1.6</source>
        <target>1.6</target>
        <encoding>${project.build.sourceEncoding}</encoding>
    </configuration>
</plugin>

Et voilà :)

cf. https://maven.apache.org/plugins/maven-compiler-plugin/compile-mojo.html

dimanche 7 avril 2013

Appeler un processus (Imagemagick) en python

Voici un petit exemple de code en python permettant d'appeler un processus externe.
Dans cet exemple, nous appelons "imagemagick" pour effectuer le redimensionnement des images contenues dans un répertoire vers deux dimensions.

#!/usr/bin/python

from glob import glob
from subprocess import check_call, CalledProcessError
import os

class ConvertError(Exception):
    """Error while trying to convert.
    """

root_path = '/home/user/Bureau/'
ext = '.jpg'
files = glob(root_path + '*' + ext)

try:
    os.mkdir(root_path + "150/")
except OSError:
    pass

try:
    os.mkdir(root_path + "650/")
except OSError:
    pass

for f in files:
    folder_path, file_name = os.path.split(f);
    img_150_path = root_path + '_150' + ext
    img_650_path = root_path + '_650' + ext
    try:
        check_call(["convert", f, "-resize", "150x150", "-quality", "80", root_path + "150/" + file_name])
        check_call(["convert", f, "-resize", "650x900", "-quality", "80", root_path + "650/" + file_name])
    except CalledProcessError:
        raise ConvertError("Error converting")
    try:
        os.renames(f, root_path + "ori/" + file_name)
    except OSError:
        raise ConvertError("Error renaming")
Related Posts Plugin for WordPress, Blogger...