Updated master, merging into patches.

This commit is contained in:
Joachim Tingvold 2015-05-04 17:45:03 +02:00
commit 6e4fe49d50
3 changed files with 26 additions and 11 deletions

View File

@ -153,9 +153,9 @@ class Photo(object):
exif = {} exif = {}
for tag, value in info.items(): for tag, value in info.items():
decoded = TAGS.get(tag, tag) decoded = TAGS.get(tag, tag)
if isinstance(value, str): if isinstance(value, str) or isinstance(value, unicode):
value = value.strip().partition("\x00")[0] value = value.strip().partition("\x00")[0]
if isinstance(decoded, str) and decoded.startswith("DateTime"): if (isinstance(decoded, str) or isinstance(decoded, unicode)) and decoded.startswith("DateTime"):
try: try:
value = datetime.strptime(value, '%Y:%m:%d %H:%M:%S') value = datetime.strptime(value, '%Y:%m:%d %H:%M:%S')
except KeyboardInterrupt: except KeyboardInterrupt:
@ -302,11 +302,17 @@ class Photo(object):
try: try:
image.save(thumb_path, "JPEG", quality=88) image.save(thumb_path, "JPEG", quality=88)
except KeyboardInterrupt: except KeyboardInterrupt:
try:
os.unlink(thumb_path) os.unlink(thumb_path)
except:
pass
raise raise
except: except:
message("save failure", os.path.basename(thumb_path)) message("save failure", os.path.basename(thumb_path))
try:
os.unlink(thumb_path) os.unlink(thumb_path)
except:
pass
def _thumbnails(self, original_path, thumb_path): def _thumbnails(self, original_path, thumb_path):
# get number of cores on the system, and use all minus one # get number of cores on the system, and use all minus one
@ -330,14 +336,17 @@ class Photo(object):
return [image_cache(self._path, size[0], size[1]) for size in Photo.thumb_sizes] return [image_cache(self._path, size[0], size[1]) for size in Photo.thumb_sizes]
@property @property
def date(self): def date(self):
correct_date = None;
if not self.is_valid: if not self.is_valid:
return datetime(1900, 1, 1) correct_date = datetime(1900, 1, 1)
if "dateTimeOriginal" in self._attributes: if "dateTimeOriginal" in self._attributes:
return self._attributes["dateTimeOriginal"] correct_date = self._attributes["dateTimeOriginal"]
elif "dateTime" in self._attributes: elif "dateTime" in self._attributes:
return self._attributes["dateTime"] correct_date = self._attributes["dateTime"]
else: else:
return self._attributes["dateTimeFile"] correct_date = self._attributes["dateTimeFile"]
return correct_date
def __cmp__(self, other): def __cmp__(self, other):
date_compare = cmp(self.date, other.date) date_compare = cmp(self.date, other.date)
if date_compare == 0: if date_compare == 0:

View File

@ -49,7 +49,10 @@ class TreeWalker:
except KeyboardInterrupt: except KeyboardInterrupt:
raise raise
except: except:
pass next_level()
message("unicode error", entry.decode(sys.getfilesystemencoding(), "replace"))
back_level()
continue
entry = os.path.join(path, entry) entry = os.path.join(path, entry)
if os.path.isdir(entry): if os.path.isdir(entry):
album.add_album(self.walk(entry)) album.add_album(self.walk(entry))

View File

@ -137,12 +137,15 @@
return PhotoFloat.cachePath(album.parent.path + "/" + album.path); return PhotoFloat.cachePath(album.parent.path + "/" + album.path);
}; };
PhotoFloat.photoPath = function(album, photo, size, square) { PhotoFloat.photoPath = function(album, photo, size, square) {
var suffix; var suffix, hash;
if (square) if (square)
suffix = size.toString() + "s"; suffix = size.toString() + "s";
else else
suffix = size.toString(); suffix = size.toString();
return "cache/" + PhotoFloat.cachePath(PhotoFloat.photoHash(album, photo) + "_" + suffix + ".jpg"); hash = PhotoFloat.cachePath(PhotoFloat.photoHash(album, photo) + "_" + suffix + ".jpg");
if (hash.indexOf("root-") === 0)
hash = hash.substring(5);
return "cache/" + hash;
}; };
PhotoFloat.originalPhotoPath = function(album, photo) { PhotoFloat.originalPhotoPath = function(album, photo) {
return "albums/" + album.path + "/" + photo.name; return "albums/" + album.path + "/" + photo.name;