Download
John Hurst
Version 1.0.0
20160813:034728
Table of Contents
1. User Manual
download.py is a Python program that downloads images
from an SD card and adds them to the Picture/Albums
catalogue. At present, there are a number of dodges used to get
this program working. These are flagged in the following text
as much as possible.
There is one optional parameter to the program:
-
The camera model from which the SD card comes. This may be
omitted, in which case the program attempts to discern the
camera model from the currently mounted SD card. (If more
than one SD card is mounted, the result is indeterminate.)
2. The Main Program
Define all the components of the full program.
"download.py" 2.1 =
We build a download-test.py program for now, until
testing is complete, in order to avoid misunderstandings!
<interpreter definition 2.2> = #! /usr/bin/python
<banner 2.3> =########################################################################
# #
# d o w n l o a d . p y #
# #
########################################################################
<basic usage information 2.4> =
2.1 The Main Routine
This is just here to give a framework to the literate
program. It will be subdivided as the program structure evolves
<main routine 2.5> =def main(model,directory):
<instantiate a camera instance for subsequent use 2.6>
<determine camera model 2.7>
# 4. get latest image number present in directory list
latest=cameradb.getModelData(model)
#print latest
# 3. open SD card images (this will take some work) and read directory
downloaddir=cameraDownloads[model]
images=os.listdir(directory)
count=0
for i in images:
if i[-3:]=='JPG' and i>latest[1]:
srcname="%s/%s" % (directory,i)
destname="%s/%s" % (downloaddir,i)
print "cp %s to %s" % (srcname,destname)
# 5. copy all images beyond this image into relevant Downloads folder
shutil.copy(srcname,destname)
# 6. ensure permissions on downloaded files are correct
os.chmod(destname,0644)
count+=1
if count==0:
print "Images are uptodate for model %s and image number %s" % (model,latest[1])
# 7. run "filePics.py" on the Downloads folder
os.chdir(downloaddir)
cmd=["/Users/ajh/bin/filePics.py"] # no args required in current directory
subp=subprocess.Popen(cmd,stdout=subprocess.PIPE,stderr=subprocess.PIPE)
(cmd_out,cmd_stderr)=subp.communicate(None)
os.chdir('/home/ajh/Pictures/Albums/2016/08')
# 8. run "photo.py" on relevant Albums subdirectories
# 8.1 first find the subdirectories
photoOut=cmd_out.split('\n')
dates=[]
for l in photoOut:
res=re.match('Scanning directory "\(\d+\)',l)
if res:
subdir=res.group(1)
dates.append(subdir)
cameradb.save()
pass
2.2 Main Routine components
2.2.1 instantiate a camera instance for subsequent use
<instantiate a camera instance for subsequent use 2.6> =cameradb=camera.camera()
cameradb.load()
2.2.2 Determine camera model
<determine camera model 2.7> =if not model:
# try to determine model name from the current SD card
(model,card)=cameradb.getModel()
The parameter model passed in is either None,
or the actual model name to be used. If the actual model name
is present, we have no work to do, and fall through. If it
is None, then we must use the camera module methods
to determine the model name.
<top level cli routine 2.8> =
3. Auxiliary Routines
3.1 Setup
<todos 3.1> =# TODO
# 20160813:031854 none to date
#
<imports 3.2> =import camera
import cgi
import getopt
import os,os.path
import re
import shutil
import subprocess
import sys
<global variables 3.3> =model=None
debug=0
cameraDownloads={'EOS600D':'/home/ajh/Pictures/EOS600D/Downloads',\
'SX230':'/home/ajh/Pictures/SX230/Downloads',\
'DSC-HX90V':'/home/ajh/Pictures/DSC-HX90V/Downloads'}
SDcards={'EOS600D':'/Volumes/EOS-64GB-01/DCIM/100CANON/',\
'SX230':'/Volumes/JOHN2016/DCIM/148___08',\
'DSC-HX90V':'/Volumes/Barb2016/DCIM/100MSDCF'}
<initialization 3.4> =
<initialization 3.5> =
<initialization 3.6> =
<initialization 3.7> =
<initialization 3.8> =
3.2 Define miscellaneous subroutines
<define miscellaneous subroutines 3.9> =def usage():
print """
download.py <flags> model
<flags>= [-d|--debug] print debugging information
[-V|--version] print version information
This program does all the work to download and process photo images
from an SD card.
... (more to come)
The debug flags give verbose output about what is happening.
"""
<define miscellaneous subroutines 3.10> =
<define miscellaneous subroutines 3.11> =
<define miscellaneous subroutines 3.12> =
<define miscellaneous subroutines 3.13> =
3.3 Collect the Command Line Options
There are two command line options:
- v
- show current version
- d
- turn on Debugging
and one (mandatory) command line parameter:
-
Specify the camera Model involved. Current alternatives
are:
<collect the command line options 3.14> =(vals,path)=getopt.getopt(sys.argv[1:],'dV',
['debug','version'])
for (opt,val) in vals:
if opt=='-d' or opt=='--debug':
debug=1
if opt=='-V' or opt=='--version':
print version
sys.exit(0)
model=None
if path:
model=path[0]
The camera model is an optional parameter, which if present,
will override any implied model determined by the program.
Set model to None to indicate that default
processing is used.
4. Indices
4.1 Files
File Name |
Defined in |
download.py |
2.1 |
4.2 Macros
4.3 Identifiers
Identifier |
Defined in |
Used in |
4.4 Document History
20161105:114902 |
ajh |
1.0.1 |
cleanup, and incorporate improved camera module |
20160813:034728 |
ajh |
1.0.0 |
first version, using draft of progam to build
|
<current version 4.1> = 1.0.0
<current date 4.2> = 20160813:034728