yet another simple static gallery generator
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

104 lines
3.3 KiB

#! /usr/bin/env python2
# -*- coding:utf-8 -*-
# pywiUpload - Piwigo gallery generator
# Copyright (C) 2009-2011 - saimon.org
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 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 General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; If not, see http://www.gnu.org/licenses/
"""Prepare and upload a gallery of images for Piwigo
This script resize images, create thumbnails with some options
(rename images, squared thumbs, ...), and upload images to a FTP server.
"""
__author__ = "Saimon (contact at saimon dot org)"
__version__ = "0.8"
__date__ = "20100722"
__copyright__ = "Copyright (C) 2009 - saimon.org"
__license__ = "GPL"
import os
import sys
from configobj import ConfigObj
from optparse import OptionParser
from pywiupload.ftp import FtpUpload
from pywiupload.image import Gallery
def read_params(config_file):
"Read params from a config file"
params = ConfigObj(config_file,file_error=True)
# convert types
params["im_width"] = int(params["im_width"])
params["im_height"] = int(params["im_height"])
params["thumb_width"] = int(params["thumb_width"])
params["thumb_height"] = int(params["thumb_height"])
params["bigimg"] = int(params["bigimg"])
params["squarethumb"] = int(params["squarethumb"])
params["jpgquality"] = int(params["jpgquality"])
params["exif"] = int(params["exif"])
params["copyright"] = int(params["copyright"])
return params
def main():
"main program"
# command line options
usage = "usage: %prog [options]"
version = "version %s, %s" % (__version__, __date__)
parser = OptionParser(usage=usage, version="%prog "+version)
parser.add_option("-c", "--config", dest="config",
help="specify an alternative config file")
parser.add_option("-i", "--imgpath", dest="imgpath",
help="specify images path")
(options, args) = parser.parse_args()
# read params from config file
config_file = options.config if options.config \
else os.path.join(sys.path[0], 'pywiUpload.conf')
print "Reading parameters ..."
params = read_params(config_file)
# create gallery
gallery = Gallery(params)
path = options.imgpath if options.imgpath else os.getcwd()
(galleryname, out_filelist) = gallery.create_gallery(path)
# upload
if raw_input("Upload images to your FTP server ? (y/[n]) ") == 'y':
ftp = FtpUpload(params["host"], params["user"], \
params["piwigo_dir"] + '/galleries')
if params["bigimg"]:
ftp.upload(out_filelist, galleryname, params["thumb_dir"],
params["bigimg_dir"])
else:
ftp.upload(out_filelist, galleryname, params["thumb_dir"])
ftp.close()
return 0
if __name__ == '__main__':
status = main()
sys.exit(status)