Cleaned up item view.
[straw.git] / scripts / straw
blobd2eb78beb1a114833b9ef27ea526c82e6183c061
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
58 def get_library_location():
59 source = None
60 if os.environ.has_key('STRAW_IN_SOURCE_DIR'):
61 source = os.path.join(get_root(), 'straw')
62 elif os.environ.has_key("STRAW_LIB"):
63 source = os.environ['STRAW_LIB']
64 else:
65 for d in sys.path:
66 sd = os.path.join(d, 'straw')
67 if os.path.isdir(sd):
68 source = sd
69 if not source:
70 raise "FileNotFoundError", "couldn't find straw library dir"
71 return source
73 def setup():
74 """
75 Run straw in the source tree
76 """
77 print 'Generating constants.py...'
78 libloc = get_library_location()
79 rootdir = get_root()
80 f = open (os.path.join(libloc,'constants.py'),'w')
81 f.write('APPNAME = "Straw"\n')
82 f.write('VERSION = "0.28-dev"\n')
83 f.write('STRAW_URL = "http://www.gnome.org/projects/straw"\n')
84 f.write('STRAW_REF_URL = "http://www.gnome.org/projects/straw-ref.html"\n')
85 f.write('dataroot = "%s"\n' % os.path.abspath(rootdir))
86 f.close()
88 # insert straw module into python path
89 sys.path.insert(0, rootdir)
90 print 'done'
92 def tear_down():
93 # remove created compiled files
94 import dircache
95 libloc = get_library_location()
96 httplibdir = os.path.join(libloc, "httplib2")
97 for d in [libloc, httplibdir]:
98 for fn in dircache.listdir(d):
99 filepath = os.path.join(d, fn)
100 if filepath.endswith(".pyc"):
101 os.remove(filepath)
102 os.remove(os.path.join(libloc, 'constants.py'))
103 print '.. exiting.'
106 def parse_args():
107 from optparse import OptionParser
108 usage = """%prog [--offline]\nDesktop feed aggregator"""
109 parser = OptionParser(usage=usage)
110 parser.set_defaults(offline=False)
111 parser.add_option("--offline", action="store_true", dest="offline", default=False,
112 help="run Straw in offline mode")
113 (options,args) = parser.parse_args()
114 return options
116 def run(options):
117 from straw import Application, Config, Constants
119 # set offline to false if offline. Previous releases just rely on the
120 # previous state of the 'offline' config. So if the user specifies
121 # offline, the next run will still be set to offline regardless if the
122 # user did not specifiy offline since it will still get the state of the
123 # offline config from the previous run.
124 offline = Config.set(Constants.OPTION_OFFLINE, options.offline)
126 app = Application.Application()
128 app.mainloop()
130 def main():
131 signal.signal(signal.SIGINT, signal.SIG_DFL)
132 options = parse_args()
133 in_source = os.environ.has_key("STRAW_IN_SOURCE_DIR")
134 prof = os.environ.has_key('STRAW_PROFILE')
136 if in_source:
137 setup()
139 if prof:
140 from tools import statprof
141 statprof.start()
143 initialize_gettext()
144 run(options)
146 if prof:
147 statprof.stop()
148 statprof.display()
150 if in_source:
151 tear_down()
153 if __name__ == '__main__':
154 main()