-
Notifications
You must be signed in to change notification settings - Fork 0
/
sanitygit.py
68 lines (58 loc) · 1.73 KB
/
sanitygit.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
"""
Perform sanity checks for Latex files in a git repository
"""
import re
import git
import os
import sys
import subprocess
try:
from sanity import SanityDir
except ImportError:
from langsci.sanity import SanityDir
def cloneorpull(url):
"""
Make a git repository available locally.
The repo is cloned if not already available locally, otherwise, it is pull'ed.
args:
url (str): the url string of the repository. It can be either the html URL or the git url
returns
str: the file path to the local repo
"""
m = re.search('langsci/([0-9]{2,}a?)',url)
githubID = m.group(1)
print("GitHub ID found:", githubID)
giturl = "https://github.com/langsci/%s.git"%githubID
gitdir = os.path.join(os.getcwd(),githubID)
print("git repo is ", giturl)
try:
git.Repo.clone_from(giturl, gitdir)
print("cloned")
except git.exc.GitCommandError:
print("repo already in file system. Pulling")
cwd = os.getcwd()
print(gitdir)
os.chdir(gitdir)
subprocess.call(["git","pull"])
os.chdir(cwd)
print("pulled")
return gitdir
if __name__ == "__main__":
"""
usage:
python3 sanitygit.py https://www.github.com/langsci/42
"""
githuburl = sys.argv[1]
ignorecodes = []
try:
ignorecodes = sys.argv[2:]
except IndexError:
pass
d = cloneorpull(githuburl)
lspdir = SanityDir(os.path.join(d,'.'),ignorecodes)
print("checking %s" % '\n '.join(['']+[f for f in lspdir.texfiles+lspdir.bibfiles]))
lspdir.check()
lspdir.printErrors()
imgdir = SanityDir(os.path.join(d,'figures'),ignorecodes)
imgdir.check()
imgdir.printErrors()