Browse Source

Add script to auto-update git repo.

5.3.8
Chris Smith 7 years ago
parent
commit
86db31fe50
1 changed files with 35 additions and 0 deletions
  1. 35
    0
      .updater/updategit.py

+ 35
- 0
.updater/updategit.py View File

@@ -0,0 +1,35 @@
1
+#!/usr/bin/python3
2
+
3
+import fileinput
4
+import re
5
+from os import close, remove, path
6
+from shutil import move
7
+from subprocess import call
8
+from tempfile import mkstemp
9
+
10
+assert path.isdir('.git'), "No git dir found"
11
+
12
+def replace(file_path, pattern, subst):
13
+    # From http://stackoverflow.com/a/39110
14
+    fh, abs_path = mkstemp()
15
+    with open(abs_path, 'w') as new_file:
16
+        with open(file_path) as old_file:
17
+            for line in old_file:
18
+                new_file.write(re.sub(pattern, subst, line))
19
+    close(fh)
20
+    remove(file_path)
21
+    move(abs_path, file_path)
22
+
23
+call(['git', 'fetch'])
24
+
25
+for line in fileinput.input():
26
+    branch, version, changelog, url = line.strip().split(' ')
27
+    branch = 'master' if branch == 'latest' else branch
28
+    call(['git', 'branch', branch, 'master']) # Will fail if the branch exists
29
+    call(['git', 'checkout', branch])
30
+    call(['git', 'rebase', 'origin/%s' % branch]) # May fail as well
31
+    replace('Dockerfile', r'^ARG url=.*', 'ARG url=%s' % url)
32
+    call(['git', 'commit', '-am', 'Auto update to version %s.\n\nChangelog: %s' % (version, changelog)])
33
+    call(['git', 'push', 'origin', branch])
34
+
35
+call(['git', 'checkout', 'master'])

Loading…
Cancel
Save