summaryrefslogtreecommitdiff
path: root/rpm_upload_repo_autosetup.py
blob: 592334580c44dbe80a42cc78afd15cdf95418f1b (plain)
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#!/usr/bin/env python3
import os
import re
import logging
import argparse


def exact_version_in_develop_branch(commit_ref_name):
    branch_name_re = re.match(r'develop-(\d+)\.(\d+)', commit_ref_name)
    if branch_name_re is None:
        return None

    major_version = int(branch_name_re.group(1))
    minor_version = int(branch_name_re.group(2))

    logging.debug('in develop branch: %s, major_version: %d, minor_version: %d'
                  % (commit_ref_name, major_version, minor_version))

    return major_version, minor_version


def exact_version_in_release_branch(commit_ref_name):
    branch_name_re = re.match(r'release-(\d+)\.(\d+)', commit_ref_name)
    if branch_name_re is None:
        return None

    major_version = int(branch_name_re.group(1))
    minor_version = int(branch_name_re.group(2))

    logging.debug('in release branch: %s, major_version: %d, minor_version: %d'
                  % (commit_ref_name, major_version, minor_version))

    return major_version, minor_version


def exact_version_in_tag(commit_ref_name):
    tag_name_re = re.match(r'v(\d+)\.(\d+)\.(\d+)', commit_ref_name)
    if tag_name_re is None:
        return None

    major_version = int(tag_name_re.group(1))
    minor_version = int(tag_name_re.group(2))
    patch_version = int(tag_name_re.group(3))

    logging.debug('in release tag: %s, major_version: %d, minor_version: %d, patch_version:%d'
                  % (commit_ref_name, major_version, minor_version, patch_version))

    return major_version, minor_version, patch_version


def main():
    logging.basicConfig(level=logging.DEBUG)

    parser = argparse.ArgumentParser(
        description='RPP upload tools - repository')

    parser.add_argument('project', help='project name')
    parser.add_argument('commit', help='commit-ref')
    args = parser.parse_args()

    project_name = args.project
    commit_ref_name = args.commit

    logging.info('project_name: %s, commit_ref_name: %s' %
                 (project_name, commit_ref_name))

    version = exact_version_in_develop_branch(commit_ref_name)
    if version:
        print('%s-%d.%d-testing' % (project_name, version[0], version[1]))

    version = exact_version_in_tag(commit_ref_name)
    if version:
        print('%s-%d.%d-stable' % (project_name, version[0], version[1]))


if __name__ == '__main__':
    main()