Added command --list/-l to list the stored packages + allowed comments after the generated data (but overrides it if action performed on)

This commit is contained in:
xdrm-brackets 2017-10-02 09:01:46 +02:00
parent ba962c8d4c
commit 1995c483d7
6 changed files with 55 additions and 5 deletions

View File

@ -18,7 +18,7 @@ with open( "%s/manifest" % path, 'r' ) as f:
# [4] search for non-installed entries in manifest # [4] search for non-installed entries in manifest
alrdy = []; alrdy = [];
findAlrdy = re.compile("^\s*\[[\. x]\]\s([a-zA-Z0-9_ \[\]-]+)$", 0); findAlrdy = re.compile("^\s*\[[\. x]\]\s([a-zA-Z0-9_ \[\]-]+).*$", 0);
with open(manifest, 'r+') as f: with open(manifest, 'r+') as f:
for line in f: for line in f:
m = findAlrdy.search(line); m = findAlrdy.search(line);

41
command/list Normal file
View File

@ -0,0 +1,41 @@
#!/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__)));
# [3] search for manifest file
manifest="";
with open( "%s/manifest" % path, 'r' ) as f:
manifest=f.readline();
# [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);
if ( m != None ):
# (1) Installed #
if m.group(1) == 'x':
print "\033[38;5;78m%s\033[0m" % (m.group(2)),
# (2) Removed (not config) #
elif m.group(1) == '.':
print "\033[38;5;208m%s\033[0m" % (m.group(2)),
# (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";
else:
print;

View File

@ -18,7 +18,7 @@ with open( "%s/manifest" % path, 'r' ) as f:
# [4] search for installed entries in manifest # [4] search for installed entries in manifest
alrdy = []; alrdy = [];
findAlrdy = re.compile("^\s*\[x\]\s(?:([a-zA-Z0-9_-]+)(?: \[deb\])?)$", 0); findAlrdy = re.compile("^\s*\[x\]\s(?:([a-zA-Z0-9_-]+)(?: \[deb\])?).*$", 0);
with open(manifest, 'r+') as f: with open(manifest, 'r+') as f:
for line in f: for line in f:
m = findAlrdy.search(line); m = findAlrdy.search(line);

View File

@ -18,7 +18,7 @@ with open( "%s/manifest" % path, 'r' ) as f:
# [4] search for installed entries in manifest # [4] search for installed entries in manifest
alrdy = []; alrdy = [];
findAlrdy = re.compile("^\s*\[x\]\s(?:([a-zA-Z0-9_-]+)(?: \[deb\])?)$", 0); findAlrdy = re.compile("^\s*\[x\]\s(?:([a-zA-Z0-9_-]+)(?: \[deb\])?).*$", 0);
with open(manifest, 'r+') as f: with open(manifest, 'r+') as f:
for line in f: for line in f:
m = findAlrdy.search(line); m = findAlrdy.search(line);

11
main
View File

@ -28,6 +28,9 @@ def showhelp():
print "\tThese logs are stored in the manifest file (default is ~/.x-migration)."; print "\tThese logs are stored in the manifest file (default is ~/.x-migration).";
print; print;
print "\033[1mOPTIONS\033[0m" print "\033[1mOPTIONS\033[0m"
print "\t-l, --list";
print "\t\tList all the packages stored in the manifest.";
print;
print "\t-d, --deb <deb_file>"; print "\t-d, --deb <deb_file>";
print "\t\tInstalls a package from a .deb file and notice it in the manifest."; print "\t\tInstalls a package from a .deb file and notice it in the manifest.";
print; print;
@ -135,7 +138,13 @@ if ( len(sys.argv) > 1 ):
with open( ("%s/manifest" % path), "w") as f: with open( ("%s/manifest" % path), "w") as f:
f.write(file); f.write(file);
# (8) If no match -> show help message # (8) --list, -l
#--------------------------------------------------------#
elif ( command == "-l" or command == "--list" ):
ossystem("/usr/bin/env python %s/command/list" % path );
# (9) If no match -> show help message
#--------------------------------------------------------# #--------------------------------------------------------#
else: else:
showhelp(); showhelp();

View File

@ -1 +1 @@
~/.x-migration /home/xdrm-brackets/.x-migration