Permalink
Switch branches/tags
Nothing to show
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
executable file 48 lines (37 sloc) 1.16 KB
#!/usr/bin/python
"""Part of my photo revising suite of tools, including choose.sh and rename.sh.
Handles POSTs from the local HTML page generated by rename.sh for choosing which
pictures I want to keep.
There are two query parameters. dir is the fully qualified directory that
contains the pictures. keep is one or more picture filenames. This script makes
a no/ subdirectory and moves all the files there except the 'keep' ones.
"""
__author__ = ['Ryan Barrett <public@ryanb.org>']
import cgi
import cgitb
import errno
import glob
import os
import shutil
import stat
cgitb.enable()
form = cgi.FieldStorage()
dir = form.getfirst('dir')
no_subdir = os.path.join(dir, 'no')
try:
os.mkdir(no_subdir)
except OSError, e:
if e.errno != errno.EEXIST:
raise
os.chmod(no_subdir, stat.S_IRWXU | stat.S_IRWXG | stat.S_IRWXO)
to_keep = form.getlist('keep')
all_files = glob.glob(os.path.join(dir, '*.*'))
for f in all_files:
if os.path.isfile(f):
shutil.move(f, no_subdir)
print 'Content-Type: text/html'
print
print 'Keeping %d out of %d files in %s.' % (len(to_keep), len(all_files), dir)
for f in to_keep:
print '<br />' + f
shutil.move(os.path.join(no_subdir, f), dir)