home *** CD-ROM | disk | FTP | other *** search
/ PC Welt 2006 November (DVD) / PCWELT_11_2006.ISO / casper / filesystem.squashfs / usr / share / launchpad-integration / launchpadintegration / urls.pyc (.txt) < prev   
Encoding:
Python Compiled Bytecode  |  2006-08-31  |  2.2 KB  |  66 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.4)
  3.  
  4. import urlparse
  5. import subprocess
  6. import os
  7.  
  8. def showUrl(url, logger = None):
  9.     '''Show the given URL in the user\'s preferred browser.
  10.  
  11.     Currently just shells out to gnome-open, which uses the browser
  12.     picked in the Gnome "preferred applications" control panel.
  13.     If Gnome is not available it uses the x-www-browser setting
  14.     '''
  15.     if logger:
  16.         logger.info('opening URL %s', url)
  17.     
  18.     if os.path.exists('/usr/bin/gnome-open'):
  19.         command = [
  20.             'gnome-open',
  21.             url]
  22.     elif os.path.exists('/usr/bin/kfmclient'):
  23.         command = [
  24.             'kfmclient',
  25.             'openURL',
  26.             url]
  27.     else:
  28.         command = [
  29.             'x-www-browser',
  30.             url]
  31.     if os.getuid() == 0 and os.environ.has_key('SUDO_USER'):
  32.         command = [
  33.             'sudo',
  34.             '-u',
  35.             os.environ['SUDO_USER']] + command
  36.     
  37.     p = subprocess.Popen(command, close_fds = True, stdin = subprocess.PIPE, stdout = subprocess.PIPE)
  38.     p.communicate()
  39.     return p.returncode
  40.  
  41.  
  42. def launchpadDistroPrefix():
  43.     distro = subprocess.Popen([
  44.         'lsb_release',
  45.         '--id',
  46.         '--short'], stdin = subprocess.PIPE, stdout = subprocess.PIPE).communicate()[0].strip()
  47.     release = subprocess.Popen([
  48.         'lsb_release',
  49.         '--codename',
  50.         '--short'], stdin = subprocess.PIPE, stdout = subprocess.PIPE).communicate()[0].strip()
  51.     return 'https://launchpad.net/distros/%s/%s/' % (distro.lower(), release)
  52.  
  53.  
  54. def getSourcePackageUrl(pkginfo):
  55.     prefix = launchpadDistroPrefix()
  56.     return urlparse.urljoin(prefix, '+sources/%s/' % pkginfo.sourcepackage)
  57.  
  58.  
  59. def getInfoUrl(pkginfo):
  60.     return urlparse.urljoin(getSourcePackageUrl(pkginfo), '+gethelp')
  61.  
  62.  
  63. def getTranslateUrl(pkginfo):
  64.     return urlparse.urljoin(getSourcePackageUrl(pkginfo), '+translate')
  65.  
  66.