Changeset 187
- Timestamp:
- Tue Sep 25 15:17:07 2007
- Files:
-
- trunk/tools.py (modified) (diff)
- trunk/jbrout.py (modified) (diff)
- trunk/db.py (modified) (diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
trunk/tools.py
r157 r187 79 79 """ 80 80 81 format = "-nfp%Y%m%d_%H%M%S" 82 #format = "-nf%Y-%m-%d_%H-%M-%S" 81 format = "p%Y%m%d_%H%M%S" 82 #format = "%Y-%m-%d_%H-%M-%S" 83 83 84 84 isWin=(sys.platform[:3] == "win") … … 153 153 out = out.decode(sys.getfilesystemencoding()) 154 154 except UnicodeDecodeError: 155 raise CommandException( cmd +"\n decoding trouble") 155 raise CommandException( cmdline +"\n decoding trouble") 155 155 156 156 # Protect against crappy output of some unnamed (ehm, … … 180 180 #---------------------------------------------------------------------------- 181 181 @staticmethod 182 def normalizeName(file):182 def prepareFile(file,needRename=True,needAutoRot=False): 182 182 #---------------------------------------------------------------------------- 183 """ rename file according its exifdate, and set datefile = date exif, 184 return the new name. 185 """ 186 buf = _Command._run( [_Command.__jhead,'-ft',_Command.format,file] ) 187 188 # il faut, alors, récupérer son nouveau nom 189 # heureusement jhead retourne ce nouveau nom ;-) 190 p = buf.find("-->") 191 if p>0: 192 # il y a u renommage de "jhead" 193 n = buf[p+3:].strip() 194 return n 195 else: 196 # il n'y a pas u de renommage ?!? 197 return file 198 # jhead est passée par là, donc le atime/mtime correspond à la date exif 199 200 183 """ 184 prepare the file (rename/rotate according exif) ... (in one jhead action (optimization)) 185 186 if needRename : 187 rename file according its exifdate, and set datefile = date exif, 188 and return the new name (or old one if not renamed) 189 190 and do autorot according exif tag if "needAutoRot" is True 191 """ 192 193 if _Command.isWin: 194 needAutoRot = False # no autorotate on windows (jpegtran trouble) 195 196 if needRename: 197 # renaming is needed, we'll need to return the new name 198 if needAutoRot: 199 buf = _Command._run( [_Command.__jhead,"-ft","-autorot","-nf"+_Command.format,file] ) 200 else: 201 buf = _Command._run( [_Command.__jhead,'-ft',"-nf"+_Command.format,file] ) 202 203 # rename has be done, we need to get the newname 204 # (we get it in jhead output) 205 p = buf.find("-->") 206 if p>0: 207 # it was renamed 208 return buf[p+3:].strip() 209 else: 210 # not renamed, return original name 211 return file 212 213 else: 214 # no renaming, return the original filename (to be compatible) 215 if needAutoRot: 216 _Command._run( [_Command.__jhead,"-ft","-autorot",file] ) 217 218 return file 219 201 220 #---------------------------------------------------------------------------- 202 221 @staticmethod … … 335 354 336 355 337 import time,datetime338 356 class DateSave: 339 357 def __init__(self,file): … … 533 551 """ 534 552 assert type(file)==unicode 535 return _Command.normalizeName(file) 553 554 return _Command.prepareFile(file,needRename=True,needAutoRot=False) 536 555 556 @staticmethod 557 def prepareFile(file,needRename,needAutoRot): 558 """ 559 prepare file, rotating/autorotating according exif tags 560 (same things as normalizename + autorot, in one action) 561 only called at IMPORT/REFRESH albums 562 """ 563 assert type(file)==unicode 564 565 return _Command.prepareFile(file,needRename,needAutoRot) 566 567 568 @staticmethod 569 def setNormalizeNameFormat(format): 570 """ set format for normalized files (see prepareFile())""" 571 _Command.format = format 572 573 537 574 def __init__(self,file): 538 575 assert type(file)==unicode,"ERROR:"+str(type(file)) -
trunk/jbrout.py
r183 r187 704 704 JBrout.conf["normalizeName"] = 0 705 705 706 707 if JBrout.conf["normalizeNameFormat"] == None: # key not present 708 JBrout.conf["normalizeNameFormat"] = "p%Y%m%d_%H%M%S" # set default 709 710 if JBrout.conf["autorotAtImport"] == None: # key not present 711 JBrout.conf["autorotAtImport"] = 1 # set default 712 713 706 714 JBrout.db.setNormalizeName( JBrout.conf["normalizeName"]==1 ) 715 JBrout.db.setNormalizeNameFormat( JBrout.conf["normalizeNameFormat"] ) 716 JBrout.db.setAutorotAtImport( JBrout.conf["autorotAtImport"]==1 ) 707 717 708 718 self.tagsInSelection=[] -
trunk/db.py
r169 r187 56 56 return s.decode("utf_8") 57 57 58 #~ class Basket:59 #~ def __init__(self,file):60 #~ self.__file=file61 #~ self.__files=[]62 #~ if os.path.isfile(file):63 #~ fid=open(file)64 #~ if fid:65 #~ b=fid.read().decode("utf_8")66 #~ for i in b.split("\n"):67 #~ i=i.strip()68 #~ if i:69 #~ self.__files.append(i)70 #~ fid.close()71 72 #~ def isBasket(self):73 #~ return len(self.__files)>074 75 #~ def clear(self):76 #~ self.__files=[]77 78 #~ def isInBasket(self,file):79 #~ assert type(file)==unicode80 #~ return file in self.__files81 82 #~ def add(self,file):83 #~ assert type(file)==unicode84 #~ if not self.isInBasket(file):85 #~ self.__files.append(file)86 #~ return True87 #~ else:88 #~ return False89 90 #~ def remove(self,file):91 #~ assert type(file)==unicode92 #~ if self.isInBasket(file):93 #~ self.__files.remove(file)94 #~ return True95 #~ else:96 #~ return False97 98 #~ def getFiles(self):99 #~ return self.__files100 101 #~ def save(self):102 #~ if self.isBasket():103 #~ fid = open(self.__file,"w")104 #~ if fid:105 #~ fid.write((u"\n".join(self.__files)).encode("utf_8"))106 #~ fid.close()107 #~ else:108 #~ try:109 #~ os.unlink(self.__file)110 #~ except:111 #~ pass112 58 113 59 class DBPhotos: 114 60 normalizeName = False 61 autorotAtImport = False 115 62 116 63 def __init__(self,file): … … 135 82 136 83 def setNormalizeName(self,v): 137 if v: 138 DBPhotos.normalizeName = True 139 else: 140 DBPhotos.normalizeName = False 84 DBPhotos.normalizeName = v 85 86 def setNormalizeNameFormat(self,v): 87 PhotoCmd.setNormalizeNameFormat(v) 88 89 def setAutorotAtImport(self,v): 90 DBPhotos.autorotAtImport = v 141 91 142 92 … … 167 117 for file in files: 168 118 yield files.index(file) 169 if DBPhotos.normalizeName: 170 file = PhotoCmd.normalizeName(file) 119 file = PhotoCmd.prepareFile(file, 120 needRename=DBPhotos.normalizeName, 121 needAutoRot=DBPhotos.autorotAtImport, 122 ) 171 123 self.__addPhoto( file ,tags,filesInBasket) 172 124
