-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathyupdate
executable file
·76 lines (64 loc) · 1.94 KB
/
yupdate
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
69
70
71
72
73
74
75
76
#!/usr/bin/env python2
# -*- coding: utf-8 -*-
#
# yupdate.py
#
# Copyright 2015-2017 Ikey Doherty <[email protected]>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
import sys
import ruamel.yaml
import os
import subprocess
import pisi.version
def usage(msg=None, ex=1):
if msg:
print(msg)
else:
print("Usage: %s [version] [url]" % sys.argv[0])
sys.exit(ex)
if __name__ == "__main__":
if len(sys.argv) != 3:
usage()
ymlfile = "package.yml"
if not os.path.exists(ymlfile):
usage("Specified file does not exist")
if not ymlfile.endswith(".yml"):
usage("%s does not look like a valid package.yml file")
newversion = sys.argv[1]
try:
d = pisi.version.Version(newversion)
except Exception as e:
print("Problematic version string: %s" % e)
sys.exit(1)
url = sys.argv[2]
file = url.split("/")[-1]
try:
r = os.system("wget \"%s\"" % url)
except:
print("Failed to download file")
sys.exit(1)
if r != 0:
print("Failed to download file")
sys.exit(1)
sha256 = subprocess.check_output(["sha256sum", file]).split()[0].strip()
with open(ymlfile, "r") as infile:
data = ruamel.yaml.round_trip_load(infile)
data['source'] = sources = []
sources.append({url: sha256})
data['release'] += 1
data['version'] = newversion
os.unlink(file)
try:
with open(ymlfile, 'w') as fp:
ruamel.yaml.round_trip_dump(
data, fp, indent=4, block_seq_indent=4, width=200,
top_level_colon_align=True, prefix_colon=' ')
except Exception as e:
print("Error writing file, may need to reset it.")
print(e)
sys.exit(1)