~ajkavanagh/+junk/useful-things

« back to all changes in this revision

Viewing changes to scripts/get_charms.py

  • Committer: Alex Kavanagh
  • Date: 2017-05-04 18:48:06 UTC
  • mto: This revision was merged to the branch mainline in revision 14.
  • Revision ID: alex.kavanagh@canonical.com-20170504184806-0meleyvp66m1o5v4
Add get_charms and sync_charmhelpers useful scripts

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
import os
 
2
import subprocess
 
3
import sys
 
4
 
 
5
ALL_REPOS_FILE = 'all_repos.txt'
 
6
CHARM_PREFIX = "./charms/"
 
7
 
 
8
 
 
9
def clone_repos(file, branch):
 
10
    with open(file, 'r') as f:
 
11
        repos = f.readlines()
 
12
    print("Doing {} repos".format(len(repos)))
 
13
    # split off the charm name from the repo
 
14
    for repo in repos:
 
15
        charm_name = repo.split('/')[-1].split('.')[0]
 
16
        print("Doing {} download".format(charm_name))
 
17
        if charm_name.startswith("charm_"):
 
18
            charm_name = charm_name[6:]
 
19
        charm_dir = CHARM_PREFIX + charm_name
 
20
        if os.path.exists(charm_dir):
 
21
            cmd = "rm -rf {}".format(charm_dir)
 
22
            subprocess.check_call(cmd.split(' '))
 
23
        cmd = "git clone {} {}".format(repo.rstrip('\n'), charm_dir)
 
24
        subprocess.check_call(cmd.split(' '))
 
25
        cmd = "cd {} && git checkout {}".format(charm_dir, branch)
 
26
        print(cmd)
 
27
        subprocess.check_call(cmd.split(' '), shell=True)
 
28
 
 
29
 
 
30
def main(argv):
 
31
    if len(argv) < 2:
 
32
        print("usage: get-charms <master || stable/nn.nn>")
 
33
        exit(1)
 
34
    branch = argv[1]
 
35
    clone_repos(ALL_REPOS_FILE, branch)
 
36
 
 
37
 
 
38
if __name__ == '__main__':
 
39
    main(sys.argv)