From 6d5dea12129a39679edde97df1b3fa7000f36f56 Mon Sep 17 00:00:00 2001 From: "Alex A. Naanou" Date: Fri, 22 Mar 2013 14:32:48 +0400 Subject: [PATCH] started testing a reversable hash (base64), gid.py now runnable form the command line and supports different GUID formats (sha/base64/text)... Signed-off-by: Alex A. Naanou --- gid.py | 50 +++++++++++++++++++++++++++++++++++++++++++++----- index2.py | 3 ++- store.py | 4 ++-- 3 files changed, 49 insertions(+), 8 deletions(-) diff --git a/gid.py b/gid.py index 1e40cf42..694201e9 100755 --- a/gid.py +++ b/gid.py @@ -1,7 +1,7 @@ #======================================================================= __version__ = '''0.0.01''' -__sub_version__ = '''20130319145754''' +__sub_version__ = '''20130322142905''' __copyright__ = '''(c) Alex A. Naanou 2011''' @@ -10,6 +10,7 @@ __copyright__ = '''(c) Alex A. Naanou 2011''' import os import sha import md5 +import base64 import time import pyexiv2 as metadata @@ -30,7 +31,7 @@ def image_gid(path, date=None, date_format='%Y%m%d-%H%M%S', default_artist='Unknown', use_ctime=False, - hash_func=sha.sha): + hash_func=lambda s: sha.sha(s).hexdigest()): ''' Calculate image GID. @@ -76,7 +77,8 @@ def image_gid(path, date=None, date = os.path.getctime(path) data['date'] = time.strftime(date_format, time.gmtime(date)) else: - date = i['Exif.Image.DateTime'].value +## date = i['Exif.Image.DateTime'].value + date = i['Exif.Photo.DateTimeOriginal'].value data['date'] = date.strftime(date_format) # check if we need an artist... if '%(artist)s' in format: @@ -88,15 +90,53 @@ def image_gid(path, date=None, pass if hash_func is not None: - return hash_func(format % data).hexdigest() + return hash_func(format % data) return format % data #----------------------------------------------------------------------- if __name__ == '__main__': - pass + from optparse import OptionParser + parser = OptionParser() + + ##!!! need to define the path so that it shoes up in -h + + parser.add_option('-t', '--text', + dest='format', + action='store_const', + const='text', + default='sha', + help='output GUID in base64 format.') + parser.add_option('-b', '--base64', + dest='format', + action='store_const', + const='base64', + default='sha', + help='output GUID in text format.') + parser.add_option('-s', '--sha', + dest='format', + action='store_const', + const='sha', + default='sha', + help='output GUID in sha format.') + + options, args = parser.parse_args() + + if len(args) != 1: + parser.print_usage() + else: + IN_PATH = args[0] + IN_PATH = IN_PATH.replace('\\', '/') + + if options.format == 'text': + print image_gid(IN_PATH, hash_func=None) + elif options.format == 'base64': + # also remove the trailing \n... + print image_gid(IN_PATH, hash_func=lambda s: base64.encodestring(s).strip()) + else: + print image_gid(IN_PATH) diff --git a/index2.py b/index2.py index 53c61c13..01afbc2e 100755 --- a/index2.py +++ b/index2.py @@ -1,7 +1,7 @@ #======================================================================= __version__ = '''0.0.01''' -__sub_version__ = '''20130319002125''' +__sub_version__ = '''20130319151025''' __copyright__ = '''(c) Alex A. Naanou 2011''' @@ -245,6 +245,7 @@ def gid_index(index, existing=None): # get file GID... GID = image_gid('%s.%s' % (os.path.join(*[config['ARCHIVE_ROOT']] + raw[0] + [raw[1]]), raw[2])) + ##!!! normalize the image format... res[GID] = { 'gid': GID, 'name': name, diff --git a/store.py b/store.py index 6ab17f41..be871a76 100755 --- a/store.py +++ b/store.py @@ -1,7 +1,7 @@ #======================================================================= __version__ = '''0.0.01''' -__sub_version__ = '''20120316182131''' +__sub_version__ = '''20130319150549''' __copyright__ = '''(c) Alex A. Naanou 2011''' @@ -168,7 +168,7 @@ class Index(mapping.Mapping): pack_ext = self.__pack_ext__ ## file_name = name + ext locations = self.__locations__(name) - # look of the file directly... + # look for the file directly... for n in locations: if os.path.exists(os.path.join(self._path, n)): return json.load(file(os.path.join(self._path, n)))