def test_format_album_name(self): album = self.TestAlbum("nnnn", datetime.datetime(2010, 12, 26, 11, 33, 12)) self.assertEqual( u"2010/12/26 hint nnnn", iu.format_album_name(album, album.name, "{yyyy}/{mm}/{dd} {hint} {album}") ) self.assertEqual( u"2010/12/26 hint nnnn", iu.format_album_name(album, album.name, "{yyyy}/{mm}/{dd} {hint} {name}") ) # Bad template. self.assertEqual("{badfield}", iu.format_album_name(album, album.name, "{badfield}"))
def test_format_album_name(self): album = self.TestAlbum('nnnn', datetime.datetime(2010, 12, 26, 11, 33, 12)) self.assertEqual( u'2010/12/26 hint nnnn', iu.format_album_name(album, album.name, '{yyyy}/{mm}/{dd} {hint} {album}')) self.assertEqual( u'2010/12/26 hint nnnn', iu.format_album_name(album, album.name, '{yyyy}/{mm}/{dd} {hint} {name}')) # Bad template. self.assertEqual('{badfield}', iu.format_album_name(album, album.name, '{badfield}'))
def process_albums(self, albums, album_types, folder_prefix, includes, excludes, options, matched=False): """Walks trough an iPhoto album tree, and discovers albums (directories).""" entries = 0 include_pattern = re.compile(su.unicode_string(includes)) exclude_pattern = None if excludes: exclude_pattern = re.compile(su.unicode_string(excludes)) # first, do the sub-albums for sub_album in albums: if self._check_abort(): return sub_name = sub_album.name if not sub_name: print "Found an album with no name: " + sub_album.albumid sub_name = "xxx" # check the album type if sub_album.albumtype == "Folder" or sub_album.albums: sub_matched = matched if include_pattern.match(sub_name): sub_matched = True new_name = folder_prefix if sub_album.albumtype == "Folder": new_name += imageutils.make_foldername(sub_name) + "/" self.process_albums(sub_album.albums, album_types, new_name, includes, excludes, options, sub_matched) continue elif (sub_album.albumtype == "None" or not sub_album.albumtype in album_types): # print "Ignoring " + sub_album.name + " of type " + \ # sub_album.albumtype continue if not matched and not include_pattern.match(sub_name): _logger.debug( u'Skipping "%s" because it does not match pattern.', sub_name) continue if exclude_pattern and exclude_pattern.match(sub_name): _logger.debug(u'Skipping "%s" because it is excluded.', sub_name) continue _logger.debug(u'Loading "%s".', sub_name) folder_hint = None if options.folderhints: folder_hint = sub_album.getfolderhint() prefix = folder_prefix if folder_hint is not None: prefix = prefix + imageutils.make_foldername(folder_hint) + "/" formatted_name = imageutils.format_album_name( sub_album, options.foldertemplate) sub_name = prefix + imageutils.make_foldername(formatted_name) sub_name = self._find_unused_folder(sub_name) # first, do the sub-albums if self.process_albums(sub_album.albums, album_types, folder_prefix, includes, excludes, options, matched) > 0: entries += 1 # now the album itself picture_directory = ExportDirectory( sub_name, sub_album, os.path.join(self.albumdirectory, sub_name)) if picture_directory.add_iphoto_images(sub_album.images, options) > 0: self.named_folders[sub_name] = picture_directory entries += 1 return entries
def process_albums(self, albums, album_types, folder_prefix, includes, excludes, options, matched=False): """Walks trough an iPhoto album tree, and discovers albums (directories).""" include_pattern = re.compile(su.unicode_string(includes)) exclude_pattern = None if excludes: exclude_pattern = re.compile(su.unicode_string(excludes)) # Figure out the folder patterns (if any) folderpatterns = [] if options.folderpatterns: for pattern in su.unicode_string(options.folderpatterns).split(','): (expression, folder) = pattern.split('/', 2) folderpatterns.append((re.compile(expression), folder)) # first, do the sub-albums for sub_album in albums: if self._check_abort(): return sub_name = sub_album.name if not sub_name: print "Found an album with no name: " + sub_album.albumid sub_name = "xxx" # check the album type if sub_album.albumtype == "Folder" or sub_album.albums: sub_matched = matched if include_pattern.match(sub_name): sub_matched = True new_name = folder_prefix if sub_album.albumtype == "Folder": new_name += imageutils.make_foldername(sub_name) + "/" self.process_albums(sub_album.albums, album_types, new_name, includes, excludes, options, sub_matched) continue elif (sub_album.albumtype == "None" or not sub_album.albumtype in album_types): # print "Ignoring " + sub_album.name + " of type " + \ # sub_album.albumtype continue if not matched and not include_pattern.match(sub_name): _logger.debug(u'Skipping "%s" because it does not match pattern.', sub_name) continue if exclude_pattern and exclude_pattern.match(sub_name): _logger.debug(u'Skipping "%s" because it is excluded.', sub_name) continue _logger.debug(u'Loading "%s".', sub_name) folder_hint = None if sub_name.find('/') != -1: (folder_hint, sub_name) = sub_name.split('/', 1) if not folder_hint and options.folderhints: folder_hint = sub_album.getfolderhint() if not folder_hint and folderpatterns: for (pattern, folder) in folderpatterns: if pattern.match(sub_album.name): if options.verbose: su.pout("Using folder %s for album %s." % (folder, sub_album.name)) folder_hint = folder break prefix = folder_prefix if folder_hint is not None: prefix = prefix + imageutils.make_foldername(folder_hint) + "/" formatted_name = imageutils.format_album_name( sub_album, sub_name, options.foldertemplate) sub_name = prefix + imageutils.make_foldername(formatted_name, options.enablesubfolders) sub_name = self._find_unused_folder(sub_name) # first, do the sub-albums self.process_albums(sub_album.albums, album_types, folder_prefix, includes, excludes, options, matched) # now the album itself picture_directory = ExportDirectory( sub_name, sub_album, os.path.join(self.albumdirectory, sub_name)) if picture_directory.add_iphoto_images(sub_album.images, options) > 0: self.named_folders[sub_name] = picture_directory return len(self.named_folders)
def process_albums(self, albums, album_types, folder_prefix, includes, excludes, options, matched=False): """Walks trough an iPhoto album tree, and discovers albums (directories).""" entries = 0 include_pattern = re.compile(su.unicode_string(includes)) exclude_pattern = None if excludes: exclude_pattern = re.compile(su.unicode_string(excludes)) # first, do the sub-albums for sub_album in albums: if self._check_abort(): return sub_name = sub_album.name if not sub_name: print "Found an album with no name: " + sub_album.albumid sub_name = "xxx" # check the album type if sub_album.albumtype == "Folder" or sub_album.albums: sub_matched = matched if include_pattern.match(sub_name): sub_matched = True new_name = folder_prefix if sub_album.albumtype == "Folder": new_name += imageutils.make_foldername(sub_name) + "/" self.process_albums(sub_album.albums, album_types, new_name, includes, excludes, options, sub_matched) continue elif (sub_album.albumtype == "None" or not sub_album.albumtype in album_types): # print "Ignoring " + sub_album.name + " of type " + \ # sub_album.albumtype continue if not matched and not include_pattern.match(sub_name): _logger.debug(u'Skipping "%s" because it does not match pattern.', sub_name) continue if exclude_pattern and exclude_pattern.match(sub_name): _logger.debug(u'Skipping "%s" because it is excluded.', sub_name) continue _logger.debug(u'Loading "%s".', sub_name) folder_hint = None if options.folderhints: folder_hint = sub_album.getfolderhint() prefix = folder_prefix if folder_hint is not None: prefix = prefix + imageutils.make_foldername(folder_hint) + "/" formatted_name = imageutils.format_album_name( sub_album, options.foldertemplate) sub_name = prefix + imageutils.make_foldername(formatted_name) sub_name = self._find_unused_folder(sub_name) # first, do the sub-albums if self.process_albums(sub_album.albums, album_types, folder_prefix, includes, excludes, options, matched) > 0: entries += 1 # now the album itself picture_directory = ExportDirectory( sub_name, sub_album, os.path.join(self.albumdirectory, sub_name)) if picture_directory.add_iphoto_images(sub_album.images, options) > 0: self.named_folders[sub_name] = picture_directory entries += 1 return entries
def process_albums(self, albums, album_types, folder_prefix, includes, excludes, options, matched=False): """Walks trough an iPhoto album tree, and discovers albums (directories).""" include_pattern = re.compile(su.unicode_string(includes)) exclude_pattern = None if excludes: exclude_pattern = re.compile(su.unicode_string(excludes)) # Figure out the folder patterns (if any) folderpatterns = [] if options.folderpatterns: for pattern in su.unicode_string(options.folderpatterns).split(','): (expression, folder) = pattern.split('/', 2) folderpatterns.append((re.compile(expression), folder)) # first, do the sub-albums for sub_album in albums: if self._check_abort(): return sub_name = sub_album.name if not sub_name: print "Found an album with no name: " + sub_album.albumid sub_name = "xxx" # check the album type if sub_album.albumtype == "Folder" or sub_album.albums: sub_matched = matched if include_pattern.match(sub_name): sub_matched = True new_name = folder_prefix if sub_album.albumtype == "Folder": new_name += imageutils.make_foldername(sub_name) + "/" self.process_albums(sub_album.albums, album_types, new_name, includes, excludes, options, sub_matched) continue elif (sub_album.albumtype == "None" or not sub_album.albumtype in album_types): # print "Ignoring " + sub_album.name + " of type " + \ # sub_album.albumtype continue if not matched and not include_pattern.match(sub_name): _logger.debug(u'Skipping "%s" because it does not match pattern.', sub_name) continue if exclude_pattern and exclude_pattern.match(sub_name): _logger.debug(u'Skipping "%s" because it is excluded.', sub_name) continue _logger.debug(u'Loading "%s".', sub_name) folder_hint = None if sub_name.find('/') != -1: (folder_hint, sub_name) = sub_name.split('/', 1) if not folder_hint and options.folderhints: folder_hint = sub_album.getfolderhint() if not folder_hint and folderpatterns: for (pattern, folder) in folderpatterns: if pattern.match(sub_album.name): if options.verbose: su.pout("Using folder %s for album %s." % (folder, sub_album.name)) folder_hint = folder break prefix = folder_prefix if folder_hint is not None: prefix = prefix + imageutils.make_foldername(folder_hint) + "/" formatted_name = imageutils.format_album_name( sub_album, sub_name, options.foldertemplate) sub_name = prefix + imageutils.make_foldername(formatted_name) sub_name = self._find_unused_folder(sub_name) # first, do the sub-albums self.process_albums(sub_album.albums, album_types, folder_prefix, includes, excludes, options, matched) # now the album itself picture_directory = ExportDirectory( sub_name, sub_album, os.path.join(self.albumdirectory, sub_name)) if picture_directory.add_iphoto_images(sub_album.images, options) > 0: self.named_folders[sub_name] = picture_directory return len(self.named_folders)