-
Notifications
You must be signed in to change notification settings - Fork 2
/
submit.py
146 lines (120 loc) · 3.68 KB
/
submit.py
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
#!/usr/bin/env python3
import sys, os, json
import tempfile as tmp
import subprocess
# template-string for release-note
release_template = """
## v{version} Changelog
---
{changes}
"""
# get a dict in list-notation
unpack = lambda x: [(k, x[k]) for k in x]
# repack a list-dict into a dict
def pack( pairs ):
d = {}
for (k, v) in pairs:
d[k] = v
return d
# get only the unique items in the given list
def unique( items ):
found = []
return [(x, found.append(x))[0] for x in items if not (x in found)]
# open and edit a File with vim, and return it's content afterwards
def vimopen(txt=''):
rns = tmp._RandomNameSequence()
name = os.path.join(tmp.gettempdir(), rns.__next__()+'.md')
f = open(name, 'w', 1)
f.write( txt )
f.close()
os.system('vim '+name)
f = open(name, 'r', 1)
data = f.read()
f.close()
os.unlink( name )
return data
# get the git-history since the last time we submitted
def command(cmd, args):
p = subprocess.Popen(['ls', '-a'], stdout=subprocess.PIPE, stderr=subprocess.PIPE, cwd=os.getcwd())
out, err = p.communicate()
return out, err
# get the git-history since the last time we committed
def git_history():
output, error = command('git', ['log', '--pretty=format:" - %cr %s" -10'])
return str(output).split('\n')
# get the haxelib.json data
def get_data():
return json.load(open('haxelib.json', 'r', 1))
# save some JSON data to 'haxelib.json'
def set_data( changes ):
data = unpack(get_data())
data += unpack(changes)
json_data = pack( data )
json.dump(json_data, open('haxelib.json', 'w', 1), indent=4)
# ask the user a question
def ask( q ):
_ask = lambda: input(q+'(y/n)')
while True:
a = _ask().lower().strip()
if (a in ['y', 'n']):
return (True if a == 'y' else False)
else:
print('answer must be "y" or "n"')
# handle version-number
def vnumber(curr, prev='0.0.0'):
pb = prev.split('.')
cb = curr.split('.')
result = ['', '', '']
i = 0
while i < len(cb):
c, p = (cb[i], pb[i])
if c.strip() in ['', '_', '!']:
result[i] = p
elif c.startswith('+'):
result[i] = str(int(p) + 1)
else:
result[i] = c
i += 1
return ('.'.join( result ))
# handle tags
def taglist(curr, prev=[]):
tags = ([] + prev)
if curr.startswith('-'):
_strip = [t.strip() for t in curr[1:].strip().split(',')]
tags = [t for t in tags if not (t in _strip)]
elif curr.strip() == '':
return prev
else:
tags += curr.strip().split(',')
tags = unique(tags)
return tags
# Prompt the user for update-info
def update_info():
data = get_data()
changes = {}
# prompt the user for the new version number
vn = input('version (currently '+data['version']+'): ')
data['version'] = changes['version'] = vnumber(vn, data['version'])
ntags = input('tags (currently '+(','.join(data['tags']))+'): ')
data['tags'] = changes['tags'] = taglist(ntags, data['tags'])
new_rnote = ask('write new releasenote?')
if new_rnote:
logs = []
while True:
l = input('changelog entry: ')
if l.strip() == '':
break
else:
logs.append(' - ' + l.strip())
data['changes'] = '\n'.join( logs )
release_note = vimopen(release_template.format( **data ))
changes['releasenote'] = release_note
return changes
def main(args):
changes = update_info()
print(json.dumps(changes, indent=4))
set_data( changes )
os.system('haxelib submit ./')
if __name__ == '__main__':
args = sys.argv[1:]
main( args )