diff --git a/.gitignore b/.gitignore index 9830045e..2da2ca61 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,5 @@ tags build *junit-xml-results +*.egg +osc.egg-info/* diff --git a/README.md b/README.md index d8d21b62..980559cf 100644 --- a/README.md +++ b/README.md @@ -21,8 +21,6 @@ To install from git, do ./setup.py build ./setup.py install - # create a symlink `osc` in your path pointing to osc-wrapper.py. - ln -s osc-wrapper.py /usr/local/bin/osc Alternatively, you can directly use `./osc-wrapper.py` from the source directory, which is easier if you develop on osc. diff --git a/osc-wrapper.py b/osc-wrapper.py index aa62decb..952f69cf 100755 --- a/osc-wrapper.py +++ b/osc-wrapper.py @@ -1,46 +1,9 @@ #!/usr/bin/env python3 -# this wrapper exists so it can be put into /usr/bin, but still allows the -# python module to be called within the source directory during development +""" +This wrapper allows osc to be called from the source directory during development. +""" -import locale -import sys -import os +import osc.babysitter -from osc import commandline, babysitter - -try: - # this is a hack to make osc work as expected with utf-8 characters, - # no matter how site.py is set... - reload(sys) - loc = locale.getpreferredencoding() - if not loc: - loc = sys.getpreferredencoding() - sys.setdefaultencoding(loc) - del sys.setdefaultencoding -except NameError: - #reload, neither setdefaultencoding are in python3 - pass - -# avoid buffering output on pipes (bnc#930137) -# Note: the following only applies to python2 -# Basically, a "print('foo')" call is translated to a corresponding -# fwrite call that writes to the stdout stream (cf. string_print -# (Objects/stringobject.c) and builtin_print (Python/bltinmodule.c)); -# If no pipe is used, stdout is a tty/refers to a terminal => -# the stream is line buffered (see _IO_file_doallocate (libio/filedoalloc.c)). -# If a pipe is used, stdout does not refer to a terminal anymore => -# the stream is fully buffered by default (see _IO_file_doallocate). -# The following fdopen call makes stdout line buffered again (at least on -# systems that support setvbuf - if setvbuf is not supported, the stream -# remains fully buffered (see PyFile_SetBufSize (Objects/fileobject.c))). -if not os.isatty(sys.stdout.fileno()): - sys.stdout = os.fdopen(sys.stdout.fileno(), sys.stdout.mode, 1) - -if not os.isatty(sys.stderr.fileno()): - sys.stderr = os.fdopen(sys.stderr.fileno(), sys.stderr.mode, 1) - -osccli = commandline.Osc() - -r = babysitter.run(osccli) -sys.exit(r) +osc.babysitter.main() diff --git a/osc/babysitter.py b/osc/babysitter.py index 80d7bc82..2dc26940 100644 --- a/osc/babysitter.py +++ b/osc/babysitter.py @@ -13,6 +13,7 @@ import sys import signal import traceback +from osc import commandline from osc import oscerr from .oscssl import CertVerificationError from osc.util.cpio import CpioError @@ -184,4 +185,29 @@ def run(prg, argv=None): print('*** Error:', e, file=sys.stderr) return 1 + +def main(): + # avoid buffering output on pipes (bnc#930137) Basically, + # a "print('foo')" call is translated to a corresponding + # fwrite call that writes to the stdout stream (cf. + # string_print (Objects/stringobject.c) and builtin_print + # (Python/bltinmodule.c)); If no pipe is used, stdout is + # a tty/refers to a terminal => the stream is line buffered + # (see _IO_file_doallocate (libio/filedoalloc.c)). If a pipe + # is used, stdout does not refer to a terminal anymore => the + # stream is fully buffered by default (see + # _IO_file_doallocate). The following fdopen call makes + # stdout line buffered again (at least on systems that + # support setvbuf - if setvbuf is not supported, the stream + # remains fully buffered (see PyFile_SetBufSize + # (Objects/fileobject.c))). + if not os.isatty(sys.stdout.fileno()): + sys.stdout = os.fdopen(sys.stdout.fileno(), sys.stdout.mode, 1) + sys.stderr = os.fdopen(sys.stderr.fileno(), sys.stderr.mode, 1) + + if not os.isatty(sys.stderr.fileno()): + sys.stderr = os.fdopen(sys.stderr.fileno(), sys.stderr.mode, 1) + + sys.exit(run(commandline.Osc())) + # vim: sw=4 et diff --git a/setup.py b/setup.py index c5c99862..4771b035 100755 --- a/setup.py +++ b/setup.py @@ -101,9 +101,13 @@ setuptools.setup( url='http://en.opensuse.org/openSUSE:OSC', download_url='https://github.com/openSUSE/osc', packages=['osc', 'osc.util'], - scripts=['osc-wrapper.py'], data_files=data_files, install_requires=['cryptography', 'urllib3'], + entry_points={ + 'console_scripts': [ + 'osc=osc.babysitter:main' + ], + }, classifiers=[ "Development Status :: 5 - Production/Stable", "Environment :: Console",