1 # Most of the common code needed by ROX applications is in ROX-Lib2.
2 # Except this code, which is needed to find ROX-Lib2 in the first place!
4 # Just make sure you import findrox before importing anything inside
8 from os
.path
import exists
11 def version(major
, minor
, micro
):
12 """Find ROX-Lib2, with a version >= (major, minor, micro), and
13 add it to sys.path. If version is missing or too old, either
14 prompt the user, or (if possible) upgrade it automatically."""
16 if os
.path
.exists('/uri/0install/rox.sourceforge.net'):
17 # We're using ZeroInstall. Good :-)
18 zpath
= '/uri/0install/rox.sourceforge.net/lib/ROX-Lib2/' \
20 if os
.path
.exists(zpath
):
21 vs
= os
.readlink(zpath
).split('-')[-1]
22 v
= map(int, vs
.split('.'))
23 if v
[0] < major
or v
[1] < minor
or v
[2] < micro
:
24 if os
.system('cd /uri/0install/rox.sourceforge.net; 0refresh'):
25 report_error('Using ROX-Lib in Zero Install, but cached version (%s) is too old (need %d.%d.%d) and updating failed (is zero-install running?)' % (vs
, major
, minor
, micro
))
26 sys
.path
.append(zpath
+ '/python')
28 print >>sys
.stderr
, "Using Zero Install, but failed to " \
29 "fetch", zpath
, "-- trying non-0install system."
32 path
= os
.environ
['LIBDIRPATH']
33 paths
= string
.split(path
, ':')
35 paths
= [os
.environ
['HOME'] + '/lib',
36 '/usr/local/lib', '/usr/lib' ]
39 p
= os
.path
.join(p
, 'ROX-Lib2')
41 # TODO: check version is new enough
42 sys
.path
.append(os
.path
.join(p
, 'python'))
45 report_error("This program needs ROX-Lib2 to run.\n" + \
46 "I tried all of these places:\n\n" + \
47 string
.join(paths
, '\n') + '\n\n' + \
48 "ROX-Lib2 is available from:\n" + \
49 "http://rox.sourceforge.net")
51 def report_error(err
):
52 "Write 'error' to stderr and, if possible, display a dialog box too."
54 sys
.stderr
.write('*** ' + err
+ '\n')
58 import pygtk
; pygtk
.require('2.0')
63 message
= gtk
.GtkLabel(err
+
64 '\n\nAlso, pygtk2 needs to be present')
65 win
.set_title('Missing ROX-Lib2')
66 win
.set_position(gtk
.WIN_POS_CENTER
)
67 message
.set_padding(20, 20)
68 win
.vbox
.pack_start(message
)
70 ok
= gtk
.GtkButton("OK")
71 ok
.set_flags(gtk
.CAN_DEFAULT
)
72 win
.action_area
.pack_start(ok
)
73 ok
.connect('clicked', gtk
.mainquit
)
76 win
.connect('destroy', gtk
.mainquit
)
80 box
= g
.MessageDialog(None, g
.MESSAGE_ERROR
, 0,
82 box
.set_title('Missing ROX-Lib2')
83 box
.set_position(g
.WIN_POS_CENTER
)
84 box
.set_default_response(g
.RESPONSE_OK
)