Skip to content

Commit

Permalink
Merge pull request #21 from timsschoen/master
Browse files Browse the repository at this point in the history
Fix ughub breaking on python2
  • Loading branch information
sreiter authored Sep 10, 2020
2 parents 0a7d9fb + 85d3b5d commit c4163eb
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 9 deletions.
18 changes: 12 additions & 6 deletions ughub.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"] + " "

ughubUtil.Write(result)
else:
print("{0:24.4} {1:10} {2:11} {3:}"
.format("NAME", "PREFIX", "SOURCE", "URL"))
Expand Down Expand Up @@ -968,7 +971,9 @@ def GetAutoCompletions(args):
result += "\n"
for p in packages:
result += p["name"] + "\n"
print(result[:-1], end="")

ughubUtil.Write(result[:-1])

return

if len(args) >= 1 and args[0] == "log":
Expand All @@ -981,16 +986,17 @@ def GetAutoCompletions(args):
for p in packages:
if PackageIsInstalled(p):
result += p["name"] + "\n"
print(result[:-1], end="")

ughubUtil.Write(result[:-1])
return

if len(args) >= 1 and args[0] == "help":
ughubHelp.PrintCommandNames()
print("\n" + ughubHelp.GetOptionStringsForCommand(args[0]), end="")
ughubHelp.PrintCommandNames()
ughubUtil.Write("\n" + ughubHelp.GetOptionStringsForCommand(args[0]))
return

if len(args) >= 1 and ughubHelp.IsCommandInHelp(args[0]):
print(ughubHelp.GetOptionStringsForCommand(args[0]), end="")
ughubUtil.Write(ughubHelp.GetOptionStringsForCommand(args[0]))
return

if len(args) == 1:
Expand Down
8 changes: 5 additions & 3 deletions ughubHelp.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@

import ughubUtil
import ughubHelpContents
import sys

class MalformedHelpContentsError(Exception) : pass

Expand Down Expand Up @@ -88,8 +89,9 @@ def PrintCommandNames():
result = ""
for cmd in GetCommandsInHelp():
for c in cmd.split(","):
result += c.strip() + "\n"
print(result[:-1], end ="")
result += c.strip() + "\n"

ughubUtil.Write(result[:-1])

# Prints help for the command specified in 'cmd'.
def PrintCommandHelp(cmdName, args=[]):
Expand All @@ -105,7 +107,7 @@ def PrintCommandHelp(cmdName, args=[]):

if shortdesc:
if "shortdescription" in cmdDict:
print(cmdDict["shortdescription"], end="")
ughubUtil.Write(cmdDict["shortdescription"])
return

print("Usage: ughub {0}".format(cmdDict["usage"]))
Expand Down
4 changes: 4 additions & 0 deletions ughubUtil.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

1 comment on commit c4163eb

@stephanmg
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Last line should end with newline, this way makes it harder for git diff.

Please sign in to comment.