Commit c99ccd2a authored by Marco Mariani's avatar Marco Mariani

cli: compatibility patches for cygwin (locale setting, check for root, --console parameter)

parent cd2f9ebc
......@@ -23,7 +23,7 @@ class Command(cliff.command.Command):
def must_be_root(func):
@functools.wraps(func)
def inner(self, *args, **kw):
if os.getuid() != 0:
if sys.platform != 'cygwin' and os.getuid() != 0:
self.app.log.error('This slapos command must be run as root.')
sys.exit(5)
return func(self, *args, **kw)
......
......@@ -114,6 +114,30 @@ class SlapOSApp(cliff.app.App):
command_manager=SlapOSCommandManager('slapos.cli'),
)
def _set_streams(self, stdin, stdout, stderr):
try:
# SlapOS: might fail in some systems
locale.setlocale(locale.LC_ALL, '')
except locale.Error:
pass
if sys.version_info[:2] == (2, 6):
# Configure the input and output streams. If a stream is
# provided, it must be configured correctly by the
# caller. If not, make sure the versions of the standard
# streams used by default are wrapped with encodings. This
# works around a problem with Python 2.6 fixed in 2.7 and
# later (http://hg.python.org/cpython/rev/e60ef17561dc/).
lang, encoding = locale.getdefaultlocale()
encoding = getattr(sys.stdout, 'encoding', None) or encoding
self.stdin = stdin or codecs.getreader(encoding)(sys.stdin)
self.stdout = stdout or codecs.getwriter(encoding)(sys.stdout)
self.stderr = stderr or codecs.getwriter(encoding)(sys.stderr)
else:
self.stdin = stdin or sys.stdin
self.stdout = stdout or sys.stdout
self.stderr = stderr or sys.stderr
def build_option_parser(self, *args, **kw):
kw.setdefault('argparse_kwargs', {})
kw['argparse_kwargs']['conflict_handler'] = 'resolve'
......
......@@ -57,6 +57,8 @@ class FormatCommand(ConfigCommand):
help="Don't actually do anything"
" (default: %(default)s)")
ap.add_argument('-c', '--console',
help="Console output (obsolete)")
return ap
@must_be_root
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment