def gem(b): logging.info('searching for Ruby gems') # Precompile a pattern for extracting the version of Ruby that was used # to install the gem. pattern = re.compile(r'gems/([^/]+)/gems') # Look for gems in all the typical places. This is easier than looking # for `gem` commands, which may or may not be on `PATH`. for globname in ('/usr/lib/ruby/gems/*/gems', '/usr/local/lib/ruby/gems/*/gems', '/var/lib/gems/*/gems'): for dirname in glob.glob(globname): # The `ruby1.9.1` (really 1.9.2) package on Maverick begins # including RubyGems in the `ruby1.9.1` package and marks the # `rubygems1.9.1` package as virtual. So for Maverick and # newer, the manager is actually `ruby1.9.1`. match = pattern.search(dirname) if blueprint.is_rpmpkgmgr(): manager = 'rubygems' else: if '1.9.1' == match.group(1) and blueprint.rubygems_virtual(): manager = 'ruby%s' % (match.group(1)) else: manager = 'rubygems%s' % (match.group(1)) for entry in os.listdir(dirname): package, version = entry.rsplit('-', 1) b.packages[manager][package].append(version)
def _dpkg_query_S(pathname): """ Return a list of package names that contain `pathname` or `[]`. This really can be a list thanks to `dpkg-divert`(1). """ if blueprint.is_rpmpkgmgr(): p = subprocess.Popen(['rpm', '-qf', '--qf', '%{name}', pathname], close_fds=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) stdout, stderr = p.communicate() if 0 != p.returncode: # If `pathname` isn't in a package but is a symbolic link, see if # the symbolic link is in a package. `postinst` programs commonly # display this pattern. try: return _dpkg_query_S(os.readlink(pathname)) except OSError: return [] packages = [] for line in stdout.splitlines(): if line.startswith('diversion '): continue try: p, _ = line.split(':', 1) packages.extend([package.strip() for package in p.split(',')]) except ValueError: pass return packages try: p = subprocess.Popen(['dpkg-query', '-S', pathname], close_fds=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) except OSError: return [] stdout, stderr = p.communicate() if 0 != p.returncode: # If `pathname` isn't in a package but is a symbolic link, see if # the symbolic link is in a package. `postinst` programs commonly # display this pattern. try: return _dpkg_query_S(os.readlink(pathname)) except OSError: return [] packages = [] for line in stdout.splitlines(): if line.startswith('diversion '): continue try: p, _ = line.split(':', 1) packages.extend([package.strip() for package in p.split(',')]) except ValueError: pass return packages
def _rpm_modified(package, pathname): """ Determine if a particular file in a package has been modified """ if not blueprint.is_rpmpkgmgr(): return false if not hasattr(_rpm_modified, '_cache'): _rpm_modified._cache = {} if package not in _rpm_modified._cache: p = subprocess.Popen(['/bin/rpm', '-Vf', pathname], close_fds=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) stdout, stderr = p.communicate() _rpm_modified._cache[package] = stdout result = _rpm_modified._cache[package].find(pathname) > -1 return result
def _dpkg_md5sum(package, pathname): """ Find the MD5 sum of the packaged version of pathname or `None` if the `pathname` does not come from a Debian package. """ if blueprint.is_rpmpkgmgr(): return None try: for line in open('/var/lib/dpkg/info/%s.md5sums' % (package)): if line.endswith('%s\n' % (pathname[1:])): return line[0:32] except IOError: pass try: for line in open('/var/lib/dpkg/status'): if line.startswith(' %s ' % (pathname)): return line[-33:-1] except IOError: pass return None
def _dpkg_query_S(pathname): """ Return the name of the package that contains `pathname` or `None`. """ if blueprint.is_rpmpkgmgr(): p = subprocess.Popen(['rpm', '-qf', '--qf', '%{name}', pathname], close_fds=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) stdout, stderr = p.communicate() if 0 != p.returncode: # If `pathname` isn't in a package but is a symbolic link, see if # the symbolic link is in a package. `postinst` programs commonly # display this pattern. try: return _dpkg_query_S(os.readlink(pathname)) except OSError: return None package = stdout return package p = subprocess.Popen(['dpkg-query', '-S', pathname], close_fds=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) stdout, stderr = p.communicate() if 0 != p.returncode: # If `pathname` isn't in a package but is a symbolic link, see if # the symbolic link is in a package. `postinst` programs commonly # display this pattern. try: return _dpkg_query_S(os.readlink(pathname)) except OSError: return None package, _ = stdout.split(':',1) return package
def _dpkg_query_S(pathname): """ Return the name of the package that contains `pathname` or `None`. """ if blueprint.is_rpmpkgmgr(): p = subprocess.Popen(['rpm', '-qf', '--qf', '%{name}', pathname], close_fds=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) stdout, stderr = p.communicate() if 0 != p.returncode: # If `pathname` isn't in a package but is a symbolic link, see if # the symbolic link is in a package. `postinst` programs commonly # display this pattern. try: return _dpkg_query_S(os.readlink(pathname)) except OSError: return None package = stdout return package p = subprocess.Popen(['dpkg-query', '-S', pathname], close_fds=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) stdout, stderr = p.communicate() if 0 != p.returncode: # If `pathname` isn't in a package but is a symbolic link, see if # the symbolic link is in a package. `postinst` programs commonly # display this pattern. try: return _dpkg_query_S(os.readlink(pathname)) except OSError: return None package, _ = stdout.split(':', 1) return package