Qnano2 executable to create nanogallery2 albums
This commit is contained in:
@@ -14,7 +14,11 @@ ex.
|
|||||||
|
|
||||||
`pip install --user --upgrade https://bitbucket.org/MoonQ/qalbum/get/tip.tar.gz`
|
`pip install --user --upgrade https://bitbucket.org/MoonQ/qalbum/get/tip.tar.gz`
|
||||||
|
|
||||||
|
## Usage
|
||||||
|
|
||||||
|
Use the command line tool `Qalbum` to render web sites.
|
||||||
|
|
||||||
|
Alternatively, use `Qnano2` to create a site powered with [nanogallery2](https://nanogallery2.nanostudio.org/).
|
||||||
|
|
||||||
----
|
----
|
||||||
The development of this software has received funding from the European Community's Seventh Framework Programme FP7/2007-2011 under grant agreement no. 201837.
|
The development of this software has received funding from the European Community's Seventh Framework Programme FP7/2007-2011 under grant agreement no. 201837.
|
||||||
|
|||||||
@@ -27,9 +27,9 @@ from datetime import datetime
|
|||||||
|
|
||||||
# (c) ville.q.rantanen@gmail.com
|
# (c) ville.q.rantanen@gmail.com
|
||||||
|
|
||||||
__version__='2.20180731'
|
__version__='2.20180827'
|
||||||
|
|
||||||
FILECONFIG=".config"
|
FILECONFIG=".qalbum.config"
|
||||||
FILEDESC="descriptions.csv"
|
FILEDESC="descriptions.csv"
|
||||||
FILEINFO="info.txt"
|
FILEINFO="info.txt"
|
||||||
SAVEDCONFIG="""attachments=boolean
|
SAVEDCONFIG="""attachments=boolean
|
||||||
|
|||||||
339
qalbum/Qnano2.py
Executable file
339
qalbum/Qnano2.py
Executable file
@@ -0,0 +1,339 @@
|
|||||||
|
#!/usr/bin/env python
|
||||||
|
#
|
||||||
|
# Copyright 2018 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 <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
import sys,os
|
||||||
|
import re
|
||||||
|
import urllib
|
||||||
|
import csv
|
||||||
|
import string
|
||||||
|
from datetime import datetime
|
||||||
|
from Qalbum import \
|
||||||
|
cleanthumbs, \
|
||||||
|
createthumbs, \
|
||||||
|
crumblinks, \
|
||||||
|
getdescriptions, \
|
||||||
|
getimagelist, \
|
||||||
|
getinfo, \
|
||||||
|
getnonconvertiblelist, \
|
||||||
|
getnonimagelist, \
|
||||||
|
getpathlist, \
|
||||||
|
nicestring, \
|
||||||
|
readconfig, \
|
||||||
|
sizestring, \
|
||||||
|
which, \
|
||||||
|
writeconfig
|
||||||
|
|
||||||
|
# (c) ville.q.rantanen@gmail.com
|
||||||
|
|
||||||
|
__version__='0.20180827'
|
||||||
|
|
||||||
|
imagesearch=re.compile('.*\.jpg$|.*\.jpeg$|.*\.gif$|.*\.png$|.*\.tif$|.*\.svg$|.*\.pdf$',re.I)
|
||||||
|
vectorsearch=re.compile('.*\.svg$|.*\.pdf$',re.I)
|
||||||
|
nonconvertiblesearch=re.compile('.*\.html$|.*\.htm$|.*\.php$',re.I)
|
||||||
|
#gifsearch=re.compile('.*gif$',re.I)
|
||||||
|
excludepaths=re.compile('.med|.tn|\..*')
|
||||||
|
doublequotes=re.compile('"')
|
||||||
|
singlequotes=re.compile("'")
|
||||||
|
stripquotes=re.compile('^"|"$')
|
||||||
|
FILECONFIG=".qalbum.config"
|
||||||
|
FILEINFO="info.txt"
|
||||||
|
FILEDESC="descriptions.csv"
|
||||||
|
|
||||||
|
def getheader(path,parent,title=""):
|
||||||
|
if title=="":
|
||||||
|
title=unicode(os.path.basename(path),encoding="utf8").encode('ascii', 'xmlcharrefreplace')
|
||||||
|
return '''<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<meta name="generator" content="Qalbum '''+__version__+'''">
|
||||||
|
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
|
||||||
|
<meta name="viewport" content="user-scalable=no, width=device-width, initial-scale=1, maximum-scale=1">
|
||||||
|
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
|
||||||
|
<link href="https://unpkg.com/nanogallery2@2.2.0/dist/css/nanogallery2.min.css" rel="stylesheet" type="text/css">
|
||||||
|
<script type="text/javascript" src="https://unpkg.com/nanogallery2@2.2.0/dist/jquery.nanogallery2.min.js"></script>
|
||||||
|
<TITLE>'''+title+'''</TITLE>
|
||||||
|
<script type="text/javascript">
|
||||||
|
$( document ).ready(function() {
|
||||||
|
$('.collapsible').each(function(i, obj) {
|
||||||
|
$(obj).children('h2').each(function () {
|
||||||
|
console.log(obj.id); // "this" is the current element in the loop
|
||||||
|
$(this).click(function(element) {
|
||||||
|
if ($(obj).height() == 28) {
|
||||||
|
$(obj).height('inherit');
|
||||||
|
$(obj).css('overflow','visible');
|
||||||
|
} else {
|
||||||
|
$(obj).height(28);
|
||||||
|
$(obj).css('overflow','hidden');
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
<style>
|
||||||
|
body {
|
||||||
|
margin: 5px;
|
||||||
|
}
|
||||||
|
#crumbcontainer {
|
||||||
|
font-size: small;
|
||||||
|
color: gray;
|
||||||
|
}
|
||||||
|
#crumbcontainer a {
|
||||||
|
color: gray;
|
||||||
|
}
|
||||||
|
.collapsible {
|
||||||
|
margin: 0px 10px 0px 0px;
|
||||||
|
padding: 0px 0px 0px 1em;
|
||||||
|
font-size: small;
|
||||||
|
border: 1px solid gray;
|
||||||
|
line-height: 2em;
|
||||||
|
}
|
||||||
|
.collapsible a {
|
||||||
|
color: black;
|
||||||
|
}
|
||||||
|
.collapsible h2 {
|
||||||
|
cursor: pointer;
|
||||||
|
margin-top: 0;
|
||||||
|
font-size: small;
|
||||||
|
color: gray;
|
||||||
|
}
|
||||||
|
.collapsible h2:hover {
|
||||||
|
text-decoration: underline;
|
||||||
|
}
|
||||||
|
#footer {
|
||||||
|
font-size: x-small;
|
||||||
|
color: gray;
|
||||||
|
}
|
||||||
|
#footer a {
|
||||||
|
color: gray;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
'''
|
||||||
|
def getfooter():
|
||||||
|
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>
|
||||||
|
</BODY>
|
||||||
|
</HTML>
|
||||||
|
'''
|
||||||
|
|
||||||
|
def imagelinks(path,list):
|
||||||
|
''' Returns the HTML string of images '''
|
||||||
|
strout='''\n<div id="Qnano2-gallery" data-nanogallery2='{
|
||||||
|
"thumbnailHeight": 90,
|
||||||
|
"thumbnailWidth": 90,
|
||||||
|
"itemsBaseURL": "",
|
||||||
|
"thumbnailDisplayOutsideScreen": false,
|
||||||
|
"thumbnailLabel": {
|
||||||
|
"position": "onBottom",
|
||||||
|
"hideIcons": true,
|
||||||
|
"titleFontSize": "0.8em"
|
||||||
|
}
|
||||||
|
}'>
|
||||||
|
'''
|
||||||
|
descriptions=getdescriptions(path,list)
|
||||||
|
for n,i in enumerate(list):
|
||||||
|
nice=nicestring(i)
|
||||||
|
try:
|
||||||
|
desc=doublequotes.sub('',unicode(descriptions[n],encoding="utf8").encode('ascii', 'xmlcharrefreplace'))
|
||||||
|
except:
|
||||||
|
desc=doublequotes.sub('',filter(lambda x: x in string.printable, descriptions[n]).encode('ascii', 'xmlcharrefreplace'))
|
||||||
|
|
||||||
|
strout += '<a href=".med/%s.jpg" data-ngthumb=".tn/%s.jpg" data-ngdownloadurl="%s">%s</a><br>\n'%(
|
||||||
|
urllib.quote(i),
|
||||||
|
urllib.quote(i),
|
||||||
|
nice.encode('ascii', 'xmlcharrefreplace'),
|
||||||
|
desc
|
||||||
|
)
|
||||||
|
strout+='</div>'
|
||||||
|
return strout
|
||||||
|
|
||||||
|
def pathlinks(path, list):
|
||||||
|
''' Returns the HTML string of subfolders '''
|
||||||
|
if len(list)==0:
|
||||||
|
return '<div id="pathcontainer"></div>'
|
||||||
|
pathstr='<div id="pathcontainer" class="collapsible"><h2>Folders</h2>'
|
||||||
|
for p in list:
|
||||||
|
nice = nicestring(p)
|
||||||
|
imglist=getimagelist(os.path.join(path,p))
|
||||||
|
nsum=str(len(imglist))
|
||||||
|
imgstr=""
|
||||||
|
#~ if len(imglist)>0:
|
||||||
|
#~ imgstr='<span class="pathbox" style="background-image:url(\''+urllib.quote(p)+'/.tn/'+urllib.quote(imglist[0])+'.jpg\');">'
|
||||||
|
#~ else:
|
||||||
|
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>'%(
|
||||||
|
unicode(p,encoding="utf8").encode('ascii', 'xmlcharrefreplace'),
|
||||||
|
urllib.quote(p),
|
||||||
|
imgstr,
|
||||||
|
nice.encode('ascii', 'xmlcharrefreplace'),
|
||||||
|
nsum
|
||||||
|
)
|
||||||
|
pathstr+='</div>'
|
||||||
|
return pathstr
|
||||||
|
|
||||||
|
def filelinks(path, list):
|
||||||
|
''' Returns the HTML string of non image files '''
|
||||||
|
if len(list) == 0:
|
||||||
|
return '<div id="attachmentcontainer"></div>'
|
||||||
|
strout = '<div id="attachmentcontainer" class="collapsible" style="height:28; overflow:hidden;">'
|
||||||
|
strout += '<h2>Attachments</h1>'
|
||||||
|
for i in list:
|
||||||
|
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>'
|
||||||
|
return strout
|
||||||
|
|
||||||
|
def traverse(path,crumbs,inputs,options):
|
||||||
|
''' The recursive main function to create the index.html and seek sub folders '''
|
||||||
|
|
||||||
|
print(path)
|
||||||
|
if (not options.recurselink) and (os.path.islink(path)):
|
||||||
|
print('Not recursing, is a link')
|
||||||
|
return
|
||||||
|
if len(crumbs)==1:
|
||||||
|
header = getheader(path,'../'*(len(crumbs)-1),inputs[0][1])
|
||||||
|
else:
|
||||||
|
header = getheader(path,'../'*(len(crumbs)-1))
|
||||||
|
|
||||||
|
pathlist = getpathlist(path, options)
|
||||||
|
imagelist = getimagelist(path, options)
|
||||||
|
if options.clean:
|
||||||
|
cleanthumbs(path)
|
||||||
|
if options.thumbs:
|
||||||
|
createthumbs(path, imagelist,options)
|
||||||
|
imagelist.extend(getnonconvertiblelist(path, options))
|
||||||
|
filelist = getnonimagelist(path, options)
|
||||||
|
print(str(len(pathlist))+' paths, '+str(len(imagelist))+' images, '+str(len(filelist))+' other files')
|
||||||
|
crumbstring=crumblinks(crumbs,options.gallery,options.parent)
|
||||||
|
pathstring=pathlinks(path, pathlist)
|
||||||
|
filestring=filelinks(path, filelist)
|
||||||
|
#filejs=filescript(path,filelist) # Filelist is not currently used in javascript
|
||||||
|
imagestring=imagelinks(path,imagelist)
|
||||||
|
#imagejs=imagescript(path,imagelist)
|
||||||
|
|
||||||
|
f=open(os.path.join(path,"index.html"),"w")
|
||||||
|
f.write(header)
|
||||||
|
f.write(crumbstring)
|
||||||
|
f.write(pathstring)
|
||||||
|
f.write('<div id="infocontainer">'+getinfo(path,options)+'</div>')
|
||||||
|
f.write(filestring)
|
||||||
|
f.write(imagestring)
|
||||||
|
f.write(getfooter())
|
||||||
|
f.close()
|
||||||
|
|
||||||
|
for p in pathlist:
|
||||||
|
nextcrumbs=[i for i in crumbs]
|
||||||
|
nextcrumbs.append(os.path.join(path,p))
|
||||||
|
traverse(os.path.join(path,p),nextcrumbs,inputs,options)
|
||||||
|
return
|
||||||
|
|
||||||
|
def setupoptions():
|
||||||
|
''' Setup the command line options '''
|
||||||
|
from argparse import ArgumentParser
|
||||||
|
parser=ArgumentParser()
|
||||||
|
parser.add_argument("-v",action='version', version=__version__)
|
||||||
|
parser.add_argument("--version",action='version', version=__version__)
|
||||||
|
parser.add_argument("-c",action="store_true",dest="writeconfig",default=False,
|
||||||
|
help="Write current configuration to file "+FILECONFIG+
|
||||||
|
" and exit. If file exists, settings read from the file, "+
|
||||||
|
"overriding switches.")
|
||||||
|
parser.add_argument("-r",action="store_true",dest="reverse",default=False,
|
||||||
|
help="Reverse sort orded")
|
||||||
|
parser.add_argument("-L",action="store_false",dest="recurselink",default=True,
|
||||||
|
help="List, but do not recurse in to symbolic link folders")
|
||||||
|
parser.add_argument("-s",type=str,dest="style",
|
||||||
|
help="User defined CSS style file.")
|
||||||
|
parser.add_argument("-t",action="store_true",dest="timesort",default=False,
|
||||||
|
help="Sort by file modification time")
|
||||||
|
parser.add_argument("-a",action="store_false",dest="attachments",default=True,
|
||||||
|
help="Disable attachments")
|
||||||
|
parser.add_argument("-i",type=str,dest="infofile",default=FILEINFO,
|
||||||
|
help="File name for info files in all folders. (Default: %(default)s)")
|
||||||
|
parser.add_argument("-g",type=str,dest="gallery",default="Gallery",
|
||||||
|
help="Name for the root gallery (Default: %(default)s)")
|
||||||
|
parser.add_argument("--gravity",type=str,dest="gravity",default="Center",
|
||||||
|
help="ImageMagick gravity for cropping. (Default: %(default)s)")
|
||||||
|
parser.add_argument("-w", type = int, dest = "width",default = 1280,
|
||||||
|
help = "Medium image size (Default: %(default)s)")
|
||||||
|
parser.add_argument("--no-thumbs",action="store_false",dest="thumbs",default=True,
|
||||||
|
help="Disable thumbnail and medium generation. Build the indexes only.")
|
||||||
|
parser.add_argument("-p", type = str, dest = "parent",
|
||||||
|
help="Add a ../[PARENT] link to point out from the gallery. If the string starts with http:// it is considered as a static URL, otherwise the relative parent path is assumed.")
|
||||||
|
parser.add_argument("startpath", type = str, action = "store", default=os.path.abspath('.'), nargs='?',
|
||||||
|
help="Root path of the gallery")
|
||||||
|
options=parser.parse_args()
|
||||||
|
options.startpath=os.path.abspath(options.startpath)
|
||||||
|
options=setupdefaultoptions(options)
|
||||||
|
return options
|
||||||
|
|
||||||
|
def setupdefaultoptions(options):
|
||||||
|
''' Adds the missing options for the options object '''
|
||||||
|
if not which('convert'):
|
||||||
|
print('You don\'t seem to have ImageMagick "convert" in PATH!')
|
||||||
|
sys.exit(1)
|
||||||
|
if 'attachments' not in options:
|
||||||
|
options.attachments=True
|
||||||
|
if 'clean' not in options:
|
||||||
|
options.clean=False
|
||||||
|
if 'force' not in options:
|
||||||
|
options.force=False
|
||||||
|
if 'infofile' not in options:
|
||||||
|
options.infofile=FILEINFO
|
||||||
|
if 'gallery' not in options:
|
||||||
|
options.gallery="Gallery"
|
||||||
|
if 'gravity' not in options:
|
||||||
|
options.gravity="Center"
|
||||||
|
if 'link' not in options:
|
||||||
|
options.link=False
|
||||||
|
if 'recursive' not in options:
|
||||||
|
options.recursive=True
|
||||||
|
if 'recurselink' not in options:
|
||||||
|
options.recurselink=True
|
||||||
|
if 'reverse' not in options:
|
||||||
|
options.reverse=False
|
||||||
|
if 'style' not in options:
|
||||||
|
options.style = None
|
||||||
|
if 'timesort' not in options:
|
||||||
|
options.timesort=False
|
||||||
|
if 'thumbs' not in options:
|
||||||
|
options.thumbs=True
|
||||||
|
if 'width' not in options:
|
||||||
|
options.width=850
|
||||||
|
return options
|
||||||
|
|
||||||
|
def execute_plain():
|
||||||
|
''' Main execution function '''
|
||||||
|
options=setupoptions()
|
||||||
|
options=readconfig(options)
|
||||||
|
options=setupdefaultoptions(options)
|
||||||
|
if options.writeconfig:
|
||||||
|
writeconfig(options)
|
||||||
|
sys.exit(0)
|
||||||
|
# Copy all resources to target folder
|
||||||
|
pathname=os.path.dirname(__file__)
|
||||||
|
fullpath=os.path.abspath(pathname)
|
||||||
|
inputs=[]
|
||||||
|
inputs.append((None,options.gallery,None))
|
||||||
|
|
||||||
|
traverse(options.startpath,[options.startpath],inputs,options)
|
||||||
|
return
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
execute_plain()
|
||||||
11
scripts/Qnano2
Executable file
11
scripts/Qnano2
Executable file
@@ -0,0 +1,11 @@
|
|||||||
|
#!/usr/bin/python
|
||||||
|
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
import re
|
||||||
|
import sys
|
||||||
|
|
||||||
|
from qalbum.Qnano2 import execute_plain
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
#sys.argv[0] = re.sub(r'(-script\.pyw|\.exe)?$', '', sys.argv[0])
|
||||||
|
sys.exit(execute_plain())
|
||||||
3
setup.py
3
setup.py
@@ -4,10 +4,11 @@ setup(
|
|||||||
packages = ['qalbum'],
|
packages = ['qalbum'],
|
||||||
scripts = ['scripts/Qalbum',
|
scripts = ['scripts/Qalbum',
|
||||||
'scripts/Qalbum-thumbnailer',
|
'scripts/Qalbum-thumbnailer',
|
||||||
|
'scripts/Qnano2',
|
||||||
'scripts/Qalbum-descriptor'],
|
'scripts/Qalbum-descriptor'],
|
||||||
package_data={'':['lib/*']},
|
package_data={'':['lib/*']},
|
||||||
include_package_data=True,
|
include_package_data=True,
|
||||||
version = '2.20180731',
|
version = '2.20180827',
|
||||||
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',
|
||||||
|
|||||||
Reference in New Issue
Block a user