-
Notifications
You must be signed in to change notification settings - Fork 1
/
homebrew_pothos_update
executable file
·49 lines (45 loc) · 1.92 KB
/
homebrew_pothos_update
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
#!/usr/bin/env python3
import os
import re
import sys
import requests
from hashlib import sha256
from pothos_scripts_common import *
def main():
if len(sys.argv) != 2:
print("Usage: %s [root path]"%sys.argv[0])
exit(-1)
ROOT = os.path.abspath(sys.argv[1])
homebrew_pothos_dir = os.path.join(ROOT, 'homebrew-pothos')
for fname in os.listdir(homebrew_pothos_dir):
if not fname.endswith('.rb'): continue
fpath = os.path.join(homebrew_pothos_dir, fname)
outlines = list()
newSha256 = None
print('Processing %s'%fpath)
for line in open(fpath).readlines():
m = re.match('\s*url\s+"https://github.com/pothosware/(.+)/archive/(.+).tar.gz"', line.strip())
if m:
repoName = m.groups()[0]
currTag = m.groups()[1]
repoDir = os.path.join(ROOT, repoName)
git_cmd(repoDir, 'remote', 'update')
tags = git_cmd(repoDir, 'tag', '-n', '--sort', 'taggerdate').strip().splitlines()
latestTag = tags[-1].split()[0]
print(latestTag)
if latestTag != currTag:
print(' Update recipe %s from %s -> %s'%(repoName, currTag, latestTag))
newUrl = 'https://github.com/pothosware/%s/archive/%s.tar.gz'%(repoName, latestTag)
print(' Downloading %s'%newUrl)
r = requests.get(newUrl)
r.raise_for_status()
newSha256 = sha256(r.content).hexdigest()
line = line.replace(currTag, latestTag)
m = re.match('\s*sha256\s+"(.+)"', line.strip())
if newSha256 and m:
line = line.replace(m.groups()[0], newSha256)
outlines.append(line)
if newSha256:
open(fpath, 'w').write(''.join(outlines))
print(' Updated %s'%fpath)
if __name__ == '__main__': main()