Exemple #1
0
 def test_custom_pretty_printer(self):
     """Test pretty printing of deb822 objects and parsed relationships."""
     printer = CustomPrettyPrinter()
     # Test pretty printing of debian.deb822.Deb822 objects.
     deb822_object = deb822_from_string('''
         Package: pretty-printed-control-fields
         Version: 1.0
         Architecture: all
     ''')
     formatted_object = printer.pformat(deb822_object)
     assert normalize_repr_output(
         formatted_object) == normalize_repr_output('''
         {'Architecture': u'all',
          'Package': u'pretty-printed-control-fields',
          'Version': u'1.0'}
     ''')
     # Test pretty printing of RelationshipSet objects.
     relationship_set = parse_depends(
         'python-deb-pkg-tools, python-pip, python-pip-accel')
     formatted_object = printer.pformat(relationship_set)
     assert normalize_repr_output(
         formatted_object) == normalize_repr_output('''
         RelationshipSet(Relationship(name='python-deb-pkg-tools', architectures=()),
                         Relationship(name='python-pip', architectures=()),
                         Relationship(name='python-pip-accel', architectures=()))
     ''')
 def test_custom_pretty_printer(self):
     printer = CustomPrettyPrinter()
     # Test pretty printing of debian.deb822.Deb822 objects.
     self.assertEqual(
         remove_unicode_prefixes(
             printer.pformat(
                 deb822_from_string('''
         Package: pretty-printed-control-fields
         Version: 1.0
         Architecture: all
     '''))),
         remove_unicode_prefixes(
             dedent('''
         {'Architecture': u'all',
          'Package': u'pretty-printed-control-fields',
          'Version': u'1.0'}
     ''')))
     # Test pretty printing of RelationshipSet objects.
     depends_line = 'python-deb-pkg-tools, python-pip, python-pip-accel'
     self.assertEqual(
         printer.pformat(parse_depends(depends_line)),
         dedent('''
         RelationshipSet(Relationship(name='python-deb-pkg-tools'),
                         Relationship(name='python-pip'),
                         Relationship(name='python-pip-accel'))
     '''))
Exemple #3
0
    def setUp(self):
        SRC_DIR = os.path.join(os.path.dirname(os.path.realpath(__file__)), '../../../')
        self.control_file = os.path.join(SRC_DIR, 'debian/control')
        self.requirements_file = os.path.join(SRC_DIR, 'requirements.txt')

        self.dpkg_name = {
            'msgpack-python': 'python3-msgpack',
            'pyyaml': 'python3-yaml'
            }

        with open(self.control_file) as handle:
            control = handle.read()

        faucet_dpkg = str()
        for line in control.split("\n"):
            if line.startswith("Package: python3-faucet"):
                faucet_dpkg += line
            elif faucet_dpkg:
                if not line:
                    break
                faucet_dpkg += "{}\n".format(line)

        faucet_dpkg = parse_control_fields(deb822_from_string(faucet_dpkg))
        self.faucet_dpkg_deps = {}
        for dep in faucet_dpkg['Depends']:
            if isinstance(dep, VersionedRelationship):
                if dep.name not in self.faucet_dpkg_deps:
                    self.faucet_dpkg_deps[dep.name] = []
                self.faucet_dpkg_deps[dep.name].append("{}{}".format(dep.operator, dep.version))
Exemple #4
0
    def setUp(self):
        SRC_DIR = os.path.join(os.path.dirname(os.path.realpath(__file__)),
                               '../../../')
        self.control_file = os.path.join(SRC_DIR, 'debian/control')
        self.requirements_file = os.path.join(SRC_DIR, 'requirements.txt')

        self.dpkg_name = {
            'msgpack-python': 'python3-msgpack',
            'pyyaml': 'python3-yaml'
        }

        with open(self.control_file, 'r', encoding='utf-8') as handle:
            control = handle.read()

        faucet_dpkg = str()
        for line in control.split("\n"):
            if line.startswith("Package: python3-faucet"):
                faucet_dpkg += line
            elif faucet_dpkg:
                if not line:
                    break
                faucet_dpkg += "\n{}".format(line)

        faucet_dpkg = parse_control_fields(deb822_from_string(faucet_dpkg))
        self.faucet_dpkg_deps = {}
        for dep in faucet_dpkg['Depends']:
            if isinstance(dep, VersionedRelationship):
                if dep.name not in self.faucet_dpkg_deps:
                    self.faucet_dpkg_deps[dep.name] = []
                self.faucet_dpkg_deps[dep.name].append("{}{}".format(
                    dep.operator, dep.version))
def inspect_package_fields(archive, cache=None):
    r"""
    Get the fields (metadata) from a ``*.deb`` archive.

    :param archive: The pathname of an existing ``*.deb`` archive.
    :param cache: The :class:`.PackageCache` to use (defaults to :data:`None`).
    :returns: A dictionary with control file fields (the result of
              :func:`.parse_control_fields()`).

    Here's an example:

    >>> from deb_pkg_tools.package import inspect_package_fields
    >>> print(repr(inspect_package_fields('python3.4-minimal_3.4.0-1+precise1_amd64.deb')))
    {'Architecture': u'amd64',
     'Conflicts': RelationshipSet(VersionedRelationship(name=u'binfmt-support', operator=u'<<', version=u'1.1.2')),
     'Depends': RelationshipSet(VersionedRelationship(name=u'libpython3.4-minimal', operator=u'=', version=u'3.4.0-1+precise1'),
                                VersionedRelationship(name=u'libexpat1', operator=u'>=', version=u'1.95.8'),
                                VersionedRelationship(name=u'libgcc1', operator=u'>=', version=u'1:4.1.1'),
                                VersionedRelationship(name=u'zlib1g', operator=u'>=', version=u'1:1.2.0')),
     'Description': u'Minimal subset of the Python language (version 3.4)\n This package contains the interpreter and some essential modules.  It can\n be used in the boot process for some basic tasks.\n See /usr/share/doc/python3.4-minimal/README.Debian for a list of the modules\n contained in this package.',
     'Installed-Size': 3586,
     'Maintainer': u'Felix Krull <*****@*****.**>',
     'Multi-Arch': u'allowed',
     'Original-Maintainer': u'Matthias Klose <*****@*****.**>',
     'Package': u'python3.4-minimal',
     'Pre-Depends': RelationshipSet(VersionedRelationship(name=u'libc6', operator=u'>=', version=u'2.15')),
     'Priority': u'optional',
     'Recommends': u'python3.4',
     'Section': u'python',
     'Source': u'python3.4',
     'Suggests': RelationshipSet(Relationship(name=u'binfmt-support')),
     'Version': u'3.4.0-1+precise1'}

    """
    if cache:
        entry = cache.get_entry('control-fields', archive)
        value = entry.get_value()
        if value is not None:
            return value
    listing = execute('dpkg-deb', '-f', archive, logger=logger, capture=True)
    fields = parse_control_fields(deb822_from_string(listing))
    if cache:
        entry.set_value(fields)
    return fields
def inspect_package_fields(archive, cache=None):
    r"""
    Get the fields (metadata) from a ``*.deb`` archive.

    :param archive: The pathname of an existing ``*.deb`` archive.
    :param cache: The :class:`.PackageCache` to use (defaults to :data:`None`).
    :returns: A dictionary with control file fields (the result of
              :func:`.parse_control_fields()`).

    Here's an example:

    >>> from deb_pkg_tools.package import inspect_package_fields
    >>> print(repr(inspect_package_fields('python3.4-minimal_3.4.0-1+precise1_amd64.deb')))
    {'Architecture': u'amd64',
     'Conflicts': RelationshipSet(VersionedRelationship(name=u'binfmt-support', operator=u'<<', version=u'1.1.2')),
     'Depends': RelationshipSet(VersionedRelationship(name=u'libpython3.4-minimal', operator=u'=', version=u'3.4.0-1+precise1'),
                                VersionedRelationship(name=u'libexpat1', operator=u'>=', version=u'1.95.8'),
                                VersionedRelationship(name=u'libgcc1', operator=u'>=', version=u'1:4.1.1'),
                                VersionedRelationship(name=u'zlib1g', operator=u'>=', version=u'1:1.2.0')),
     'Description': u'Minimal subset of the Python language (version 3.4)\n This package contains the interpreter and some essential modules.  It can\n be used in the boot process for some basic tasks.\n See /usr/share/doc/python3.4-minimal/README.Debian for a list of the modules\n contained in this package.',
     'Installed-Size': 3586,
     'Maintainer': u'Felix Krull <*****@*****.**>',
     'Multi-Arch': u'allowed',
     'Original-Maintainer': u'Matthias Klose <*****@*****.**>',
     'Package': u'python3.4-minimal',
     'Pre-Depends': RelationshipSet(VersionedRelationship(name=u'libc6', operator=u'>=', version=u'2.15')),
     'Priority': u'optional',
     'Recommends': u'python3.4',
     'Section': u'python',
     'Source': u'python3.4',
     'Suggests': RelationshipSet(Relationship(name=u'binfmt-support')),
     'Version': u'3.4.0-1+precise1'}

    """
    if cache:
        entry = cache.get_entry('control-fields', archive)
        value = entry.get_value()
        if value is not None:
            return value
    listing = execute('dpkg-deb', '-f', archive, logger=logger, capture=True)
    fields = parse_control_fields(deb822_from_string(listing))
    if cache:
        entry.set_value(fields)
    return fields
 def test_custom_pretty_printer(self):
     printer = CustomPrettyPrinter()
     # Test pretty printing of debian.deb822.Deb822 objects.
     self.assertEqual(remove_unicode_prefixes(printer.pformat(deb822_from_string('''
         Package: pretty-printed-control-fields
         Version: 1.0
         Architecture: all
     '''))), remove_unicode_prefixes(dedent('''
         {'Architecture': u'all',
          'Package': u'pretty-printed-control-fields',
          'Version': u'1.0'}
     ''')))
     # Test pretty printing of RelationshipSet objects.
     depends_line = 'python-deb-pkg-tools, python-pip, python-pip-accel'
     self.assertEqual(printer.pformat(parse_depends(depends_line)), dedent('''
         RelationshipSet(Relationship(name='python-deb-pkg-tools'),
                         Relationship(name='python-pip'),
                         Relationship(name='python-pip-accel'))
     '''))
Exemple #8
0
 def test_custom_pretty_printer(self):
     """Test pretty printing of deb822 objects and parsed relationships."""
     printer = CustomPrettyPrinter()
     # Test pretty printing of debian.deb822.Deb822 objects.
     deb822_object = deb822_from_string('''
         Package: pretty-printed-control-fields
         Version: 1.0
         Architecture: all
     ''')
     formatted_object = printer.pformat(deb822_object)
     assert normalize_repr_output(formatted_object) == normalize_repr_output('''
         {'Architecture': u'all',
          'Package': u'pretty-printed-control-fields',
          'Version': u'1.0'}
     ''')
     # Test pretty printing of RelationshipSet objects.
     relationship_set = parse_depends('python-deb-pkg-tools, python-pip, python-pip-accel')
     formatted_object = printer.pformat(relationship_set)
     assert normalize_repr_output(formatted_object) == normalize_repr_output('''
         RelationshipSet(Relationship(name='python-deb-pkg-tools', architectures=()),
                         Relationship(name='python-pip', architectures=()),
                         Relationship(name='python-pip-accel', architectures=()))
     ''')
Exemple #9
0
    def test_requirements_match(self):
        """Test all requirements are listed as apt package dependencies."""

        SRC_DIR = os.path.join(os.path.dirname(os.path.realpath(__file__)),
                               '../../../')
        control_file = os.path.join(SRC_DIR, 'debian/control')
        requirements_file = os.path.join(SRC_DIR, 'requirements.txt')

        real_name = {
            'msgpack-python': 'python3-msgpack',
            'pyyaml': 'python3-yaml'
        }

        with open(control_file) as handle:
            control = handle.read()

        faucet_dpkg = str()
        for line in control.split("\n"):
            if line.startswith("Package: python3-faucet"):
                faucet_dpkg += line
            elif len(faucet_dpkg) > 0:
                if not line:
                    break
                faucet_dpkg += "{}\n".format(line)

        faucet_dpkg = parse_control_fields(deb822_from_string(faucet_dpkg))
        faucet_dpkg_deps = [x.name for x in faucet_dpkg['Depends']]

        for item in pip.req.parse_requirements(requirements_file,
                                               session="unittest"):
            if isinstance(item, pip.req.InstallRequirement):
                if item.name in real_name:
                    self.assertIn(real_name[item.name], faucet_dpkg_deps)
                else:
                    self.assertIn("python3-{}".format(item.name),
                                  faucet_dpkg_deps)
Exemple #10
0
def parse_pkgs_gz(file):
    fields = []
    s = gzip.open(file, 'rb').read()
    for i in s.strip().split('\n\n'):
        fields.append(parse_control_fields(deb822_from_string(i)))
    return fields
Exemple #11
0
            d['_from'] = 'packages/' + pname
            d['_to'] = 'packages/' + oneDep.name
            relation = edgeCol.createDocument(d).save()
        else:
            print("Unknown relationshitp: " + repr(oneDep))


#
# Main import routine
#

onePackage = ''
for line in open('/tmp/allpackages', encoding='utf-8'):
    # Package blocks are separated by new lines.
    if len(line) == 1 and len(onePackage) > 4:
        pkg = deb822_from_string(onePackage)
        pname = pkg['Package']
        pkg1 = parse_control_fields(pkg)
        p = PackageToDict(pkg1)
        try:
            packagesCol.createDocument(p).save()
            for key in pkg1.keys():
                # filter for fields with relations:
                if isinstance(pkg1[key], deb_pkg_tools.deps.RelationshipSet):
                    # save one relation set to field:
                    saveDependencyToEdgeCol(getEdgeCol(key), pkg1[key], pname,
                                            False)
            onePackage = ''
        except CreationError:
            pass
    else: