Example #1
0
def generate_sources_file(distro, comp):
    data = common.myStringIO()
    component = common.db_packages.packages.find({'repos': {'distro': distro, 'component': comp}, 'dsc': {'$exists': True}}, {'dsc': 1, 'sources': 1})
    for pkg in component:
        for k, v in pkg['dsc'].iteritems():
            if k == 'Source':
                data.write("Package: {0}\n".format(v))
            else:
                data.write("{0}: {1}\n".format(k.capitalize(), v))
        data.write("Directory: storage\n")
        # c-c-c-c-combo!
        files = [x for x in pkg['sources'] if reduce(lambda a,n: a or x['name'].endswith(n), ['tar.gz', 'tar.xz', '.dsc'], False)]

        def gen_para(algo, files):
            for f in files:
                data.write(" {0} {1} {2}\n".format(hexlify(f[algo]), f['size'], f['storage_key']))

        data.write("Files: \n")
        gen_para('md5', files)
        data.write("Checksums-Sha1: \n")
        gen_para('sha1', files)
        data.write("Checksums-Sha256: \n")
        gen_para('sha256', files)

        data.write("\n")
    # to prevent generating of empty file
    data.write("\n")
    return data
Example #2
0
def generate_packages_file(distro, comp, arch):
    data = common.myStringIO()
    distro = common.db_packages.packages.find({'repos': {'distro': distro, 'component': comp}, 'debs.Architecture': arch})
    for pkg in distro:
        # see https://wiki.debian.org/RepositoryFormat#Architectures - 'all' arch goes with other arhes' Packages index
        for deb in (x for x in pkg['debs'] if x['Architecture'] == arch or x['Architecture'] == 'all'):
            for k, v in deb.iteritems():
                if k == 'md5':
                    string = "MD5sum: {0}\n".format(hexlify(v))
                elif k == 'sha1':
                    string = "SHA1: {0}\n".format(hexlify(v))
                elif k == 'sha256':
                    string = "SHA256: {0}\n".format(hexlify(v))
                elif k == 'sha512':
                    string = "SHA512: {0}\n".format(hexlify(v))
                elif k == 'storage_key':
                    string = "Filename: {0}\n".format(os.path.join(common.config['repo_daemon']['storage_subdir'],v))
                else:
                    string = "{0}: {1}\n".format(k.capitalize().encode('utf-8'), unicode(v).encode('utf-8'))
                data.write(string)
            data.write("\n")
    # to prevent generating of empty file
    data.write("\n")
    return data