python3 compatible, not python2 anymore

This commit is contained in:
Q
2020-09-22 09:10:41 +03:00
parent 38f26a3c69
commit fb31b64f45
8 changed files with 165 additions and 123 deletions

View File

@@ -1,4 +1,4 @@
#!/usr/bin/env python #!/usr/bin/env python3
# #
# Copyright 2016 Ville Rantanen # Copyright 2016 Ville Rantanen
# #
@@ -18,6 +18,8 @@
import sys,os import sys,os
import re import re
import urllib import urllib
import urllib.parse
from html.parser import HTMLParser
import shutil import shutil
import csv import csv
import subprocess import subprocess
@@ -27,7 +29,7 @@ from datetime import datetime
# (c) ville.q.rantanen@gmail.com # (c) ville.q.rantanen@gmail.com
__version__='2.20190411a' __version__='2.20200922'
FILECONFIG=".config" FILECONFIG=".config"
FILEDESC="descriptions.csv" FILEDESC="descriptions.csv"
@@ -72,8 +74,8 @@ singlequotes=re.compile("'")
stripquotes=re.compile('^"|"$') stripquotes=re.compile('^"|"$')
def getheader(path,parent,title=""): def getheader(path,parent,title=""):
if title=="": if title == "":
title=unicode(os.path.basename(path),encoding="utf8").encode('ascii', 'xmlcharrefreplace') title = unescape(os.path.basename(path))
return '''<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> return '''<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<HTML> <HTML>
<HEAD> <HEAD>
@@ -89,6 +91,7 @@ def getheader(path,parent,title=""):
</HEAD> </HEAD>
<BODY> <BODY>
''' '''
def getfooter(): def getfooter():
return ''' return '''
<div id="footer">Generated with Qalbum '''+__version__+''' ('''+datetime.today().strftime("%y-%m-%d %H:%M")+''') <a href="https://bitbucket.org/MoonQ/qalbum/wiki/Home" target="_TOP">Need help?</a></div> <div id="footer">Generated with Qalbum '''+__version__+''' ('''+datetime.today().strftime("%y-%m-%d %H:%M")+''') <a href="https://bitbucket.org/MoonQ/qalbum/wiki/Home" target="_TOP">Need help?</a></div>
@@ -177,49 +180,53 @@ def getpathlist(path,options=False):
paths.sort(key=lambda x: natural_sort_key(x)) paths.sort(key=lambda x: natural_sort_key(x))
return paths return paths
def pathscript(path,list): def pathscript(path,list):
''' Returns the javascript string of pathlist and pathimage arrays ''' ''' Returns the javascript string of pathlist and pathimage arrays '''
scrstr='<script language="javascript">var pathlist=[' scrstr = '<script language="javascript">var pathlist=['
elements=[] parser = HTMLParser()
elements = []
for p in list: for p in list:
imglist=getimagelist(os.path.join(path,p)) imglist = getimagelist(os.path.join(path,p))
pathlist=getpathlist(os.path.join(path,p)) pathlist = getpathlist(os.path.join(path,p))
this_str='{ name:"'+unicode(p,encoding="utf8").encode('ascii', 'xmlcharrefreplace')+'", ' this_str = '{ name:"'+ parser.unescape(p) + '", '
this_str+='size:'+str(len(imglist)+len(pathlist))+', ' this_str += 'size:' + str(len(imglist) + len(pathlist)) + ', '
if len(imglist)>0: if len(imglist) > 0:
this_str+='image:"'+unicode(p,encoding="utf8").encode('ascii', 'xmlcharrefreplace')+'/.tn/'+unicode(imglist[0],encoding="utf8").encode('ascii', 'xmlcharrefreplace')+'.jpg"}' this_str += 'image:"'+parser.unescape(p) + '/.tn/'+parser.unescape(imglist[0]) + '.jpg"}'
else: else:
this_str+='image:"" }' this_str += 'image:"" }'
elements.append(this_str) elements.append(this_str)
scrstr+=','.join(elements)+'];</script>' scrstr += ','.join(elements) + '];</script>'
return scrstr return scrstr
def pathlinks(path,list): def pathlinks(path,list):
''' Returns the HTML string of subfolders ''' ''' Returns the HTML string of subfolders '''
if len(list)==0: if len(list) == 0:
return '<div id="pathcontainer"></div>' return '<div id="pathcontainer"></div>'
pathstr='<div id="pathcontainer">' pathstr = '<div id="pathcontainer">'
pathstr+='<h1>Subfolders</h1>' pathstr += '<h1>Subfolders</h1>'
for p in list: for p in list:
nice=nicestring(p) nice = nicestring(p)
imglist=getimagelist(os.path.join(path,p)) imglist = getimagelist(os.path.join(path,p))
nsum=str(len(imglist)) nsum = str(len(imglist))
imgstr="" imgstr = ""
if len(imglist)>0: if len(imglist) > 0:
imgstr='<span class="pathbox" style="background-image:url(\''+urllib.quote(p)+'/.tn/'+urllib.quote(imglist[0])+'.jpg\');">' imgstr = '<span class="pathbox" style="background-image:url(\''+urllib.parse.quote(p)+'/.tn/'+urllib.parse.quote(imglist[0])+'.jpg\');">'
else: else:
imgstr='<span class="pathbox">' imgstr = '<span class="pathbox">'
pathstr += '<a title="%s" href="%s/index.html">%s<span class="pathlink"><span class="pathlinktext">%s (%s)</span></span></span></a>'%( pathstr += '<a title="%s" href="%s/index.html">%s<span class="pathlink"><span class="pathlinktext">%s (%s)</span></span></span></a>'%(
unicode(p,encoding="utf8").encode('ascii', 'xmlcharrefreplace'), unescape(p),
urllib.quote(p), urllib.parse.quote(p),
imgstr, imgstr,
nice.encode('ascii', 'xmlcharrefreplace'), unescape(nice),
nsum nsum
) )
pathstr+='</script>' pathstr += '</script>'
pathstr+='</div>' pathstr += '</div>'
return pathstr return pathstr
def imagescript(path,list): def imagescript(path,list):
''' Returns the javascript string of imagelist and imagedesc ''' ''' Returns the javascript string of imagelist and imagedesc '''
strout='<script language="javascript">var imagelist=[' strout='<script language="javascript">var imagelist=['
@@ -230,10 +237,10 @@ def imagescript(path,list):
elements=[] elements=[]
for i in list: for i in list:
try: try:
desc=singlequotes.sub("\\'",unicode(descriptions[n],encoding="utf8").encode('ascii', 'xmlcharrefreplace')) desc=singlequotes.sub("\\'",unescape(descriptions[n]))
except: except:
desc=singlequotes.sub("\\'",filter(lambda x: x in string.printable, descriptions[n]).encode('ascii', 'xmlcharrefreplace')) desc=singlequotes.sub("\\'",unescape(filter(lambda x: x in string.printable, descriptions[n])))
this_str='\n{name:"'+unicode(i,encoding="utf8").encode('ascii', 'xmlcharrefreplace')+'", ' this_str='\n{name:"' + unescape(i) + '", '
this_str+='desc:\''+desc+'\', ' this_str+='desc:\''+desc+'\', '
this_str+='size:\''+str(sizes[n])+'\', ' this_str+='size:\''+str(sizes[n])+'\', '
this_str+='time:'+str(times[n])+'}' this_str+='time:'+str(times[n])+'}'
@@ -242,54 +249,58 @@ def imagescript(path,list):
strout+=','.join(elements)+'];</script>' strout+=','.join(elements)+'];</script>'
return strout return strout
def imagelinks(path,list): def imagelinks(path,list):
''' Returns the HTML string of images ''' ''' Returns the HTML string of images '''
if len(list)==0: if len(list) == 0:
return '<div id="thumbcontainer"></div>' return '<div id="thumbcontainer"></div>'
strout='<div id="thumbcontainer"><noscript>' strout = '<div id="thumbcontainer"><noscript>'
strout+='<h1>Images</h1>' strout += '<h1>Images</h1>'
descriptions=getdescriptions(path,list) descriptions = getdescriptions(path,list)
n=0 n=0
for i in list: for i in list:
nice=nicestring(i) nice=nicestring(i)
try: try:
desc=doublequotes.sub('',unicode(descriptions[n],encoding="utf8").encode('ascii', 'xmlcharrefreplace')) desc=doublequotes.sub('',unescape(descriptions[n]))
except: except:
desc=doublequotes.sub('',filter(lambda x: x in string.printable, descriptions[n]).encode('ascii', 'xmlcharrefreplace')) desc=doublequotes.sub('',unescape(filter(lambda x: x in string.printable, descriptions[n])))
strout += '<span class="imagebox thumbbox" id="n%d"><a href="%s"><img class="thumbimage" "title="%s" src=".tn/%s.jpg"><br/>%s</a></span>'%( strout += '<span class="imagebox thumbbox" id="n%d"><a href="%s"><img class="thumbimage" "title="%s" src=".tn/%s.jpg"><br/>%s</a></span>'%(
n, n,
urllib.quote(i), urllib.parse.quote(i),
desc, desc,
urllib.quote(i), urllib.parse.quote(i),
nice.encode('ascii', 'xmlcharrefreplace') nice
) )
n+=1 n += 1
strout+='</noscript></div>' strout += '</noscript></div>'
return strout return strout
def filescript(path,list): def filescript(path,list):
''' Returns the javascript string of filelist ''' ''' Returns the javascript string of filelist '''
strout='<script language="javascript">var filelist=[' strout = '<script language="javascript">var filelist=['
elements=[]; elements = []
for i in list: for i in list:
elements.append('"'+unicode(i,encoding="utf8").encode('ascii', 'xmlcharrefreplace')+'"') elements.append('"' + unescape(i) + '"')
strout+=','.join(elements)+'];</script>' strout += ','.join(elements)+ '];</script>'
return strout return strout
def filelinks(path,list): def filelinks(path,list):
''' Returns the HTML string of non image files ''' ''' Returns the HTML string of non image files '''
strout='<div id="attachmentcontainer">' strout = '<div id="attachmentcontainer">'
if len(list)>0: if len(list) > 0:
strout+='<h2>Attachments</h1>' strout += '<h2>Attachments</h1>'
n=0 n=0
for i in list: for i in list:
size=sizestring(os.path.getsize(os.path.join(path,i))) size = sizestring(os.path.getsize(os.path.join(path,i)))
strout+='<span class="attachmentbox" id="a'+str(n)+'"><a href="'+urllib.quote(i)+'">'+unicode(i,encoding="utf8").encode('ascii', 'xmlcharrefreplace')+' ['+size+']</a></span>' strout += '<span class="attachmentbox" id="a'+str(n)+'"><a href="'+urllib.parse.quote(i)+'">' + unescape(i) +' ['+size+']</a></span>'
n+=1 n += 1
strout+='</div>' strout += '</div>'
return strout return strout
def cleanthumbs(path): def cleanthumbs(path):
''' clears .med and .tn for unused thumbs ''' ''' clears .med and .tn for unused thumbs '''
print('clearing unused thumbs...') print('clearing unused thumbs...')
@@ -299,6 +310,7 @@ def cleanthumbs(path):
clearfolder(path,os.path.join(path,'.med'),re.compile("(.*)(.jpg)")) clearfolder(path,os.path.join(path,'.med'),re.compile("(.*)(.jpg)"))
return return
def clearfolder(path,tnpath,regex): def clearfolder(path,tnpath,regex):
''' clears given folder ''' ''' clears given folder '''
list=getimagelist(tnpath) list=getimagelist(tnpath)
@@ -312,6 +324,7 @@ def clearfolder(path,tnpath,regex):
continue continue
return return
def createthumbs(path,list,options): def createthumbs(path,list,options):
''' Runs imagemagick Convert to create medium sized and thumbnail images ''' ''' Runs imagemagick Convert to create medium sized and thumbnail images '''
if len(list)==0: if len(list)==0:
@@ -320,15 +333,15 @@ def createthumbs(path,list,options):
os.mkdir(os.path.join(path,'.tn')) os.mkdir(os.path.join(path,'.tn'))
if not os.path.exists(os.path.join(path,'.med')): if not os.path.exists(os.path.join(path,'.med')):
os.mkdir(os.path.join(path,'.med')) os.mkdir(os.path.join(path,'.med'))
n=1 n = 1
nsum=len(list) nsum = len(list)
r=str(options.width) r = str(options.width)
res=r+'x'+r+'>' res = r + 'x' + r + '>'
print('') print('')
for i in list: for i in list:
outmedium=os.path.join(path,'.med',i+'.jpg') outmedium = os.path.join(path,'.med',i+'.jpg')
outthumb=os.path.join(path,'.tn',i+'.jpg') outthumb = os.path.join(path,'.tn',i+'.jpg')
inpath=os.path.join(path,i) inpath = os.path.join(path,i)
if (options.force) and os.path.exists(outmedium): if (options.force) and os.path.exists(outmedium):
os.unlink(outmedium) os.unlink(outmedium)
if (options.force) and os.path.exists(outthumb): if (options.force) and os.path.exists(outthumb):
@@ -343,6 +356,7 @@ def createthumbs(path,list,options):
print_clear('') print_clear('')
return return
def create_medium_bitmap(infile,outfile,r,link=False,vector=False): def create_medium_bitmap(infile,outfile,r,link=False,vector=False):
if link: if link:
os.symlink('../'+os.path.basename(infile),outfile) os.symlink('../'+os.path.basename(infile),outfile)
@@ -355,6 +369,7 @@ def create_medium_bitmap(infile,outfile,r,link=False,vector=False):
convp=subprocess.call(convargs) convp=subprocess.call(convargs)
return return
def create_thumb_bitmap(infile,outfile,vector=False,gravity='Center'): def create_thumb_bitmap(infile,outfile,vector=False,gravity='Center'):
if vector: if vector:
convargs=['convert','-density','300x300',infile,'-background','white','-flatten','-thumbnail','90x90^','-gravity',gravity,'-crop','90x90+0+0','+repage','-quality','75',outfile] convargs=['convert','-density','300x300',infile,'-background','white','-flatten','-thumbnail','90x90^','-gravity',gravity,'-crop','90x90+0+0','+repage','-quality','75',outfile]
@@ -363,13 +378,14 @@ def create_thumb_bitmap(infile,outfile,vector=False,gravity='Center'):
convp=subprocess.call(convargs) convp=subprocess.call(convargs)
return return
def getdescriptions(path,list): def getdescriptions(path,list):
''' Read descriptions.csv file and returns a list of descriptions. ''' Read descriptions.csv file and returns a list of descriptions.
Missing descriptions are replaced with the file name. ''' Missing descriptions are replaced with the file name. '''
if not os.path.exists(os.path.join(path,FILEDESC)): if not os.path.exists(os.path.join(path,FILEDESC)):
return list return list
desc=[i for i in list] desc=[i for i in list]
reader = csv.reader(open(os.path.join(path,FILEDESC),'rb'), reader = csv.reader(open(os.path.join(path,FILEDESC),'rt'),
delimiter='\t', delimiter='\t',
doublequote=False, doublequote=False,
escapechar='\\', escapechar='\\',
@@ -381,6 +397,7 @@ def getdescriptions(path,list):
desc[i]=stripquotes.sub('',row[1]) desc[i]=stripquotes.sub('',row[1])
return desc return desc
def getinfo(path,options): def getinfo(path,options):
''' Read info.txt file and returns the content. ''' Read info.txt file and returns the content.
Missing info file returns empty string. ''' Missing info file returns empty string. '''
@@ -389,34 +406,36 @@ def getinfo(path,options):
reader = open(os.path.join(path,options.infofile),'r') reader = open(os.path.join(path,options.infofile),'r')
return unicode(reader.read(),encoding="utf8",errors="ignore").encode('ascii','xmlcharrefreplace') return unicode(reader.read(),encoding="utf8",errors="ignore").encode('ascii','xmlcharrefreplace')
def crumblinks(crumbs,title,parent):
''' Create the HTML string for crumb trails '''
strout='<div id="crumbcontainer">' def crumblinks(crumbs, title, parent):
''' Create the HTML string for crumb trails '''
strout = '<div id="crumbcontainer">'
if parent: if parent:
if not parent.startswith('http://'): if not parent.startswith('http://'):
parent="../"*(len(crumbs))+parent parent = "../"*(len(crumbs))+parent
strout+='<a href="'+parent+'">'+'Home'.encode('ascii', 'xmlcharrefreplace')+'</a>: ' strout += '<a href="' + parent + '">' + 'Home' + '</a>: '
i=1 i = 1
for c in crumbs: for c in crumbs:
cname=os.path.basename(c) cname = os.path.basename(c)
if i==1: if i == 1:
cname=title cname = title
cdepth=len(crumbs)-i cdepth = len(crumbs) - i
clink="../"*cdepth clink = "../"*cdepth
strout+='<a href="'+clink+'index.html">'+unicode(cname,encoding="utf8").encode('ascii', 'xmlcharrefreplace')+'</a>: ' strout += '<a href="'+ clink +'index.html">'+ unescape(cname) + '</a>: '
i+=1 i += 1
strout+='</div>' strout += '</div>'
return strout return strout
def print_clear(s): def print_clear(s):
sys.stdout.write("\033[1K\r") sys.stdout.write("\033[1K\r")
sys.stdout.write(str(s)) sys.stdout.write(str(s))
sys.stdout.flush() sys.stdout.flush()
def nicestring(s): def nicestring(s):
''' Returns a nice version of a long string ''' ''' Returns a nice version of a long string '''
s = unicode(s, encoding = "utf8") s = unescape(s)
if len(s)<20: if len(s)<20:
return s return s
s=s.replace("_"," ") s=s.replace("_"," ")
@@ -425,6 +444,7 @@ def nicestring(s):
s=s[0:26]+".."+s[-3:] s=s[0:26]+".."+s[-3:]
return s return s
def sizestring(size): def sizestring(size):
''' Returns human readable file size string ''' ''' Returns human readable file size string '''
for x in ['b','kb','Mb','Gb','Tb']: for x in ['b','kb','Mb','Gb','Tb']:
@@ -436,6 +456,10 @@ def sizestring(size):
size /= 1024.0 size /= 1024.0
def unescape(s):
return HTMLParser().unescape(s)
def natural_sort_key(s, _nsre=re.compile('([0-9]+)')): def natural_sort_key(s, _nsre=re.compile('([0-9]+)')):
''' Natural sort / Claudiu@Stackoverflow ''' ''' Natural sort / Claudiu@Stackoverflow '''
return [int(text) if text.isdigit() else text.lower() return [int(text) if text.isdigit() else text.lower()
@@ -459,6 +483,7 @@ def which(program):
return None return None
def traverse(path,crumbs,inputs,options): def traverse(path,crumbs,inputs,options):
''' The recursive main function to create the index.html and seek sub folders ''' ''' The recursive main function to create the index.html and seek sub folders '''

View File

@@ -1,4 +1,4 @@
#!/usr/bin/env python #!/usr/bin/env python3
# #
# Copyright 2018 Ville Rantanen # Copyright 2018 Ville Rantanen
# #
@@ -18,10 +18,11 @@
import sys,os import sys,os
import re import re
import urllib import urllib
import urllib.parse
import csv import csv
import string import string
from datetime import datetime from datetime import datetime
from Qalbum import \ from qalbum.Qalbum import \
cleanthumbs, \ cleanthumbs, \
createthumbs, \ createthumbs, \
crumblinks, \ crumblinks, \
@@ -34,12 +35,13 @@ from Qalbum import \
nicestring, \ nicestring, \
readconfig, \ readconfig, \
sizestring, \ sizestring, \
unescape, \
which, \ which, \
writeconfig writeconfig
# (c) ville.q.rantanen@gmail.com # (c) ville.q.rantanen@gmail.com
__version__='0.20190411a' __version__='0.20200922'
imagesearch=re.compile('.*\.jpg$|.*\.jpeg$|.*\.gif$|.*\.png$|.*\.tif$|.*\.svg$|.*\.pdf$',re.I) imagesearch=re.compile('.*\.jpg$|.*\.jpeg$|.*\.gif$|.*\.png$|.*\.tif$|.*\.svg$|.*\.pdf$',re.I)
vectorsearch=re.compile('.*\.svg$|.*\.pdf$',re.I) vectorsearch=re.compile('.*\.svg$|.*\.pdf$',re.I)
@@ -53,9 +55,10 @@ FILECONFIG=".config"
FILEINFO="info.txt" FILEINFO="info.txt"
FILEDESC="descriptions.csv" FILEDESC="descriptions.csv"
def getheader(path,parent,title=""): def getheader(path,parent,title=""):
if title=="": if title=="":
title=unicode(os.path.basename(path),encoding="utf8").encode('ascii', 'xmlcharrefreplace') title=unescape(os.path.basename(path))
return '''<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> return '''<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html> <html>
<head> <head>
@@ -125,6 +128,8 @@ body {
</head> </head>
<body> <body>
''' '''
def getfooter(): def getfooter():
return ''' return '''
<div id="footer">Generated with Qnano2 '''+__version__+''' ('''+datetime.today().strftime("%y-%m-%d %H:%M")+''') <a href="https://bitbucket.org/MoonQ/qalbum" target="_TOP">Source</a></div> <div id="footer">Generated with Qnano2 '''+__version__+''' ('''+datetime.today().strftime("%y-%m-%d %H:%M")+''') <a href="https://bitbucket.org/MoonQ/qalbum" target="_TOP">Source</a></div>
@@ -132,6 +137,7 @@ def getfooter():
</HTML> </HTML>
''' '''
def imagelinks(path,list): def imagelinks(path,list):
''' Returns the HTML string of images ''' ''' Returns the HTML string of images '''
strout='''\n<div id="Qnano2-gallery" data-nanogallery2='{ strout='''\n<div id="Qnano2-gallery" data-nanogallery2='{
@@ -160,43 +166,45 @@ def imagelinks(path,list):
for n,i in enumerate(list): for n,i in enumerate(list):
nice=nicestring(i) nice=nicestring(i)
try: try:
desc=doublequotes.sub('',unicode(descriptions[n],encoding="utf8").encode('ascii', 'xmlcharrefreplace')) desc=doublequotes.sub('',unescape(descriptions[n]))
except: except:
desc=doublequotes.sub('',filter(lambda x: x in string.printable, descriptions[n]).encode('ascii', 'xmlcharrefreplace')) desc=doublequotes.sub('',unescape(filter(lambda x: x in string.printable, descriptions[n])))
strout += '<a href=".med/%s.jpg" data-ngthumb=".tn/%s.jpg" data-ngdownloadurl="%s">%s</a><br>\n'%( strout += '<a href=".med/%s.jpg" data-ngthumb=".tn/%s.jpg" data-ngdownloadurl="%s">%s</a><br>\n'%(
urllib.quote(i), urllib.parse.quote(i),
urllib.quote(i), urllib.parse.quote(i),
urllib.quote(i), urllib.parse.quote(i),
desc desc
) )
strout+='</div>' strout += '</div>'
return strout return strout
def pathlinks(path, list): def pathlinks(path, list):
''' Returns the HTML string of subfolders ''' ''' Returns the HTML string of subfolders '''
if len(list)==0: if len(list) == 0:
return '<div id="pathcontainer"></div>' return '<div id="pathcontainer"></div>'
pathstr='<div id="pathcontainer" class="collapsible"><h2>Folders</h2>' pathstr = '<div id="pathcontainer" class="collapsible"><h2>Folders</h2>'
for p in list: for p in list:
nice = nicestring(p) nice = nicestring(p)
imglist=getimagelist(os.path.join(path,p)) imglist = getimagelist(os.path.join(path,p))
nsum=str(len(imglist)) nsum = str(len(imglist))
imgstr="" imgstr = ""
#~ if len(imglist)>0: #~ if len(imglist)>0:
#~ imgstr='<span class="pathbox" style="background-image:url(\''+urllib.quote(p)+'/.tn/'+urllib.quote(imglist[0])+'.jpg\');">' #~ imgstr='<span class="pathbox" style="background-image:url(\''+urllib.quote(p)+'/.tn/'+urllib.quote(imglist[0])+'.jpg\');">'
#~ else: #~ else:
imgstr='<span class="pathbox">' imgstr = '<span class="pathbox">'
pathstr += '<div><li><a title="%s" href="%s/index.html">%s<span class="pathlink"><span class="pathlinktext">%s (%s)</span></span></span></a></div>'%( pathstr += '<div><li><a title="%s" href="%s/index.html">%s<span class="pathlink"><span class="pathlinktext">%s (%s)</span></span></span></a></div>'%(
unicode(p,encoding="utf8").encode('ascii', 'xmlcharrefreplace'), unescape(p),
urllib.quote(p), urllib.parse.quote(p),
imgstr, imgstr,
nice.encode('ascii', 'xmlcharrefreplace'), nice,
nsum nsum
) )
pathstr+='</div>' pathstr += '</div>'
return pathstr return pathstr
def filelinks(path, list): def filelinks(path, list):
''' Returns the HTML string of non image files ''' ''' Returns the HTML string of non image files '''
if len(list) == 0: if len(list) == 0:
@@ -204,11 +212,12 @@ def filelinks(path, list):
strout = '<div id="attachmentcontainer" class="collapsible" style="height:28; overflow:hidden;">' strout = '<div id="attachmentcontainer" class="collapsible" style="height:28; overflow:hidden;">'
strout += '<h2>Attachments</h1>' strout += '<h2>Attachments</h1>'
for i in list: for i in list:
size=sizestring(os.path.getsize(os.path.join(path,i))) size = sizestring(os.path.getsize(os.path.join(path,i)))
strout+='<div class="attachmentbox"><li><a href="'+urllib.quote(i)+'">'+unicode(i,encoding="utf8").encode('ascii', 'xmlcharrefreplace')+' ['+size+']</a></div>' strout += '<div class="attachmentbox"><li><a href="'+urllib.parse.quote(i)+'">' + unescape(i) +' ['+size+']</a></div>'
strout+='</div>' strout += '</div>'
return strout return strout
def traverse(path,crumbs,inputs,options): def traverse(path,crumbs,inputs,options):
''' The recursive main function to create the index.html and seek sub folders ''' ''' The recursive main function to create the index.html and seek sub folders '''
@@ -253,6 +262,7 @@ def traverse(path,crumbs,inputs,options):
traverse(os.path.join(path,p),nextcrumbs,inputs,options) traverse(os.path.join(path,p),nextcrumbs,inputs,options)
return return
def setupoptions(): def setupoptions():
''' Setup the command line options ''' ''' Setup the command line options '''
from argparse import ArgumentParser from argparse import ArgumentParser
@@ -327,6 +337,7 @@ def setupdefaultoptions(options):
options.width=850 options.width=850
return options return options
def execute_plain(): def execute_plain():
''' Main execution function ''' ''' Main execution function '''
options=setupoptions() options=setupoptions()

View File

@@ -1 +1 @@
from Qalbum import * from qalbum.Qalbum import *

View File

@@ -1,4 +1,4 @@
#!/usr/bin/python #!/usr/bin/env python3
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
import re import re

View File

@@ -1,4 +1,4 @@
#!/usr/bin/env python #!/usr/bin/env python3
# #
# Copyright 2016 Ville Rantanen # Copyright 2016 Ville Rantanen
# #
@@ -39,13 +39,14 @@ def createdesc(path,list,options):
nsum=len(list) nsum=len(list)
for i in list: for i in list:
inpath=os.path.join(path,i) inpath=os.path.join(path,i)
desc=create_description(inpath,options.format).rstrip().replace('\n','<br/>') desc = create_description(inpath,options.format).decode('utf-8').rstrip().replace('\n','<br/>')
outfile.write(i+"\t"+desc+'\n') outfile.write(i+"\t"+desc+'\n')
outfile.flush() outfile.flush()
print('('+str(n)+'/'+str(nsum)+') '+i+"\t"+desc) print('('+str(n)+'/'+str(nsum)+') '+i+"\t"+desc)
n+=1 n+=1
return return
def create_description(infile,format): def create_description(infile,format):
if format=='AbsolutelyEverything': if format=='AbsolutelyEverything':
idargs=['identify','-verbose',infile+'[0]'] idargs=['identify','-verbose',infile+'[0]']
@@ -55,6 +56,7 @@ def create_description(infile,format):
output = idp.stdout.read() output = idp.stdout.read()
return output return output
def traverse(path,options): def traverse(path,options):
''' The recursive main function to create the thumbs and seek sub folders ''' ''' The recursive main function to create the thumbs and seek sub folders '''
print(path) print(path)
@@ -68,6 +70,7 @@ def traverse(path,options):
traverse(os.path.join(path,p),options) traverse(os.path.join(path,p),options)
return return
def execute(): def execute():
''' Main execution ''' ''' Main execution '''
parser=ArgumentParser() parser=ArgumentParser()
@@ -92,10 +95,10 @@ def execute():
'%f: %wx%h %[size]', '%f: %wx%h %[size]',
'%f<br/><i>%[EXIF:DateTimeOriginal] %[EXIF:ExposureTime]s F%[EXIF:FNumber]</i>', '%f<br/><i>%[EXIF:DateTimeOriginal] %[EXIF:ExposureTime]s F%[EXIF:FNumber]</i>',
'AbsolutelyEverything'] 'AbsolutelyEverything']
if options.preset<1: if options.preset < 1:
print "Presets:" print("Presets:")
for row in range(len(presets)): for row in range(len(presets)):
print row+1," ",presets[row] print(row+1," ",presets[row])
sys.exit(0) sys.exit(0)
if options.format=="": if options.format=="":
if options.preset>len(presets): if options.preset>len(presets):

View File

@@ -1,4 +1,4 @@
#!/usr/bin/env python #!/usr/bin/env python3
# #
# Copyright 2016 Ville Rantanen # Copyright 2016 Ville Rantanen
# #
@@ -37,6 +37,7 @@ def traverse(path,options):
traverse(os.path.join(path,p),options) traverse(os.path.join(path,p),options)
return return
def setupoptions(): def setupoptions():
''' Setup options ''' ''' Setup options '''
usage='''Usage: %(prog)s [options] folder usage='''Usage: %(prog)s [options] folder
@@ -62,12 +63,14 @@ folder is the root folder of the image album (defaults to current folder).'''
options=Qalbum.setupdefaultoptions(options) options=Qalbum.setupdefaultoptions(options)
return options return options
def execute(): def execute():
''' Main execution ''' ''' Main execution '''
options=setupoptions() options=setupoptions()
traverse(options.startpath,options) traverse(options.startpath,options)
return return
if __name__ == "__main__": if __name__ == "__main__":
execute() execute()

View File

@@ -1,4 +1,4 @@
#!/usr/bin/python #!/usr/bin/env python3
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
import re import re

View File

@@ -8,12 +8,12 @@ setup(
'scripts/Qalbum-descriptor'], 'scripts/Qalbum-descriptor'],
package_data={'':['lib/*']}, package_data={'':['lib/*']},
include_package_data=True, include_package_data=True,
version = '2.20190411a', version = '2.20200922',
description = 'A tool to create a web gallery from a folder structure of images / other files.', description = 'A tool to create a web gallery from a folder structure of images / other files.',
author = 'Ville Rantanen', author = 'Ville Rantanen',
author_email = 'ville.q.rantanen@gmail.com', author_email = 'ville.q.rantanen@gmail.com',
url = 'https://bitbucket.org/MoonQ/qalbum', url = 'https://bitbucket.org/MoonQ/qalbum',
download_url = 'https://bitbucket.org/MoonQ/qalbum/get/tip.tar.gz', download_url = 'https://bitbucket.org/MoonQ/qalbum/get/master.tar.gz',
keywords = ['album', 'generator', 'javascript'], keywords = ['album', 'generator', 'javascript'],
classifiers = [], classifiers = [],
license = 'MIT', license = 'MIT',