Fixed stderr error output

Signed-off-by: Dimitris Zlatanidis <d.zlatanidis@gmail.com>
This commit is contained in:
Dimitris Zlatanidis 2022-04-25 22:29:02 +03:00
parent f41b395d1f
commit 4c12b784be
2 changed files with 47 additions and 49 deletions

View file

@ -171,7 +171,7 @@ Homepage: https://dslackw.gitlab.io/slpkg/
print(options.__doc__)
def usage(repo):
def usage(repo, stderr):
"""Usage: slpkg [COMMANDS|OPTIONS] {repository|package...}
Commands:
@ -229,3 +229,5 @@ def usage(repo):
raise SystemExit(1)
print(usage.__doc__)
print("For more information try 'slpkg -h, --help' or view manpage\n")
if stderr == 1:
raise SystemExit(stderr)

View file

@ -105,7 +105,7 @@ class ArgParse(BlackList):
print("\n Please update the packages lists. Run 'slpkg update'.\n"
" This command should be used to synchronize the packages\n"
" lists from the repositories that are enabled.\n")
raise SystemExit()
raise SystemExit(1)
def help_version(self):
"""Help and version info
@ -117,7 +117,7 @@ class ArgParse(BlackList):
self.args[1:] == []):
prog_version()
else:
usage("")
usage("", 1)
def command_update(self):
"""Update package lists repositories
@ -133,7 +133,7 @@ class ArgParse(BlackList):
repos.remove(rp)
update.run(repos)
else:
usage("")
usage("", 1)
def command_upgrade(self):
"""Recreate repositories package lists
@ -149,7 +149,7 @@ class ArgParse(BlackList):
repos.remove(rp)
upgrade.run(repos)
else:
usage("")
usage("", 1)
def command_update_slpkg(self):
"""Slpkg it self update
@ -157,7 +157,7 @@ class ArgParse(BlackList):
if len(self.args) == 2 and self.args[0] == "update-slpkg":
it_self_update()
else:
usage("")
usage("", 1)
def command_repo_enable(self):
"""Repositories enable/disable
@ -166,7 +166,7 @@ class ArgParse(BlackList):
if len(self.args) == 1 and self.args[0] == "repo-enable":
RepoEnable().choose()
else:
usage("")
usage("", 1)
def command_repo_list(self):
"""Repositories list
@ -174,7 +174,7 @@ class ArgParse(BlackList):
if len(self.args) == 1 and self.args[0] == "repo-list":
RepoList().repos()
else:
usage("")
usage("", 1)
def command_repo_add(self):
"""Add custom repositories
@ -182,7 +182,7 @@ class ArgParse(BlackList):
if len(self.args) == 3 and self.args[0] == "repo-add":
Repo().add(self.args[1], self.args[2])
else:
usage("")
usage("", 1)
def command_repo_remove(self):
"""Remove custom repositories
@ -190,7 +190,7 @@ class ArgParse(BlackList):
if len(self.args) == 2 and self.args[0] == "repo-remove":
Repo().remove(self.args[1])
else:
usage("")
usage("", 1)
def command_repo_info(self):
"""Repositories informations
@ -201,9 +201,9 @@ class ArgParse(BlackList):
RepoInfo().view(self.args[1])
elif (len(self.args) > 1 and self.args[0] == "repo-info" and
self.args[1] not in RepoList().all_repos):
usage(self.args[1])
usage(self.args[1], 1)
else:
usage("")
usage("", 1)
def command_health(self):
"""Check package health
@ -214,7 +214,7 @@ class ArgParse(BlackList):
self.args[1] == "--silent"):
PackageHealth(mode=self.args[1]).test()
else:
usage("")
usage("", 1)
def command_deps_status(self):
"""Print dependencies status
@ -234,7 +234,7 @@ class ArgParse(BlackList):
"--tree" in self.args and image):
DependenciesStatus(image).tree()
else:
usage("")
usage("", 1)
def command_new_config(self):
"""Manage .new configuration files
@ -242,14 +242,14 @@ class ArgParse(BlackList):
if len(self.args) == 1 and self.args[0] == "new-config":
NewConfig().run()
else:
usage("")
usage("", 1)
def command_clean_tmp(self):
"""Clean all downloaded packages and sources"""
if len(self.args) == 1 and self.args[0] == "clean-tmp":
clean_tmp()
else:
usage("")
usage("", 1)
def auto_build(self):
"""Auto built tool
@ -261,7 +261,7 @@ class ArgParse(BlackList):
if len(self.args) >= 3 and self.args[0] in options:
AutoBuild(self.args[1], self.args[2:], self.meta.path).run()
else:
usage("")
usage("", 1)
def pkg_list(self):
"""List of packages by repository
@ -280,8 +280,7 @@ class ArgParse(BlackList):
if flag[2] == arg:
name = True
if arg not in flag:
usage("")
raise SystemExit()
usage("", 1)
if (len(self.args) > 1 and len(self.args) <= 5 and
self.args[0] in options):
if self.args[1] in self.meta.repositories:
@ -290,9 +289,9 @@ class ArgParse(BlackList):
INDEX,
installed)
else:
usage(self.args[1])
usage(self.args[1], 1)
else:
usage("")
usage("", 1)
def pkg_upgrade(self):
"""Check and upgrade packages by repository
@ -327,16 +326,16 @@ class ArgParse(BlackList):
SBoInstall(sbo_upgrade(skip, flag), flag).start(
is_upgrade=True)
else:
usage(self.args[1])
usage(self.args[1], 1)
elif len(self.args) == 1 and self.args[0] in options:
Updates(repo="").ALL()
elif len(self.args) == 2 and self.args[0] in options:
Updates(self.args[1]).run()
elif (len(self.args) >= 2 and self.args[0] in options and
self.args[1] not in self.meta.repositories):
usage(self.args[1])
usage(self.args[1], 1)
else:
usage("")
usage("", 1)
def __pkg_upgrade_flags(self, flags):
"""Manage flags for package upgrade option
@ -344,8 +343,7 @@ class ArgParse(BlackList):
# Check for typos or unssuported flags
for arg in self.args[2:]:
if arg not in flags:
usage("")
raise SystemExit()
usage("", 1)
flag, skip = [], ""
if flags[0] in self.args:
@ -397,9 +395,9 @@ class ArgParse(BlackList):
self.args[1] in self.meta.repositories):
SBoInstall(self.args[2:], flag).start(is_upgrade=False)
else:
usage(self.args[1])
usage(self.args[1], 1)
else:
usage("")
usage("", 1)
def pkg_tracking(self):
"""Tracking package dependencies
@ -428,17 +426,16 @@ class ArgParse(BlackList):
for arg in self.args:
if arg.startswith("--"):
if arg not in additional_options:
usage("")
raise SystemExit()
usage("", 1)
if (len(self.args) >= 3 and len(self.args) <= 3 and
self.args[0] in options and
self.args[1] in self.meta.repositories):
TrackingDeps(self.args[2], self.args[1], flag).run()
elif (len(self.args) >= 2 and
self.args[1] not in self.meta.repositories):
usage(self.args[1])
usage(self.args[1], 1)
else:
usage("")
usage("", 1)
def sbo_network(self):
"""View slackbuilds packages
@ -466,7 +463,7 @@ class ArgParse(BlackList):
additional_options[0] in flag):
SBoNetwork("", flag).view()
else:
usage("sbo")
usage("sbo", 1)
def pkg_blacklist(self):
"""Manage blacklist packages
@ -496,7 +493,7 @@ class ArgParse(BlackList):
self.args.remove(flag[1])
self.black_remove(self.args[1:])
else:
usage("")
usage("", 1)
def pkg_queue(self):
"""Manage packages in queue
@ -542,7 +539,7 @@ class ArgParse(BlackList):
queue.build()
queue.install()
else:
usage("")
usage("", 1)
def bin_install(self):
"""Install Slackware binary packages
@ -570,7 +567,7 @@ class ArgParse(BlackList):
packages = self.args[2:]
PackageManager(packages).install(flag)
else:
usage("")
usage("", 1)
def bin_upgrade(self):
"""Install-upgrade Slackware binary packages
@ -593,7 +590,7 @@ class ArgParse(BlackList):
packages = self.args[2:]
PackageManager(packages).upgrade(flag)
else:
usage("")
usage("", 1)
def bin_remove(self):
"""Remove Slackware packages
@ -637,7 +634,7 @@ class ArgParse(BlackList):
packages = [""]
PackageManager(packages).remove(flag, extra)
else:
usage("")
usage("", 1)
def bin_find(self):
"""Find installed packages
@ -663,7 +660,7 @@ class ArgParse(BlackList):
elif len(self.args) > 1 and self.args[0] in options:
PackageManager(packages).find(flag)
else:
usage("")
usage("", 1)
def pkg_desc(self):
"""Print slack-desc by repository
@ -697,9 +694,9 @@ class ArgParse(BlackList):
PkgDesc(self.args[2], self.args[1], paint="").view()
elif (len(self.args) > 1 and self.args[0] in options and
self.args[1] not in self.meta.repositories):
usage(self.args[1])
usage(self.args[1], 1)
else:
usage("")
usage("", 1)
def pkg_find(self):
"""Find packages from all enabled repositories
@ -718,7 +715,7 @@ class ArgParse(BlackList):
if len(self.args) > 1 and self.args[0] in options:
FindFromRepos().find(packages, flag)
else:
usage("")
usage("", 1)
def pkg_contents(self):
"""Print packages contents
@ -731,7 +728,7 @@ class ArgParse(BlackList):
if len(self.args) > 1 and self.args[0] in options:
PackageManager(packages).display()
else:
usage("")
usage("", 1)
def congiguration(self):
"""Manage slpkg configuration file
@ -756,7 +753,7 @@ class ArgParse(BlackList):
self.args[1] == (command[2])):
conf.reset()
else:
usage("")
usage("", 1)
def auto_detect(self, args):
"""Check for already Slackware binary packages exist
@ -781,7 +778,7 @@ class ArgParse(BlackList):
if not_found:
for ntf in not_found:
self.msg.pkg_not_found("", ntf, "Not installed", "")
raise SystemExit()
raise SystemExit(1)
def if_checklist(self):
try:
@ -789,7 +786,7 @@ class ArgParse(BlackList):
except ImportError:
print("Require 'pythondialog': Install with 'slpkg -s sbo "
"python3-pythondialog'")
raise SystemExit()
raise SystemExit(1)
def main():
@ -800,8 +797,7 @@ def main():
argparse = ArgParse(args)
if len(args) == 0:
usage("")
raise SystemExit()
usage("", 1)
argparse.auto_detect(args)
@ -861,7 +857,7 @@ def main():
try:
arguments[args[0]]()
except KeyError:
usage("")
usage("", 1)
if __name__ == "__main__":