several fixes, mostly to gid.py

Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
Alex A. Naanou 2012-03-17 00:44:04 +04:00
parent 48b3fbd8dc
commit 2a4159b6d1
2 changed files with 24 additions and 15 deletions

20
gid.py
View File

@ -1,7 +1,7 @@
#======================================================================= #=======================================================================
__version__ = '''0.0.01''' __version__ = '''0.0.01'''
__sub_version__ = '''20120315140451''' __sub_version__ = '''20120316225150'''
__copyright__ = '''(c) Alex A. Naanou 2011''' __copyright__ = '''(c) Alex A. Naanou 2011'''
@ -61,12 +61,16 @@ def image_gid(path, date=None,
} }
##!!! this might fail... ##!!! this might fail...
i = metadata.ImageMetadata('%s' % path) i = metadata.ImageMetadata('%s' % path)
i.read() try:
i.read()
except IOError:
# can't read exif...
i = None
# check if we need a date in the id... # check if we need a date in the id...
if '%(date)s' in format: if '%(date)s' in format:
if date is not None: if date is not None:
data['date'] = time.strftime(date_format, time.gmtime(date)) data['date'] = time.strftime(date_format, time.gmtime(date))
elif use_ctime: elif use_ctime or i is None:
date = os.path.getctime(path) date = os.path.getctime(path)
data['date'] = time.strftime(date_format, time.gmtime(date)) data['date'] = time.strftime(date_format, time.gmtime(date))
else: else:
@ -74,10 +78,12 @@ def image_gid(path, date=None,
data['date'] = date.strftime(date_format) data['date'] = date.strftime(date_format)
# check if we need an artist... # check if we need an artist...
if '%(artist)s' in format: if '%(artist)s' in format:
try: data['artist'] = default_artist
data['artist'] = i['Exif.Image.Artist'].value.strip().replace(' ', '_') if i is not None:
except KeyError: try:
data['artist'] = default_artist data['artist'] = i['Exif.Image.Artist'].value.strip().replace(' ', '_')
except KeyError:
pass
if hash_func is not None: if hash_func is not None:
return hash_func(format % data).hexdigest() return hash_func(format % data).hexdigest()

View File

@ -1,7 +1,7 @@
#======================================================================= #=======================================================================
__version__ = '''0.0.01''' __version__ = '''0.0.01'''
__sub_version__ = '''20120315151510''' __sub_version__ = '''20120317004325'''
__copyright__ = '''(c) Alex A. Naanou 2011''' __copyright__ = '''(c) Alex A. Naanou 2011'''
@ -33,9 +33,9 @@ from gid import image_gid
#----------------------------------------------------------------------- #-----------------------------------------------------------------------
CONFIG_NAME = 'test_config.json' ##CONFIG_NAME = 'hdd9_config.json'
##CONFIG_NAME = 'tmp_config.json' CONFIG_NAME = 'P7000_config.json'
##CONFIG_NAME = 'tmp_config.json.bak' ##CONFIG_NAME = 'staging_config.json'
config = json.load(open(CONFIG_NAME)) config = json.load(open(CONFIG_NAME))
@ -262,9 +262,11 @@ def gid_index(index, existing=None):
#----------------------------------------------------------------------- #-----------------------------------------------------------------------
if __name__ == '__main__': if __name__ == '__main__':
INDEX_PATH = os.path.join('test', 'index2') INDEX_PATH = config.get('INDEX_ROOT', os.path.join('test', 'index2'))
FILE_LIST = os.path.join('test', 'flatfilelist.json') FILE_LIST = os.path.join('test', 'flatfilelist-P7000.json')
## FILE_LIST = os.path.join('test', 'flatfilelist-120kfiles.json')
## FILE_LIST = os.path.join('test', 'flatfilelist.json')
BUILD_FILE_LIST = False if os.path.exists(FILE_LIST) else True BUILD_FILE_LIST = False if os.path.exists(FILE_LIST) else True
@ -311,11 +313,12 @@ if __name__ == '__main__':
len([ e for e in lst if e[2] == RAW]), len([ e for e in lst if e[2] == RAW]),
len(failed)) len(failed))
pprint(GID_index.values()[0]) ##!!! this is really slow because it pulls ALL the data... wonder who wrote this? :)
pprint(GID_index.itervalues().next())
## store.dump(GID_index, INDEX_PATH) ## store.dump(GID_index, INDEX_PATH)
store.pack(INDEX_PATH) ## store.pack(INDEX_PATH)