1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38 """
39 exiftran.py a wrapper for the original exiftran fprovided by Gerd Korn
40 http://linux.bytesex.org/fbida/
41
42 Needs libexif-dev, libjepg-dev and python-dev to be installed on the system.
43
44 """
45 __author__ = "Jerome Kieffer"
46 __licence__ = "GPLv2"
47 __contact__ = "Jerome.Kieffer@terre-adelie.org"
48
49 import os, threading, logging
50
51 installdir = os.path.dirname(__file__)
52
53 try:
54 import libexiftran
55 exiftranExe = None
56 print "Successfully imported libexiftran"
57 except:
58 print "Failed to import libexiftran: use old fashion"
59 if os.name == 'nt':
60 exiftranExe = os.path.join(installdir, "exiftran.exe ")
61 elif os.name == 'posix':
62 exiftranPath = os.path.join(installdir, "exiftran ")
63 if not os.path.isfile(exiftranPath):
64 for oneExeDir in os.environ["PATH"].split(os.pathsep):
65 if os.path.isfile(os.path.join(oneExeDir, "exiftran")):
66 exiftranPath = os.path.join(oneExeDir, "exiftran ")
67 MaxJPEGMem = 1000000
68 exiftranExe = "JPEGMEM=%i %s " % (MaxJPEGMem, exiftranPath)
74 """
75 This is static class implementing libexiftran in a more pythonic way
76 """
77 semaphore = threading.Semaphore()
78
79
80 @staticmethod
82 """
83 actual exiftran launcher
84 @param action: 0 for autorotate, 1 for 180 deg, 2 for 270 deg and 9 for 90 deg reotation clockwise
85 @type action: integer
86 @param filename: name of the jpeg file to process
87 @type filename: string
88 """
89 logging.debug("Exiftran._exiftranThread %s %s" % (action, filename))
90 if exiftranExe is None:
91 libexiftran.run(action, filename)
92 else:
93 if action == 0:action = "a"
94 os.system('%s -ip -%s "%s" ' % (exiftranExe, action, filename))
95 Exiftran.semaphore.release()
96
97
98 @staticmethod
100 """
101 rotate the given file by 90 degrees clockwise
102 @param filename: name of the JPEG file to rotate
103 @type filename: python string
104 """
105 logging.debug("Exiftran.rotate90 %s" % (filename))
106 Exiftran.semaphore.acquire()
107 myThread = threading.Thread(target=Exiftran._exiftranThread, args=(9, filename))
108 myThread.start()
109
110
111 @staticmethod
113 """
114 rotate the given file by 180 degrees
115 @param filename: name of the JPEG file to rotate
116 @type filename: python string
117 """
118 logging.debug("Exiftran.rotate180 %s" % (filename))
119 Exiftran.semaphore.acquire()
120 myThread = threading.Thread(target=Exiftran._exiftranThread, args=(1, filename))
121 myThread.start()
122
123
124 @staticmethod
126 """
127 rotate the given file by 90 degrees counter-clockwise (270deg clockwise)
128 @param filename: name of the JPEG file to rotate
129 @type filename: python string
130 """
131 logging.debug("Exiftran.rotate270 %s" % (filename))
132 Exiftran.semaphore.acquire()
133 myThread = threading.Thread(target=Exiftran._exiftranThread, args=(2, filename))
134 myThread.start()
135
136
137 @staticmethod
139 """
140 auto rotate the given file
141 @param filename: name of the JPEG file to rotate
142 @type filename: python string
143 """
144 logging.debug("Exiftran.autorotate %s" % (filename))
145 Exiftran.semaphore.acquire()
146 myThread = threading.Thread(target=Exiftran._exiftranThread, args=(0, filename))
147 myThread.start()
148
149
150 @staticmethod
152 """return the value of the semaphore, either 0 or 1"""
153 return Exiftran.semaphore._Semaphore__value
154