#! /bin/env python # # this very simple python script copies new files from the Nikon camera # and keeps a counter of the last ones you've copied. No more cut and # paste, no more cp command, no more nothing. Just issue the command, # no arguments needed. # # There are quite a few assumptions though: # # Base directory where the camera will mount its filesystem (base=) # JPG files of the DSC_nnnn pattern (jpg=) # # Todo: check for the RAW (NEF) files as well as combined JPG/NEF files # check for NDF (Nikon Dust Off) images # # History: 22-oct-2006 Created Peter Teuben # 23-oct-2006 Loop over root,base,ext PJT # 27-oct-2006 uppercase and lower case # 20-nov-2006 added slop (reina mode) # # $Id: get-nikon,v 1.3 2007/03/26 23:22:07 teuben Exp $ import os,sys root1 = '/media' #root2 = '/LEXAR MEDIA/' #root2 = '/NIKON D80' root2 = '/NIKON D80-1' #root2 = '/NIKON D70S-1' root3 = '/DCIM' #root4 = '/101ND70S' #root4 = '/100ND70S' root4 = '/100NCD80' root4 = '/101NCD80' #root = ['/media/LEXAR MEDIA/DCIM/101ND70S/'] #root = ['/media/LEXAR MEDIA/DCIM/101ND70S/'] #root = ['/media/LEXAR MEDIA/dcim/101nd70s/'] #root = ['/home/data/pics/2006/10/22'] root = [root1 + root2 + root3 + root4] base = ['DSC_', '_DSC'] ext = ['JPG', 'NEF', 'NDF'] fmt = '%04d' slop = 20 counter_file = os.environ['HOME'] + '/.nikon' def find_num(num): files=[] for r in root: for b in base: for e in ext: template = "%s/%s%s.%s" % (r,b,fmt,e) file = template % num if os.path.exists(file): files.append(file) return files def get_last(): if os.path.exists(counter_file): f = open(counter_file,"r"); l = f.readline() last = int(l) else: print "No file %s; starting at 0" % counter_file print "Or issue the command (for example):" print " echo 1433 > %s" % counter_file last = 0 return last def put_last(last): f = open(counter_file,"w"); f.write("%d\n" % last) f.close() if __name__ == '__main__': last = get_last() first = last print "Previously last found NIKON file counter: %d" % last while True: last = last + 1 files = find_num(last) if len(files) == 0: last = last - 1 for l in range(last+1,last+slop+1): print "oops, trying next one....%d" % l files = find_num(l) if len(files) > 0: last = l print "OK, found one on %d" % l break if len(files) == 0: if last > first: print "Updating %s with %s" % (counter_file,last) put_last(last) else: print "Warning: no new files found in %s" % root print "Reset counter using something like:" print " echo 1433 > %s" % counter_file break print "Copying ",files for file in files: #cmd = "cp -p '%s' ." % file cmd = "cp '%s' ." % file os.system(cmd)