From 576f9f7c128f555b7160fb016ef75350c75ecc86 Mon Sep 17 00:00:00 2001 From: Kevin Murray Date: Tue, 17 Jun 2014 12:00:21 +1000 Subject: [PATCH 1/6] [fixeyefi] initial commit --- fix_eyefi/.gitignore | 28 ++++++++++++++++++++++++++++ fix_eyefi/setup.py | 42 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 70 insertions(+) create mode 100644 fix_eyefi/.gitignore create mode 100644 fix_eyefi/setup.py diff --git a/fix_eyefi/.gitignore b/fix_eyefi/.gitignore new file mode 100644 index 0000000..9261f7c --- /dev/null +++ b/fix_eyefi/.gitignore @@ -0,0 +1,28 @@ +*.swp + +# python compiled files +*.pyc +*.pyo + +# testing +.coverage +.tox + +# Packages +*.egg +*.egg-info +dist +build +eggs +parts +var +sdist +develop-eggs +.installed.cfg +MANIFEST* + +# Installer logs +pip-log.txt + +# ctags +tags diff --git a/fix_eyefi/setup.py b/fix_eyefi/setup.py new file mode 100644 index 0000000..8e6c06b --- /dev/null +++ b/fix_eyefi/setup.py @@ -0,0 +1,42 @@ +from setuptools import setup + +desc = """ +fixeyefi: fix eyefi cache dumps +""" + +install_requires = [ + "docopt==0.6.1", + ] + +test_requires = [ + "coverage==3.7.1", + "nose==1.3.0", + "pep8==1.4.6", + "pylint==1.0.0", + ] + +setup( + name="fixeyefi", + py_modules=['fixeyefi', ], + version="0.0.0a", + install_requires=install_requires, + tests_require=test_requires, + description=desc, + author="Kevin Murray", + author_email="spam@kdmurray.id.au", + url="https://github.com/borevitzlab/traitcapture-bin", + keywords=["timestream", "timelapse", "photography", "video"], + classifiers=[ + "Programming Language :: Python", + "Programming Language :: Python :: 2", + "Development Status :: 3 - Alpha", + "Environment :: Console", + "Intended Audience :: Developers", + "Operating System :: OS Independent", + "Topic :: Software Development :: Libraries :: Python Modules", + "Topic :: Scientific/Engineering :: Bio-Informatics", + "License :: OSI Approved :: GNU General Public License v3 or later " + + "(GPLv3+)", + ], + test_suite="test", + ) From bb11692ff65203c31d760839b6c77d90d5f427bb Mon Sep 17 00:00:00 2001 From: Kevin Murray Date: Tue, 17 Jun 2014 12:00:51 +1000 Subject: [PATCH 2/6] mv fix_eyefi to fixeyefi --- {fix_eyefi => fixeyefi}/.gitignore | 0 {fix_eyefi => fixeyefi}/setup.py | 0 2 files changed, 0 insertions(+), 0 deletions(-) rename {fix_eyefi => fixeyefi}/.gitignore (100%) rename {fix_eyefi => fixeyefi}/setup.py (100%) diff --git a/fix_eyefi/.gitignore b/fixeyefi/.gitignore similarity index 100% rename from fix_eyefi/.gitignore rename to fixeyefi/.gitignore diff --git a/fix_eyefi/setup.py b/fixeyefi/setup.py similarity index 100% rename from fix_eyefi/setup.py rename to fixeyefi/setup.py From cb6bd13a1d9310867af7454facd1d073aa709aac Mon Sep 17 00:00:00 2001 From: Kevin Murray Date: Tue, 17 Jun 2014 12:52:07 +1000 Subject: [PATCH 3/6] [fixeyefi] initial version of fixeyefi.py --- fixeyefi/fixeyefi.py | 84 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 84 insertions(+) create mode 100644 fixeyefi/fixeyefi.py diff --git a/fixeyefi/fixeyefi.py b/fixeyefi/fixeyefi.py new file mode 100644 index 0000000..6eeee5f --- /dev/null +++ b/fixeyefi/fixeyefi.py @@ -0,0 +1,84 @@ +from __future__ import print_function +import docopt +import csv +import glob +from os import path, makedirs +from shutil import copyfile, move + +FILETYPES = { + b'\xFF\xD8\xFF': "JPG", + b'\x49\x49\x2A': "CR2", + } +CLI_DOC = """ +USAGE: + fixeyefi.py [-m] -c CONFIG -i EYEFI_BASE + +OPTIONS: + -i EYEFI_BASE Base directory of eyefi cache. Should contain MAC address + sub-folders. + -c CONFIG Config csv in format: MAC,Destination + -m Move files, don't copy +""" + +def parse_config(opts): + cameras = [] + with open(opts['-c']) as csvfh: + csv_lines = csv.DictReader(csvfh) + for line in csv_lines: + try: + mac = line["MAC"] + dest = line["Destination"] + except KeyError: + print("ERROR: Malformed csv file. It should look like:\n") + print("MAC,Destination\n18:03:73:3d:b7:56,/destination/dir") + exit(1) + camera = { + "MAC": mac, + "Source": path.join(opts['-i'], mac), + "Destination": dest, + } + cameras.append(camera) + return cameras + +def find_imgs(cam): + imgs = glob.glob("{}/*".format(cam['Source'])) + for img in imgs: + yield (path.basename(img), img) + +def get_img_format(img): + with open(img, "rb") as img_fh: + magic = img_fh.read(3) + try: + return FILETYPES[magic] + except KeyError: + return None + + +def main(opts): + cams = parse_config(opts) + for cam in cams: + count = 0 + print("Processing {}".format(cam["MAC"])) + for name, img in find_imgs(cam): + fmt = get_img_format(img) + if not fmt: + print("Skipping {}, not a JPG or TIFF".format(img)) + count += 1 + continue + dest = path.join(cam['Destination'], fmt, + "{}.{}".format(name, fmt)) + destdir = path.dirname(dest) + if not path.exists(destdir): + makedirs(destdir) + if opts['-m']: + move(img, dest) + else: + copyfile(img, dest) + if count % 10 == 0: + print("Processed {: 5} images".format(count), end='\r') + count += 1 + +if __name__ == '__main__': + opts = docopt.docopt(CLI_DOC) + main(opts) + From cd6c4e01b363a3ea32d46abca0ace617fc9abfd4 Mon Sep 17 00:00:00 2001 From: Kevin Murray Date: Tue, 17 Jun 2014 12:56:43 +1000 Subject: [PATCH 4/6] [fixeyefi] fix progress printer --- fixeyefi/fixeyefi.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/fixeyefi/fixeyefi.py b/fixeyefi/fixeyefi.py index 6eeee5f..1f1ddbf 100644 --- a/fixeyefi/fixeyefi.py +++ b/fixeyefi/fixeyefi.py @@ -4,6 +4,7 @@ import glob from os import path, makedirs from shutil import copyfile, move +import sys FILETYPES = { b'\xFF\xD8\xFF': "JPG", @@ -76,6 +77,7 @@ def main(opts): copyfile(img, dest) if count % 10 == 0: print("Processed {: 5} images".format(count), end='\r') + sys.stdout.flush() count += 1 if __name__ == '__main__': From aad5d7329091034d37ccc91b42e12679904693f7 Mon Sep 17 00:00:00 2001 From: Kevin Murray Date: Fri, 20 Jun 2014 13:39:29 +1000 Subject: [PATCH 5/6] [fixeyefi] output final count of images --- fixeyefi/fixeyefi.py | 1 + 1 file changed, 1 insertion(+) diff --git a/fixeyefi/fixeyefi.py b/fixeyefi/fixeyefi.py index 1f1ddbf..249d0e1 100644 --- a/fixeyefi/fixeyefi.py +++ b/fixeyefi/fixeyefi.py @@ -79,6 +79,7 @@ def main(opts): print("Processed {: 5} images".format(count), end='\r') sys.stdout.flush() count += 1 + print("Processed {: 5} images. Done!".format(count)) if __name__ == '__main__': opts = docopt.docopt(CLI_DOC) From 3026beeb17612757d513d4f8775eac01d0cbe863 Mon Sep 17 00:00:00 2001 From: Kevin Murray Date: Fri, 20 Jun 2014 13:57:05 +1000 Subject: [PATCH 6/6] [fixeyefi] bump setup.py version --- fixeyefi/setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fixeyefi/setup.py b/fixeyefi/setup.py index 8e6c06b..ce1b564 100644 --- a/fixeyefi/setup.py +++ b/fixeyefi/setup.py @@ -18,7 +18,7 @@ setup( name="fixeyefi", py_modules=['fixeyefi', ], - version="0.0.0a", + version="0.1.0rc1", install_requires=install_requires, tests_require=test_requires, description=desc,