Package imagizer :: Module exiftran
[hide private]
[frames] | no frames]

Source Code for Module imagizer.exiftran

  1  #!/usr/bin/env python 
  2  # -*- coding: UTF8 -*- 
  3  #******************************************************************************\ 
  4  #* $Source$ 
  5  #* $Id$ 
  6  #* 
  7  #* Copyright (C) 2006-2010,  Jérôme Kieffer <kieffer@terre-adelie.org> 
  8  #* Conception : Jérôme KIEFFER, Mickael Profeta & Isabelle Letard 
  9  #* Licence GPL v2 
 10  #* 
 11  #* This program is free software; you can redistribute it and/or modify 
 12  #* it under the terms of the GNU General Public License as published by 
 13  #* the Free Software Foundation; either version 2 of the License, or 
 14  #* (at your option) any later version. 
 15  #* 
 16  #* This program is distributed in the hope that it will be useful, 
 17  #* but WITHOUT ANY WARRANTY; without even the implied warranty of 
 18  #* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
 19  #* GNU General Public License for more details. 
 20  #* 
 21  #* You should have received a copy of the GNU General Public License 
 22  #* along with this program; if not, write to the Free Software 
 23  #* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 
 24  #* 
 25  #*****************************************************************************/ 
 26   
 27  # 
 28  # Liste des dépendances : python, PIL, Glade-2 
 29  # Exiftran existe en version windows maintenant ... nous utilisons une verison modifiée ...!!!! 
 30  # 
 31  #todo liste des fonctions a implemanter .... 
 32  # - se passer de exiftran 
 33  # - la version windows et la version mac 
 34  # - faire une doc décente. 
 35  # - proposer d'exporter toutes les photos dans un seul répertoire (pas de jour) 
 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': #sys.platform == 'win32': 
 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 # OK up to 100 Mpix 
 68          exiftranExe = "JPEGMEM=%i %s " % (MaxJPEGMem, exiftranPath) 
69 70 71 72 73 -class Exiftran(object):
74 """ 75 This is static class implementing libexiftran in a more pythonic way 76 """ 77 semaphore = threading.Semaphore() 78 79 80 @staticmethod
81 - def _exiftranThread(action, filename):
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
99 - def rotate90(filename):
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
112 - def rotate180(filename):
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
125 - def rotate270(filename):
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
138 - def autorotate(filename):
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
151 - def getSemaphoreValue():
152 """return the value of the semaphore, either 0 or 1""" 153 return Exiftran.semaphore._Semaphore__value
154