#! /usr/bin/python3 import sys import os from clint import arguments from clint.textui import puts, indent, colored from dpkgunlockercli import DpkgUnlockerCli def usage(): puts("Usage") with indent(4): puts("dpkgunlocker-cli [FLAGS...] ACTION") puts("Actions") with indent(4): puts("showinfo") puts("unlock") puts("Flags") with indent(4): puts("-h --help : Show help") puts("-u --unattended: Run the unlock command without prompting for user confirmation") puts("-k --kill: Run the unlocke command killing the associated running process. It can cause problems if used incorrectly ") sys.exit(1) #def usage def isDpkgUnlocker_running(): if os.path.exists('/var/run/dpkgUnlocker.lock'): print(" [Dpkg-Unlocker-Cli]: Dpkg-Unlocker is now running. Wait a moment and try again") sys.exit(1) #def isDpkgUnlocked_running if __name__ == '__main__': if os.geteuid() != 0: print(" [DpkgUnlocker-Cli]: You need be root!") sys.exit(1) isDpkgUnlocker_running() args = arguments.Args().copy mode=False kill=False if args.contains(["-h","--help"]) or len(args.all) == 0 : usage() if args.contains(["-u","--unattended"]): mode=True index = args.first(["-u","--unattended"]) args.pop(index) if args.contains(["-k","--kill"]): kill=True index = args.first(["-k","--kill"]) args.pop(index) action = args.pop(0) dpkgunlockercli = DpkgUnlockerCli(args.get(0)) if action == "showinfo": sys.exit(dpkgunlockercli.showInfo(mode,kill)) elif action=="unlock": sys.exit(dpkgunlockercli.unlock(mode,kill)) else: usage()