1
0
mirror of https://github.com/openSUSE/osc.git synced 2024-12-27 10:16:14 +01:00

Move print_msg() to the 'osc.output' module

This commit is contained in:
Daniel Mach 2024-03-05 15:40:37 +01:00
parent 27bf13a774
commit 866d178345
9 changed files with 48 additions and 41 deletions

View File

@ -1,7 +1,7 @@
from . import api
from .common import format_msg_project_package_options
from .common import print_msg
from .. import oscerr
from ..output import print_msg
def add_channels(apiurl, project, package=None, enable_all=False, skip_disabled=False, print_to="debug"):

View File

@ -1,27 +1,4 @@
import sys
def print_msg(*args, print_to="debug"):
from .. import conf
if print_to is None:
return
elif print_to == "debug":
# print a debug message to stderr if config["debug"] is set
if conf.config["debug"]:
print("DEBUG:", *args, file=sys.stderr)
elif print_to == "verbose":
# print a verbose message to stdout if config["verbose"] or config["debug"] is set
if conf.config["verbose"] or conf.config["debug"]:
print(*args)
elif print_to == "stdout":
# print the message to stdout
print(*args)
elif print_to == "stderr":
# print the message to stderr
print(*args, file=sys.stderr)
else:
raise ValueError(f"Invalid value of the 'print_to' option: {print_to}")
from ..output.output import print_msg
def format_msg_project_package_options(

View File

@ -21,6 +21,7 @@ from . import commandline
from . import conf as osc_conf
from . import core as osc_core
from . import oscerr
from . import output
from .OscConfigParser import configparser
from .oscssl import CertVerificationError
from .util.cpio import CpioError
@ -108,8 +109,8 @@ def run(prg, argv=None):
except AttributeError:
body = ''
_private.print_msg(e.hdrs, print_to="debug")
_private.print_msg(body, print_to="debug")
output.print_msg(e.hdrs, print_to="debug")
output.print_msg(body, print_to="debug")
if e.code in [400, 403, 404, 500]:
if b'<summary>' in body:
@ -153,7 +154,7 @@ def run(prg, argv=None):
print(e.message, file=sys.stderr)
except oscerr.OscIOError as e:
print(e.msg, file=sys.stderr)
_private.print_msg(e.e, print_to="debug")
output.print_msg(e.e, print_to="debug")
except (oscerr.WrongOptions, oscerr.WrongArgs) as e:
print(e, file=sys.stderr)
return 2

View File

@ -33,6 +33,7 @@ from . import commands as osc_commands
from . import conf
from . import git_scm
from . import oscerr
from . import output
from . import store as osc_store
from .core import *
from .grabber import OscFileGrabber
@ -269,7 +270,7 @@ class MainCommand(Command):
def load_commands(self):
if IN_VENV:
_private.print_msg("Running in virtual environment, skipping loading plugins installed outside the virtual environment.", print_to="stderr")
output.print_msg("Running in virtual environment, skipping loading plugins installed outside the virtual environment.", print_to="stderr")
for module_prefix, module_path in self.MODULES:
module_path = os.path.expanduser(module_path)
@ -4315,7 +4316,7 @@ Please submit there instead, or use --nodevelproject to force direct submission.
except:
print('Error while checkout package:\n', package, file=sys.stderr)
_private.print_msg('Note: You can use "osc delete" or "osc submitpac" when done.\n', print_to="verbose")
output.print_msg('Note: You can use "osc delete" or "osc submitpac" when done.\n', print_to="verbose")
@cmdln.alias('branchco')
@cmdln.alias('bco')
@ -4466,7 +4467,7 @@ Please submit there instead, or use --nodevelproject to force direct submission.
if opts.checkout:
checkout_package(apiurl, targetprj, package, server_service_files=False,
expand_link=True, prj_dir=Path(targetprj))
_private.print_msg('Note: You can use "osc delete" or "osc submitpac" when done.\n', print_to="verbose")
output.print_msg('Note: You can use "osc delete" or "osc submitpac" when done.\n', print_to="verbose")
else:
apiopt = ''
if conf.get_configParser().get("general", "apiurl", fallback=None) != apiurl:
@ -10125,7 +10126,7 @@ Please submit there instead, or use --nodevelproject to force direct submission.
def _load_plugins(self):
if IN_VENV:
_private.print_msg("Running in virtual environment, skipping loading legacy plugins.", print_to="stderr")
output.print_msg("Running in virtual environment, skipping loading legacy plugins.", print_to="stderr")
return
plugin_dirs = [

View File

@ -21,10 +21,10 @@ import urllib3.response
import urllib3.util
from . import __version__
from . import _private
from . import conf
from . import oscerr
from . import oscssl
from . import output
from .util.helper import decode_it
@ -690,7 +690,7 @@ class SignatureAuthHandler(AuthHandlerBase):
return False
if not self.ssh_keygen_path:
_private.print_msg("Skipping signature auth because ssh-keygen is not available", print_to="debug")
output.print_msg("Skipping signature auth because ssh-keygen is not available", print_to="debug")
return False
if not self.sshkey_known():

View File

@ -50,6 +50,7 @@ from . import _private
from . import conf
from . import meter
from . import oscerr
from . import output
from . import store as osc_store
from .connection import http_request, http_GET, http_POST, http_PUT, http_DELETE
from .store import Store
@ -524,7 +525,7 @@ class Serviceinfo:
raise oscerr.PackageNotInstalled(f"obs-service-{cmd[0]}")
cmd[0] = "/usr/lib/obs/service/" + cmd[0]
cmd = cmd + ["--outdir", temp_dir]
_private.print_msg("Run source service:", " ".join(cmd), print_to="verbose")
output.print_msg("Run source service:", " ".join(cmd), print_to="verbose")
r = run_external(*cmd)
if r != 0:
@ -3893,7 +3894,7 @@ def set_devel_project(apiurl, prj, pac, devprj=None, devpac=None, print_to="debu
devprj,
devpac,
)
_private.print_msg(msg, print_to=print_to)
output.print_msg(msg, print_to=print_to)
package_obj = obs_api.Package.from_api(apiurl, prj, pac)
@ -4811,7 +4812,7 @@ def get_review_list(
xpath_base = xpath_join(xpath_base, 'action/source/@%(kind)s=\'%(val)s\'', op='or', inner=True)
xpath = xpath_join(xpath, xpath_base % {'kind': kind, 'val': val}, op='and', nexpr_parentheses=True)
_private.print_msg(f"[ {xpath} ]", print_to="debug")
output.print_msg(f"[ {xpath} ]", print_to="debug")
res = search(apiurl, request=xpath)
collection = res['request']
requests = []
@ -4952,7 +4953,7 @@ def get_exact_request_list(
if req_type:
xpath += f" and action/@type='{req_type}'"
_private.print_msg(f"[ {xpath} ]", print_to="debug")
output.print_msg(f"[ {xpath} ]", print_to="debug")
res = search(apiurl, request=xpath)
collection = res['request']
@ -5625,7 +5626,7 @@ def checkout_package(
oldproj = None
if conf.config['checkout_rooted']:
if prj_dir.stem == '/':
_private.print_msg(f"checkout_rooted ignored for {prj_dir}", print_to="verbose")
output.print_msg(f"checkout_rooted ignored for {prj_dir}", print_to="verbose")
# ?? should we complain if not is_project_dir(prj_dir) ??
else:
# if we are inside a project or package dir, ascend to parent
@ -5652,7 +5653,7 @@ def checkout_package(
root_dots = root_dots / ("../" * n)
if str(root_dots) != '.':
_private.print_msg(f"{prj_dir} is project dir of {oldproj}. Root found at {os.path.abspath(root_dots)}", print_to="verbose")
output.print_msg(f"{prj_dir} is project dir of {oldproj}. Root found at {os.path.abspath(root_dots)}", print_to="verbose")
prj_dir = root_dots / prj_dir
if not pathname:

View File

@ -1,5 +1,6 @@
from .key_value_table import KeyValueTable
from .input import get_user_input
from .output import print_msg
from .tty import colorize
from .widechar import wc_ljust
from .widechar import wc_width

26
osc/output/output.py Normal file
View File

@ -0,0 +1,26 @@
import sys
def print_msg(*args, print_to="debug"):
from .. import conf
if print_to is None:
return
elif print_to == "debug":
# print a debug message to stderr if config["debug"] is set
if conf.config["debug"]:
print("DEBUG:", *args, file=sys.stderr)
elif print_to == "verbose":
# print a verbose message to stdout if config["verbose"] or config["debug"] is set
if conf.config["verbose"] or conf.config["debug"]:
print(*args)
elif print_to == "stdout":
# print the message to stdout
print(*args)
elif print_to == "stderr":
# print the message to stderr
print(*args, file=sys.stderr)
else:
raise ValueError(f"Invalid value of the 'print_to' option: {print_to}")

View File

@ -3,8 +3,8 @@ import io
import unittest
import osc.conf
from osc._private import print_msg
from osc.output import KeyValueTable
from osc.output import print_msg
class TestKeyValueTable(unittest.TestCase):