Exemple #1
0
def get_repository_packages(repository):
    """Get list of packages for a repository."""
    timezone = pytz.timezone(settings.TIME_ZONE)
    now = datetime.now(tz=timezone)
    repopkgs = []
    for arch in repository.arch.split(','):
        build = {
            'id': '%s_%s' % (repository.name, repository.version.version),
            'repo': repository,
            'arch': arch,
            'date': None,
            'files': [],
        }
        filename = repository.path_packages_gz(arch)
        build['date'] = os.stat(filename).st_mtime
        with gzip.open(filename, 'rb') as _file:
            pkg = {}
            for line in _file.readlines():
                line = line.strip().decode('utf-8')
                if len(line) == 0:
                    if pkg:
                        pkg['repoarch'] = '%s_%s' % (
                            repository.name,
                            repository.version.codename,
                        )
                        pkg['repo'] = repository
                        pkg['distro'] = repository.name
                        pkg['arch'] = arch
                        pkgfilename = repo_path_join(repository.name,
                                                     pkg['Filename'])
                        fstat = os.stat(pkgfilename)
                        pkg['size'] = fstat.st_size
                        date_time = datetime.fromtimestamp(fstat.st_mtime,
                                                           tz=timezone)
                        pkg['builddatetime'] = date_time
                        add_hours = repository.build_frequency
                        if repository.active and add_hours > 0:
                            nextbuilddatetime = (date_time +
                                                 timedelta(hours=add_hours))
                            if nextbuilddatetime > now:
                                pkg['nextbuilddatetime'] = nextbuilddatetime
                        pkg['basename'] = os.path.basename(pkg['Filename'])
                        pkg['anchor'] = '%s_%s_%s_%s' % (
                            repository.name,
                            repository.version.codename,
                            pkg['Version'],
                            arch,
                        )
                        if 'Source' not in pkg:
                            pkg['Source'] = pkg['Package']
                        pkg['version_type'] = ('dev'
                                               if 'dev' in pkg['Version']
                                               else 'stable')
                        repopkgs.append(pkg)
                    pkg = {}
                match = re.match('^([^ ]+): (.*)$', line)
                if match:
                    pkg[match.group(1)] = match.group(2)
    return repopkgs
Exemple #2
0
def get_repository_packages(repository):
    """Get list of packages for a repository."""
    timezone = pytz.timezone(settings.TIME_ZONE)
    now = datetime.now(tz=timezone)
    repopkgs = []
    for arch in repository.arch.split(','):
        build = {
            'id': '%s_%s' % (repository.name, repository.version.version),
            'repo': repository,
            'arch': arch,
            'date': None,
            'files': [],
        }
        filename = repository.path_packages_gz(arch)
        build['date'] = os.stat(filename).st_mtime
        with gzip.open(filename, 'rb') as _file:
            pkg = {}
            for line in _file.readlines():
                line = line.strip().decode('utf-8')
                if len(line) == 0:
                    if pkg:
                        pkg['repoarch'] = '%s_%s' % (
                            repository.name,
                            repository.version.codename,
                        )
                        pkg['repo'] = repository
                        pkg['distro'] = repository.name
                        pkg['arch'] = arch
                        pkgfilename = repo_path_join(repository.name,
                                                     pkg['Filename'])
                        fstat = os.stat(pkgfilename)
                        pkg['size'] = fstat.st_size
                        date_time = datetime.fromtimestamp(fstat.st_mtime,
                                                           tz=timezone)
                        pkg['builddatetime'] = date_time
                        add_hours = repository.build_frequency
                        if repository.active and add_hours > 0:
                            nextbuilddatetime = (date_time +
                                                 timedelta(hours=add_hours))
                            if nextbuilddatetime > now:
                                pkg['nextbuilddatetime'] = nextbuilddatetime
                        pkg['basename'] = os.path.basename(pkg['Filename'])
                        pkg['anchor'] = '%s_%s_%s_%s' % (
                            repository.name,
                            repository.version.codename,
                            pkg['Version'],
                            arch,
                        )
                        if 'Source' not in pkg:
                            pkg['Source'] = pkg['Package']
                        pkg['version_type'] = ('dev' if 'dev' in pkg['Version']
                                               else 'stable')
                        repopkgs.append(pkg)
                    pkg = {}
                match = re.match('^([^ ]+): (.*)$', line)
                if match:
                    pkg[match.group(1)] = match.group(2)
    return repopkgs
Exemple #3
0
 def path_packages_gz(self, arch):
     """Return path/name to the Packages.gz file of repository."""
     return repo_path_join(self.name, 'dists',
                           self.version.codename, 'main',
                           'binary-%s' % arch, 'Packages.gz')
Exemple #4
0
 def path_packages_gz(self, arch):
     """Return path/name to the Packages.gz file of repository."""
     return repo_path_join(self.domain, 'dists',
                           self.version.codename, 'main',
                           'binary-%s' % arch, 'Packages.gz')
Exemple #5
0
def repos(request, files=''):
    """Page with debian repositories."""
    debpkgs = []
    try:
        for repo in Repo.objects.all():
            repopkgs = []
            for arch in repo.arch.split(','):
                build = {
                    'id': '%s_%s' % (repo.name, repo.version.version),
                    'repo': repo,
                    'arch': arch,
                    'date': None,
                    'files': [],
                }
                filename = repo.path_packages_gz(arch)
                build['date'] = stat(filename).st_mtime
                _file = gzip.open(filename, 'rb')
                if _file:
                    pkg = {}
                    for line in _file.readlines():
                        line = line.strip()
                        if len(line) == 0:
                            if pkg:
                                pkg['repoarch'] = '%s_%s' % (
                                    repo.name, repo.version.version)
                                pkg['repo'] = repo
                                pkg['arch'] = arch
                                pkgfilename = repo_path_join(repo.domain,
                                                             pkg['Filename'])
                                fstat = stat(pkgfilename)
                                pkg['size'] = fstat.st_size
                                date_time = datetime.fromtimestamp(
                                    fstat.st_mtime)
                                pkg['builddate'] = date_time.strftime(
                                    '%Y-%m-%d')
                                pkg['buildtime'] = date_time.strftime('%H:%M')
                                pkg['builddatetime'] = pkg['builddate'] + \
                                    pkg['buildtime']
                                pkg['basename'] = \
                                    path.basename(pkg['Filename'])
                                pkg['anchor'] = '%s_%s_%s_%s' % (
                                    repo.name, repo.version.codename,
                                    pkg['Version'], arch)
                                if 'Source' not in pkg:
                                    pkg['Source'] = pkg['Package']
                                repopkgs.append(pkg)
                            pkg = {}
                        match = re.match('^([^ ]+): (.*)$', line)
                        if match:
                            pkg[match.group(1)] = match.group(2)
                    _file.close()
            debpkgs.extend(sorted(repopkgs, key=lambda p: p['builddatetime'],
                                  reverse=True))
    except:
        pass
    return render_to_response(
        'download/debian.html',
        {
            'debpkgs': debpkgs,
            'allfiles': files == 'files',
        },
        context_instance=RequestContext(request))
Exemple #6
0
def repos(request, active='active', files=''):
    """Page with debian repositories."""
    repositories = []
    debpkgs = []
    if active == 'active':
        repositories = (Repo.objects.all().filter(active=1).filter(
            visible=1).order_by('priority'))
    else:
        repositories = (Repo.objects.all().filter(
            visible=1).order_by('priority'))
    for repo in repositories:
        try:
            repopkgs = []
            for arch in repo.arch.split(','):
                build = {
                    'id': '%s_%s' % (repo.name, repo.version.version),
                    'repo': repo,
                    'arch': arch,
                    'date': None,
                    'files': [],
                }
                filename = repo.path_packages_gz(arch)
                build['date'] = stat(filename).st_mtime
                _file = gzip.open(filename, 'rb')
                if _file:
                    pkg = {}
                    for line in _file.readlines():
                        line = line.strip()
                        if len(line) == 0:
                            if pkg:
                                pkg['repoarch'] = '%s_%s' % (
                                    repo.name, repo.version.version)
                                pkg['repo'] = repo
                                pkg['arch'] = arch
                                pkgfilename = repo_path_join(
                                    repo.domain, pkg['Filename'])
                                fstat = stat(pkgfilename)
                                pkg['size'] = fstat.st_size
                                date_time = datetime.fromtimestamp(
                                    fstat.st_mtime)
                                pkg['builddate'] = date_time.strftime(
                                    '%Y-%m-%d')
                                pkg['buildtime'] = date_time.strftime('%H:%M')
                                pkg['builddatetime'] = pkg['builddate'] + \
                                    pkg['buildtime']
                                pkg['basename'] = \
                                    path.basename(pkg['Filename'])
                                pkg['anchor'] = '%s_%s_%s_%s' % (
                                    repo.name, repo.version.codename,
                                    pkg['Version'], arch)
                                if 'Source' not in pkg:
                                    pkg['Source'] = pkg['Package']
                                repopkgs.append(pkg)
                            pkg = {}
                        match = re.match('^([^ ]+): (.*)$', line)
                        if match:
                            pkg[match.group(1)] = match.group(2)
                    _file.close()
            debpkgs.extend(
                sorted(repopkgs,
                       key=lambda p: p['builddatetime'],
                       reverse=True))
        except:
            pass
    return render(
        request,
        'download/debian.html',
        {
            'debpkgs': debpkgs,
            'active': active,
            'allfiles': files == 'files',
            'repositories': repositories,
        },
    )