aboutsummaryrefslogtreecommitdiff
path: root/https-sync-repos.py
blob: acd86944eefb1352a847d5f5006146ab9ebaa69f (plain) (blame)
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
#!/usr/bin/env python

# Synchronize Cryptech git repositories by scraping URLs from the
# automatically generated Trac page.  Yes, we know too much about how
# the generation script and Trac format this page, c'est la vie.

from urllib                     import urlopen
from xml.etree.ElementTree      import ElementTree
from subprocess                 import check_call
from os.path                    import isdir
from sys                        import exit

# URL for automatically generated Trac page listing repositories.

trac_page = "https://wiki.cryptech.is/wiki/GitRepositories"

head = "https://git.cryptech.is/"
tail = ".git"
errs = 0

for elt in ElementTree(file = urlopen(trac_page)).iter("{http://www.w3.org/1999/xhtml}code"):
    if elt.text.startswith(head) and elt.text.endswith(tail):
        url  = elt.text
        repo = url[len(head):-len(tail)]
        pull = isdir(repo)
        print("")
        print(url)
        try:
            if pull:
                check_call(("git", "fetch", "--all", "--prune"), cwd = repo)
                check_call(("git", "merge", "--ff-only"), cwd = repo)
            else:
                check_call(("git", "clone", url, repo))
        except:
            print("** Error", "pulling" if pull else "cloning", repo)
            errs += 1

exit(errs)