Skip to content

Commit

Permalink
Added command line option for deconfliction.
Browse files Browse the repository at this point in the history
  • Loading branch information
jgfield committed May 28, 2011
1 parent a851645 commit 2f01401
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 16 deletions.
12 changes: 7 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,13 @@ Usage
1. Run this:
python exportiphoto.py [options] <iPhoto Library dir> <destination dir>
Options include:
-a, --albums use albums instead of events
-m, --metadata write metadata to images
-f, --faces store faces as keywords (requires -m)
-q, --quiet use quiet mode
-d, --date stop using date prefix in folder name
-a, --albums use albums instead of events
-m, --metadata write metadata to images
-f, --faces store faces as keywords (requires -m)
-q, --quiet use quiet mode
-d, --date stop using date prefix in folder name
-x, --deconflict deconflict export directories of same name

2. There is no step 2

note that the -m flag is only available if extra libraries are installed;
Expand Down
33 changes: 22 additions & 11 deletions exportiphoto.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,12 @@ class iPhotoLibraryError(Exception):

class iPhotoLibrary(object):
def __init__(self, albumDir, destDir, use_album=False, use_date=False,
use_faces=False, use_metadata=False, quiet=False):
use_faces=False, use_metadata=False, deconflict=False, quiet=False):
self.use_album = use_album
self.use_date = use_date
self.use_faces = use_faces
self.use_metadata = use_metadata
self.deconflict = deconflict
self.dest_dir = destDir
self.output_dirs = set()
self.output_files = set()
Expand Down Expand Up @@ -235,11 +236,12 @@ def walk(self, funcs):

# Deconflict output directories
targetFileDir = os.path.join(self.dest_dir, outputPath)
j = 1
while targetFileDir in self.output_dirs:
targetFileDir = os.path.join(self.dest_dir, outputPath + " %02d"%j)
j += 1
self.output_dirs.add(targetFileDir)
if self.deconflict:
j = 1
while targetFileDir in self.output_dirs:
targetFileDir = os.path.join(self.dest_dir, outputPath + " %02d"%j)
j += 1
self.output_dirs.add(targetFileDir)

self.status("* Processing %i of %i: %s (%i images)...\n" % (
i,
Expand Down Expand Up @@ -276,12 +278,15 @@ def copyImage(self, imageId, folderName, folderDate):

mFilePath = image["ImagePath"]
basename = os.path.basename(mFilePath)

# Deconflict ouput filenames
tFilePath = os.path.join(folderName, basename)
j = 1
while tFilePath in self.output_files:
tFilePath = os.path.join(folderName, "%02d_"%j + basename)
j += 1
self.output_files.add(tFilePath)
if self.deconflict:
j = 1
while tFilePath in self.output_files:
tFilePath = os.path.join(folderName, "%02d_"%j + basename)
j += 1
self.output_files.add(tFilePath)

# Skip unchanged files, unless we're writing metadata.
if not self.use_metadata and os.path.exists(tFilePath):
Expand Down Expand Up @@ -390,6 +395,11 @@ def error(msg):
help="stop use date prefix in folder name"
)

option_parser.add_option("-x", "--deconflict",
action="store_true", dest="deconflict",
help="deconflict export directories of same name"
)

if pyexiv2:
option_parser.add_option("-m", "--metadata",
action="store_true", dest="metadata",
Expand All @@ -415,6 +425,7 @@ def error(msg):
use_date=options.date,
use_faces=options.faces,
use_metadata=options.metadata,
deconflict=options.deconflict,
quiet=options.quiet)
def copyImage(imageId, folderName, folderDate):
library.copyImage(imageId, folderName, folderDate)
Expand Down

0 comments on commit 2f01401

Please sign in to comment.