Пример #1
0
def gen_package(filepath):
    deb_info = inspect_package_fields(filepath)
    ret = 'Package: {}\n'.format(deb_info.get('Package'))
    ret += 'Name: {}\n'.format(deb_info.get('Name'))
    ret += 'Description: {}\n'.format(deb_info.get('Description'))
    ret += 'Section: {}\n'.format(deb_info.get('Section'))
    ret += 'Depends: {}\n'.format(deb_info.get('Depends') is not None and deb_info.get('Depends') or '')
    ret += 'Conflicts: {}\n'.format(deb_info.get('Conflicts') is not None and deb_info.get('Conflicts') or '')
    ret += 'Priority: {}\n'.format(deb_info.get('Priority') is not None and deb_info.get('Priority') or 'optional')
    ret += 'Architecture: {}\n'.format(deb_info.get('Architecture'))
    ret += 'Author: {}\n'.format(deb_info.get('Author'))
    ret += 'Homepage: {}\n'.format(deb_info.get('Homepage') is not None and deb_info.get('Homepage') or '')
    ret += 'Maintainer: {}\n'.format(deb_info.get('Maintainer'))
    ret += 'Version: {}\n'.format(deb_info.get('Version'))
    ret += 'Filename: ./{}\n'.format(filepath)
    ret += 'MD5sum: {}\n'.format(get_hash(filepath, 'md5'))
    ret += 'SHA1: {}\n'.format(get_hash(filepath, 'sha1'))
    ret += 'SHA256: {}\n'.format(get_hash(filepath, 'sha256'))
    ret += 'SHA512: {}\n'.format(get_hash(filepath, 'sha512'))
    ret += 'Depiction: https://bwat.ph03nix.club/description.html?id={}\n'.format(deb_info.get('Package'))
    ret += 'Size: {}\n'.format(get_size(filepath))
    info = {
        "name": deb_info.get('Name'),
        "description": deb_info.get('Description')
    }
    folder = 'packageinfo'
    with open(os.path.join(folder, deb_info.get('Package')), 'w') as f:
        f.write(json.dumps(info))
    return ret
Пример #2
0
def scan_packages(repository, packages_file=None, cache=None):
    """
    A reimplementation of the ``dpkg-scanpackages -m`` command in Python.

    Updates a ``Packages`` file based on the Debian package archive(s) found in
    the given directory. Uses :py:class:`.PackageCache` to (optionally) speed
    up the process significantly by caching package metadata and hashes on
    disk. This explains why this function can be much faster than
    ``dpkg-scanpackages -m``.

    :param repository: The pathname of a directory containing Debian
                       package archives (a string).
    :param packages_file: The pathname of the ``Packages`` file to update
                          (a string). Defaults to the ``Packages`` file in
                          the given directory.
    :param cache: The :py:class:`.PackageCache` to use (defaults to ``None``).
    """
    # By default the `Packages' file inside the repository is updated.
    if not packages_file:
        packages_file = os.path.join(repository, 'Packages')
    # Update the `Packages' file.
    timer = Timer()
    package_archives = glob.glob(os.path.join(repository, '*.deb'))
    num_packages = len(package_archives)
    spinner = Spinner(total=num_packages)
    with open(packages_file, 'wb') as handle:
        for i, archive in enumerate(optimize_order(package_archives), start=1):
            fields = dict(inspect_package_fields(archive, cache=cache))
            fields.update(get_packages_entry(archive, cache=cache))
            deb822_dict = unparse_control_fields(fields)
            deb822_dict.dump(handle)
            handle.write(b'\n')
            spinner.step(label="Scanning package metadata", progress=i)
    spinner.clear()
    logger.debug("Wrote %i entries to output Packages file in %s.", num_packages, timer)
Пример #3
0
 def extractControlFile(self, filename):
     dfile = {}
     try:
         dfile = repr(inspect_package_fields(filename))
     except:
         pass
     print dfile
     return json.dumps(dfile)
Пример #4
0
def get_info_from_deb(path):
    """Return data pulled from a deb archive."""
    info = {}
    data = inspect_package_fields(path)
    info["name"] = data["Package"]
    info["version"] = data["Version"]
    log.debug("Info from deb: {}".format(info))
    return info
Пример #5
0
def get_deb_pkg_name(filename, host=None, c=None):
    if host:
        if c is None:
            c = remote.create_connection(host)
        stdin, stdout, stderr = c.exec_command(
            f"dpkg --info {filename} | grep Package: | sed 's/^.*: //'"
        )
        return stdout.read().decode('utf-8').strip()
    else:
        from deb_pkg_tools.package import inspect_package_fields
        meta_info = inspect_package_fields(filename)
        pkg_name = meta_info.get('Package')
        return pkg_name
Пример #6
0
    def control_fields(self):
        """
        The control fields extracted from the Debian binary package archive.

        :returns: A dictionary with control fields generated by
                  :py:func:`.inspect_package_fields()`.
        """
        if self['control_fields']:
            try:
                return self.cache.decode(self['control_fields'])
            except Exception as e:
                logger.warning("Failed to load cached control fields of %s! (%s)", self.pathname, e)
        control_fields = inspect_package_fields(self.pathname)
        update_query = 'update package_cache set control_fields = ? where pathname = ?'
        self.cache.execute(update_query, self.cache.encode(control_fields), self.pathname)
        return control_fields
Пример #7
0
    def control_fields(self):
        """
        The control fields extracted from the Debian binary package archive.

        :returns: A dictionary with control fields generated by
                  :py:func:`.inspect_package_fields()`.
        """
        if self['control_fields']:
            try:
                return self.cache.decode(self['control_fields'])
            except Exception as e:
                logger.warning(
                    "Failed to load cached control fields of %s! (%s)",
                    self.pathname, e)
        control_fields = inspect_package_fields(self.pathname)
        update_query = 'update package_cache set control_fields = ? where pathname = ?'
        self.cache.execute(update_query, self.cache.encode(control_fields),
                           self.pathname)
        return control_fields
Пример #8
0
def scan_packages(repository, packages_file=None, cache=None):
    """
    A reimplementation of the ``dpkg-scanpackages -m`` command in Python.

    Updates a ``Packages`` file based on the Debian package archive(s) found in
    the given directory. Uses :class:`.PackageCache` to (optionally) speed
    up the process significantly by caching package metadata and hashes on
    disk. This explains why this function can be much faster than
    ``dpkg-scanpackages -m``.

    :param repository: The pathname of a directory containing Debian
                       package archives (a string).
    :param packages_file: The pathname of the ``Packages`` file to update
                          (a string). Defaults to the ``Packages`` file in
                          the given directory.
    :param cache: The :class:`.PackageCache` to use (defaults to :data:`None`).
    """
    # By default the `Packages' file inside the repository is updated.
    if not packages_file:
        packages_file = os.path.join(repository, 'Packages')
    # Update the `Packages' file.
    timer = Timer()
    package_archives = glob.glob(os.path.join(repository, '*.deb'))
    num_packages = len(package_archives)
    spinner = Spinner(total=num_packages)
    with open(packages_file, 'wb') as handle:
        for i, archive in enumerate(optimize_order(package_archives), start=1):
            fields = dict(inspect_package_fields(archive, cache=cache))
            fields.update(get_packages_entry(archive, cache=cache))
            deb822_dict = unparse_control_fields(fields)
            deb822_dict.dump(handle)
            handle.write(b'\n')
            spinner.step(label="Scanning package metadata", progress=i)
    spinner.clear()
    logger.debug("Wrote %i entries to output Packages file in %s.",
                 num_packages, timer)