def search(args): """Search for package names containing the given pattern If '::' is found in the search term, use a debtags search; example: $ wajig search implemented-in::python balazar - adventure/action game Balazar -- Arkanae II, reforged scepters compizconfig-settings-manager - Compizconfig Settings Manager ... """ if len(args.patterns) == 1 and '::' in args.patterns[0]: util.requires_package('debtags') command = 'debtags search ' + args.patterns[0] if args.verbose: command += ' --full' elif not args.verbose: command = "apt-cache --names-only search {}" command = command.format(" ".join(args.patterns)) elif args.verbose == 1: import shlex args.patterns = [shlex.quote(pattern) for pattern in args.patterns] command = "apt-cache search {} | grep -E --ignore-case '{}'" command = command.format(" ".join(args.patterns), "\|".join(args.patterns)) else: command = "apt-cache search --full " + " ".join(args.patterns) perform.execute(command)
def search(args): """Search for package names containing the given pattern If '::' is found in the search term, use a debtags search; example: $ wajig search implemented-in::python balazar - adventure/action game Balazar -- Arkanae II, reforged scepters compizconfig-settings-manager - Compizconfig Settings Manager ... """ if len(args.patterns) == 1 and '::' in args.patterns[0]: util.requires_package('debtags') command = 'debtags search ' + args.patterns[0] if args.verbose: command += ' --full' elif not args.verbose: command = "apt --names-only search {}" command = command.format(" ".join(args.patterns)) elif args.verbose == 1: import shlex args.patterns = [shlex.quote(pattern) for pattern in args.patterns] command = "apt search {} | grep -E --ignore-case '{}'" command = command.format(" ".join(args.patterns), "\|".join(args.patterns)) else: command = "apt search --full " + " ".join(args.patterns) perform.execute(command)
def versions(args): """List version and distribution of given packages""" util.requires_package("apt-show-versions") if args.packages: for package in args.packages: perform.execute("apt-show-versions " + package) else: perform.execute("apt-show-versions")
def addrepo(args): """Add a Launchpad PPA (Personal Package Archive) repository An example that shows how to add the daily builds of Google's Chromium browser: $ wajig addrepo ppa:chromium-daily""" util.requires_package("add-apt-repository") perform.execute("/usr/bin/add-apt-repository " + args.ppa, root=True)
def build(args): """Get source packages, unpack them, and build binary packages from them. This also installs the needed build-dependencies if needed.""" util.requires_package("sudo") # First make sure dependencies are met if not builddeps(args): command = "apt-get {} source --build " + " ".join(args.packages) command = command.format(args.noauth) perform.execute(command)
def removeorphans(args): """Remove orphaned libraries""" util.requires_package("deborphan") packages = "" for package in perform.execute("deborphan", pipe=True): packages += " " + package.strip() if packages: command = "/usr/bin/apt-get --auto-remove remove {} {}" command = command.format(args.yes, packages) perform.execute(command, root=True, log=True)
def addrepo(args): """Add a Launchpad PPA (Personal Package Archive) repository An example that shows how to add the daily builds of Google's Chromium browser: $ wajig addrepo ppa:chromium-daily """ util.requires_package("add-apt-repository") perform.execute("/usr/bin/add-apt-repository " + args.ppa, root=True)
def build(args): """Get source packages, unpack them, and build binary packages from them. Note: This also installs the needed build-dependencies if needed """ util.requires_package("sudo") # First make sure dependencies are met if not builddeps(args): command = "apt-get {} source --build " + " ".join(args.packages) command = command.format(args.noauth) perform.execute(command)
def purgeorphans(args): """Purge orphaned libraries (not required by installed packages)""" # Deborphans does not require root, but dpkg does, # so build up the orphans list first, then pass that to dpkg. util.requires_package("deborphan") packages = "" for package in perform.execute("deborphan", pipe=True): packages += " " + package.strip() if packages: command = "/usr/bin/apt-get --auto-remove purge {} {}" command = command.format(args.yes, packages) perform.execute(command, root=True, log=True)
def whichpackage(args): """Search for files matching a given pattern within packages Note: if no match is found, the apt-file repository is checked""" try: out = perform.execute("dpkg --search " + args.pattern, getoutput=True) except subprocess.CalledProcessError: util.requires_package("apt-file") perform.execute("apt-file search " + args.pattern) else: try: print(out.decode().strip()) # will get here when on --simulate mode except AttributeError: pass
def upgrade(args): """Conservative system upgrade This will not go as far remove packages in order to fulfill the upgrade, so may leave stale packages around. Use 'dist-upgrade' to avoid that. """ packages = util.upgradable() if packages: if args.backup: util.requires_package("dpkg-repack") util.requires_package("fakeroot") util.backup_before_upgrade(packages) command = "/usr/bin/apt-get {} {} {} --show-upgraded --with-new-pkgs upgrade" command = command.format(args.local, args.yes, args.noauth) perform.execute(command, root=True, log=True) else: print('No upgradeable packages. Did you run "wajig update" first?')
def upgrade(args): """Conservative system upgrade This will not go as far remove packages in order to fulfill the upgrade, so may leave stale packages around. Use 'dist-upgrade' to avoid that. """ packages = util.upgradable() if packages: if args.backup: util.requires_package("dpkg-repack") util.requires_package("fakeroot") util.backup_before_upgrade(packages) command = ( "/usr/bin/apt-get {} {} {} --show-upgraded --with-new-pkgs upgrade" ) command = command.format(args.local, args.yes, args.noauth) perform.execute(command, root=True, log=True) else: print('No upgradeable packages. Did you run "wajig update" first?')
def distupgrade(args): """Comprehensive system upgrade This may remove some packages in order to ensure no package is left stale. Use the more conservative 'upgrade' command to avoid that. """ packages = util.upgradable(distupgrade=True) if not packages and not args.dist: print('No upgrades. Did you run "wajig update" beforehand?') return if args.backup: util.requires_package("dpkg-repack") util.requires_package("fakeroot") util.backup_before_upgrade(packages, distupgrade=True) cmd = "/usr/bin/apt-get --show-upgraded {} {} {} ".format(args.local, args.yes, args.noauth) if args.dist: cmd += "--target-release " + args.dist + " " cmd += "dist-upgrade" perform.execute(cmd, root=True, log=True)
def distupgrade(args): """Comprehensive system upgrade This may remove some packages in order to ensure no package is left stale. Use the more conservative 'upgrade' command to avoid that. """ packages = util.upgradable(distupgrade=True) if not packages and not args.dist: print('No upgrades. Did you run "wajig update" beforehand?') return if args.backup: util.requires_package("dpkg-repack") util.requires_package("fakeroot") util.backup_before_upgrade(packages, distupgrade=True) cmd = "/usr/bin/apt --show-upgraded {} {} {} ".format( args.local, args.yes, args.noauth ) if args.dist: cmd += "--target-release " + args.dist + " " cmd += "full-upgrade" perform.execute(cmd, root=True, log=True)
def orphans(args): """List libraries not required by any installed package """ util.requires_package("deborphan") perform.execute("deborphan")
def integrity(args): """Check the integrity of installed packages (through checksums)""" util.requires_package("debsums") perform.execute("debsums --all --silent")
def nonfree(args): """List packages that don't meet the Debian Free Software Guidelines""" util.requires_package("vrms") perform.execute("vrms")
def repackage(args): """Generate a .deb file from an installed package""" util.requires_package("dpkg-repack") util.requires_package("fakeroot") command = "fakeroot --unknown-is-real dpkg-repack " + args.package perform.execute(command)
def verify(args): """Check package's md5sum""" util.requires_package("debsums") perform.execute("debsums " + args.package)
def updatepciids(args): """Updates the local list of PCI ids from the internet master list""" util.requires_package("pciutils", path="/usr/bin/update-pciids") perform.execute("/usr/bin/update-pciids", root=True)
def tasksel(args): """Run the task selector to install groups of packages""" util.requires_package("tasksel") perform.execute("/usr/bin/tasksel", root=True, log=True)
def updateusbids(args): """Updates the local list of USB ids from the internet master list""" util.requires_package("usbutils", path="/usr/sbin/update-usbids") perform.execute("/usr/sbin/update-usbids", root=True)
def reportbug(args): """Report a bug in a package using Debian BTS (Bug Tracking System)""" util.requires_package("reportbug", "/usr/bin/reportbug") perform.execute("reportbug " + args.package)
def rbuilddeps(args): """Display the packages which build-depend on the given package""" util.requires_package("grep-dctrl") command = "grep-available -sPackage -FBuild-Depends,Build-Depends-Indep " command = command + args.package + " /var/lib/apt/lists/*Sources" perform.execute(command)
def searchapt(args): """Find nearby Debian package repositories""" util.requires_package("netselect-apt") command = "netselect-apt " + args.dist perform.execute(command)
def move(args): """Move packages in the download cache to a local Debian mirror""" util.requires_package("apt-move") perform.execute("/usr/bin/apt-move update", root=True)
def listdaemons(args): """List the daemons that wajig can start, stop, restart, or reload""" util.requires_package("chkconfig") perform.execute("chkconfig")
def source(args): """Retrieve and unpack sources for the named packages""" util.requires_package("dpkg-source") perform.execute("apt-get source " + " ".join(args.packages))
def test_util_requires_package(self): res = util.requires_package("ls", "/bin/ls", test=True) self.assertTrue(res) res = util.requires_package("ls", "TEST", test=True) self.assertFalse(res)