Download

John Hurst

Version 1.0.0

20160813:034728

Table of Contents

1 User Manual
2 The Main Program
2.1 The Main Routine
2.2 Main Routine components
2.2.1 instantiate a camera instance for subsequent use
2.2.2 Determine camera model
3 Auxiliary Routines
3.1 Setup
3.2 Define miscellaneous subroutines
3.3 Collect the Command Line Options
4 Indices
4.1 Files
4.2 Macros
4.3 Identifiers
4.4 Document History


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:

  1. 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 =
<interpreter definition 2.2> <banner 2.3> <basic usage information 2.4> <todos 3.1> <imports 3.2> <global variables 3.3> <initialization 3.4,3.5,3.6,3.7,3.8> <define miscellaneous subroutines 3.9,3.10,3.11,3.12,3.13> <main routine 2.5> <top level cli routine 2.8>

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
Chunk referenced in 2.1
<banner 2.3> =
######################################################################## # # # d o w n l o a d . p y # # # ########################################################################
Chunk referenced in 2.1
<basic usage information 2.4> =
# A program to download images from SD cards # # John Hurst # version <current version 4.1>, <current date 4.2> #
Chunk referenced in 2.1

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
Chunk referenced in 2.1

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()
Chunk referenced in 2.5

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()
Chunk referenced in 2.5

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> =
if __name__ == '__main__': <collect the command line options 3.14> dir=SDcards[model] if dir: main(model,dir) else: print "Need to code SD card directory for model %s" % (model)
Chunk referenced in 2.1

3. Auxiliary Routines

3.1 Setup

<todos 3.1> =
# TODO # 20160813:031854 none to date #
Chunk referenced in 2.1
<imports 3.2> =
import camera import cgi import getopt import os,os.path import re import shutil import subprocess import sys
Chunk referenced in 2.1

<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'}
Chunk referenced in 2.1
<initialization 3.4> =
Chunk referenced in 2.1
Chunk defined in 3.4,3.5,3.6,3.7,3.8
<initialization 3.5> =
Chunk referenced in 2.1
Chunk defined in 3.4,3.5,3.6,3.7,3.8
<initialization 3.6> =
Chunk referenced in 2.1
Chunk defined in 3.4,3.5,3.6,3.7,3.8
<initialization 3.7> =
Chunk referenced in 2.1
Chunk defined in 3.4,3.5,3.6,3.7,3.8
<initialization 3.8> =
Chunk referenced in 2.1
Chunk defined in 3.4,3.5,3.6,3.7,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. """
Chunk referenced in 2.1
Chunk defined in 3.9,3.10,3.11,3.12,3.13
<define miscellaneous subroutines 3.10> =
Chunk referenced in 2.1
Chunk defined in 3.9,3.10,3.11,3.12,3.13
<define miscellaneous subroutines 3.11> =
Chunk referenced in 2.1
Chunk defined in 3.9,3.10,3.11,3.12,3.13
<define miscellaneous subroutines 3.12> =
Chunk referenced in 2.1
Chunk defined in 3.9,3.10,3.11,3.12,3.13
<define miscellaneous subroutines 3.13> =
Chunk referenced in 2.1
Chunk defined in 3.9,3.10,3.11,3.12,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:

<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]
Chunk referenced in 2.8

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

Chunk Name Defined in Used in
banner 2.3 2.1
basic usage information 2.4 2.1
collect the command line options 3.14 2.8
current date 4.2 2.4
current version 4.1 2.4
define miscellaneous subroutines 3.9, 3.10, 3.11, 3.12, 3.13 2.1
determine camera model 2.7 2.5
global variables 3.3 2.1
imports 3.2 2.1
initialization 3.4, 3.5, 3.6, 3.7, 3.8 2.1
instantiate a camera instance for subsequent use 2.6 2.5
interpreter definition 2.2 2.1
main routine 2.5 2.1
todos 3.1 2.1
top level cli routine 2.8 2.1

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
Chunk referenced in 2.4
<current date 4.2> = 20160813:034728
Chunk referenced in 2.4