Browse Source

change command line args

pull/9/merge
Simon 15 years ago
parent
commit
a314a815f6
  1. 24
      pywiUpload.py
  2. 1
      pywiupload/ftp.py
  3. 17
      pywiupload/image.py
  4. 3
      runtests.py

24
pywiUpload.py

@ -59,7 +59,7 @@ def main():
"main program"
# command line options
usage = "usage: %prog [options]"
usage = "usage: %prog [options] inputdir outputdir"
version = "version %s, %s" % (__version__, __date__)
parser = OptionParser(usage=usage, version="%prog "+version)
@ -67,11 +67,23 @@ def main():
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()
if len(args) != 2:
parser.print_help()
sys.exit()
input_dir = args[0]
output_dir = args[1]
if not os.path.isdir(input_dir):
print "Directory %s does not exist." % input_dir
sys.exit(1)
if not os.path.isdir(output_dir):
print "Create %s" % output_dir
os.makedirs(output_dir)
# read params from config file
config_file = options.config if options.config \
else os.path.join(sys.path[0], 'pywiUpload.conf')
@ -81,9 +93,7 @@ def main():
# create gallery
gallery = Gallery(params)
path = options.imgpath if options.imgpath else os.getcwd()
(galleryname, out_filelist) = gallery.create_gallery(path)
out_filelist = gallery.create_gallery(input_dir, output_dir)
# upload
if raw_input("Upload images to your FTP server ? (y/[n]) ") == 'y':

1
pywiupload/ftp.py

@ -36,6 +36,7 @@ class FtpUpload:
self.ftp = ftplib.FTP(host, user, password)
self.ftp.cwd(basedir)
# FIXME: galname
def upload(self, imgfilelist, galname, thumb_dir, bigimg_dir=None):
"Upload images to a FTP server"

17
pywiupload/image.py

@ -34,7 +34,6 @@ class Gallery:
def __init__(self, params):
self.filepath = ""
self.galname = ""
self.params = params
def getpath(self, pathname):
@ -42,18 +41,14 @@ class Gallery:
return os.path.join(self.filepath, self.params[pathname]) \
if self.params.has_key(pathname) else ""
def create_gallery(self, path):
def create_gallery(self, input_dir, output_dir):
"create image gallery"
imglist = get_filelist(path, self.params['fileExtList'])
print "Found %i images in %s" % (len(imglist), path)
imglist = get_filelist(input_dir, self.params['fileExtList'])
print "Found %i images in %s" % (len(imglist), input_dir)
while self.galname == "":
self.galname = raw_input('Enter gallery name: ')
self.filepath = output_dir
self.filepath = os.path.join(os.path.dirname(imglist[0]),
self.galname)
print "Create output dir ..."
print "Create output directories ..."
try:
os.makedirs(self.getpath('thumb_dir'))
except OSError:
@ -65,7 +60,7 @@ class Gallery:
except OSError:
pass
return (self.galname, self.process_images(imglist))
return self.process_images(imglist)
def process_images(self, imglist):
"prepare images"

3
runtests.py

@ -41,9 +41,8 @@ if __name__ == '__main__':
# create gallery
gallery = Gallery(params)
(galleryname, filelist) = gallery.create_gallery("./test")
filelist = gallery.create_gallery("./test", "./test/output")
print "\n:: Output for gallery %s" % galleryname
print "images : %s" % filelist[0]
print "thumbnails : %s" % filelist[1]
print "big images : %s" % filelist[2]

Loading…
Cancel
Save