fix proxy support
[straw.git] / src / straw
blob44dcc666b8b6ced7764d1d86a12ade10c5023719
1 #!/usr/bin/env python
3 # Copyright (c) 2002-2004 Juri Pakaste <juri@iki.fi>
5 # This program is free software; you can redistribute it and/or
6 # modify it under the terms of the GNU General Public License as
7 # published by the Free Software Foundation; either version 2 of the
8 # License, or (at your option) any later version.
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 # General Public License for more details.
15 # You should have received a copy of the GNU General Public
16 # License along with this program; if not, write to the
17 # Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 # Boston, MA 02111-1307, USA.
20 # save the location of the script at the start before anything can modify
21 # sys.path
22 import sys
23 location = sys.path[0]
25 # wrap stdout to print unicode chars in the $TERM
26 import codecs
27 sys.stdout = codecs.lookup('utf-8')[-1](sys.stdout)
29 import signal
30 import os
31 import os.path
32 import time
33 import pygtk
34 pygtk.require("2.0")
35 import gtk
37 def find_straw_lib():
38 sdir = None
39 if ENV_IN_SOURCE:
40 sdir = os.path.join(location, "lib")
41 elif ENV_LIB_DIR:
42 sdir = os.environ["STRAW_LIB"]
43 else:
44 for d in sys.path:
45 sd = os.path.join(d, 'straw')
46 if os.path.isdir(sd):
47 sdir = sd
49 if not sdir:
50 h, t = os.path.split(os.path.split(os.path.abspath(sys.argv[0]))[0])
51 if t == 'bin':
52 libdir = os.path.join(h, 'lib')
53 fp = os.path.join(libdir, 'straw')
54 if os.path.isdir(fp):
55 sdir = fp
56 if not sdir:
57 raise "FileNotFoundError", "couldn't find straw library dir"
58 return sdir
60 def setup_source():
61 """
62 Run straw in the source tree
63 """
64 currentdir = os.path.dirname(os.path.abspath(sys.argv[0]))
65 prefix = os.path.abspath(os.path.join(currentdir, '..'))
66 print 'Generating constants.py...'
67 f = open (os.path.join(sdir,'constants.py'),'w')
68 f.write('APPNAME = "Straw"\n')
69 f.write('VERSION = "0.28"\n')
70 f.write('STRAW_URL = "http://www.gnome.org/projects/straw"\n')
71 f.write('STRAW_REF_URL = "http://www.gnome.org/projects/straw-ref.html"\n')
72 f.write('libdir = "%s"\n' % sdir)
73 f.write('localedir = "%s"\n' % os.path.join(prefix, 'po'))
74 f.write('datadir = "%s"\n' % os.path.join(prefix, 'data'))
75 f.write('imagedir = "%s"\n' % os.path.join(prefix, 'images'))
76 f.write('gladedir = "%s"\n' % os.path.join(prefix, 'glade'))
77 f.close()
78 print 'done'
80 def cleanup_source():
81 # remove created compiled files
82 import dircache
83 httplibdir = os.path.join(sdir, 'httplib2')
84 for d in [sdir, httplibdir]:
85 for fn in dircache.listdir(d):
86 filepath = os.path.join(d, fn)
87 if filepath.endswith(".pyc"):
88 os.remove(filepath)
89 os.remove(os.path.join(sdir, 'constants.py'))
90 print '.. exiting.'
93 def parse_args():
94 from optparse import OptionParser
95 usage = """%prog [--offline]\nDesktop feed aggregator"""
96 parser = OptionParser(usage=usage)
97 parser.set_defaults(offline=False)
98 parser.add_option("--offline", action="store_true", dest="offline", default=False,
99 help="run Straw in offline mode")
100 (options,args) = parser.parse_args()
101 return options
103 def run(options):
104 if ENV_IN_SOURCE:
105 from lib import Application, Config
106 else:
107 from straw import Application, Config
109 # set offline to false if offline. Previous releases just rely on the
110 # previous state of the 'offline' config. So if the user specifies
111 # offline, the next run will still be set to offline regardless if the
112 # user did not specifiy offline since it will still get the state of the
113 # offline config from the previous run.
114 config = Config.get_instance()
115 if options.offline:
116 config.offline = True
117 else:
118 config.offline = False
119 app = Application.Application()
120 # load tray if it's a standard install
121 if not ENV_IN_SOURCE:
122 app.load_tray()
123 app.mainloop()
125 def main():
126 signal.signal(signal.SIGINT, signal.SIG_DFL)
127 options = parse_args()
128 if ENV_IN_SOURCE:
129 setup_source()
131 run(options)
133 if ENV_IN_SOURCE:
134 cleanup_source()
136 # setup path and environment
137 ENV_IN_SOURCE = os.environ.has_key("STRAW_IN_SOURCE_DIR")
138 ENV_LIB_DIR = os.environ.has_key("STRAW_LIB")
139 sdir = find_straw_lib()
140 if sdir not in sys.path:
141 sys.path.insert(0,sdir)
143 if __name__ == '__main__':
144 main()