Beispiel #1
0
    def handle(self, *args, **options):

        for dist in list_items(SAMPLES_DIR, True, False):
            for comp in list_items(os.path.join(SAMPLES_DIR, dist), True, False):
                for sample in find_files(os.path.join(SAMPLES_DIR, dist, comp)):
                    try:
                        include_deb(LOCAL_ROOT, dist, comp, sample)
                    except:
                        logger.info('There are no packages here!')
Beispiel #2
0
def index_selected():
    from tribus.common.utils import list_items, find_files
    from tribus.common.reprepro import include_deb
    from tribus.config.pkgrecorder import LOCAL_ROOT, SAMPLES_DIR
    for dist in list_items(SAMPLES_DIR, True, False):
        for comp in list_items(os.path.join(SAMPLES_DIR, dist), True, False):
            for sample in find_files(os.path.join(SAMPLES_DIR, dist, comp)):
                with lcd('%(reprepro_dir)s' % env):
                    try:
                        include_deb(LOCAL_ROOT, dist, comp, sample)
                    except:
                        logger.info('There are no packages here!')
Beispiel #3
0
 def get_sphinx_locale_list(self):
     return set(
         filter(
             None,
             list_items(path=get_path([DOCDIR, 'rst', 'i18n']),
                        dirs=True,
                        files=False))) - set(['pot'])
Beispiel #4
0
def index_sample_packages():
    '''
    Indexa los paquetes descargados en el repositorio.
    '''

    from tribus.common.utils import list_items, find_files
    from tribus.common.reprepro import include_deb
    dirs = [
        os.path.dirname(f) for f in find_files(env.sample_packages_dir, 'list')
    ]
    dists = filter(None,
                   list_items(env.sample_packages_dir, dirs=True, files=False))
    with lcd('%(reprepro_dir)s' % env):
        for directory in dirs:
            # No se me ocurre una mejor forma (dinamica) de hacer esto
            dist = [
                dist_name for dist_name in dists if dist_name in directory
            ][0]
            results = [
                each for each in os.listdir(directory) if each.endswith('.deb')
            ]
            if results:
                include_deb(env.reprepro_dir, dist, directory)
            else:
                logger.info('There are no packages in %s' % directory)
Beispiel #5
0
def reset_repository(repository_root):
    '''
    Elimina las distribuciones existentes en un repositorio.
    '''
    
    os.chdir(repository_root)
    dists = list_items(os.path.join(repository_root, 'dists'), True, False)
    for dist in dists:
        local("reprepro removefilter %s \'Section\'" % dist)
Beispiel #6
0
 def handle(self, *args, **options):
     dirs = [
         os.path.dirname(f) for f in find_files(sample_packages_dir, 'list')
     ]
     dists = filter(None,
                    list_items(sample_packages_dir, dirs=True, files=False))
     for directory in dirs:
         # No se me ocurre una mejor forma (dinamica) de hacer esto
         dist = [
             dist_name for dist_name in dists if dist_name in directory
         ][0]
         results = [
             each for each in os.listdir(directory) if each.endswith('.deb')
         ]
         if results:
             include_deb(reprepro_dir, dist, directory)
         else:
             logger.info('There are no packages in %s' % directory)
Beispiel #7
0
def fill_db_from_cache(cache_dir_path):
    '''
    Records the data from each control file in the cache folder into the database.
    
    :param cache_dir_path: path where the package cache is stored.

    .. versionadded:: 0.1
    '''
    
    control_files = list_items(cache_dir_path, False, True)
    for control_file in control_files:
        name, _ = control_file.split(".")
        branch, comp, _ = name.split("_")
        control_file_path = os.path.join(cache_dir_path, control_file)
        for paragraph in deb822.Packages.iter_paragraphs(gzip.open(control_file_path, 'r')):
            try:
                Package.objects.create_auto(paragraph, branch, comp)
            except:
                logger.error('Could not record %s' % paragraph['Package'])
Beispiel #8
0
def fill_db_from_cache(cache_dir_path):
    '''
    Records the data from each control file in the cache folder into the database.
    
    :param cache_dir_path: path where the package cache is stored.

    .. versionadded:: 0.1
    '''

    local_branches = filter(
        None, list_items(path=cache_dir_path, dirs=True, files=False))
    for branch in local_branches:
        dist_sub_paths = [
            os.path.dirname(f) for f in find_files(
                os.path.join(cache_dir_path, branch), 'Packages.gz')
        ]
        for path in dist_sub_paths:
            for p in find_files(path, "Packages.gz"):
                for paragraph in deb822.Packages.iter_paragraphs(
                        gzip.open(p, 'r')):
                    record_paragraph(paragraph, branch)
Beispiel #9
0
def create_repository(repository_root, distributions_path):
    '''
    Creates and initializes a packages repository from a
    `distributions` configuration file. 
    
    :param repository_root: path where the repository will be created.
    
    :param distributions_path: path to the `distributions` configuration file.
    '''
    
    conf_dir = os.path.join(repository_root, 'conf')
    dist_dst = os.path.join(conf_dir, 'distributions')
    
    if not os.path.isdir(repository_root):
        os.makedirs(conf_dir)
    
    shutil.copyfile(distributions_path, dist_dst)
    os.chdir(repository_root)
    local("reprepro -VVV export")
    with open(os.path.join(repository_root, 'distributions'), 'w') as f:
        for dist in list_items(os.path.join(repository_root, 'dists'), True, False):
            f.write('%s dists/%s/Release\n' % (dist, dist))
Beispiel #10
0
def index_sample_packages():
    from tribus.common.utils import list_items, find_files
    dirs = [
        os.path.dirname(f) for f in find_files(env.sample_packages_dir, 'list')
    ]
    dists = filter(None,
                   list_items(env.sample_packages_dir, dirs=True, files=False))
    with lcd('%(reprepro_dir)s' % env):
        for directory in dirs:
            # No se me ocurre una mejor forma (dinamica) de hacer esto
            dist = [
                dist_name for dist_name in dists if dist_name in directory
            ][0]
            results = [
                each for each in os.listdir(directory) if each.endswith('.deb')
            ]
            if results:
                with settings(command='reprepro includedeb %s %s/*.deb' %
                              (dist, directory)):
                    local('%(command)s' % env, capture=False)
            else:
                logger.info('There are no packages in %s' % directory)
Beispiel #11
0
def update_db_from_cache(changes, cache_dir_path=None):
    """
    Updates all packages in a control file.
    If a package exists but the MD5sum field is different from the one
    stored in the database then it updates the package data fields.
    If the package doesn't exists then its created.
    If the package exists in the database but is not found in the control
    file then its deleted.
    
    :param cache_dir_path: path to the desired cache directory
    
    .. versionadded:: 0.1
    """
    
    if cache_dir_path:
        control_files = list_items(cache_dir_path, False, True)
    else:
        control_files = changes
    for control_file in control_files:
        name, _ = control_file.split(".")
        branch, comp, arch = name.split("_")
        path = os.path.join(cache_dir_path, control_file)
        try:
            paragraphs = deb822.Packages.iter_paragraphs(gzip.open(path))
        except IOError, e:
            logger.warning('Could not read control file in %s, error code #%s' % (path, e))
        else:
            logger.info('=====================')
            logger.info('Updating packages in %s:%s:%s' % (branch, comp, arch))
            existent_packages = []
            for paragraph in paragraphs:
                existent_packages.append(paragraph['Package'])
                exists = Details.objects.filter(package__Name=paragraph['Package'],
                                                Architecture=paragraph['Architecture'],
                                                Distribution=branch, 
                                                Component = comp)
                if exists:
                    if paragraph['md5sum'] != exists[0].MD5sum:
                        logger.info('The md5 checksum does not match in the package \'%s\':' % paragraph['Package'])
                        logger.info('\'%s\' != \'%s\' ' % (paragraph['md5sum'], exists[0].MD5sum))
                        update_paragraph(paragraph, branch, comp)
                    else:
                        logger.info('Nothing to change \'%s\':' % paragraph['Package'])
                else:
                    try:
                        Package.objects.create_auto(paragraph, branch, comp)
                    except:
                        logger.error('Could not record %s' % paragraph['Package'])
            
            bd_packages = Package.objects.filter(Details__Distribution=branch,
                                                 Details__Component = comp
                                                 ).filter(Q(Details__Architecture='all') |
                                                          Q(Details__Architecture=arch)).distinct()
            for package in bd_packages:
                if package.Name not in existent_packages:
                    print package.Name, "not in %s %s %s" % (branch, comp, arch)
                    for detail in package.Details.all():
                        if (detail.Distribution == branch and detail.Component == comp and
                            (detail.Architecture == arch or detail.Architecture == 'all')):
                            for relation in detail.Relations.all():
                                detail.Relations.remove(relation)
                                exists = Details.objects.filter(Relations=relation)
                                if not exists:
                                    relation.delete()
                            logger.info('Removing \'%s\' from \'%s\'...'
                                        % (detail, package.Name))
                            detail.delete()
                    if not package.Details.all():
                        logger.info('Removing %s...' % package.Name)
                        package.delete()