コード例 #1
0
ファイル: utils.py プロジェクト: sdaru/patchman
def process_update(host, update_string, security):
    """ Processes a single sanitized update string and converts to an update
    object. Only works if the original package exists. Returns None otherwise
    """
    update_str = update_string.split()
    repo_id = update_str[2]

    parts = update_str[0].rpartition('.')
    package_str = parts[0]
    arch_str = parts[2]

    p_epoch, p_version, p_release = find_evr(update_str[1])

    package_arches = PackageArchitecture.objects.all()
    with transaction.atomic():
        p_arch, c = package_arches.get_or_create(name=arch_str)

    package_names = PackageName.objects.all()
    with transaction.atomic():
        p_name, c = package_names.get_or_create(name=package_str)

    packages = Package.objects.all()
    with transaction.atomic():
        package, c = packages.get_or_create(name=p_name,
                                            arch=p_arch,
                                            epoch=p_epoch,
                                            version=p_version,
                                            release=p_release,
                                            packagetype='R')
    try:
        repo = Repository.objects.get(repo_id=repo_id)
    except Repository.DoesNotExist:
        repo = None
    if repo:
        for mirror in repo.mirror_set.all():
            with transaction.atomic():
                MirrorPackage.objects.create(mirror=mirror, package=package)

    installed_packages = host.packages.filter(name=p_name,
                                              arch=p_arch,
                                              packagetype='R')
    if installed_packages:
        installed_package = installed_packages[0]
        updates = PackageUpdate.objects.all()
        with transaction.atomic():
            update, c = updates.get_or_create(oldpackage=installed_package,
                                              newpackage=package,
                                              security=security)
        return update
コード例 #2
0
ファイル: utils.py プロジェクト: j4ckzh0u/patchman
def extract_arch_packages(data):
    """ Extract package metadata from an arch linux tarfile
    """
    from packages.utils import find_evr
    extracted = BytesIO(extract(data, 'gz'))
    tf = tarfile.open(fileobj=extracted, mode='r:*')
    packages = set()
    plen = len(tf.getnames())
    if plen > 0:
        ptext = 'Extracting packages: '
        progress_info_s.send(sender=None, ptext=ptext, plen=plen)
        for i, tarinfo in enumerate(tf):
            progress_update_s.send(sender=None, index=i + 1)
            if tarinfo.isfile():
                name_sec = ver_sec = arch_sec = False
                t = tf.extractfile(tarinfo).read()
                for line in t.decode('utf-8').splitlines():
                    if line.startswith('%NAME%'):
                        name_sec = True
                        continue
                    if name_sec:
                        name_sec = False
                        name = line
                        continue
                    if line.startswith('%VERSION%'):
                        ver_sec = True
                        continue
                    if ver_sec:
                        ver_sec = False
                        epoch, version, release = find_evr(line)
                        continue
                    if line.startswith('%ARCH%'):
                        arch_sec = True
                        continue
                    if arch_sec:
                        arch_sec = False
                        arch = line
                        continue
                package = PackageString(name=name.lower(),
                                        epoch=epoch,
                                        version=version,
                                        release=release,
                                        arch=arch,
                                        packagetype='A')
                packages.add(package)
    else:
        info_message.send(sender=None, text='No packages found in repo')
    return packages