Rev 190: Update code to properly handle loading failures. in http://bazaar.launchpad.net/%7Ejameinel/bzr-gtk/small-fixes
John Arbash Meinel
john at arbash-meinel.com
Thu Apr 19 22:31:18 BST 2007
At http://bazaar.launchpad.net/%7Ejameinel/bzr-gtk/small-fixes
------------------------------------------------------------
revno: 190
revision-id: john at arbash-meinel.com-20070419213038-80g223n0050jmphn
parent: john at arbash-meinel.com-20070419210440-v5dnea8gbau0a8fm
committer: John Arbash Meinel <john at arbash-meinel.com>
branch nick: gtk
timestamp: Thu 2007-04-19 16:30:38 -0500
message:
Update code to properly handle loading failures.
And do more searching to find the glade and .ui files.
In 'olive-gtk' the '_' function was not defined, so it would die when
trying to report startup failures.
In 'olive/guifiles.py' it now searches around for olive.glade
rather than only looking in 2 places. Once it finds olive.glade,
it assumes that cmenu.ui will be nearby.
modified:
olive-gtk olivegtk-20060716233821-osq2ryyn2ht8pe91-1
olive/guifiles.py gladefile.py-20061025081716-mc0e5w3fcin4rcgv-1
-------------- next part --------------
=== modified file 'olive-gtk'
--- a/olive-gtk 2007-02-04 12:11:31 +0000
+++ b/olive-gtk 2007-04-19 21:30:38 +0000
@@ -37,19 +37,25 @@
os.execvp(python, [python] + sys.argv)
except OSError:
pass
- print >>sys.stderr, _('bzr: error: cannot find a suitable python interpreter (need %d.%d or later)') % NEED_VERS
+ print >>sys.stderr, ('bzr: error: cannot find a suitable python interpreter'
+ ' (need %d.%d or later)'
+ ) % NEED_VERS
sys.exit(1)
try:
- import pygtk
- pygtk.require("2.0")
+ import pygtk
+ pygtk.require("2.0")
except:
- pass
+ pass
+
try:
- import gtk
- import gtk.glade
+ import gtk
+ import gtk.glade
except:
- print >>sys.stderr, _('You need to install python-glade2 and/or pygtk2 (gtk2) or set your PYTHONPATH correctly.\ntry: export PYTHONPATH=/usr/local/lib/python2.4/site-packages/')
+ print >>sys.stderr, ('You need to install python-glade2 and/or pygtk2 (gtk2)'
+ ' or set your PYTHONPATH correctly.\n'
+ 'try: export PYTHONPATH=/usr/local/lib/python2.4/site-packages/'
+ )
sys.exit(1)
# gettext support
=== modified file 'olive/guifiles.py'
--- a/olive/guifiles.py 2006-10-25 16:29:18 +0000
+++ b/olive/guifiles.py 2007-04-19 21:30:38 +0000
@@ -18,37 +18,41 @@
import sys
+GLADEFILENAMES = ["/usr/share/olive/olive.glade",
+ "/usr/local/share/olive/olive.glade",
+ "/opt/share/olive/olive.glade",
+ "/opt/local/share/olive/olive.glade",
+ ]
+
# Get the glade file name
if sys.platform == 'win32':
- GLADEFILENAME = os.path.join(os.path.dirname(sys.executable),
- "share/olive/olive.glade")
-else:
- GLADEFILENAME = "/usr/share/olive/olive.glade"
-
-if not os.path.isfile(GLADEFILENAME):
- # Load from sources directory if not installed
- dir_ = os.path.split(os.path.dirname(__file__))[0]
- GLADEFILENAME = os.path.join(dir_, "olive.glade")
- # Check again
- if not os.path.isfile(GLADEFILENAME):
- # Fail
- print _('Glade file cannot be found.')
- sys.exit(1)
+ GLADEFILENAMES = [os.path.join(os.path.dirname(sys.executable),
+ "share/olive/olive.glade")]
+
+dir_ = os.path.split(os.path.dirname(__file__))[0]
+# Check first if we are running from source
+GLADEFILENAMES.insert(0, os.path.join(dir_, "olive.glade"))
+
+GLADEFILENAME = None
+
+for path in GLADEFILENAMES:
+ if os.path.isfile(path):
+ GLADEFILENAME = path
+ break
+
+if GLADEFILENAME is None:
+ # Fail
+ print _('Glade file cannot be found.')
+ sys.exit(1)
+
+UIFILEDIR = os.path.dirname(GLADEFILENAME)
# Get the cmenu.ui file name
-if sys.platform == 'win32':
- UIFILENAME = os.path.dirname(sys.executable) + "/share/olive/cmenu.ui"
-else:
- UIFILENAME = "/usr/share/olive/cmenu.ui"
+UIFILENAME = os.path.join(UIFILEDIR, 'cmenu.ui')
if not os.path.isfile(UIFILENAME):
- # Load from current directory if not installed
- dir_ = os.path.split(os.path.dirname(__file__))[0]
- UIFILENAME = os.path.join(dir_, "cmenu.ui")
- # Check again
- if not os.path.isfile(UIFILENAME):
- # Fail
- print _('UI description file cannot be found.')
- sys.exit(1)
+ # Fail
+ print _('UI description file cannot be found.')
+ sys.exit(1)
More information about the bazaar-commits
mailing list