apt-plus/command/install

56 lines
1.5 KiB
Plaintext
Raw Permalink Normal View History

#!/usr/bin/env python
2017-01-01 18:17:29 +00:00
import re;
from os import system as ossystem;
from os import path as ospath;
from sys import argv as sysargv;
# [1] get absolute path
path = ospath.dirname(ospath.dirname(ospath.realpath(__file__)));
2017-01-01 18:17:29 +00:00
# [2] get packages
packages = sysargv[1:];
# [3] search for manifest file
manifest="";
with open( "%s/manifest" % path, 'r' ) as f:
manifest=f.readline();
# [4] search for non-installed entries in manifest
alrdy = [];
findAlrdy = re.compile("^\s*\[[\. x]\]\s([a-zA-Z0-9_ \[\]-]+).*$", 0);
2017-01-01 18:17:29 +00:00
with open(manifest, 'r+') as f:
for line in f:
m = findAlrdy.search(line);
2017-01-01 18:17:29 +00:00
if ( m != None ):
alrdy.append( m.group(1) ) ;
# [5] Install packages
installed = [];
for pkg in packages:
print "\033[38;5;208m[install](%d/%d) %s\033[0m" % (packages.index(pkg)+1, len(packages), pkg);
exitcode = ossystem("sudo apt-get install %s" % pkg);
2017-01-01 18:17:29 +00:00
# if all ran successfully
if ( exitcode == 0 ):
print "\033[38;5;78msuccess\033[0m";
installed.append( pkg );
else:
print "\033[38;5;161merror\033[0m";
# [6] update manifest
for pkg in installed:
print "\033[38;5;39m[notifying](%d/%d) %s\033[0m" % (installed.index(pkg)+1, len(installed), pkg);
# if new package
if( not pkg in alrdy ):
with open(manifest, "a") as f:
f.write(" [x] %s\n" % pkg);
else:
with open(manifest, 'r') as reader:
replaced = reader.read().replace("[ ] %s" % pkg, "[x] %s" % pkg).replace("[.] %s" % pkg, "[x] %s" % pkg);
with open(manifest, 'w') as writer:
writer.write( replaced );