From bacbb35bbcb2c3e59b1fbed964bc4a5fd2a4c99d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim=20Sch=C3=B6n?= Date: Wed, 9 Sep 2020 11:09:21 +0200 Subject: [PATCH 1/2] Fix ughub breaking on python2 --- ughub.py | 18 +++++++++++++----- ughubHelp.py | 10 +++++++--- 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/ughub.py b/ughub.py index 1a78c36..f934d6a 100644 --- a/ughub.py +++ b/ughub.py @@ -448,10 +448,13 @@ def ListPackages(args): namesonly = ughubUtil.HasCommandlineOption(args, ("--namesonly",)) if namesonly: + result = "" for key in sorted(packageDict.keys()): pkgs = packageDict[key] for pkg in pkgs: - print(pkg["name"], end=" ") + result += pkg["name"] + " " + sys.stdout.write(result) + sys.stdout.flush() else: print("{0:24.4} {1:10} {2:11} {3:}" .format("NAME", "PREFIX", "SOURCE", "URL")) @@ -968,7 +971,9 @@ def GetAutoCompletions(args): result += "\n" for p in packages: result += p["name"] + "\n" - print(result[:-1], end="") + + sys.stdout.write(result[:-1]) + sys.stdout.flush() return if len(args) >= 1 and args[0] == "log": @@ -981,16 +986,19 @@ def GetAutoCompletions(args): for p in packages: if PackageIsInstalled(p): result += p["name"] + "\n" - print(result[:-1], end="") + sys.stdout.write(result[:-1]) + sys.stdout.flush() return if len(args) >= 1 and args[0] == "help": ughubHelp.PrintCommandNames() - print("\n" + ughubHelp.GetOptionStringsForCommand(args[0]), end="") + sys.stdout.write("\n" + ughubHelp.GetOptionStringsForCommand(args[0])) + sys.stdout.flush() return if len(args) >= 1 and ughubHelp.IsCommandInHelp(args[0]): - print(ughubHelp.GetOptionStringsForCommand(args[0]), end="") + sys.stdout.write(ughubHelp.GetOptionStringsForCommand(args[0])) + sys.stdout.flush() return if len(args) == 1: diff --git a/ughubHelp.py b/ughubHelp.py index 86dfedd..5b1f643 100644 --- a/ughubHelp.py +++ b/ughubHelp.py @@ -28,6 +28,7 @@ import ughubUtil import ughubHelpContents +import sys class MalformedHelpContentsError(Exception) : pass @@ -88,8 +89,10 @@ def PrintCommandNames(): result = "" for cmd in GetCommandsInHelp(): for c in cmd.split(","): - result += c.strip() + "\n" - print(result[:-1], end ="") + result += c.strip() + "\n" + + sys.stdout.write(result[:-1]) + sys.stdout.flush() # Prints help for the command specified in 'cmd'. def PrintCommandHelp(cmdName, args=[]): @@ -105,7 +108,8 @@ def PrintCommandHelp(cmdName, args=[]): if shortdesc: if "shortdescription" in cmdDict: - print(cmdDict["shortdescription"], end="") + sys.stdout.write(cmdDict["shortdescription"]) + sys.stdout.flush() return print("Usage: ughub {0}".format(cmdDict["usage"])) From 85d3b5d9beb4d7ae27cd4ca8da1f294a844ea14e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim=20Sch=C3=B6n?= Date: Thu, 10 Sep 2020 15:41:42 +0200 Subject: [PATCH 2/2] Fixed small error when listing with --namesonly and introduced ughubUtil.Write() --- ughub.py | 20 +++++++++----------- ughubHelp.py | 6 ++---- ughubUtil.py | 4 ++++ 3 files changed, 15 insertions(+), 15 deletions(-) diff --git a/ughub.py b/ughub.py index f934d6a..4d7d8a9 100644 --- a/ughub.py +++ b/ughub.py @@ -453,8 +453,8 @@ def ListPackages(args): pkgs = packageDict[key] for pkg in pkgs: result += pkg["name"] + " " - sys.stdout.write(result) - sys.stdout.flush() + + ughubUtil.Write(result) else: print("{0:24.4} {1:10} {2:11} {3:}" .format("NAME", "PREFIX", "SOURCE", "URL")) @@ -972,8 +972,8 @@ def GetAutoCompletions(args): for p in packages: result += p["name"] + "\n" - sys.stdout.write(result[:-1]) - sys.stdout.flush() + ughubUtil.Write(result[:-1]) + return if len(args) >= 1 and args[0] == "log": @@ -986,19 +986,17 @@ def GetAutoCompletions(args): for p in packages: if PackageIsInstalled(p): result += p["name"] + "\n" - sys.stdout.write(result[:-1]) - sys.stdout.flush() + + ughubUtil.Write(result[:-1]) return if len(args) >= 1 and args[0] == "help": - ughubHelp.PrintCommandNames() - sys.stdout.write("\n" + ughubHelp.GetOptionStringsForCommand(args[0])) - sys.stdout.flush() + ughubHelp.PrintCommandNames() + ughubUtil.Write("\n" + ughubHelp.GetOptionStringsForCommand(args[0])) return if len(args) >= 1 and ughubHelp.IsCommandInHelp(args[0]): - sys.stdout.write(ughubHelp.GetOptionStringsForCommand(args[0])) - sys.stdout.flush() + ughubUtil.Write(ughubHelp.GetOptionStringsForCommand(args[0])) return if len(args) == 1: diff --git a/ughubHelp.py b/ughubHelp.py index 5b1f643..fd398d5 100644 --- a/ughubHelp.py +++ b/ughubHelp.py @@ -91,8 +91,7 @@ def PrintCommandNames(): for c in cmd.split(","): result += c.strip() + "\n" - sys.stdout.write(result[:-1]) - sys.stdout.flush() + ughubUtil.Write(result[:-1]) # Prints help for the command specified in 'cmd'. def PrintCommandHelp(cmdName, args=[]): @@ -108,8 +107,7 @@ def PrintCommandHelp(cmdName, args=[]): if shortdesc: if "shortdescription" in cmdDict: - sys.stdout.write(cmdDict["shortdescription"]) - sys.stdout.flush() + ughubUtil.Write(cmdDict["shortdescription"]) return print("Usage: ughub {0}".format(cmdDict["usage"])) diff --git a/ughubUtil.py b/ughubUtil.py index 39279db..fb5e2b8 100644 --- a/ughubUtil.py +++ b/ughubUtil.py @@ -94,3 +94,7 @@ def RemoveOptions(args): if len(a) > 0 and a[0] != "-": filteredArgs.append(a) return filteredArgs + +def Write(string): + sys.stdout.write(string) + sys.stdout.flush() \ No newline at end of file