OSDN Git Service

Add command line arguments.
authorAiwota Programmer <aiwotaprog@tetteke.tk>
Mon, 21 Aug 2006 13:59:46 +0000 (22:59 +0900)
committerAiwota Programmer <aiwotaprog@tetteke.tk>
Mon, 21 Aug 2006 13:59:46 +0000 (22:59 +0900)
src/hage1

index 2bac2b7..48aef07 100755 (executable)
--- a/src/hage1
+++ b/src/hage1
@@ -22,20 +22,66 @@ pygtk.require('2.0')
 import gtk
 import gnome.ui
 import gobject
+import getopt
+import sys
 
+from Hage1 import thread_window
+from Hage1 import board_window
 from Hage1 import brdlist_window
 from Hage1 import brdlist
 from Hage1 import config
 APPNAME = 'Hage1'
 APPVERSION = '0.1'
 
+def usage():
+    print """usage: hage1 [-s bbs | -b board | -t thread]
+-s, --bbs bbs       : bbs id
+-b, --board board   : board id, ignored if bbs is empty
+-t, --thread thread : thread id, ignored if bbs and board is empty"""
+
+def getoption():
+    bbs = None
+    board = None
+    thread = None
+
+    try:
+        opts, args = getopt.getopt(
+            sys.argv[1:], "hs:b:t:", ["help", "bbs=", "board=", "thread="])
+    except getopt.GetoptError, msg:
+        print msg
+        usage()
+        sys.exit(2)
+    for option, value in opts:
+        if option in ("-h", "--help"):
+            usage()
+            sys.exit()
+        elif option in ("-s", "--bbs"):
+            bbs = value
+        elif option in ("-b", "--board"):
+            board = value
+        elif option in ("-t", "--thread"):
+            thread = value
+
+    return bbs, board, thread
+    
 if __name__ == "__main__":
-    bbs = "2ch"
-    board = "morningcoffee"
+
+    # get option
+    bbs, board, thread = getoption()
+
     gnome.init(APPNAME, APPVERSION)
     gobject.threads_init()
     config.APPNAME = APPNAME
     # init brdlist after setting config.APPNAME
     brdlist.init()
-    brdlist_window.open_brdlist(bbs)
+
+    if not bbs:
+        brdlist_window.open_brdlist("2ch")
+    elif not board:
+        brdlist_window.open_brdlist(bbs)
+    elif not thread:
+        board_window.open_board(bbs, board)
+    else:
+        thread_window.open_thread(bbs, board, thread)
+
     gtk.main()