git » galala » commit 41106b5

Add rescan_album command

author Rodrigo Campos
2013-08-13 09:57:06 UTC
committer Rodrigo Campos
2013-08-13 10:30:56 UTC
parent 2f445de7a60758983bb243318cba187ec0c5b06f

Add rescan_album command

Signed-off-by: Rodrigo Campos <rodrigo@sdfg.com.ar>

galala +24 -2

diff --git a/galala b/galala
index 29d4466..6e27fbf 100755
--- a/galala
+++ b/galala
@@ -174,6 +174,19 @@ def delete_album(page, shortname):
     page.albums.remove(a)
     return True
 
+def rescan_album(page, shortname):
+    # Get the album "data" (title, etc.) to create one with the same data later
+    old_a = find_album(page, shortname)
+    if not old_a:
+        print "ERROR: invalid album shortname"
+        return False
+
+    delete_album(page, shortname)
+
+    # This adds the album again re-scanning the images used
+    _add_album(page, old_a.shortname, old_a.title,old_a.text)
+    return True
+
 
 HELP = '''
 Use one of:
@@ -191,6 +204,11 @@ Use one of:
         the next time you generate. But, keep in mind that the files already
         created for this album (if any) will still be there.
 
+    galala rescan_album FILENAME ALBUM_SHORTNAME
+        The same album is preserved, except that it asks you for the image path
+        and adds those images. This command is equivalent to delete the album and
+        create it again with the same shortname, title and text.
+
     galala generate FILENAME OUT_PATH
         Generates static HTML for the page given in FILENAME to OUT_PATH.
 '''
@@ -216,13 +234,17 @@ if __name__ == '__main__':
         page = common.page_load(sys.argv[2])
         add_albums(page)
         common.page_save(page, sys.argv[2])
-    elif cmd == 'delete_album':
+    elif cmd in ['delete_album', 'rescan_album']:
         if len(sys.argv) != 4:
             print HELP
             sys.exit(1)
         page = common.page_load(sys.argv[2])
         shortname = sys.argv[3]
-        success = delete_album(page, shortname)
+        if cmd == 'delete_album':
+            success = delete_album(page, shortname)
+        elif cmd == 'rescan_album':
+            success = rescan_album(page, shortname)
+
         if success:
             common.page_save(page, sys.argv[2])
     else: