87 lines
2.0 KiB
Python
87 lines
2.0 KiB
Python
#!/usr/bin/env python
|
|
|
|
import re;
|
|
from os import system as ossystem;
|
|
from os import path as ospath;
|
|
import sys;
|
|
|
|
from parser import Manifest, Package;
|
|
|
|
# [1] get absolute path
|
|
#========================================================#
|
|
path = ospath.dirname(ospath.dirname(ospath.realpath(__file__)));
|
|
|
|
|
|
# [2] get @deb_file argument
|
|
#========================================================#
|
|
|
|
# [2] get group option (if set)
|
|
OPTGROUP = None;
|
|
ARGS = sys.argv;
|
|
if( len(sys.argv) > 2 and ( sys.argv[1] == "-g" or sys.argv[1] == "--group" ) ):
|
|
OPTGROUP = sys.argv[2];
|
|
ARGS = ARGS[0:1] + ARGS[3:];
|
|
|
|
deb_file = ARGS[1];
|
|
|
|
|
|
# [3] search for manifest file
|
|
#========================================================#
|
|
man = Manifest.Manifest();
|
|
|
|
|
|
|
|
# [5] Install the deb_file
|
|
#========================================================#
|
|
pkgName = "";
|
|
|
|
# (1) Try to install #
|
|
print "\033[38;5;208m[deb-install] %s\033[0m" % (deb_file);
|
|
exitcode = ossystem("sudo dpkg -i %s > %s/stdout" % (deb_file, 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 = 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 existing package update it
|
|
if( man.hasPackage(pkgName) ):
|
|
pkgReg = man.getPackage(pkgName);
|
|
if( OPTGROUP != None ):
|
|
man.mvPackage(pkgName, OPTGROUP);
|
|
pkgReg._deb = True;
|
|
pkgReg.install();
|
|
|
|
# else create package
|
|
else:
|
|
pkgNew = Package.Package(pkgName, 'x', deb=True);
|
|
if( OPTGROUP != None ):
|
|
man.addPackage(pkgNew, OPTGROUP);
|
|
else:
|
|
man.addPackage(pkgNew);
|
|
|
|
man.save();
|
|
|