From ae7ccdb6039346f2118729a564e874de1eb18f3a Mon Sep 17 00:00:00 2001 From: Daniel Mach Date: Thu, 28 Nov 2024 14:44:29 +0100 Subject: [PATCH] Move running obs_scm_bridge into run_obs_scm_bridge() function --- osc/commandline.py | 7 ++----- osc/conf.py | 12 ++++++++++++ osc/core.py | 15 ++++++++++----- 3 files changed, 24 insertions(+), 10 deletions(-) diff --git a/osc/commandline.py b/osc/commandline.py index 53ff6f995..7e18ce141 100644 --- a/osc/commandline.py +++ b/osc/commandline.py @@ -5387,7 +5387,7 @@ def do_checkout(self, subcmd, opts, *args): from .core import parseRevisionOption from .core import print_request_list from .core import revision_is_empty - from .core import run_external + from .core import run_obs_scm_bridge from .core import show_files_meta from .core import show_project_meta from .core import show_scmsync @@ -5506,10 +5506,7 @@ def do_checkout(self, subcmd, opts, *args): scm_url = show_scmsync(apiurl, project) if scm_url is not None and not opts.native_obs_package: - if not os.path.isfile('/usr/lib/obs/service/obs_scm_bridge'): - raise oscerr.OscIOError(None, 'Install the obs-scm-bridge package to work on packages managed in scm (git)!') - os.putenv("OSC_VERSION", get_osc_version()) - run_external(['/usr/lib/obs/service/obs_scm_bridge', '--outdir', str(prj_dir), '--url', scm_url]) + run_obs_scm_bridge(url=scm_url, target_dir=str(prj_dir)) Project.init_project(apiurl, prj_dir, project, conf.config['do_package_tracking'], scm_url=scm_url) print(statfrmt('A', prj_dir)) diff --git a/osc/conf.py b/osc/conf.py index 468296d53..4a9b08efb 100644 --- a/osc/conf.py +++ b/osc/conf.py @@ -1308,6 +1308,18 @@ def apiurl_aliases(self): ini_key="download-assets-cmd", ) # type: ignore[assignment] + obs_scm_bridge_cmd: str = Field( + default= + shutil.which("obs_scm_bridge", path="/usr/lib/obs/service") + or "/usr/lib/obs/service/obs_scm_bridge", + description=textwrap.dedent( + """ + Path to the 'obs_scm_bridge' tool used for cloning scmsync projects and packages. + """ + ), + ini_key="obs-scm-bridge-cmd", + ) # type: ignore[assignment] + vc_cmd: str = Field( default=shutil.which("vc", path="/usr/lib/build:/usr/lib/obs-build") or "/usr/lib/build/vc", description=textwrap.dedent( diff --git a/osc/core.py b/osc/core.py index efb4c5d0a..22c9006ac 100644 --- a/osc/core.py +++ b/osc/core.py @@ -3080,6 +3080,14 @@ def make_dir( return pkg_path +def run_obs_scm_bridge(url: str, target_dir: str): + if not os.path.isfile(conf.config.obs_scm_bridge_cmd): + raise oscerr.OscIOError(None, "Install the obs-scm-bridge package to work on packages managed in scm (git)!") + env = os.environ.copy() + env["OSC_VERSION"] = get_osc_version() + run_external([conf.config.obs_scm_bridge_cmd, "--outdir", target_dir, "--url", url], env=env) + + def checkout_package( apiurl: str, project: str, @@ -3153,9 +3161,6 @@ def checkout_package( root = ET.fromstring(meta_data) scmsync_element = root.find("scmsync") if not native_obs_package and scmsync_element is not None and scmsync_element.text is not None: - if not os.path.isfile('/usr/lib/obs/service/obs_scm_bridge'): - raise oscerr.OscIOError(None, 'Install the obs-scm-bridge package to work on packages managed in scm (git)!') - scm_url = scmsync_element.text directory = make_dir(apiurl, project, package, pathname, prj_dir, conf.config['do_package_tracking'], outdir) if revision is not None: @@ -3165,8 +3170,8 @@ def checkout_package( scmsync_obsinfo = ScmsyncObsinfo.from_api(apiurl, project, package, rev=revision) scm_url = f"{scmsync_obsinfo.url}#{scmsync_obsinfo.revision}" - os.putenv("OSC_VERSION", get_osc_version()) - run_external(['/usr/lib/obs/service/obs_scm_bridge', '--outdir', directory, '--url', scm_url]) + scm_url = scmsync_element.text + run_obs_scm_bridge(url=scm_url, target_dir=directory) Package.init_package(apiurl, project, package, directory, size_limit, meta, progress_obj, scm_url)