def load(self): ''' Loads the package list from a repo database file ''' if not isfile(self._db): return {} if not tarfile.is_tarfile(self._db): raise Exception( _('File is no valid database: {0}').format(self._db)) db = tarfile.open(self._db) packages = {} for member in (m for m in db.getmembers() if m.isfile() and m.name.endswith('desc')): desc = db.extractfile(member).read().decode('utf8') infos = dict( ((k.lower(), v) for k, v in re.findall('%([A-Z256]+)%\n([^\n]+)\n', desc))) if any(True for k in ['name', 'version', 'filename'] if k not in infos): raise Exception(_('Missing database entry: {0}').format(r)) path = join(self._path, infos['filename']) packages[infos['name']] = Package(infos['name'], infos['version'], path, infos) db.close() return packages
def load_from_db(self): ''' Loads the package list from a repo database file ''' if not isfile(self._db): return {} try: db = open_tarfile(self._db) except: raise DbError(_('Could not open database: {0}').format(self._db)) packages = {} for member in (m for m in db.getmembers() if m.isfile() and basename(m.name) == Repo.DESC): try: desc = db.extractfile(member).read().decode('utf8') info = DescParser(desc).parse() except ParserError as e: raise DbError( _('Invalid db entry: {0}: {1}').format( member.name, e.message)) except: raise DbError( _('Could not read db entry: {0}').format(member.name)) path = join(self._path, info['filename']) packages[info['name']] = Package(info['name'], info['version'], path, info) try: db.close() except: raise DbError(_('Could not close database: {0}').format(self._db)) return packages
def _make_package(path): ''' Makes a new package ''' Msg.process(_('Forging a new package: {0}').format(path)) Log.log(_('Forging a new package: {0}').format(path)) try: return Package.forge(path) except DependencyError as e: LocalRepo._install_deps(e.deps) try: return Package.from_pkgbuild(e.pkgbuild, ignore_deps=True) except LocalRepoError as e: LocalRepo.error(e) except LocalRepoError as e: LocalRepo.error(e)
def _make_package(path, force=False): ''' Makes a new package ''' Msg.process(_('Forging a new package: {0}').format(path)) Log.log(_('Forging a new package: {0}').format(path)) try: return Package.forge(path, force=force) except DependencyError as e: installed_deps = LocalRepo._install_deps(e.deps) try: pkg = Package.from_pkgbuild(e.pkgbuild, ignore_deps=True, force=force) except LocalRepoError as e: LocalRepo.error(e) if Config.get('uninstall-deps', True) and installed_deps: LocalRepo._uninstall_deps(e.deps) return pkg except LocalRepoError as e: LocalRepo.error(e)
def add(self, paths, upgrade=False): ''' Add packages to the repo ''' for path in paths: Msg.process(_('Making a new package')) try: pkg = Package.forge(path) if upgrade: Msg.process(_('Upgrading package:'), pkg.name) self.repo.upgrade(pkg) else: Msg.process(_('Adding package to the repo:'), pkg.name) self.repo.add(pkg) except Exception as e: Msg.error(str(e)) return False return True
def shutdown(error): ''' Clean up ''' Package.clean() exit(0) if not error else exit(1)
def shutdown(status=0): ''' Cleans up and exits with status ''' Package.clean() Log.close() exit(status)