def _check_repository(self, repodir): if not osp.isdir(repodir): raise cli.CommandError("Repository %s doesn't exist" % repodir) for section in ('dists', 'incoming'): subdir = osp.join(repodir, section) if not osp.isdir(subdir): raise cli.CommandError( "Repository %s isn't properly initialized (no %r directory)" % (repodir, section)) return debrepo.DebianRepository(self.logger, repodir)
def _check_changes_file(self, changes_file): """basic tests to determine debian changes file""" if not changes_file.endswith('.changes'): raise cli.CommandError( '%s is not a debian changes file (bad extension)' % changes_file) if not osp.isfile(changes_file): raise cli.CommandError( '%s doesn\'t exist or is not a regulary file' % changes_file) try: return Changes(changes_file) except Exception as ex: raise cli.CommandError('%s is not a debian changes file: %s' % (changes_file, ex))
def run(self, args): if not args: destdir = self.config.repositories_directory repositories = [] for dirname in os.listdir(destdir): try: self._check_repository(osp.join(destdir, dirname)) except cli.CommandError as e: self.logger.debug(e) else: repositories.append(dirname) self.logger.info("%s available repositories in '%s'" % (len(repositories), destdir)) repositories = sorted(repositories) print(os.linesep.join(repositories)) return path = _repo_path(self.config, args.pop(0)) repo = self._check_repository(path) if self.config.section not in ('dists', 'incoming'): raise cli.CommandError('Unknown section %s' % self.config.section) if len(args) == 0 and not self.config.distribution: lines = [] for root, dirs, files in os.walk( osp.join(path, self.config.section)): orphaned = [] for d in dirs: dirpath = osp.join(root, d) if osp.islink(dirpath): line = '%s is symlinked to %s' % (dirpath, os.readlink(dirpath)) else: nb = len(glob(osp.join(dirpath, "*.changes"))) if nb: line = "%s contains %d changes files" % (dirpath, nb) else: line = "%s is empty" % dirpath if self.config.orphaned: orphaned = self.get_orphaned_files(repo, d) if orphaned: line += " and %d orphaned files" % len( orphaned) lines.append(line) self.logger.info( "%s: %s available distribution(s) in '%s' section", path, len(lines), self.config.section) for line in lines: print(line) else: self._print_changes_files(repo, self.config.section, self.config.distribution) if self.config.orphaned: orphaned = self.get_orphaned_files(repo, self.config.distribution) if orphaned: self.logger.warn("%s: has %s orphaned file(s)", path, len(orphaned)) print('\n'.join(orphaned))
def run(self, args): repo = self._check_repository(_repo_path(self.config, args.pop(0))) self.debian_changes = {} for filename in args: changes = self._check_changes_file(filename) if self.config.distribution: distrib = self.config.distribution else: distrib = changes['Distribution'] try: distribdir = repo.check_distrib('incoming', distrib) self._check_signature(changes) self._run_checkers(changes) except cli.CommandError as ex: self.logger.error(ex) # ignore this changes file continue if self.config.remove: move = sht.mv else: move = sht.cp self.process_changes_file(changes, distribdir, self.config.upload_group, move) if not self.debian_changes: raise cli.CommandError('No changes file uploaded')
def run(self, args): repodir = _repo_path(self.config, args.pop(0)) if self.config.update and not osp.exists(repodir): raise cli.CommandError("Repository %s doesn't exist" % repodir) if 'all' in self.config.distributions: dists = ['lenny', 'squeeze', 'sid'] else: dists = self.config.distributions # creation of the repository for subdir, group in (('incoming', self.config.upload_group), ('dists', self.config.publish_group), ('archive', self.config.publish_group)): subdir = osp.join(repodir, subdir) for distname in dists: if not osp.isdir(subdir): os.makedirs(subdir) if group: self.schown(subdir, group=group) self.schmod(subdir, 0o2775) # sticky group distribdir = osp.join(subdir, distname) if not osp.isdir(distribdir): os.makedirs(distribdir) self.logger.info('created %s', distribdir) else: self.logger.info('%s directory already exists', distribdir) if group: self.schown(distribdir, group=group) self.schmod(distribdir, 0o2775) # sticky group if group and self.config.update: for fname in os.listdir(distribdir): self.schown(osp.join(distribdir, fname), group=group)
def _repo_path(config, directory): if not osp.isabs(directory): if not config.repositories_directory: raise cli.CommandError( 'Give either an absolute path to a directory that should ' 'hold the repository or a repository name and specify its ' 'directory using --repositories-directory') directory = osp.join(config.repositories_directory, directory) return directory
def _check_signature(self, changes): """raise error if the changes files and appropriate dsc files are not correctly signed """ if self.config.check_signature: try: changes.check_sig() except BadSignature as ex: raise cli.CommandError( "%s. Check if the PGP block exists and if the key is in your " "keyring" % ex)
def run(self, args): repo = self._check_repository(_repo_path(self.config, args.pop(0))) distribs = set() self.debian_changes = {} # we have to launch the publication sequentially lockfile = osp.join(repo.directory, 'ldi.lock') with FileLock(lockfile): changes_files = repo.incoming_changes_files(args) if not changes_files and not self.config.refresh: self.logger.error("no changes file to publish in %s", repo.incoming_directory) if os.isatty(0) and not self.config.no_confirm and changes_files: self.logger.info('Publishing the following changes files:\n%s', '\n'.join(changes_files)) if not sht.ASK.confirm('Do you want to proceed?'): raise cli.CommandError('user abort') for filename in changes_files: # distribution name is the same as the incoming directory name # it lets override a valid suite by a more private one (for # example: contrib, volatile, experimental, ...) distrib = osp.basename(osp.dirname(filename)) destdir = repo.check_distrib('dists', distrib) changes = self._check_changes_file(filename) try: self._check_signature(changes) self._run_checkers(changes) except cli.CommandError as ex: self.logger.error(ex) # ignore this changes file continue # perform a copy instead of a move to reset file ownership self.process_changes_file(changes, destdir, self.config.publish_group, rm=True, force=self.config.force) # mark distribution to be refreshed at the end distribs.add(distrib) repo.generate_aptconf() if self.config.refresh: distribs = ('*', ) for distrib in distribs: try: self._apt_refresh(repo, distrib) except Exception as ex: self.logger.error(ex)
def _run_checkers(self, changes): checkers = self.config.checkers try: changes.run_checkers(checkers) except Exception as ex: raise cli.CommandError(str(ex))