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.py < prev    next >
Encoding:
Python Source  |  2006-08-02  |  2.0 KB  |  54 lines

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