2025-01-15 10:42:44 +01:00
|
|
|
import vcs.base
|
|
|
|
|
2025-01-15 11:30:00 +01:00
|
|
|
from lxml import etree as ET
|
|
|
|
|
2025-02-04 15:30:23 +01:00
|
|
|
import os
|
|
|
|
import sys
|
2025-02-05 09:23:02 +01:00
|
|
|
import shutil
|
2025-01-15 10:45:06 +01:00
|
|
|
import osc.core
|
|
|
|
from urllib.error import HTTPError, URLError
|
|
|
|
|
2025-01-15 10:42:44 +01:00
|
|
|
class OSC(vcs.base.VCSBase):
|
|
|
|
"""VCS interface implementation for OSC"""
|
|
|
|
|
2025-02-05 09:23:02 +01:00
|
|
|
def __init__(self, apiurl: str):
|
2025-01-15 10:42:44 +01:00
|
|
|
self.apiurl = apiurl
|
|
|
|
|
|
|
|
@property
|
|
|
|
def name(self) -> str:
|
2025-02-05 09:23:02 +01:00
|
|
|
return "OSC"
|
2025-01-15 10:45:06 +01:00
|
|
|
|
|
|
|
def _get(self, l, query=None):
|
|
|
|
"""Construct a complete URL, and issue an HTTP GET to it."""
|
|
|
|
url = osc.core.makeurl(self.apiurl, l, query)
|
|
|
|
return osc.core.http_GET(url)
|
|
|
|
|
|
|
|
def get_path(self, *args):
|
|
|
|
try:
|
|
|
|
return self._get(args)
|
|
|
|
except HTTPError as e:
|
|
|
|
if e.code != 404:
|
|
|
|
raise e
|
|
|
|
return None
|
2025-01-15 11:30:00 +01:00
|
|
|
|
2025-02-04 15:30:23 +01:00
|
|
|
def checkout_package(
|
|
|
|
self,
|
|
|
|
target_project: str,
|
|
|
|
target_package: str,
|
|
|
|
pathname,
|
|
|
|
**kwargs
|
|
|
|
):
|
|
|
|
_stdout = sys.stdout
|
|
|
|
sys.stdout = open(os.devnull, 'w')
|
|
|
|
try:
|
|
|
|
result = osc.core.checkout_package(
|
|
|
|
self.apiurl,
|
|
|
|
target_project,
|
|
|
|
target_package,
|
|
|
|
pathname=pathname,
|
|
|
|
**kwargs
|
|
|
|
)
|
2025-02-05 09:23:02 +01:00
|
|
|
shutil.rmtree(os.path.join(target_package, '.osc'))
|
2025-02-04 15:30:23 +01:00
|
|
|
finally:
|
|
|
|
sys.stdout = _stdout
|
|
|
|
return result
|