Esempio n. 1
0
 def testSplitCPV(self):
   """Test splitting CPV into components."""
   cpv = 'foo/bar-4.5.6_alpha-r6'
   cat, pv = cpv.split('/', 1)
   split_pv = portage_util.SplitPV(pv)
   split_cpv = portage_util.SplitCPV(cpv)
   self.assertEquals(split_cpv.category, cat)
   for k, v in split_pv._asdict().iteritems():
     self.assertEquals(getattr(split_cpv, k), v)
Esempio n. 2
0
def SplitPVPath(path):
    """Utility function to run both SplitEbuildPath and SplitPV.

  Args:
    path: Ebuild path to run those functions on.

  Returns:
    The output of SplitPV.
  """
    return portage_util.SplitPV(portage_util.SplitEbuildPath(path)[2])
Esempio n. 3
0
 def testSplitPV(self):
   """Test splitting PVs into package and version components."""
   pv = 'bar-1.2.3_rc1-r5'
   package, version_no_rev, rev = tuple(pv.split('-'))
   split_pv = portage_util.SplitPV(pv)
   self.assertEquals(split_pv.pv, pv)
   self.assertEquals(split_pv.package, package)
   self.assertEquals(split_pv.version_no_rev, version_no_rev)
   self.assertEquals(split_pv.rev, rev)
   self.assertEquals(split_pv.version, '%s-%s' % (version_no_rev, rev))
Esempio n. 4
0
    def _GetOverrideLicense(self):
        """Look in COPYRIGHT_ATTRIBUTION_DIR for license with copyright attribution.

    For dev-util/bsdiff-4.3-r5, the code will look for
    dev-util/bsdiff-4.3-r5
    dev-util/bsdiff-4.3
    dev-util/bsdiff

    It is ok to have more than one bsdiff license file, and an empty file acts
    as a rubout (i.e. an empty dev-util/bsdiff-4.4 will shadow dev-util/bsdiff
    and tell the licensing code to look in the package source for a license
    instead of using dev-util/bsdiff as an override).

    Returns:
      False (no license found) or a multiline license string.
    """
        license_read = None
        # dev-util/bsdiff-4.3-r5 -> bsdiff-4.3-r5
        filename = os.path.basename(self.fullnamerev)
        license_path = os.path.join(COPYRIGHT_ATTRIBUTION_DIR,
                                    os.path.dirname(self.fullnamerev))
        pv = portage_util.SplitPV(filename)
        pv_no_rev = '%s-%s' % (pv.package, pv.version_no_rev)
        for filename in (pv.pv, pv_no_rev, pv.package):
            file_path = os.path.join(license_path, filename)
            logging.debug(
                'Looking for override copyright attribution license in %s',
                file_path)
            if os.path.exists(file_path):
                # Turn
                # /../merlin/trunk/src/third_party/chromiumos-overlay/../dev-util/bsdiff
                # into
                # chromiumos-overlay/../dev-util/bsdiff
                short_dir_path = os.path.join(
                    *file_path.rsplit(os.path.sep, 5)[1:])
                license_read = 'Copyright Attribution License %s:\n\n' % short_dir_path
                license_read += ReadUnknownEncodedFile(
                    file_path, 'read copyright attribution license')
                break

        return license_read
Esempio n. 5
0
 def setUp(self):
     self.build_root = self.tempdir
     self.fake_packages = []
     # Prepare a fake chroot.
     self.fake_chroot = os.path.join(self.build_root,
                                     'chroot/build/amd64-host')
     fake_pkgdb_path = os.path.join(self.fake_chroot, 'var/db/pkg')
     os.makedirs(fake_pkgdb_path)
     for cat, pkgs in self.fake_pkgdb.iteritems():
         catpath = os.path.join(fake_pkgdb_path, cat)
         if cat == 'invalid':
             # Invalid category is a file. Should not be delved into.
             osutils.Touch(catpath)
             continue
         os.makedirs(catpath)
         for pkg in pkgs:
             pkgpath = os.path.join(catpath, pkg)
             if pkg == 'invalid':
                 # Invalid package is a file instead of a directory/
                 osutils.Touch(pkgpath)
                 continue
             os.makedirs(pkgpath)
             if pkg.endswith('-invalid'):
                 # Invalid package does not meet existence of "%s/%s.ebuild" file.
                 osutils.Touch(os.path.join(pkgpath, 'whatever'))
                 continue
             # Create the package.
             osutils.Touch(os.path.join(pkgpath, pkg + '.ebuild'))
             if cat.startswith('-'):
                 # Invalid category.
                 continue
             # Correct pkg.
             pv = portage_util.SplitPV(pkg)
             key = '%s/%s' % (cat, pv.package)
             self.fake_packages.append((key, pv.version))
     # Add contents to with/files-1.
     osutils.WriteFile(
         os.path.join(fake_pkgdb_path, 'with', 'files-1', 'CONTENTS'),
         ''.join(' '.join(entry) + '\n' for entry in self.fake_files))