home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2008 February / PCWFEB08.iso / Software / Freeware / Miro 1.0 / Miro_Installer.exe / xulrunner / python / resources.py < prev    next >
Encoding:
Python Source  |  2007-11-12  |  2.7 KB  |  66 lines

  1. # Miro - an RSS based video player application
  2. # Copyright (C) 2005-2007 Participatory Culture Foundation
  3. #
  4. # This program is free software; you can redistribute it and/or modify
  5. # it under the terms of the GNU General Public License as published by
  6. # the Free Software Foundation; either version 2 of the License, or
  7. # (at your option) any later version.
  8. #
  9. # This program is distributed in the hope that it will be useful,
  10. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12. # GNU General Public License for more details.
  13. #
  14. # You should have received a copy of the GNU General Public License
  15. # along with this program; if not, write to the Free Software
  16. # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
  17.  
  18. from xpcom import components
  19. import os, sys
  20. import re
  21. import urllib
  22.  
  23. import config
  24. import prefs
  25.  
  26. # Strategy: ask the directory service for
  27. # NS_XPCOM_CURRENT_PROCESS_DIR, the directory "associated with this
  28. # process," which is read to mean the root of the Mozilla
  29. # installation. Use a fixed offset from this path.
  30.  
  31. # Another copy appears in components/pybridge.py, in the bootstrap
  32. # code; if you change this function, change that one too.
  33. def appRoot():
  34.     # This reports the path to xulrunner.exe -- admittedly a little
  35.     # misleading. In general, this will be in a 'xulrunner'
  36.     # subdirectory underneath the actual application root directory.
  37.     klass = components.classes["@mozilla.org/file/directory_service;1"]
  38.     service = klass.getService(components.interfaces.nsIProperties)
  39.     file = service.get("XCurProcD", components.interfaces.nsIFile)
  40.     return file.path
  41.  
  42. def resourceRoot():
  43.     return os.path.join(appRoot(), '..', 'resources')
  44.  
  45. # Note: some of these functions are probably not absolutely correct in
  46. # the face of funny characters in the input paths. In particular,
  47. # url() doesn't DTRT when the path contains spaces. But they should be
  48. # sufficient for resolving resources, since we have control over the
  49. # filenames.
  50.  
  51. # Find the full path to a resource data file. 'relative_path' is
  52. # expected to be supplied in Unix format, with forward-slashes as
  53. # separators. The output, though, uses the native platform separator.
  54. def path(relative_path):
  55.     abspath = os.path.abspath(os.path.join(resourceRoot(), relative_path))
  56.     return abspath.replace("/", "\\")
  57.  
  58. def url(relative_path):
  59.     return absoluteUrl(path(relative_path))
  60.  
  61. def absoluteUrl(absolute_path):
  62.     """Like url, but without adding the resource directory.
  63.     """
  64.     absolute_path = absolute_path.encode('utf_8')
  65.     return u"file:///" + urllib.quote(absolute_path, safe=":~\\")
  66.