[equo] monkey patch argparse.ArgumentParser to fix UTF-8 strings handling
See bug 4049.
This commit is contained in:
@@ -11,7 +11,6 @@
|
||||
"""
|
||||
import argparse
|
||||
import errno
|
||||
import functools
|
||||
import os
|
||||
import shlex
|
||||
import subprocess
|
||||
@@ -61,7 +60,7 @@ class SoloManage(SoloCommand):
|
||||
nsargs = parser.parse_args(self._args)
|
||||
except IOError as err:
|
||||
sys.stderr.write("%s\n" % (err,))
|
||||
return functools.partial(self.print_help, parser), []
|
||||
return parser.print_help, []
|
||||
|
||||
self._nsargs = nsargs
|
||||
return self._call_locked, [nsargs.func]
|
||||
|
||||
@@ -9,7 +9,6 @@
|
||||
B{Entropy Command Line Client}.
|
||||
|
||||
"""
|
||||
import functools
|
||||
import sys
|
||||
import argparse
|
||||
|
||||
@@ -85,7 +84,7 @@ Manage Entropy Library Cache.
|
||||
nsargs = parser.parse_args(self._args)
|
||||
except IOError as err:
|
||||
sys.stderr.write("%s\n" % (err,))
|
||||
return functools.partial(self.print_help, parser), []
|
||||
return parser.print_help, []
|
||||
|
||||
self._nsargs = nsargs
|
||||
return self._call_locked, [nsargs.func]
|
||||
|
||||
@@ -9,7 +9,6 @@
|
||||
B{Entropy Command Line Client}.
|
||||
|
||||
"""
|
||||
import functools
|
||||
import os
|
||||
import sys
|
||||
import argparse
|
||||
@@ -71,7 +70,7 @@ Remove downloaded packages and clean temporary directories.
|
||||
nsargs = parser.parse_args(self._args)
|
||||
except IOError as err:
|
||||
sys.stderr.write("%s\n" % (err,))
|
||||
return functools.partial(self.print_help, parser), []
|
||||
return parser.print_help, []
|
||||
|
||||
return self._call_locked, [self._cleanup]
|
||||
|
||||
|
||||
@@ -26,6 +26,31 @@ import entropy.tools
|
||||
|
||||
from solo.utils import enlightenatom
|
||||
|
||||
|
||||
def _fix_argparse_print_help():
|
||||
"""
|
||||
Fix argparse.ArgumentParser.print_help to always work
|
||||
with UTF-8 characters and pipes. See bug 4049.
|
||||
"""
|
||||
class _Printer(object):
|
||||
|
||||
@classmethod
|
||||
def write(self, string):
|
||||
print_generic(string)
|
||||
|
||||
original_print_help = argparse.ArgumentParser.print_help
|
||||
|
||||
def _print_help(zelf, file=None):
|
||||
if file is None:
|
||||
file = _Printer
|
||||
return original_print_help(zelf, file=file)
|
||||
|
||||
argparse.ArgumentParser.print_help = _print_help
|
||||
|
||||
|
||||
_fix_argparse_print_help()
|
||||
|
||||
|
||||
class SoloCommand(object):
|
||||
"""
|
||||
Base class for Solo commands
|
||||
@@ -97,22 +122,6 @@ class SoloCommand(object):
|
||||
"--quiet", "-q", action="store_true", default=False,
|
||||
help=_("quiet output"))
|
||||
|
||||
def print_help(self, parser):
|
||||
"""
|
||||
ArgumentParser.print_help wrapper that properly handles
|
||||
UTF-8 encoding in a fault-tolerant way. Also see bug #4049.
|
||||
|
||||
@param parser: an ArgumentParser object
|
||||
@type parser: argparse.ArgumentParser
|
||||
"""
|
||||
class _Printer(object):
|
||||
|
||||
@classmethod
|
||||
def write(self, string):
|
||||
print_generic(string)
|
||||
|
||||
parser.print_help(file=_Printer)
|
||||
|
||||
def parse(self):
|
||||
"""
|
||||
Parse the actual arguments and return
|
||||
|
||||
@@ -9,7 +9,6 @@
|
||||
B{Entropy Command Line Client}.
|
||||
|
||||
"""
|
||||
import functools
|
||||
import os
|
||||
import errno
|
||||
import sys
|
||||
@@ -93,7 +92,7 @@ Manage package file updates.
|
||||
nsargs = parser.parse_args(self._args)
|
||||
except IOError as err:
|
||||
sys.stderr.write("%s\n" % (err,))
|
||||
return functools.partial(self.print_help, parser), []
|
||||
return parser.print_help, []
|
||||
|
||||
self._nsargs = nsargs
|
||||
return self._call_locked, [nsargs.func]
|
||||
|
||||
@@ -9,7 +9,6 @@
|
||||
B{Entropy Command Line Client}.
|
||||
|
||||
"""
|
||||
import functools
|
||||
import sys
|
||||
import argparse
|
||||
import time
|
||||
@@ -78,7 +77,7 @@ Test system integrity by checking installed packages dependencies.
|
||||
nsargs = parser.parse_args(self._args)
|
||||
except IOError as err:
|
||||
sys.stderr.write("%s\n" % (err,))
|
||||
return functools.partial(self.print_help, parser), []
|
||||
return parser.print_help, []
|
||||
|
||||
self._ask = nsargs.ask
|
||||
self._quiet = nsargs.quiet
|
||||
|
||||
@@ -90,7 +90,7 @@ class SoloHelp(SoloCommand):
|
||||
aliases_str)
|
||||
desc = descriptor.get_description()
|
||||
group.add_argument(name, help=darkgreen(desc), action="store_true")
|
||||
self.print_help(parser)
|
||||
parser.print_help()
|
||||
if not self._args:
|
||||
return 1
|
||||
return 0
|
||||
|
||||
@@ -9,7 +9,6 @@
|
||||
B{Entropy Command Line Client}.
|
||||
|
||||
"""
|
||||
import functools
|
||||
import sys
|
||||
import argparse
|
||||
|
||||
@@ -68,7 +67,7 @@ Upgrade the System to a new branch.
|
||||
nsargs = parser.parse_args(self._args)
|
||||
except IOError as err:
|
||||
sys.stderr.write("%s\n" % (err,))
|
||||
return functools.partial(self.print_help, parser), []
|
||||
return parser.print_help, []
|
||||
|
||||
self._branch = nsargs.branch
|
||||
|
||||
|
||||
@@ -9,7 +9,6 @@
|
||||
B{Entropy Command Line Client}.
|
||||
|
||||
"""
|
||||
import functools
|
||||
import sys
|
||||
import argparse
|
||||
import time
|
||||
@@ -98,7 +97,7 @@ Test system integrity by looking for missing libraries.
|
||||
nsargs = parser.parse_args(self._args)
|
||||
except IOError as err:
|
||||
sys.stderr.write("%s\n" % (err,))
|
||||
return functools.partial(self.print_help, parser), []
|
||||
return parser.print_help, []
|
||||
|
||||
self._nsargs = nsargs
|
||||
return self._call_locked, [self._test]
|
||||
|
||||
@@ -9,7 +9,6 @@
|
||||
B{Entropy Command Line Client}.
|
||||
|
||||
"""
|
||||
import functools
|
||||
import sys
|
||||
import argparse
|
||||
|
||||
@@ -78,7 +77,7 @@ class SoloMaskUnmask(SoloCommand):
|
||||
nsargs = parser.parse_args(self._args)
|
||||
except IOError as err:
|
||||
sys.stderr.write("%s\n" % (err,))
|
||||
return functools.partial(self.print_help, parser), []
|
||||
return parser.print_help, []
|
||||
|
||||
self._packages = nsargs.packages
|
||||
self._pretend = nsargs.pretend
|
||||
|
||||
@@ -9,7 +9,6 @@
|
||||
B{Entropy Command Line Client}.
|
||||
|
||||
"""
|
||||
import functools
|
||||
import sys
|
||||
import argparse
|
||||
|
||||
@@ -137,7 +136,7 @@ Match package names.
|
||||
nsargs = parser.parse_args(self._args)
|
||||
except IOError as err:
|
||||
sys.stderr.write("%s\n" % (err,))
|
||||
return functools.partial(self.print_help, parser), []
|
||||
return parser.print_help, []
|
||||
|
||||
self._quiet = nsargs.quiet
|
||||
self._verbose = nsargs.verbose
|
||||
|
||||
@@ -9,7 +9,6 @@
|
||||
B{Entropy Command Line Client}.
|
||||
|
||||
"""
|
||||
import functools
|
||||
import sys
|
||||
import argparse
|
||||
|
||||
@@ -68,7 +67,7 @@ Read Repository Notice Board.
|
||||
nsargs = parser.parse_args(self._args)
|
||||
except IOError as err:
|
||||
sys.stderr.write("%s\n" % (err,))
|
||||
return functools.partial(self.print_help, parser), []
|
||||
return parser.print_help, []
|
||||
|
||||
self._nsargs = nsargs
|
||||
return self._call_unlocked, [self._reader]
|
||||
|
||||
@@ -9,7 +9,6 @@
|
||||
B{Entropy Command Line Client}.
|
||||
|
||||
"""
|
||||
import functools
|
||||
import os
|
||||
import sys
|
||||
import argparse
|
||||
@@ -169,7 +168,7 @@ Execute advanced tasks on Entropy packages and the running system.
|
||||
nsargs = parser.parse_args(self._args)
|
||||
except IOError as err:
|
||||
sys.stderr.write("%s\n" % (err,))
|
||||
return functools.partial(self.print_help, parser), []
|
||||
return parser.print_help, []
|
||||
|
||||
self._nsargs = nsargs
|
||||
return self._call_locked, [nsargs.func]
|
||||
|
||||
@@ -9,7 +9,6 @@
|
||||
B{Entropy Command Line Client}.
|
||||
|
||||
"""
|
||||
import functools
|
||||
import os
|
||||
import sys
|
||||
import re
|
||||
@@ -328,7 +327,7 @@ Repository query tools.
|
||||
nsargs = parser.parse_args(self._args)
|
||||
except IOError as err:
|
||||
sys.stderr.write("%s\n" % (err,))
|
||||
return functools.partial(self.print_help, parser), []
|
||||
return parser.print_help, []
|
||||
|
||||
self._nsargs = nsargs
|
||||
return self._call_locked, [nsargs.func]
|
||||
|
||||
@@ -9,7 +9,6 @@
|
||||
B{Entropy Command Line Client}.
|
||||
|
||||
"""
|
||||
import functools
|
||||
import os
|
||||
import sys
|
||||
import argparse
|
||||
@@ -143,7 +142,7 @@ Manage Entropy Repositories.
|
||||
nsargs = parser.parse_args(self._args)
|
||||
except IOError as err:
|
||||
sys.stderr.write("%s\n" % (err,))
|
||||
return functools.partial(self.print_help, parser), []
|
||||
return parser.print_help, []
|
||||
|
||||
self._nsargs = nsargs
|
||||
return self._call_locked, [nsargs.func]
|
||||
|
||||
@@ -9,7 +9,6 @@
|
||||
B{Entropy Command Line Client}.
|
||||
|
||||
"""
|
||||
import functools
|
||||
import os
|
||||
import errno
|
||||
import sys
|
||||
@@ -149,7 +148,7 @@ Tools to rescue the running system.
|
||||
nsargs = parser.parse_args(self._args)
|
||||
except IOError as err:
|
||||
sys.stderr.write("%s\n" % (err,))
|
||||
return functools.partial(self.print_help, parser), []
|
||||
return parser.print_help, []
|
||||
|
||||
self._nsargs = nsargs
|
||||
return self._call_locked, [nsargs.func]
|
||||
|
||||
@@ -9,7 +9,6 @@
|
||||
B{Entropy Command Line Client}.
|
||||
|
||||
"""
|
||||
import functools
|
||||
import sys
|
||||
import argparse
|
||||
|
||||
@@ -96,7 +95,7 @@ Search for packages.
|
||||
nsargs = parser.parse_args(self._args)
|
||||
except IOError as err:
|
||||
sys.stderr.write("%s\n" % (err,))
|
||||
return functools.partial(self.print_help, parser), []
|
||||
return parser.print_help, []
|
||||
|
||||
self._quiet = nsargs.quiet
|
||||
self._verbose = nsargs.verbose
|
||||
|
||||
@@ -9,7 +9,6 @@
|
||||
B{Entropy Command Line Client}.
|
||||
|
||||
"""
|
||||
import functools
|
||||
import os
|
||||
import sys
|
||||
import argparse
|
||||
@@ -189,7 +188,7 @@ System security tools.
|
||||
nsargs = parser.parse_args(self._args)
|
||||
except IOError as err:
|
||||
sys.stderr.write("%s\n" % (err,))
|
||||
return functools.partial(self.print_help, parser), []
|
||||
return parser.print_help, []
|
||||
|
||||
self._nsargs = nsargs
|
||||
return self._call_locked, [nsargs.func]
|
||||
|
||||
@@ -9,7 +9,6 @@
|
||||
B{Entropy Command Line Client}.
|
||||
|
||||
"""
|
||||
import functools
|
||||
import sys
|
||||
import argparse
|
||||
|
||||
@@ -68,7 +67,7 @@ Show Repositories status.
|
||||
nsargs = parser.parse_args(self._args)
|
||||
except IOError as err:
|
||||
sys.stderr.write("%s\n" % (err,))
|
||||
return functools.partial(self.print_help, parser), []
|
||||
return parser.print_help, []
|
||||
|
||||
return self._call_unlocked, [self._status]
|
||||
|
||||
|
||||
@@ -9,7 +9,6 @@
|
||||
B{Entropy Command Line Client}.
|
||||
|
||||
"""
|
||||
import functools
|
||||
import os
|
||||
import sys
|
||||
import argparse
|
||||
@@ -172,7 +171,7 @@ Manage User Generate Content (votes, comments, files).
|
||||
nsargs = parser.parse_args(self._args)
|
||||
except IOError as err:
|
||||
sys.stderr.write("%s\n" % (err,))
|
||||
return functools.partial(self.print_help, parser), []
|
||||
return parser.print_help, []
|
||||
|
||||
self._nsargs = nsargs
|
||||
return self._call_locked, [nsargs.func]
|
||||
|
||||
@@ -9,7 +9,6 @@
|
||||
B{Entropy Command Line Client}.
|
||||
|
||||
"""
|
||||
import functools
|
||||
import sys
|
||||
import argparse
|
||||
|
||||
@@ -89,7 +88,7 @@ Report unused packages that could be removed.
|
||||
nsargs = parser.parse_args(self._args)
|
||||
except IOError as err:
|
||||
sys.stderr.write("%s\n" % (err,))
|
||||
return functools.partial(self.print_help, parser), []
|
||||
return parser.print_help, []
|
||||
|
||||
self._quiet = nsargs.quiet
|
||||
self._sortbysize = nsargs.sortbysize
|
||||
|
||||
@@ -9,7 +9,6 @@
|
||||
B{Entropy Command Line Client}.
|
||||
|
||||
"""
|
||||
import functools
|
||||
import sys
|
||||
import argparse
|
||||
|
||||
@@ -78,7 +77,7 @@ Update Entropy Repositories.
|
||||
nsargs = parser.parse_args(self._args)
|
||||
except IOError as err:
|
||||
sys.stderr.write("%s\n" % (err,))
|
||||
return functools.partial(self.print_help, parser), []
|
||||
return parser.print_help, []
|
||||
|
||||
self._force = nsargs.force
|
||||
self._repositories += nsargs.repo
|
||||
|
||||
Reference in New Issue
Block a user