-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.py
More file actions
executable file
·36 lines (29 loc) · 1.1 KB
/
setup.py
File metadata and controls
executable file
·36 lines (29 loc) · 1.1 KB
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
#!env/bin/python3
import tarfile, os, yaml, requests, shutil
from io import BytesIO
def cwd(*filenames):
return os.path.join(os.environ["HOME"], *filenames)
def setup():
latest = yaml.load(open("manifest.yaml"))["data"]
for program, data in latest.items():
print(program,data)
prom = requests.get(data["url"], allow_redirects=True, stream=True)
prom.raw.decode_content=True
tgz = prom.raw.read()
tgz = BytesIO(tgz)
tf = tarfile.open(fileobj=tgz)
if not os.path.exists(cwd(program)):
os.makedirs(cwd(program))
for m in tf.getmembers():
for promfile in data["files"]:
if m.name.endswith(promfile):
with open(cwd(program,promfile),"wb") as wd:
fdata = tf.extractfile(m).read()
wd.write(fdata)
os.chmod(cwd(program,promfile), m.mode)
shutil.copy("prometheus.yml", cwd("prometheus.yml"))
with open(cwd("promservices.yaml"),"wt") as wd:
wd.write("[]")
print("Done")
if __name__=='__main__':
setup()