Use regexps from git_helper

This commit is contained in:
Mikhail f. Shiryaev 2022-01-31 16:58:31 +01:00
parent c5db40f679
commit e338396a76
No known key found for this signature in database
GPG Key ID: 4B02ED204C7D93F4
2 changed files with 12 additions and 23 deletions

View File

@ -1,4 +1,5 @@
#!/usr/bin/env python
import argparse
import os.path as p
import re
import subprocess
@ -21,6 +22,15 @@ def removesuffix(string: str, suffix: str):
return string
def commit(name: str):
r = re.compile(SHA_REGEXP)
if not r.match(name):
raise argparse.ArgumentTypeError(
"commit hash should contain exactly 40 hex characters"
)
return name
class Runner:
"""lightweight check_output wrapper with stripping last NEW_LINE"""

View File

@ -8,19 +8,7 @@ from typing import Tuple
from artifactory import ArtifactorySaaSPath # type: ignore
from build_download_helper import dowload_build_with_progress
# Py 3.8 removeprefix and removesuffix
def removeprefix(string: str, prefix: str):
if string.startswith(prefix):
return string[len(prefix) :] # noqa: ignore E203, false positive
return string
def removesuffix(string: str, suffix: str):
if string.endswith(suffix):
return string[: -len(suffix)]
return string
from git_helper import TAG_REGEXP, commit, removeprefix, removesuffix
# Necessary ENV variables
@ -124,7 +112,7 @@ class S3:
class Release:
def __init__(self, name: str):
r = re.compile(r"^v\d{2}[.]\d+[.]\d+[.]\d+-(testing|prestable|stable|lts)$")
r = re.compile(TAG_REGEXP)
# Automatically remove refs/tags/ if full refname passed here
name = removeprefix(name, "refs/tags/")
if not r.match(name):
@ -212,15 +200,6 @@ class Artifactory:
return self.__path_helper("_tgz", package_file)
def commit(name: str):
r = re.compile(r"^([0-9]|[a-f]){40}$")
if not r.match(name):
raise argparse.ArgumentTypeError(
"commit hash should contain exactly 40 hex characters"
)
return name
def parse_args() -> argparse.Namespace:
parser = argparse.ArgumentParser(
formatter_class=argparse.ArgumentDefaultsHelpFormatter,