forked from pulp/devel
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcheckout.py
executable file
·71 lines (54 loc) · 2.39 KB
/
checkout.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#!/usr/bin/env python3
import argparse
import os
import subprocess
import sys
import requests
import yaml
# Make a Python 3 virtualenv and install requests and PyYAML
# pyvenv pulp_checkout
# source pulp_checkout/bin/activate
# pip install requests PyYAML
#
# Run the script using the Python3 interpreter
# python checkout.py
REPOS = ['crane', 'pulp', 'pulp_docker', 'pulp_ostree', 'pulp_puppet', 'pulp_python', 'pulp_rpm']
BASE_DIR_TEMPLATE = '~/devel/%s'
def get_args():
parser = argparse.ArgumentParser(description='Checkout your repos to a version of Pulp')
parser.add_argument('--version', default='master', help='the version of Pulp to check out')
parser.add_argument('--remote', default='pulp', help='the name of the pulp remote to fetch from')
return parser.parse_args()
def get_yaml(args):
url = "https://raw.githubusercontent.com/pulp/pulp_packaging/master/ci/config/releases/%s.yaml" % args.version
r = requests.get(url)
if r.status_code == 404:
raise ValueError("Release config not found.")
if r.status_code != 200:
raise RuntimeError('An exception occured while fetching the release config')
return yaml.load(r.text)
def check_checkouts(args):
for repo in REPOS:
checkout_path = os.path.expanduser(BASE_DIR_TEMPLATE % repo)
if os.path.exists(checkout_path):
try:
subprocess.run(["git", "diff", "--exit-code"], check=True, cwd=checkout_path)
except subprocess.CalledProcessError:
print("\n\nThe repo '%s' has uncommitted changes. Either commit or revert those changes to continue.\n\nNo changes were made." % repo)
sys.exit(1)
def fetch_and_checkout(args, yaml):
for repo in REPOS:
checkout_path = os.path.expanduser(BASE_DIR_TEMPLATE % repo)
if os.path.exists(checkout_path):
subprocess.run(["git", "fetch", args.remote], check=True, cwd=checkout_path)
for entry in yaml['repositories']:
if entry['name'] == repo:
subprocess.run(["git", "checkout", "%s/%s" % (args.remote, entry['git_branch'])], check=True, cwd=checkout_path)
subprocess.run(["find", "./", "-name", "*.py[c0]", "-delete"], cwd=checkout_path)
def main():
args = get_args()
check_checkouts(args)
yaml = get_yaml(args)
fetch_and_checkout(args, yaml)
if __name__ == "__main__":
main()