apt-plus/command/remove

62 lines
1.4 KiB
Python
Executable File

#!/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 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:];
# [2] get packages
packages = ARGS[1:];
# [3] search for manifest file
man = Manifest.Manifest();
# [5] Remove packages
removed = [];
for pkg in packages:
print "\033[38;5;208m[remove](%d/%d) %s\033[0m" % (packages.index(pkg)+1, len(packages), pkg);
exitcode = ossystem("sudo apt-get remove %s" % pkg);
# if all ran successfully
if ( exitcode == 0 ):
print "\033[38;5;78msuccess\033[0m";
removed.append( pkg );
else:
print "\033[38;5;161merror\033[0m";
# [6] update manifest
for pkg in removed:
print "\033[38;5;39m[notifying](%d/%d) %s\033[0m" % (removed.index(pkg)+1, len(removed), pkg);
# if existing package update it
if( man.hasPackage(pkg) ):
pkgReg = man.getPackage(pkg);
pkgReg.remove();
if( OPTGROUP != None ):
man.mvPackage(pkg, OPTGROUP);
# else create package
else:
pkgNew = Package.Package(pkg, '.');
man.addPackage(pkgNew);
if( OPTGROUP != None ):
man.addPackage(pkgNew, OPTGROUP);
else:
man.addPackage(pkgNew);
man.save();