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 not os
.getenv('ROXLIB_DISABLE_ZEROINSTALL') and 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('0refresh rox.sourceforge.net'):
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'))
44 if major
== 1 and minor
== 9 and micro
< 10:
45 return # Can't check version
46 if not hasattr(rox
, 'roxlib_version'):
48 if (major
, minor
, micro
) <= rox
.roxlib_version
:
50 report_error("This program needs ROX-Lib2 (version %d.%d.%d) " % \
51 (major
, minor
, micro
) + "to run.\n" + \
52 "I tried all of these places:\n\n" + \
53 string
.join(paths
, '\n') + '\n\n' + \
54 "ROX-Lib2 is available from:\n" + \
55 "http://rox.sourceforge.net")
57 def report_error(err
):
58 "Write 'error' to stderr and, if possible, display a dialog box too."
60 sys
.stderr
.write('*** ' + err
+ '\n')
64 import pygtk
; pygtk
.require('2.0')
69 message
= gtk
.GtkLabel(err
+
70 '\n\nAlso, pygtk2 needs to be present')
71 win
.set_title('Missing ROX-Lib2')
72 win
.set_position(gtk
.WIN_POS_CENTER
)
73 message
.set_padding(20, 20)
74 win
.vbox
.pack_start(message
)
76 ok
= gtk
.GtkButton("OK")
77 ok
.set_flags(gtk
.CAN_DEFAULT
)
78 win
.action_area
.pack_start(ok
)
79 ok
.connect('clicked', gtk
.mainquit
)
82 win
.connect('destroy', gtk
.mainquit
)
86 box
= g
.MessageDialog(None, g
.MESSAGE_ERROR
, 0,
88 box
.set_title('Missing ROX-Lib2')
89 box
.set_position(g
.WIN_POS_CENTER
)
90 box
.set_default_response(g
.RESPONSE_OK
)