7 ################################################################################
9 # Copyright (c) 2010 University of Tsukuba Linux User Group
11 # This file is part of "gwit".
13 # "gwit" is free software: you can redistribute it and/or modify
14 # it under the terms of the GNU General Public License as published by
15 # the Free Software Foundation, either version 3 of the License, or
16 # (at your option) any later version.
18 # "gwit" is distributed in the hope that it will be useful,
19 # but WITHOUT ANY WARRANTY; without even the implied warranty of
20 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 # GNU General Public License for more details.
23 # You should have received a copy of the GNU General Public License
24 # along with "gwit". If not, see <http://www.gnu.org/licenses/>.
26 ################################################################################
32 from ConfigParser import SafeConfigParser
34 __version__ = '0.9.2-beta'
35 __author__ = 'University of Tsukuba Linux User Group <staff@tsukuba-linux.org>'
40 Copyright (C) %(year)s %(copyright)s
41 %(name)s comes with ABSOLUTELY NO WARRANTY.
42 You may redistribute copies of %(name)s
43 under the terms of the GNU General Public License.
44 For more information about these matters, see the file named COPYING.""" % {
46 "version" : __version__,
48 "copyright" : __author__,
51 if __name__ == "__main__":
53 p = optparse.OptionParser()
54 p.add_option("-u", "--user", dest="user",
55 help="choose auth user", metavar="USER")
56 p.add_option("--add", dest="add", action="store_true",
58 p.add_option("-v", "--version", dest="version",
59 action="store_true", help="print version")
61 (options, args) = p.parse_args()
68 confp = SafeConfigParser()
70 # Config file absolute path (~/.gwit/config)
71 conf_dir = os.path.expanduser("~/.gwit")
72 if not os.path.isdir(conf_dir):
74 conf_path = os.path.join(conf_dir, "config")
76 # Set gwit library path into python path
77 script_path = os.path.realpath(__file__)
78 #lib_path = os.path.join(os.path.dirname(script_path), "../")
79 #sys.path.insert(0, os.path.realpath(lib_path))
82 fexist = os.path.isfile(conf_path)
88 if not fexist or options.add:
90 from gwitlib import SetupWizard
95 # if setup ok, set settings
97 confp.set("DEFAULT", "default_user", setup.screen_name)
98 confp.add_section(setup.screen_name)
99 confp.set(setup.screen_name, "ckey", setup.keys[0])
100 confp.set(setup.screen_name, "csecret", setup.keys[1])
101 confp.set(setup.screen_name, "atoken", setup.keys[2])
102 confp.set(setup.screen_name, "asecret", setup.keys[3])
103 confp.set(setup.screen_name, "footer", "")
104 user = setup.screen_name
108 fp = open(conf_path, "w")
117 settings["DEFAULT"] = dict(confp.items("DEFAULT"))
118 for i in confp.sections():
119 settings[i] = dict(confp.items(i))
122 if options.user != None:
127 user = settings["DEFAULT"]["default_user"]
130 keys = (settings[user]["ckey"], settings[user]["csecret"],
131 settings[user]["atoken"], settings[user]["asecret"])
133 print >>sys.stderr, "[Error] User '%s' not exists in config file." % options.user
134 print >>sys.stderr, "Try `gwit --add` to add user."
138 from gwitlib import Main
139 gwit = Main(user, keys)