[BIGUPDATE] now works with groups

This commit is contained in:
xdrm-brackets 2017-10-06 14:29:09 +02:00
parent 6c06a7a651
commit 3d6c59d8e5
13 changed files with 711 additions and 248 deletions

81
command/addppa Normal file
View File

@ -0,0 +1,81 @@
#!/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 );

View File

@ -3,7 +3,9 @@
import re;
from os import system as ossystem;
from os import path as ospath;
from sys import argv as sysargv;
import sys;
from parser import Manifest, Package;
# [1] get absolute path
#========================================================#
@ -12,28 +14,23 @@ path = ospath.dirname(ospath.dirname(ospath.realpath(__file__)));
# [2] get @deb_file argument
#========================================================#
deb_file = sysargv[1];
# [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
#========================================================#
manifest="";
with open( "%s/manifest" % path, 'r' ) as f:
manifest=f.readline();
man = Manifest.Manifest();
# [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 deb_file
#========================================================#
pkgName = "";
@ -50,7 +47,7 @@ with open( "%s/stdout" % path, 'r' ) as f:
m = findName.search(line);
if ( m != None ):
pkgName = "%s [deb]" % m.group(1);
pkgName = m.group(1);
# (3) On success and notice user #
@ -69,13 +66,21 @@ else:
#========================================================#
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);
# 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();
with open(manifest, 'w') as writer:
writer.write( replaced );

View File

@ -3,27 +3,27 @@
import re;
from os import system as ossystem;
from os import path as ospath;
from sys import argv as sysargv;
import sys;
from parser import Manifest, Package;
# [1] get absolute path
path = ospath.dirname(ospath.dirname(ospath.realpath(__file__)));
# [2] get packages
packages = sysargv[1:];
# [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:];
# [3] get packages
packages = ARGS[1:];
# [3] search for manifest file
manifest="";
with open( "%s/manifest" % path, 'r' ) as f:
manifest=f.readline();
man = Manifest.Manifest();
# [4] search for non-installed entries in manifest
alrdy = [];
findAlrdy = re.compile("^\s*\[[\. x]\]\s([a-zA-Z0-9_ \[\]-]+).*$", 0);
with open(manifest, 'r+') as f:
for line in f:
m = findAlrdy.search(line);
if ( m != None ):
alrdy.append( m.group(1) ) ;
# [5] Install packages
installed = [];
@ -43,13 +43,19 @@ for pkg in packages:
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);
# if existing package update it
if( man.hasPackage(pkg) ):
pkgReg = man.getPackage(pkg);
pkgReg.install();
if( OPTGROUP != None ):
man.mvPackage(pkg, OPTGROUP);
with open(manifest, 'w') as writer:
writer.write( replaced );
# else create package
else:
pkgNew = Package.Package(pkg, 'x');
if( OPTGROUP != None ):
man.addPackage(pkgNew, OPTGROUP);
else:
man.addPackage(pkgNew);
man.save();

View File

@ -3,39 +3,51 @@
import re;
from os import system as ossystem;
from os import path as ospath;
from sys import argv as sysargv;
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;
if( len(sys.argv) > 2 and ( sys.argv[1] == "-g" or sys.argv[1] == "--group" ) ):
OPTGROUP = sys.argv[2];
# [3] search for manifest file
manifest="";
with open( "%s/manifest" % path, 'r' ) as f:
manifest=f.readline();
man = Manifest.Manifest();
# [4] search for installed entries in manifest
pkgRegex = re.compile("^\s*\[(x| |\.)\]\s+(?:([a-zA-Z0-9_-]+)( \[deb\])?).*$", 0);
with open(manifest, 'r+') as f:
for line in f:
m = pkgRegex.search(line);
# [4] If group selected
if( OPTGROUP != None ):
if ( m != None ):
if( not man.hasGroup(OPTGROUP) ):
print "Unknown group";
exit(1);
# (1) Installed #
if m.group(1) == 'x':
print "\033[38;5;78m%s\033[0m" % (m.group(2)),
print "[%s]" % OPTGROUP;
for pkg_name in man._pkg[OPTGROUP]:
pkg = man._pkg[OPTGROUP][pkg_name];
if( pkg.isInstalled() ):
print "\033[38;5;78m",;
elif( pkg.isRemoved() ):
print "\033[38;5;208m",;
elif( pkg.isPurged() ):
print "\033[38;5;161m",;
# (2) Removed (not config) #
elif m.group(1) == '.':
print "\033[38;5;208m%s\033[0m" % (m.group(2)),
print "%s\033[0m" % pkg.serialize();
# (3) purged #
elif m.group(1) == ' ':
print "\033[38;5;161m%s\033[0m" % (m.group(2)),
# (4) If from deb #
if m.group(3) != None:
print "\033[0;49;34m[deb]\033[0m";
# [4] List all
else:
print;
for group in man._pkg:
print "[%s]" % group;
for pkg_name in man._pkg[group]:
pkg = man._pkg[group][pkg_name];
if( pkg.isInstalled() ):
print "\033[38;5;78m",;
elif( pkg.isRemoved() ):
print "\033[38;5;208m",;
elif( pkg.isPurged() ):
print "\033[38;5;161m",;
print "%s\033[0m" % pkg.serialize();

290
command/parser/Manifest.py Normal file
View File

@ -0,0 +1,290 @@
#!/usr/bin/env python
import re;
from os import path as ospath;
from Package import Package;
# (1) Initialisation
#--------------------------------------------------------#
# (1) Get absolute path #
ROOT = ospath.dirname( ospath.dirname(ospath.dirname(ospath.realpath(__file__))) );
# (2) Class declaration
#--------------------------------------------------------#
class Manifest:
_grp_re = r'^\[-\] (?P<name>.+)$';
_pkg_re = r'^(?P<pad>\s+)\[(?P<sta>[ x\.])\] (?P<name>[\w\.-]+)(?:\s*(?P<deb>\[deb\])|(?:\s*\[(?P<ppa>[\w\.-]+\/[\w\.-]+)\]))?(?:\s*# (?P<com>.+))?\s*$';
# (1) Constructor
#
# @file<String> Manifest file
#
#--------------------------------------------------------#
def __init__(self):
# (1) Try to read manifest path #
self._path = None;
with open( "%s/manifest" % ROOT, 'r' ) as f:
self._path = f.readline();
# (2) Manage error #
if( self._path == None ):
raise Exception('No manifest file given');
# (3) Initialize attributes #
self._grp = [];
self._pkg = {};
# (4) Parse the manifest file #
self._parse();
# (2) Parser method
#
#--------------------------------------------------------#
def _parse(self):
# (0) Init
#--------------------------------------------------------#
# (1) Create group matcher #
grpMatcher = re.compile(self._grp_re);
# (2) Create pkg matches #
pkgMatcher = re.compile(self._pkg_re);
# (3) Local variables #
grp = False;
grp_name = None;
# (2) Search for groups
#--------------------------------------------------------#
with open( "%s" % self._path, 'r' ) as f:
for l,line in enumerate(f):
# (1) If seeking for group #
if( grp == False ):
## {1} Check regex with the line ##
match = grpMatcher.search(line);
## {2} If don't match -> pass ##
if( match == None ):
continue;
## {3} Register group ##
grp = True;
grp_name = match.group('name');
self._grp.append( grp_name );
self._pkg[grp_name] = {};
# (2) If seeking for group's packages #
else:
## {1} Check regex with the line ##
match = pkgMatcher.search(line);
## {2} If don't match -> back to group seeking ##
if( match == None ):
grp = False;
continue;
## {3} Register package ##
pkg = Package(
name = match.group('name'),
sta = match.group('sta'),
pad = len(match.group('pad')),
deb = match.group('deb') != None,
ppa = match.group('ppa') if match.group('ppa') != None else None,
com = match.group('com') if match.group('com') != None else None
);
self._pkg[grp_name][match.group('name')] = pkg;
# (3) Return if a group exists
#
# @name<String> Group name
#
# @return exists<bool> Whether the group exists
#
#--------------------------------------------------------#
def hasGroup(self, name):
return name in self._grp;
# (4) Creates a group if it does not exist
#
# @name<String> Group name
#
# @return created<id> Created id
#
#--------------------------------------------------------#
def createGroup(self, name):
# (1) Error if already exists #
if( self.hasGroup(name) ):
return None;
# (2) Create group #
self._grp.append(name);
self._pkg[name] = [];
# (3) Return status #
for g,grp in enumerate(self._grp):
if( grp == name ):
return g;
return None;
# (5) Get a group's id
#
# @name<String> Group name
#
# @return id<int> Group id (None on error)
#
#--------------------------------------------------------#
def getGroup(self, name):
# (1) Error if doesn't exist #
if( not self.hasGroup(name) ):
return None;
# (2) Return id #
for g,grp in enumerate(self._grp):
if( grp == name ):
return g;
return None;
# (6) Check if the package exists
#
# @name<String> Package name
#
# @return exists<bool> Whether the package exists
#
#--------------------------------------------------------#
def hasPackage(self, name):
for grp in self._pkg:
for pkg in self._pkg[grp]:
if( pkg == name ):
return True;
return False;
# (7) Get a package by name
#
# @name<String> Package name
#
#--------------------------------------------------------#
def getPackage(self, name):
for grp in self._pkg:
for pkg in self._pkg[grp]:
if( pkg == name ):
return self._pkg[grp][pkg];
return None;
# (8) Adds a new package to a group
#
# @package<Package> Package object
# @group<String> Group name
#
# @return id<(int,int)> (id_group, id_pkg) of the created package (None on error)
#
#--------------------------------------------------------#
def addPackage(self, pkg, group="misc"):
# (1) Check pkg type #
if( not isinstance(pkg, Package) ):
return None;
# (2) Error if already exists #
if( self.hasPackage(pkg._name) ):
return None;
# (3) If missing group -> fail #
if( not self.hasGroup(group) ):
return None;
# (4) Create package #
self._pkg[group][ pkg.getName() ] = pkg;
# (4) Return status #
return True;
# (8) Move a package to another group
#
# @package<Package> Package name
# @group<String> Group name
#
# @return moved<bool> Whether it have been moved
#
#--------------------------------------------------------#
def mvPackage(self, pkg_name, group="misc"):
# (1) Error if not exists #
if( not self.hasPackage(pkg_name) ):
return False;
# (2) If missing group -> fail #
if( not self.hasGroup(group) ):
return False;
# (3) Get package #
pkgRef = self.getPackage(pkg_name);
# (4) Copy package to new group #
self._pkg[group][ pkg_name ] = pkgRef;
# (5) Remove package from old group #
for grp in self._pkg:
if( grp == group ):
continue;
for pkg in self._pkg[grp]:
if( pkg == pkg_name ):
del self._pkg[grp][pkg_name];
break;
# (4) Return status #
return True;
# (9) Save the current manifest
#
#--------------------------------------------------------#
def save(self):
with open( "%s" % self._path, 'w' ) as f:
for grp in self._pkg:
f.write("[-] %s\n" % grp );
for pkg in self._pkg[grp]:
f.write("%s\n" % self._pkg[grp][pkg].serialize());
f.write("\n");

109
command/parser/Package.py Normal file
View File

@ -0,0 +1,109 @@
#!/usr/bin/env python
class Package:
_com_pad = 40;
# (1) Constructs a new package
#
# @name<String> Package name
# @state<char> Package state ('x', ' ', '.')
# @com<String> Package comm (default: None)
# @ppa<(String, String)> Package ppa (default: None)
# @deb<Path> Path to local deb file (if deb) (default: None)
# @pad<int> Number of pad spaces (default: 2)
#
#--------------------------------------------------------#
def __init__(self, name=None, sta=None, com=None, ppa=None, deb=False, pad=2):
# (1) Arguments check
#--------------------------------------------------------#
# (1) Is name set #
if( name == None ):
raise Exception('Missing argument "name" !');
# (2) deb set but not a bool #
if( not isinstance(deb, bool) ):
raise Exception('Argument "deb" must be a boolean !');
# (3) Check pad is (+) int #
try:
pad = int(pad);
if( pad < 0 ):
raise Exception('Argument "pad" must be a positive integer !');
except ValueError:
raise Exception('Argument "pad" must be a positive integer !');
# (4) Check state #
if( sta != 'x' and sta != '.' and sta != ' ' ):
raise Exception('Argument "sta" is invalid or missing !');
# (2) Set attributes
#--------------------------------------------------------#
self._name = name;
self._sta = sta;
self._com = com;
self._ppa = "%s/%s" % (ppa[0], ppa[1]) if ppa != None else None;
self._deb = deb;
self._pad = pad;
# (2) Getters
def getName(self):
return self._name;
def getDeb(self):
return self._deb;
def getPpa(self):
return self._ppa;
def getPad(self):
return self._pad;
def getCom(self):
return self._com;
def isInstalled(self):
return self._sta == 'x';
def isRemoved(self):
return self._sta == '.';
def isPurged(self):
return self._sta == ' ';
def install(self):
self._sta = 'x';
def remove(self):
self._sta = '.';
def purge(self):
self._sta = ' ';
# (3) Serialize
#
#--------------------------------------------------------#
def serialize(self):
raw = '%s[%s] %s' % ( ' '*self._pad, self._sta, self._name);
if( self._ppa != None ):
raw += ' [%s]' % self._ppa;
elif( self._deb ):
raw += ' [deb]';
if( self._com != None ):
raw += ' ' * (self._com_pad - len(raw));
raw += '# %s' % self._com;
return raw;

View File

@ -3,31 +3,28 @@
import re;
from os import system as ossystem;
from os import path as ospath;
from sys import argv as sysargv;
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 = sysargv[1:];
packages = ARGS[1:];
# [3] search for manifest file
manifest="";
with open( "%s/manifest" % path, 'r' ) as f:
manifest=f.readline();
# [4] search for installed entries in manifest
alrdy = [];
findAlrdy = re.compile("^\s*\[x\]\s(?:([a-zA-Z0-9_-]+)(?: \[deb\])?).*$", 0);
with open(manifest, 'r+') as f:
for line in f:
m = findAlrdy.search(line);
if ( m != None ):
alrdy.append( m.group(1) ) ;
man = Manifest.Manifest();
# [5] Purge packages
purged = [];
for pkg in packages:
print "\033[38;5;208m[purge](%d/%d) %s\033[0m" % (packages.index(pkg)+1, len(packages), pkg);
exitcode = ossystem("sudo apt-get purge %s" % pkg);
@ -44,13 +41,20 @@ for pkg in packages:
for pkg in purged:
print "\033[38;5;39m[notifying](%d/%d) %s\033[0m" % (purged.index(pkg)+1, len(purged), pkg);
# if new package
if( not pkg in alrdy ):
with open(manifest, "a") as f:
f.write(" [ ] %s\n" % pkg);
else:
with open(manifest, 'r') as reader:
replaced = reader.read().replace("[x] %s" % pkg, "[ ] %s" % pkg).replace("[x] %s [deb]" % pkg, "[ ] %s [deb]" % pkg);
# if existing package update it
if( man.hasPackage(pkg) ):
pkgReg = man.getPackage(pkg);
pkgReg.purge();
if( OPTGROUP != None ):
man.mvPackage(pkg, OPTGROUP);
with open(manifest, 'w') as writer:
writer.write( replaced );
# else create package
else:
pkgNew = Package.Package(pkg, ' ');
if( OPTGROUP != None ):
man.addPackage(pkgNew, OPTGROUP);
else:
man.addPackage(pkgNew);
man.save();

View File

@ -3,31 +3,29 @@
import re;
from os import system as ossystem;
from os import path as ospath;
from sys import argv as sysargv;
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 = sysargv[1:];
packages = ARGS[1:];
# [3] search for manifest file
manifest="";
with open( "%s/manifest" % path, 'r' ) as f:
manifest=f.readline();
# [4] search for installed entries in manifest
alrdy = [];
findAlrdy = re.compile("^\s*\[x\]\s(?:([a-zA-Z0-9_-]+)(?: \[deb\])?).*$", 0);
with open(manifest, 'r+') as f:
for line in f:
m = findAlrdy.search(line);
if ( m != None ):
alrdy.append( m.group(1) ) ;
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);
@ -44,13 +42,20 @@ for pkg in packages:
for pkg in removed:
print "\033[38;5;39m[notifying](%d/%d) %s\033[0m" % (removed.index(pkg)+1, len(removed), pkg);
# if new package
if( not pkg in alrdy ):
with open(manifest, "a") as f:
f.write(" [.] %s\n" % pkg);
else:
with open(manifest, 'r') as reader:
replaced = reader.read().replace("[x] %s" % pkg, "[.] %s" % pkg).replace("[x] %s [deb]" % pkg, "[.] %s [deb]" % pkg);
# if existing package update it
if( man.hasPackage(pkg) ):
pkgReg = man.getPackage(pkg);
pkgReg.remove();
if( OPTGROUP != None ):
man.mvPackage(pkg, OPTGROUP);
with open(manifest, 'w') as writer:
writer.write( replaced );
# else create package
else:
pkgNew = Package.Package(pkg, '.');
man.addPackage(pkgNew);
if( OPTGROUP != None ):
man.addPackage(pkgNew, OPTGROUP);
else:
man.addPackage(pkgNew);
man.save();

70
main
View File

@ -20,6 +20,11 @@ def showhelp():
print;
print "\033[1mSYNOPSIS\033[0m"
print "\tapt-plus <command> <packages>";
print "\tapt-plus -g <group> <command> <packages>";
print "\tapt-plus --gropu <group> <command> <packages>";
print;
print "\t-g, --group <group>";
print "\t\tProccess actions within a specific group (applies to: install, purge, remove, list, deb install).";
print;
print "\033[1mDESCRIPTION\033[0m"
print ""
@ -57,14 +62,27 @@ def showhelp():
print "\t-u, --update";
print "\t\tUpgrades packages and kernel and cleans after";
print;
print "\t-a, --add-ppa <ppa_link>";
print "\t\tAdds the <ppa_link> repository to dpkg then update it";
print;
# [2] Command dispatch (if at least 1 arg)
#========================================================#
if ( len(sys.argv) > 1 ):
# (1) Manage optional -g --group modifier
#--------------------------------------------------------#
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) Normal arguments
#--------------------------------------------------------#
# (1) Get the command argument (first) #
command = sys.argv[1];
command = ARGS[1];
# (1) --update, -u
#--------------------------------------------------------#
@ -83,21 +101,27 @@ if ( len(sys.argv) > 1 ):
elif ( command == "-d" or command == "--deb" ):
# if package/s given
if ( len(sys.argv) < 3 ):
if ( len(ARGS) < 3 ):
sys.exit("\n(!) Missing argument <deb_file>");
ossystem("/usr/bin/env python %s/command/debinstall %s" % (path, sys.argv[2]) );
if( OPTGROUP != None ):
ossystem("/usr/bin/env python %s/command/debinstall -g %s %s" % (path, OPTGROUP, ARGS[2]) );
else:
ossystem("/usr/bin/env python %s/command/debinstall %s" % (path, ARGS[2]) );
# (4) --install, -i
#--------------------------------------------------------#
elif ( command == "-i" or command == "--install" ):
# if package/s given
if ( len(sys.argv) < 3 ):
if ( len(ARGS) < 3 ):
sys.exit("\n(!) Missing argument <packages>");
packages = " ".join(sys.argv[2:]);
packages = " ".join(ARGS[2:]);
if( OPTGROUP != None ):
ossystem("/usr/bin/env python %s/command/install -g %s %s" % (path, OPTGROUP, packages) );
else:
ossystem("/usr/bin/env python %s/command/install %s" % (path, packages) );
# (5) --remove, -r
@ -105,20 +129,27 @@ if ( len(sys.argv) > 1 ):
elif ( command == "-r" or command == "--remove" ):
# if package/s given
if ( len(sys.argv) < 3 ):
if ( len(ARGS) < 3 ):
sys.exit("\n(!) Missing argument <packages>");
packages = " ".join(sys.argv[2:]);
packages = " ".join(ARGS[2:]);
if( OPTGROUP != None ):
ossystem("/usr/bin/env python %s/command/remove -g %s %s" % (path, OPTGROUP, packages) );
else:
ossystem("/usr/bin/env python %s/command/remove %s" % (path, packages) );
# (6) --purge, -p
#--------------------------------------------------------#
elif ( command == "-p" or command == "--purge" ):
# if package/s given
if ( len(sys.argv) < 3 ):
if ( len(ARGS) < 3 ):
sys.exit("\n(!) Missing argument <packages>");
packages = " ".join(sys.argv[2:]);
packages = " ".join(ARGS[2:]);
if( OPTGROUP != None ):
ossystem("/usr/bin/env python %s/command/purge -g %s %s" % (path, OPTGROUP, packages) );
else:
ossystem("/usr/bin/env python %s/command/purge %s" % (path, packages) );
# (7) --manifest, -m
@ -126,15 +157,15 @@ if ( len(sys.argv) > 1 ):
elif ( command == "-m" or command == "--manifest" ):
# (1) If argument missing -> abort #
if ( len(sys.argv) < 3 ):
if ( len(ARGS) < 3 ):
sys.exit("\n(!) Missing argument <manifest_file>");
# (2) If argument is not a valid file -> abort #
elif ( not ospath.isfile(sys.argv[2]) ):
elif ( not ospath.isfile(ARGS[2]) ):
sys.exit("Given path isn't a file");
# (3) Store absolute path in ./manifest file #
file = ospath.realpath(sys.argv[2]);
file = ospath.realpath(ARGS[2]);
with open( ("%s/manifest" % path), "w") as f:
f.write(file);
@ -142,9 +173,22 @@ if ( len(sys.argv) > 1 ):
#--------------------------------------------------------#
elif ( command == "-l" or command == "--list" ):
if( OPTGROUP != None ):
ossystem("/usr/bin/env python %s/command/list -g %s" % (path, OPTGROUP) );
else:
ossystem("/usr/bin/env python %s/command/list" % path );
# (9) If no match -> show help message
# (9) --add-ppa, -a
#--------------------------------------------------------#
elif ( command == "-a" or command == "--add-ppa" ):
# if ppa is given
if ( len(ARGS) < 3 ):
sys.exit("\n(!) Missing argument <ppa_link>");
ossystem("/usr/bin/env python %s/command/addppa %s" % (path, ARGS[2]) );
# (10) If no match -> show help message
#--------------------------------------------------------#
else:
showhelp();

View File

@ -1 +1 @@
/home/xdrm-brackets/.x-migration
/home/xdrm-brackets/.apt-plus

View File

@ -1,108 +0,0 @@
#!/usr/bin/env python
import re;
from os import path as ospath;
# (1) Initialisation
#--------------------------------------------------------#
# (1) Get absolute path #
ROOT = ospath.dirname(ospath.dirname(ospath.realpath(__file__)));
# (2) Class declaration
#--------------------------------------------------------#
class Class:
_grp_re = r'^\[-\] (?P<name>.+)$';
_pkg_re = r'^(?P<pad>\s+)\[[ x\.]\] (?P<name>[\w\.-]+)(?:\s*(?P<deb>\[deb\])|(?:\s*\[(?P<ppa>[\w\.-]+\/[\w\.-]+)\]))?(?:\s*# (?P<com>.+))?\s*$';
# (1) Constructor
#
# @file<String> Manifest file
#
#--------------------------------------------------------#
def __init__(self):
# (1) Try to read manifest path #
self._path = None;
with open( "%s/manifest" % ROOT, 'r' ) as f:
self._path = f.readline();
# (2) Manage error #
if( self._path == None ):
raise Exception('No manifest file given');
# (3) Initialize attributes #
self._grp = [];
self._pkg = {};
# (2) Parser method
#
#--------------------------------------------------------#
def _parse(self):
# (0) Init
#--------------------------------------------------------#
# (1) Create group matcher #
grpMatcher = re.compile(self._grp_re);
# (2) Create pkg matches #
pkgMatcher = re.compile(self._pkg_re);
# (3) Local variables #
grp = False;
grp_name = None;
# (2) Search for groups
#--------------------------------------------------------#
with open( "%s" % self._path, 'r' ) as f:
for l,line in enumerate(f):
# (1) If seeking for group #
if( grp == False ):
## {1} Check regex with the line ##
match = grpMatcher.search(line);
## {2} If don't match -> pass ##
if( match == None ):
continue;
## {3} Register group ##
grp = True;
grp_name = match.group('name');
self._grp.append( grp_name );
self._pkg[grp_name] = [];
# (2) If seeking for group's packages #
else:
## {1} Check regex with the line ##
match = pkgMatcher.search(line);
## {2} If don't match -> back to group seeking ##
if( match == None ):
grp = False;
continue;
## {3} Register package ##
pkg = {
'pad': len(match.group('pad')),
'name': match.group('name'),
'is_deb': match.group('deb') != None,
'ppa': match.group('ppa') if match.group('ppa') != None else None,
'com': match.group('com') if match.group('com') != None else None
};
self._pkg[grp_name].append(pkg);
print self._grp;
print self._pkg;

15
test.py Normal file
View File

@ -0,0 +1,15 @@
#!/usr/bin/env python
from parser import Manifest;
from parser import Package;
p = Manifest.Manifest();
pkg = Package.Package('pkgname', 'x', com="blabla sdfkj dfskj", deb=True);
# print p.hasPackage('blender');
p.addPackage(pkg, 'Basis');
pkg.remove();
# print p._pkg['Basis']['pkgname'].serialize();
p.save();