OSDN Git Service

Add command line arguments.
[fukui-no-namari/fukui-no-namari.git] / src / hage1
1 #!/usr/bin/env python
2
3 # Copyright (C) 2006 by Aiwota Programmer
4 # aiwotaprog@tetteke.tk
5 #
6 # This program is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 2 of the License, or
9 # (at your option) any later version.
10 #
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 # GNU General Public License for more details.
15 #
16 # You should have received a copy of the GNU General Public License
17 # along with this program; if not, write to the Free Software
18 # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
19
20 import pygtk
21 pygtk.require('2.0')
22 import gtk
23 import gnome.ui
24 import gobject
25 import getopt
26 import sys
27
28 from Hage1 import thread_window
29 from Hage1 import board_window
30 from Hage1 import brdlist_window
31 from Hage1 import brdlist
32 from Hage1 import config
33 APPNAME = 'Hage1'
34 APPVERSION = '0.1'
35
36 def usage():
37     print """usage: hage1 [-s bbs | -b board | -t thread]
38 -s, --bbs bbs       : bbs id
39 -b, --board board   : board id, ignored if bbs is empty
40 -t, --thread thread : thread id, ignored if bbs and board is empty"""
41
42 def getoption():
43     bbs = None
44     board = None
45     thread = None
46
47     try:
48         opts, args = getopt.getopt(
49             sys.argv[1:], "hs:b:t:", ["help", "bbs=", "board=", "thread="])
50     except getopt.GetoptError, msg:
51         print msg
52         usage()
53         sys.exit(2)
54     for option, value in opts:
55         if option in ("-h", "--help"):
56             usage()
57             sys.exit()
58         elif option in ("-s", "--bbs"):
59             bbs = value
60         elif option in ("-b", "--board"):
61             board = value
62         elif option in ("-t", "--thread"):
63             thread = value
64
65     return bbs, board, thread
66     
67 if __name__ == "__main__":
68
69     # get option
70     bbs, board, thread = getoption()
71
72     gnome.init(APPNAME, APPVERSION)
73     gobject.threads_init()
74     config.APPNAME = APPNAME
75     # init brdlist after setting config.APPNAME
76     brdlist.init()
77
78     if not bbs:
79         brdlist_window.open_brdlist("2ch")
80     elif not board:
81         brdlist_window.open_brdlist(bbs)
82     elif not thread:
83         board_window.open_board(bbs, board)
84     else:
85         thread_window.open_thread(bbs, board, thread)
86
87     gtk.main()