git » galala » commit 2f445de

Add delete_album command

author Rodrigo Campos
2013-08-10 15:07:10 UTC
committer Rodrigo Campos
2013-08-13 10:30:14 UTC
parent 528281a5cc2069f02234aa74d6dd54d0be1c54a6

Add delete_album command

Now there are "too many" options and is more readable the help output if we add
some spaces between them.

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

galala +33 -0

diff --git a/galala b/galala
index 14e0912..29d4466 100755
--- a/galala
+++ b/galala
@@ -141,6 +141,14 @@ def _add_album(page, shortname, title, text):
 
     page.albums.append(a)
 
+def find_album(page, shortname):
+    """Find the album "shortname" on page "page" (the shortname is unique)"""
+    for a in page.albums:
+        if a.shortname == shortname:
+            return a
+
+    return None
+
 def add_albums(page):
     while True:
         shortname = raw_input("Album shortname (empty to skip): ")
@@ -157,6 +165,15 @@ def add_albums(page):
 
         print
 
+def delete_album(page, shortname):
+    a = find_album(page, shortname)
+    if not a:
+        print "ERROR: invalid album shortname"
+        return False
+
+    page.albums.remove(a)
+    return True
+
 
 HELP = '''
 Use one of:
@@ -164,9 +181,16 @@ Use one of:
     galala new_page FILENAME
         Creates a new page and will ask to optionally add albums to it. The
         filename given will store the page information in .ini format.
+
     galala add_albums FILENAME
         Adds albums to the given page. It will ask for the information
         interactively, and update the page file.
+
+    galala delete_album FILENAME ALBUM_SHORTNAME
+        This command deletes the album from FILENAME so it will not be included
+        the next time you generate. But, keep in mind that the files already
+        created for this album (if any) will still be there.
+
     galala generate FILENAME OUT_PATH
         Generates static HTML for the page given in FILENAME to OUT_PATH.
 '''
@@ -192,6 +216,15 @@ if __name__ == '__main__':
         page = common.page_load(sys.argv[2])
         add_albums(page)
         common.page_save(page, sys.argv[2])
+    elif cmd == 'delete_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 success:
+            common.page_save(page, sys.argv[2])
     else:
         print "ERROR: unknown command"
         sys.exit(1)