From 1995c483d703dcc7774662343e72106e93e4620d Mon Sep 17 00:00:00 2001 From: xdrm-brackets Date: Mon, 2 Oct 2017 09:01:46 +0200 Subject: [PATCH] Added command --list/-l to list the stored packages + allowed comments after the generated data (but overrides it if action performed on) --- command/install | 2 +- command/list | 41 +++++++++++++++++++++++++++++++++++++++++ command/purge | 2 +- command/remove | 2 +- main | 11 ++++++++++- manifest | 2 +- 6 files changed, 55 insertions(+), 5 deletions(-) create mode 100644 command/list diff --git a/command/install b/command/install index 1dd188d..f64989b 100755 --- a/command/install +++ b/command/install @@ -18,7 +18,7 @@ with open( "%s/manifest" % path, 'r' ) as f: # [4] search for non-installed entries in manifest 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: for line in f: m = findAlrdy.search(line); diff --git a/command/list b/command/list new file mode 100644 index 0000000..defb508 --- /dev/null +++ b/command/list @@ -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; \ No newline at end of file diff --git a/command/purge b/command/purge index 755cf60..c1cfcc8 100755 --- a/command/purge +++ b/command/purge @@ -18,7 +18,7 @@ with open( "%s/manifest" % path, 'r' ) as f: # [4] search for installed entries in manifest 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: for line in f: m = findAlrdy.search(line); diff --git a/command/remove b/command/remove index 17b1fd4..abec02f 100755 --- a/command/remove +++ b/command/remove @@ -18,7 +18,7 @@ with open( "%s/manifest" % path, 'r' ) as f: # [4] search for installed entries in manifest 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: for line in f: m = findAlrdy.search(line); diff --git a/main b/main index f5dc544..1f93886 100755 --- a/main +++ b/main @@ -28,6 +28,9 @@ def showhelp(): print "\tThese logs are stored in the manifest file (default is ~/.x-migration)."; print; print "\033[1mOPTIONS\033[0m" + print "\t-l, --list"; + print "\t\tList all the packages stored in the manifest."; + print; print "\t-d, --deb "; print "\t\tInstalls a package from a .deb file and notice it in the manifest."; print; @@ -135,7 +138,13 @@ if ( len(sys.argv) > 1 ): with open( ("%s/manifest" % path), "w") as f: 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: showhelp(); diff --git a/manifest b/manifest index 2a2ad89..73efadb 100755 --- a/manifest +++ b/manifest @@ -1 +1 @@ -~/.x-migration +/home/xdrm-brackets/.x-migration \ No newline at end of file