~fredg/twadeb

cb0df37291d7c6bd38999bb668729b6cbae0fc1e — alienus 10 years ago a909c3b
testing dpkg -r today pkgs
1 files changed, 18 insertions(+), 7 deletions(-)

M twadeb.py
M twadeb.py => twadeb.py +18 -7
@@ 18,6 18,7 @@ import glob
import argparse
from time import gmtime, strftime
import socket
import subprocess

# Program information
my_url = 'https://gitlab.com/alienus/twadeb'


@@ 34,6 35,10 @@ parser.add_argument('-t', '--today', action="store_true",
        default=False,
        help='show today installed/upgraded packages')

parser.add_argument('-r', '--remove', action="store_true",
        default=False,
        help='use with --today, remove today installed packages')

parser.add_argument('-l', '--list', action="store",
        dest='nb', default='10',
        help='list last NB installed/upgraded packages')


@@ 57,7 62,7 @@ alldpkg = '/var/log/dpkg.*'
nb = int(args.nb)
full = args.full
today = args.today

remove = args.remove
#
#
#


@@ 116,13 121,20 @@ def lastNpkgs(nb):
         print('-'*72)
    for elt in lPkg:
        date, time, keyword, package, verbef, ver = elt
        if today:
        if today and date == strftime("%Y-%m-%d"):
            nb = nbPkgs
            if full:
                sys.exit(\
                'full option is useless with the today one, aborting...')
            nb = nbPkgs
            if date == strftime("%Y-%m-%d"):
                print(package)
            print(package)
            if remove:
                print('Do you want to remove this package?: ')
                yn = input('Y(es)/N(o):')
                if yn == 'Y'or yn == 'y' or yn == 'Yes':
                    subprocess.call(["sudo", "dpkg", "-r", package])
                else:
                    sys.exit('Aborting...')
                
        elif full:
            keyword = keyword.replace('install', 'I').replace('upgrade', 'U')
            print(keyword, date, time, package.ljust(22), ver)


@@ 134,8 146,7 @@ def main():
    # Build the dpkglog file (/tmp/dpkg.twadeb)
    dpkgFiles(alldpkg, dpkglog)
    #
    if nb:
        lastNpkgs(nb)
    lastNpkgs(nb)


if __name__ == '__main__':