-
Notifications
You must be signed in to change notification settings - Fork 11
/
ybump
executable file
·51 lines (47 loc) · 1.63 KB
/
ybump
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
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
#
# ybump.py
#
# Copyright 2015-2020 Solus Project
#
# 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
from ruamel.yaml import YAML
## The YAML 1.2 spec technically does not allow key names to be greater than 128 characters. This is problematic for us
## as we use the source URI as the key in ypkg, causing the infamous splitting of long source names and causing lines
## to start with `- ?`. Override this limit in ruamel to allow us to continue to mangle the YAML spec in this way.
## 32x the limit oughta be enough for anyone, right?
from ruamel.yaml.emitter import Emitter
Emitter.MAX_SIMPLE_KEY_LENGTH = 4096
def usage(msg=None, ex=1):
if msg:
print(msg)
else:
print(("Usage: %s file.yml" % sys.argv[0]))
sys.exit(ex)
if __name__ == "__main__":
if len(sys.argv) != 2:
usage()
with open(sys.argv[1]) as fp:
lines = fp.readlines()
fp.seek(0)
yaml = YAML()
data = yaml.load(fp)
data['release'] += 1
maxwidth = len(max(lines, key=len))
try:
with open(sys.argv[1], 'w') as fp:
yaml.indent(mapping=4, sequence=4, offset=4)
yaml.top_level_colon_align = True
yaml.prefix_colon = ' '
yaml.width = maxwidth
yaml.dump(data, fp)
except Exception as e:
print("Error writing file, may need to reset it.")
print(e)
sys.exit(1)