def vcs_upgrade(): ''' Upgrades all VCS packages from the AUR ''' Msg.process(_('Updating all VCS packages')) Log.log(_('Starting a VCS upgrade')) vcs = [pkg for pkg in LocalRepo._repo if LocalRepo._repo[pkg].is_vcs] if not vcs: Msg.info(_('No VCS packages found')) return Msg.process(_('Retrieving package info from the AUR')) updates, errors = Aur.packages(vcs) for e in errors: Msg.error(e) if not updates: Msg.info(_('No updates found')) return Msg.result('\n'.join(updates)) if not Msg.ask(_('Upgrade?')): Msg.info(_('Bye')) return LocalRepo.add([pkg['uri'] for pkg in updates.values()], force=True)
def clear_cache(): ''' Clears the repo cache ''' Msg.process(_('Clearing the cache')) try: LocalRepo._repo.clear_cache() Log.log(_('Cleared cache')) except LocalRepoError as e: LocalRepo.error(e)
def restore_db(): ''' Try to restore the database file ''' Msg.process(_('Restoring database')) try: LocalRepo._repo.restore_db() Log.log(_('Restored Database')) except LocalRepoError as e: LocalRepo.error(e)
def init(path, config_file=Config.CONFIGFILE): ''' Needs the path to repo, or the repo name if specified in the config file ''' try: Config.init(path, config_file) LocalRepo._repo = Repo(Config.get('path', path)) Log.init(LocalRepo._repo.path) BuildLog.init(LocalRepo._repo.path) PkgbuildLog.init(LocalRepo._repo.path) except LocalRepoError as e: LocalRepo.error(e)
def add(paths, force=False): ''' Adds packages to the repo ''' for path in paths: pkg = LocalRepo._make_package(path) try: Msg.process(_('Adding package to the repo: {0}').format(pkg.name)) LocalRepo._repo.add(pkg, force=force) Log.log(_('Added Package: {0} {1}').format(pkg.name, pkg.version)) except LocalRepoError as e: LocalRepo.error(e)
def remove(names): ''' Removes packages from the repo ''' missing = [name for name in names if not LocalRepo._repo.has(name)] if missing: Msg.error(_('Packages do not exist: {0}').format(', '.join(missing))) LocalRepo.shutdown(1) Msg.process(_('Removing packages: {0}').format(', '.join(names))) try: LocalRepo._repo.remove(names) Log.log(_('Removed packages: {0}').format(', '.join(names))) except LocalRepoError as e: LocalRepo.error(e)
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 aur_upgrade(): ''' Upgrades all packages from the AUR ''' pkgs = [pkg for pkg in LocalRepo._repo if pkg not in Config.get('no-aur-upgrade', [])] Msg.info(_('{0} packages found').format(len(pkgs))) Log.log(_('Starting an AUR upgrade')) if len(pkgs) is 0: Msg.info(_('Nothing to do')) return Msg.process(_('Retrieving package info from the AUR')) pkgs, errors = Aur.packages(pkgs) for e in errors: Msg.error(e) Msg.info(_('{0} packages found').format(len(pkgs))) Msg.process(_('Checking for updates')) updates = [] for name, pkg in ((name, pkg) for name, pkg in pkgs.items() if name in LocalRepo._repo): oldpkg = LocalRepo._repo[name] if oldpkg.has_smaller_version_than(pkg['version']): updates.append(pkg) Msg.result('{0} ({1} -> {2})'.format(name, oldpkg.version, pkg['version'])) if not updates: Msg.info(_('All packages are up to date')) return if not Msg.ask(_('Upgrade?')): Msg.info(_('Bye')) LocalRepo.shutdown(1) LocalRepo.add([pkg['uri'] for pkg in updates], force=True)
def vcs_upgrade(): ''' Upgrades all VCS packages from the AUR ''' Msg.process(_('Updating all VCS packages')) Log.log(_('Starting a VCS upgrade')) vcs = LocalRepo._repo.vcs_packages if not vcs: Msg.info(_('No VCS packages found')) return Msg.process(_('Retrieving package info from the AUR')) try: updates = Aur.packages(vcs) except LocalRepoError as e: LocalRepo.error(e) Msg.result('\n'.join(updates)) if not Msg.ask(_('Upgrade?')): Msg.info(_('Bye')) return LocalRepo.add([pkg['uri'] for pkg in updates.values()], force=True)
def aur_upgrade(): ''' Upgrades all packages from the AUR ''' Msg.info(_('{0} packages found').format(LocalRepo._repo.size)) Log.log(_('Starting an AUR upgrade')) if LocalRepo._repo.size is 0: Msg.info(_('Nothing to do')) return Msg.process(_('Retrieving package info from the AUR')) try: pkgs = Aur.packages(LocalRepo._repo.packages) except LocalRepoError as e: LocalRepo.error(e) Msg.info(_('{0} packages found').format(len(pkgs))) Msg.process(_('Checking for updates')) updates = [] for name, pkg in ((name, pkg) for name, pkg in pkgs.items() if LocalRepo._repo.has(name)): oldpkg = LocalRepo._repo.package(name) if oldpkg.has_smaller_version_than(pkg['version']): updates.append(pkg) Msg.result('{0} ({1} -> {2})'.format(name, oldpkg.version, pkg['version'])) if not updates: Msg.info(_('All packages are up to date')) return if not Msg.ask(_('Upgrade?')): Msg.info(_('Bye')) LocalRepo.shutdown(1) LocalRepo.add([pkg['uri'] for pkg in updates], force=True)
def test_log(self, error=False): msgs = ['Hello!', 'This is just a test...', 'Everything is fine... hopefully'] Log.init(self.repo) for msg in msgs: Log.error(msg) if error else Log.log(msg) Log.close() with open(self.log) as f: i = 0 p = '^\[[0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}\] ' if error: p += '\[\w+\] ' for line in f: self.assertRegex(line, p + msgs[i] + '\n') i += 1
def check(): ''' Run an integrity check ''' Msg.info(_('{0} packages found').format(len(LocalRepo._repo))) Msg.process(_('Running integrity check')) errors = LocalRepo._repo.check() if not errors: Msg.info(_('No errors found')) Log.log(_('Finished integrity check without any errors')) return Log.log(_('Finished integrity check with errors:')) for e in errors: Msg.result(e) Log.error(e)
def check(): ''' Run an integrity check ''' Msg.info(_('{0} packages found').format(LocalRepo._repo.size)) Msg.process(_('Running integrity check')) errors = LocalRepo._repo.check() if not errors: Msg.info(_('No errors found')) Log.log(_('Finished integrity check without any errors')) return Log.log(_('Finished integrity check with errors:')) for e in errors: Msg.result(e) Log.error(e)
def test_log(self, error=False): msgs = [ 'Hello!', 'This is just a test...', 'Everything is fine... hopefully' ] Log.init(self.repo) for msg in msgs: Log.error(msg) if error else Log.log(msg) Log.close() with open(self.log) as f: i = 0 p = '^\[[0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}\] ' if error: p += '\[\w+\] ' for line in f: self.assertRegex(line, p + msgs[i] + '\n') i += 1
def error(error): ''' Prints the error message and shuts down ''' Msg.error(error.message) Log.error(error.message) LocalRepo.shutdown(1)
def shutdown(status=0): ''' Cleans up and exits with status ''' Package.clean() Log.close() exit(status)