-
Notifications
You must be signed in to change notification settings - Fork 5
/
__init__.py
executable file
·68 lines (50 loc) · 1.7 KB
/
__init__.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
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import datetime
import json
import os
import subprocess
import bikeshed
def main():
updateAndCommit()
def updateAndCommit():
print(datetime.datetime.utcnow())
print(subprocess.check_output("git pull", shell=True).decode(encoding="utf-8"))
scriptPath = os.path.dirname(os.path.realpath(__file__))
dataPath = os.path.join(scriptPath, "data")
try:
with open(os.path.join(dataPath, "manifest.txt"), "r", encoding="utf-8") as fh:
oldDate, _, oldManifest = fh.read().partition("\n")
except:
raise
updateDataFiles(path=dataPath)
try:
with open(os.path.join(dataPath, "manifest.txt"), "r", encoding="utf-8") as fh:
_, _, newManifest = fh.read().partition("\n")
except:
raise
if oldManifest == newManifest:
# No change
print(f"Manifest is unchanged since {oldDate}, nothing to be committed")
return
diffFiles = diffManifest(oldManifest, newManifest)
os.chdir(scriptPath)
print(subprocess.check_output("git add data", shell=True))
print(
subprocess.check_output(
f"git commit -m 'update {len(diffFiles)} files: {', '.join(diffFiles)}'",
shell=True,
)
)
print(subprocess.check_output("git push", shell=True))
def updateDataFiles(path):
bikeshed.constants.quiet = 0
bikeshed.update.update(path=path, manifestMode="skip")
def diffManifest(old, new):
oldLines = set(old.split("\n"))
newLines = set(new.split("\n"))
diffLines = oldLines ^ newLines
diffFiles = set(line.partition(" ")[2] for line in diffLines)
return sorted(diffFiles)
if __name__ == "__main__":
main()