diff --git a/Qalbum-descriptor.py b/Qalbum-descriptor.py new file mode 100755 index 0000000..e4d15fe --- /dev/null +++ b/Qalbum-descriptor.py @@ -0,0 +1,127 @@ +#!/usr/bin/env python +# +# Copyright 2012 Ville Rantanen +# +# this program is free software: you can redistribute it and/or modify it +# under the terms of the GNU Lesser General Public License as published +# by the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public License +# along with this program. If not, see . + +import sys,os +import re +import shutil +import subprocess +from optparse import OptionParser +from math import ceil + +# (c) ville.rantanen@helsinki.fi + +imagesearch=re.compile('.*\.jpg$|.*\.jpeg$|.*\.gif$|.*\.png$|.*\.svg$|.*\.pdf$',re.I) +excludepaths=re.compile('_med|_tn|\..*') +DESCFILE='descriptions.csv' + +def getimagelist(path): + ''' Returns a list of images matching the regex ''' + list=os.listdir(path) + imgs=[] + for f in list: + if (imagesearch.match(os.path.join(path,f))) and (os.path.isfile(os.path.join(path,f))): + imgs.append(f) + return imgs + +def getpathlist(path): + ''' Returns a list of subfolders not matching the exclusion regex ''' + list=os.listdir(path) + paths=[] + for d in list: + if (not excludepaths.match(d)) and (os.path.isdir(os.path.join(path,d))): + paths.append(d) + return paths + +def createdesc(path,list): + ''' Runs imagemagick identify to create descriptions of images ''' + if len(list)==0: + return + if os.path.exists(os.path.join(path,DESCFILE)): + if options.force: + os.remove(os.path.join(path,DESCFILE)) + else: + print('Descriptions exist, not overwriting.') + return + outfile=open(os.path.join(path,DESCFILE),'w') + n=1 + nsum=len(list) + for i in list: + inpath=os.path.join(path,i) + desc=create_description(inpath,options.format) + outfile.write(i+"\t"+desc) + outfile.flush() + print('('+str(n)+'/'+str(nsum)+') '+i+"\t"+desc[0:-1]) + n+=1 + return + +def create_description(infile,format): + idargs=['identify','-format',format,infile+'[0]'] + idp=subprocess.Popen(idargs,stdout=subprocess.PIPE) + output = idp.stdout.read() + return output + +def traverse(path): + ''' The recursive main function to create the thumbs and seek sub folders ''' + print(path) + pathlist=getpathlist(path) + imagelist=getimagelist(path) + print(str(len(pathlist))+' paths') + print(str(len(imagelist))+' images') + createdesc(path,imagelist) + if options.recursive: + for p in pathlist: + traverse(os.path.join(path,p)) + return + +def execute(): + ''' Main execution ''' + usage='''Usage: %prog [options] folder +folder is the root folder of the image album.''' + parser=OptionParser(usage=usage) + parser.add_option("-f",action="store_true",dest="force",default=False, + help="Force rewriting of descriptions") + parser.add_option("--format",type="str",dest="format",default="", + help="""Formatting string, see: http://www.imagemagick.org/script/escape.php. + Setting this option will override the presets""") + parser.add_option("-r",action="store_true",dest="recursive",default=False, + help="Recurse in to subfolders") + parser.add_option("-p",type="int",dest="preset",default=1, + help="presets for descriptions. \"-p 0\" to get the list") + global options + (options,args)=parser.parse_args() + if len(args) != 1 and options.preset!=0: + parser.error("incorrect number of arguments") + presets=[ + '%f: %[EXIF:DateTimeOriginal]', + '%f: %wx%h %[size]', + '%f
%[EXIF:DateTimeOriginal] %[EXIF:ExposureTime]s F%[EXIF:FNumber]'] + if options.preset<1: + for row in range(len(presets)): + print row+1," ",presets[row] + sys.exit(0) + if options.format=="": + if options.preset>len(presets): + parse.error("No such preset") + options.format=presets[options.preset-1] + + traverse(os.path.abspath(args[0])) + return + +execute() +sys.exit(0) + + diff --git a/Qalbum.py b/Qalbum.py index 5f9d73d..51ceabb 100755 --- a/Qalbum.py +++ b/Qalbum.py @@ -1,6 +1,6 @@ #!/usr/bin/env python # -# Copyright 2011 Ville Rantanen +# Copyright 2012 Ville Rantanen # # This program is free software: you can redistribute it and/or modify it # under the terms of the GNU Lesser General Public License as published @@ -26,7 +26,7 @@ from datetime import datetime # (c) ville.rantanen@helsinki.fi -__version__='1.5b' +__version__='1.5' webfilesearch=re.compile('.*index.html$|.*gallerystyle.css$|.*galleryscript.js$|.*descriptions.csv$|\..*',re.I) imagesearch=re.compile('.*\.jpg$|.*\.jpeg$|.*\.gif$|.*\.png$|.*\.svg$|.*\.pdf$',re.I) @@ -50,6 +50,13 @@ def getheader(path,parent,title=""): ''' +def getfooter(): + return ''' + + + + +''' def getimagelist(path): ''' Returns a list of images matching the regex ''' @@ -68,7 +75,7 @@ def getfiletimes(path,list): ''' Returns a list of modification times ''' times=[] for p in list: - times.append(os.path.getmtime(os.path.join(path,p))) + times.append(int(os.path.getmtime(os.path.join(path,p)))) return times def getnonimagelist(path): @@ -237,9 +244,10 @@ def getdescriptions(path,list): escapechar='\\', quoting=csv.QUOTE_NONE) for row in reader: - if row[0] in list: - i=list.index(stripquotes.sub('',row[0])) - desc[i]=stripquotes.sub('',row[1]) + if len(row)>1: + if row[0] in list: + i=list.index(stripquotes.sub('',row[0])) + desc[i]=stripquotes.sub('',row[1]) return desc def crumblinks(crumbs): @@ -320,7 +328,7 @@ def traverse(path,crumbs): f.write(imagestring) f.write(filestring) f.write('
') - f.write(footer) + f.write(getfooter()) f.close() createthumbs(path,imagelist) for p in pathlist: @@ -339,12 +347,6 @@ class AndurilOptions: self.attachments=True def execute(cf): - global footer - footer=''' - - - -''' global inputs global options inputs=[] @@ -438,12 +440,6 @@ folder is the root folder of the image album.''' # Copy all resources to target folder shutil.copyfile(os.path.join(fullpath,'gallerystyle.css'),os.path.join(startpath,'gallerystyle.css')) shutil.copyfile(os.path.join(fullpath,'galleryscript.js'),os.path.join(startpath,'galleryscript.js')) - global footer - footer=''' - - - -''' global inputs inputs=[] inputs.append((None,'Gallery',None)) diff --git a/galleryscript.js b/galleryscript.js index 1655202..33184f5 100644 --- a/galleryscript.js +++ b/galleryscript.js @@ -1,5 +1,5 @@ /* -Copyright 2011 Ville Rantanen +Copyright 2012 Ville Rantanen This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published @@ -548,7 +548,7 @@ function keypressed(e) { } // o: originals if (unicode==79) { - fliporiginalsi(); + fliporiginals(); } // f: fullscreen if (unicode==70) {