82 lines
2.1 KiB
Plaintext
82 lines
2.1 KiB
Plaintext
|
#!/usr/bin/env python
|
||
|
|
||
|
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__)));
|
||
|
|
||
|
|
||
|
# [2] get @ppa_link argument
|
||
|
#========================================================#
|
||
|
ppa_link = sysargv[1];
|
||
|
|
||
|
|
||
|
# [3] search for manifest file
|
||
|
#========================================================#
|
||
|
manifest="";
|
||
|
with open( "%s/manifest" % path, 'r' ) as f:
|
||
|
manifest=f.readline();
|
||
|
|
||
|
|
||
|
|
||
|
# [4] search for already installed entries in manifest
|
||
|
#========================================================#
|
||
|
alrdy = [];
|
||
|
findPkg = re.compile("^\s*\[[\. x]\]\s([a-zA-Z0-9_ \[\]-]+)$", 0);
|
||
|
with open(manifest, 'r+') as f:
|
||
|
for line in f:
|
||
|
m = findPkg.search(line);
|
||
|
if ( m != None ):
|
||
|
alrdy.append( m.group(1) ) ;
|
||
|
|
||
|
|
||
|
# [5] Install the ppa_link
|
||
|
#========================================================#
|
||
|
pkgName = "";
|
||
|
|
||
|
# (1) Try to install #
|
||
|
print "\033[38;5;208m[deb-install] %s\033[0m" % (ppa_link);
|
||
|
exitcode = ossystem("sudo dpkg -i %s > %s/stdout" % (ppa_link, path));
|
||
|
|
||
|
# (2) Read local stdout copy of stdout #
|
||
|
findName = re.compile("^Unpacking ([a-zA-Z0-9_-]+)", re.MULTILINE)
|
||
|
with open( "%s/stdout" % path, 'r' ) as f:
|
||
|
line = f.read();
|
||
|
print line;
|
||
|
m = findName.search(line);
|
||
|
|
||
|
if ( m != None ):
|
||
|
pkgName = "%s [deb]" % m.group(1);
|
||
|
|
||
|
|
||
|
# (3) On success and notice user #
|
||
|
if ( exitcode == 0 and len(pkgName) > 0 ):
|
||
|
print "\033[38;5;78msuccess\033[0m";
|
||
|
|
||
|
# (4) On failure notice user -> abort #
|
||
|
else:
|
||
|
print "\033[38;5;161merror\033[0m";
|
||
|
exit(1);
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
# [6] Update manifest
|
||
|
#========================================================#
|
||
|
print "\033[38;5;39m[notifying] %s\033[0m" % (pkgName);
|
||
|
|
||
|
# if new package
|
||
|
if( not pkgName in alrdy ):
|
||
|
with open(manifest, "a") as f:
|
||
|
f.write(" [x] %s\n" % pkgName);
|
||
|
else:
|
||
|
with open(manifest, 'r') as reader:
|
||
|
replaced = reader.read().replace("[ ] %s" % pkgName, "[x] %s" % pkgName).replace("[.] %s" % pkgName, "[x] %s" % pkgName);
|
||
|
|
||
|
with open(manifest, 'w') as writer:
|
||
|
writer.write( replaced );
|