#!/usr/bin/env python2 """ Blog image uploader ./do.py -p test/ -u *.JPG -p set path, don't forget trailing slash -u no upload (optional) """ import sys import getopt import os files = sys.argv[1:] path = None upload = 1 output = '' try: opts, args = getopt.getopt(sys.argv[1:], "up:", ["noupload", "path="]) except getopt.GetoptError: # print help information and exit: print __doc__ sys.exit(2) for o, a in opts: if o in ("-u", "--noupload"): upload = 0 if o in ("-p", "--path"): path = a files = args if not path or not args: print __doc__ sys.exit(2) print "Number of files: %d" % len(files) if upload: os.system('ssh melkinpaasi mkdir /home/fs/hendry/public_html/pictures/' + path) for file in files: print "Dealing with: %s" % file os.system('/usr/bin/feh -g 640x480 ' + file) description = raw_input("Description: ") url = '!_http://www.cs.helsinki.fi/u/hendry/pictures/' + path + file + '(' + description + ')!\n' if upload: os.system('/usr/bin/scp ' + file + ' melkinpaasi:public_html/pictures/' + path + ' 2>&1 &') output += url if upload: os.system('ssh melkinpaasi /bin/chmod -R a+rx /home/fs/hendry/public_html/pictures/' + path) print print output print