-
Notifications
You must be signed in to change notification settings - Fork 78
/
Copy pathretire_rpm_git_repo.py
executable file
·49 lines (41 loc) · 1.84 KB
/
retire_rpm_git_repo.py
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
#!/usr/bin/env python3
import argparse
import os
import subprocess
from github import Github
def main():
parser = argparse.ArgumentParser(description='Retires a RPM source git repository that is not needed anymore')
parser.add_argument('name', help='name of repository')
parser.add_argument('version', help='version of XCP-ng in which the package was retired, in form X.Y, e.g. 8.0')
parser.add_argument('reason', help='reason for retirement. Start with lowercase letter, no ending dot.')
parser.add_argument('token_file',
help='file containing github authentication token',
nargs='?',
default=os.path.join(os.path.dirname(os.path.realpath(__file__)), 'github.txt'))
args = parser.parse_args()
name = args.name
version = args.version
reason = args.reason
# authenticate to Github
token = open(args.token_file).read().strip()
g = Github(token)
org = g.get_organization('xcp-ng-rpms')
repo = org.get_repo(args.name)
readme = """RPM sources for the %s package in XCP-ng (https://xcp-ng.org/).
**This package has been retired in XCP-ng %s.**
Reason: %s.
""" % (name, version, reason)
os.chdir(args.name)
subprocess.check_call(['git', 'checkout', 'master'])
subprocess.check_call(['git', 'pull'])
subprocess.check_call(['git', 'rm', '*'])
open('README.md', 'w').write(readme)
subprocess.check_call(['git', 'add', 'README.md'])
open('.retired', 'w').close()
subprocess.check_call(['git', 'add', '.retired'])
subprocess.check_call(['git', 'commit', '-m', 'This package has been retired in XCP-ng %s' % version])
subprocess.check_call(['git', 'push'])
# update repository description
repo.edit(name, description="[retired in %s] %s" % (version, repo.description))
if __name__ == "__main__":
main()