File: shared.py

package info (click to toggle)
openscap 1.4.2%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 125,040 kB
  • sloc: xml: 527,109; ansic: 91,390; sh: 19,789; python: 2,515; perl: 444; makefile: 49
file content (44 lines) | stat: -rw-r--r-- 1,206 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import argparse as ap

import github


def update_parser_with_common_stuff(parser):
    parser.add_argument("--owner", default="openscap")
    group = parser.add_mutually_exclusive_group(required=True)
    group.add_argument("--auth-token")


def get_milestone(repo, name):
    milestones = repo.get_milestones()
    matches = [m for m in milestones if m.title == name]
    assert len(matches) <= 1, \
        f"Expected to find at most one milestone {name}, found {len(matches)}"
    if len(matches) == 0:
        return None
    else:
        return matches[0]


def get_github(args):
    if args.auth_token is not None:
        return github.Github(args.auth_token)
    else:
        assert 0, "Credentials were not supplied"


def get_repo(github, owner):
    repo = github.get_repo(f"{owner}/openscap")
    return repo


def version_type(string):
    components = string.split(".")
    shortest_component_len = min([len(x) for x in components])
    if len(components) != 3 or shortest_component_len == 0:
        msg = (
            "Expected version number of form X.Y.Z, where X, Y, Z are strings. "
            f"Got: '{string}'"
        )
        raise ap.ArgumentTypeError(msg)
    return string