PKZN)photocopy/__init__.py""" Copy your photos from an SD card or camera to a specific directory. """ from .version import VERSION, __version__ try: from .photocopy import main except ImportError: # This may raise an error when importing version to install. pass PKNa;F++photocopy/photocopy.py#!/usr/bin/env python """Usage: photocopy.py [options] Options: -h --help Show this help and exit. --version Show version and exit. -d --dry-run Show what will happen. -j --ignore-jpg Ignore (or delete when moving) JPG files when a RAW file with the same name exists. -e --event=EVENT The name of the event in the photos. A subdirectory will be created for this event in the original directory. -m --move Move files instead of copying. -f --date-format=FORMAT The date format to use [default: %Y-%m-%d]. -v --verbose Talk more. """ import datetime import glob import logging import os import re import shutil import sys import exifread from docopt import docopt from .version import VERSION logger = logging.getLogger(__name__) RAW_EXTENSIONS = ("cr2", "arw", "dng") def set_up_logging(arguments): if arguments["--verbose"]: level = logging.DEBUG else: level = logging.INFO logger.setLevel(level) ch = logging.StreamHandler() ch.setLevel(level) formatter = logging.Formatter("%(message)s") ch.setFormatter(formatter) logger.addHandler(ch) def get_created_date(filename): created_date = None if re.search("\.(jpeg|jpg|%s)$" % "|".join(RAW_EXTENSIONS), filename.lower()): logger.debug(" File probably has an EXIF tag, checking...") image = open(filename, "rb") tags = exifread.process_file(image, details=False, stop_tag="Image DateTime") read_date = ( tags["Image DateTime"].values or tags["EXIF DateTimeOriginal"].values or tags["EXIF DateTimeDigitized"].values ) if read_date: created_date = datetime.datetime.strptime(read_date, "%Y:%m:%d %H:%M:%S") if not created_date: created_date = datetime.datetime.fromtimestamp(os.path.getmtime(filename)) return created_date def file_sorting_key(filename): """ Extract a key for a filename sort, putting JPEGs before everything else. """ extension = filename.lower()[filename.rfind(".") + 1 :] key = 0 if extension in ("jpg", "jpeg") else 1 return (key, filename) def main(args=None): if args is None: args = sys.argv[1:] arguments = docopt(__doc__, argv=args, version=VERSION) set_up_logging(arguments) source_dir = arguments[""] destination_dir = arguments[""] files_in_source = sorted(os.listdir(source_dir), key=file_sorting_key) for file in files_in_source: file_extension = file[file.rfind(".") + 1 :].lower() source = os.path.join(source_dir, file) logger.debug("Examining %s..." % source) if arguments["--ignore-jpg"] and file_extension in ("jpg", "jpeg"): # Discover other files with the same extension. files = glob.glob(source[: source.rfind(".")] + ".*") extensions = [fn[-3:].lower() for fn in files] if any(extension in RAW_EXTENSIONS for extension in extensions): if arguments.get("--move"): logger.debug(" Deleting file because another RAW file exists.") if not arguments.get("--dry-run"): os.remove(source) else: logger.debug(" Skipping file because another RAW file exists.") continue created_date = get_created_date(source) logger.debug(" Creation date is %s." % created_date) destination = os.path.join( destination_dir, created_date.strftime(arguments["--date-format"]) ) if arguments["--event"]: destination = os.path.join(destination, arguments["--event"]) if not os.path.isdir(destination) and not arguments.get("--dry-run"): os.makedirs(destination) dest_filename = os.path.join(destination, os.path.basename(source)) if os.path.exists(dest_filename): logger.info( " Destination file %s already exists, skipping." % dest_filename ) continue if arguments.get("--move"): logger.info(" Moving: %s -> %s..." % (source, destination)) if not arguments.get("--dry-run"): shutil.move(source, destination) else: logger.info(" Copying: %s -> %s..." % (source, destination)) if not arguments.get("--dry-run"): shutil.copy(source, destination) if __name__ == "__main__": main() PKN%O``photocopy/version.pyNUM_VERSION = (0, 2, 0) VERSION = ".".join(str(nv) for nv in NUM_VERSION) __version__ = VERSION PK!H/ 0&,*photocopy-0.2.0.dist-info/entry_points.txtN+I/N.,()*/O/r3PKNyY>>!photocopy-0.2.0.dist-info/LICENSEThe MIT License (MIT) Copyright (c) 2014 Stavros Korokithakis Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.PK!HJVSaphotocopy-0.2.0.dist-info/WHEEL HM K-*ϳR03rOK-J,/RH,rzd&Y)r$[)T&UD"PK!Hޮ|"photocopy-0.2.0.dist-info/METADATAeOo0 Dﶒl@Ɇ]aIt-Ķ c1m%:KRԒe0Yd۷4;ktC $"Gu2xج`޶)WSY?L A>3|ٿUz'̥.;,tÈ{:BL6gd G=ȗ <_W`ŸQ[ !-22W1"[i##)a*$Q"hDW8bê#ۜd\HHY}ZZ/,AB)rKR5u, hj`"Z|CVk#l2L>$M/PK!HęӇu photocopy-0.2.0.dist-info/RECORD}ιz@>)Re$FAM%0OVMQ:!\aTWDhntsN%H)O8R4 3yb/oD"lSTkt1Ty`E" Yzl8?D/%ՖeS{D\c*fawե~*ΨqE:L(6KB4IYJ;S˞=7J^OU'au_NV1bmyIvF@quz5;n`r6ڇ>}8 T:)gm8j)yB$kI~=ځ\@{xKbrR_ߺ|k PKZN)photocopy/__init__.pyPKNa;F++-photocopy/photocopy.pyPKN%O``photocopy/version.pyPK!H/ 0&,*photocopy-0.2.0.dist-info/entry_points.txtPKNyY>>!photocopy-0.2.0.dist-info/LICENSEPK!HJVSa photocopy-0.2.0.dist-info/WHEELPK!Hޮ|"photocopy-0.2.0.dist-info/METADATAPK!HęӇu photocopy-0.2.0.dist-info/RECORDPK[