Cleaned up item view.
[straw.git] / scripts / straw-local
blobcb74e8e77d50c0e5797f6863e66414f5e15e1259
1 #!/usr/bin/env python
3 # Copyright (c) 2002-2004 Juri Pakaste <juri@iki.fi>
4 # Copyright (c) 2005-2007 Straw Contributors
6 # This program is free software; you can redistribute it and/or
7 # modify it under the terms of the GNU General Public License as
8 # published by the Free Software Foundation; either version 2 of the
9 # License, or (at your option) any later version.
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 GNU
14 # General Public License for more details.
16 # You should have received a copy of the GNU General Public
17 # License along with this program; if not, write to the
18 # Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 # Boston, MA 02111-1307, USA.
22 # wrap stdout to print unicode chars in the $TERM
23 import codecs, sys
24 sys.stdout = codecs.lookup('utf-8')[-1](sys.stdout)
26 import signal, os, os.path, time
27 import pygtk
28 pygtk.require("2.0")
29 import gtk, gtk.glade
32 def initialize_gettext():
33 import gettext, locale
34 from straw import defs
36 appname = defs.PACKAGE
37 localedir = "%s/%s" % (defs.DATA_DIR,'locale')
39 gettext.bindtextdomain(appname, localedir)
40 gettext.bind_textdomain_codeset(appname, 'UTF-8')
41 gettext.textdomain(appname)
42 gettext.install(appname, localedir, unicode=1)
44 locale.bindtextdomain(appname, localedir)
45 locale.bind_textdomain_codeset(appname, localedir)
46 locale.textdomain(appname)
48 gtk.glade.bindtextdomain(appname, localedir)
49 return
51 def get_root():
52 dir = os.path.dirname (os.path.abspath
53 (sys._getframe().f_code.co_filename))
54 rootdir = os.path.abspath(os.path.join(dir, ".."))
55 return rootdir
57 def get_library_location():
58 return os.path.join(get_root(), 'straw')
60 def setup():
61 """
62 Run straw in the source tree
63 """
64 # insert straw module into python path
65 sys.path.insert(0, get_root())
67 # fake straw.defs
68 import imp
69 import straw
70 m = straw.defs = sys.modules["straw.defs"] = imp.new_module("straw.defs")
72 m.BIN_DIR = None
73 m.DATA_DIR = None
74 m.LIB_DIR = None
75 m.VERSION = "uninstalled"
76 m.PACKAGE = "straw"
77 m.PYTHONDIR = None
78 m.STRAW_HOME = "http://www.gnome.org/projects/straw"
79 m.STRAW_DATA_DIR = os.path.join(get_root(), "data")
81 from straw import error
82 error.setup_log()
84 def tear_down():
85 # remove created compiled files
86 import dircache
87 libloc = get_library_location()
88 httplibdir = os.path.join(libloc, "httplib2")
89 for d in [libloc, httplibdir]:
90 for fn in dircache.listdir(d):
91 filepath = os.path.join(d, fn)
92 if filepath.endswith(".pyc"):
93 os.remove(filepath)
95 def parse_args():
96 from optparse import OptionParser
97 usage = """%prog [--offline]\nDesktop feed aggregator"""
98 parser = OptionParser(usage=usage)
99 parser.set_defaults(offline=False)
100 parser.add_option("--offline", action="store_true", dest="offline", default=False,
101 help="run Straw in offline mode")
102 (options,args) = parser.parse_args()
103 return options
105 def run(options):
106 from straw import Application, Config, Constants
108 # set offline to false if offline. Previous releases just rely on the
109 # previous state of the 'offline' config. So if the user specifies
110 # offline, the next run will still be set to offline regardless if the
111 # user did not specifiy offline since it will still get the state of the
112 # offline config from the previous run.
113 offline = Config.set(Constants.OPTION_OFFLINE, options.offline)
115 app = Application.Application()
117 app.mainloop()
119 def main():
120 signal.signal(signal.SIGINT, signal.SIG_DFL)
121 options = parse_args()
122 prof = os.environ.has_key('STRAW_PROFILE')
124 setup()
126 if prof:
127 from tools import statprof
128 statprof.start()
130 initialize_gettext()
131 run(options)
133 if prof:
134 statprof.stop()
135 statprof.display()
137 tear_down()
139 if __name__ == '__main__':
140 main()