-
-
Save vrld/5671846 to your computer and use it in GitHub Desktop.
Quick hack to get a more comfortable search tool on APT-based distros. Inspired by gentoo's wonderful `eix'.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
class AnsiColor: | |
default = '\033[00;30m' | |
bold = '\033[01;30m' | |
green = '\033[00;32m' | |
boldgreen = '\033[01;32m' | |
boldred = '\033[01;31m' | |
pass | |
def human_readable_size(size): | |
from math import log | |
size = float(size) | |
exp = max(int(log(size, 1024)), 0) | |
mant = int(.5 + size / float(1024**exp)) | |
return '{0} {1}'.format(mant, ('Byte', 'KB', 'MB', 'GB', 'TB', 'PB')[exp]) | |
def more_info(pkg): | |
ret = [] | |
if pkg.is_installed: | |
ret.append('{0.boldgreen}(installed)'.format(AnsiColor)) | |
if pkg.essential: | |
ret.append('{0.boldred}(essential)'.format(AnsiColor)) | |
return AnsiColor.default+' '.join(ret) | |
def main(): | |
import apt, re, sys | |
if len(sys.argv) < 2: | |
print """Usage: aix [query] | |
[query] is a (python) regex that the package name must match""" | |
return 1 | |
query = re.compile(sys.argv[1]) | |
cache = apt.Cache() | |
for k in filter(lambda x: query.search(x), cache.keys()): | |
p = cache[k] | |
print '{1.boldgreen}*{1.default} {0.section}/{1.bold}{0.name}{1.default}'.format(p, AnsiColor),more_info(p) | |
print '\t{1.green}Size:{1.default} {0}'.format(human_readable_size(p.candidate.size), AnsiColor) | |
if p.candidate.homepage != '': | |
print '\t{1.green}Homepage:{1.default} {0.homepage}'.format(p.candidate, AnsiColor) | |
print '\t{1.green}Description:{1.default} {0.summary}'.format(p.candidate, AnsiColor) | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment