diff --git a/osc/core.py b/osc/core.py index f3fdde38..658150d5 100755 --- a/osc/core.py +++ b/osc/core.py @@ -31,6 +31,7 @@ except ImportError: +DISTURL_RE = re.compile(r"^(?P.*)://(?P.*?)/(?P.*?)/(?P.*?)/(?P.*)-(?P.*)$") BUFSIZE = 1024*1024 store = '.osc' @@ -1530,6 +1531,20 @@ def is_package_dir(d): return os.path.exists(os.path.join(d, store, '_project')) and \ os.path.exists(os.path.join(d, store, '_package')) +def parse_disturl(disturl): + """Parse a disturl, returns tuple (apiurl, project, source, repository, + revision), else raises an oscerr.WrongArgs exception + """ + + m = DISTURL_RE.match(disturl) + if not m: + raise oscerr.WrongArgs("`%s' does not look like disturl") + + apiurl = m.group('apiurl') + if apiurl.split('.')[0] != 'api': + apiurl = 'https://api.' + ".".join(apiurl.split('.')[1:]) + return (apiurl, m.group('project'), m.group('source'), m.group('repository'), m.group('revision')) + def slash_split(l): """Split command line arguments like 'foo/bar' into 'foo' 'bar'.