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.
15 If 'rox' is already in PYTHONPATH, just use that (assume the injector
22 #print "Using ROX-Lib in PYTHONPATH"
23 if (major
, minor
, micro
) > rox
.roxlib_version
:
24 print >>sys
.stderr
, "WARNING: ROX-Lib version " \
25 "%d.%d.%d requested, but using version " \
26 "%d.%d.%d from %s" % \
28 rox
.roxlib_version
[0],
29 rox
.roxlib_version
[1],
30 rox
.roxlib_version
[2],
34 if not os
.getenv('ROXLIB_DISABLE_ZEROINSTALL') and os
.path
.exists('/uri/0install/rox.sourceforge.net'):
35 # We're using ZeroInstall. Good :-)
36 zpath
= '/uri/0install/rox.sourceforge.net/lib/ROX-Lib2/' \
38 if os
.path
.exists(zpath
):
39 vs
= os
.readlink(zpath
).split('-')[-1]
40 v
= map(int, vs
.split('.'))
41 if v
[0] < major
or v
[1] < minor
or v
[2] < micro
:
42 if os
.system('0refresh rox.sourceforge.net'):
43 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
))
44 sys
.path
.append(zpath
+ '/python')
46 print >>sys
.stderr
, "Using Zero Install, but failed to " \
47 "fetch", zpath
, "-- trying non-0install system."
50 path
= os
.environ
['LIBDIRPATH']
51 paths
= string
.split(path
, ':')
53 paths
= [os
.environ
['HOME'] + '/lib',
54 '/usr/local/lib', '/usr/lib' ]
57 p
= os
.path
.join(p
, 'ROX-Lib2')
59 # TODO: check version is new enough
60 sys
.path
.append(os
.path
.join(p
, 'python'))
62 if major
== 1 and minor
== 9 and micro
< 10:
63 return # Can't check version
64 if not hasattr(rox
, 'roxlib_version'):
66 if (major
, minor
, micro
) <= rox
.roxlib_version
:
68 report_error("This program needs ROX-Lib2 (version %d.%d.%d) " % \
69 (major
, minor
, micro
) + "to run.\n" + \
70 "I tried all of these places:\n\n" + \
71 string
.join(paths
, '\n') + '\n\n' + \
72 "ROX-Lib2 is available from:\n" + \
73 "http://rox.sourceforge.net")
75 def report_error(err
):
76 "Write 'error' to stderr and, if possible, display a dialog box too."
78 sys
.stderr
.write('*** ' + err
+ '\n')
82 import pygtk
; pygtk
.require('2.0')
87 message
= gtk
.GtkLabel(err
+
88 '\n\nAlso, pygtk2 needs to be present')
89 win
.set_title('Missing ROX-Lib2')
90 win
.set_position(gtk
.WIN_POS_CENTER
)
91 message
.set_padding(20, 20)
92 win
.vbox
.pack_start(message
)
94 ok
= gtk
.GtkButton("OK")
95 ok
.set_flags(gtk
.CAN_DEFAULT
)
96 win
.action_area
.pack_start(ok
)
97 ok
.connect('clicked', gtk
.mainquit
)
100 win
.connect('destroy', gtk
.mainquit
)
104 box
= g
.MessageDialog(None, g
.MESSAGE_ERROR
, 0,
106 box
.set_title('Missing ROX-Lib2')
107 box
.set_position(g
.WIN_POS_CENTER
)
108 box
.set_default_response(g
.RESPONSE_OK
)