-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetup.py
200 lines (166 loc) · 5.88 KB
/
setup.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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
#!/usr/bin/env python
# coding: utf8
from setuptools import setup, find_packages
import subprocess
import os
from sys import argv, stderr, exit
name = "pygrim"
desc = "lightweight python frontend framework"
FAIL = '\033[91m'
ENDC = '\033[0m'
def find_files(where, suffixes=("py",), links=True):
files = []
try:
for f in os.listdir(where):
full_path = os.path.join(where, f)
if not os.path.isfile(full_path):
stderr.write("not file %r\n" % (f,))
continue
# endif
if not links and os.path.islink(full_path):
stderr.write("link %r\n" % (f,))
continue
# endif
if f.rsplit(".", 1)[-1] not in suffixes:
stderr.write("not suffix %r\n" % (f,))
continue
# endif
stderr.write("!add %r\n" % (f,))
files.append(full_path)
# endif
except OSError:
stderr.write(
FAIL + "Err on dir %s/%s" % (os.getcwd(), where) + ENDC + "\n")
raise
return files
def get_git_val(*val):
return subprocess.check_output(["git"] + list(val)).strip()
def get_version():
with open("debian/version") as version_in:
version = version_in.read().strip()
return version
def get_package_name():
return name
def call_cmd(cmd):
subprocess.call([cmd], shell=True)
def check_cmd(cmd):
return subprocess.check_output([cmd], shell=True).strip()
def current_branch():
return check_cmd('git name-rev --name-only HEAD')
def need_push_pull():
call_cmd("git fetch")
behind = check_cmd("git rev-list HEAD..origin/{}".format(current_branch()))
ahead = check_cmd("git rev-list origin/{}..HEAD".format(current_branch()))
if ahead:
print "[E]\t nemas pushnuto"
raise Exception('je treba pushnout')
if behind:
print "[E]\t nemas pulnuto"
raise Exception('je treba pullnout')
def edit_version():
call_cmd('${EDITOR} debian/version')
def check_repo():
return
version = get_version()
cmd = """ssh debian.ats "aptly package search \\
\'{pkg_name}, \$Version ({operator}{version})\'" """
current = cmd.format(
pkg_name=name, version=version, operator="="
)
is_current = check_cmd(current)
if is_current:
print "[E]\ttato verze uz v repu je"
raise Exception("tato verze uz v repu je")
else:
print "[OK]\ttato verze v repu neni, muzu pokracovat"
newer = cmd.format(
pkg_name=name, version=version, operator=">"
)
is_newer = check_cmd(newer)
if is_newer:
text = """[?]\tv repu jsou uz novejsi verze nez {version}\n {newer},
pokracovat? [a]no, [n]e - vychozi """.format(
version=version, newer=is_newer)
r = raw_input(text)
if r != "a":
raise Exception('odmitnuto pridani starsi verze')
else:
print "[OK]\tnovejsi verze v repu neni, pokracuju"
def fill_changelog():
write_version_to_changelog = \
"DEBFULLNAME='{author}' dch -v {version} --distribution testing COMMIT MESSASGES".format(
author=get_git_val('config', 'user.name'), version=get_version()
)
call_cmd(write_version_to_changelog)
tag_cmd = "git describe --tags --match '{pkg_name}*' --abbrev=0".format(
pkg_name=name)
last_tag = check_cmd(tag_cmd)
last_tag = last_tag.strip()
print "[I]\tlast tag " + last_tag
try:
messages_cmd = "git log {last_tag}..HEAD --format='%s' . |\
grep -v 'Merge branch' | \
grep -v 'version {pkg}'".format(last_tag=last_tag, pkg=name)
commit_messages = check_cmd(messages_cmd)
commit_messages = commit_messages.strip()
messages_list = commit_messages.split('\n')
for message in messages_list:
print "[I]\t zapisuju commit message {} do changelogu".format(
message)
call_cmd("DEBFULLNAME='{author}' dch -a '{message}'".format(
message=message, author=get_git_val('config', 'user.name')
)
)
except subprocess.CalledProcessError as ex:
res = raw_input("""[?]\tzda se, ze od posledniho tagu nejsou zandne commity
presto pokracovat [a]no, [n]e default
""")
if res != "a":
raise ex
return
def create_tag():
tag = "{}-{}".format(name, get_version())
call_cmd("git reset HEAD")
call_cmd("git add debian/version debian/changelog")
call_cmd('git commit -m "version {tag}"'.format(tag=tag))
call_cmd('git tag "{tag}"'.format(tag=tag))
# TODO: when we annotate tags, use --follow-tags prior to push origin <tag>
# call_cmd("git push --follow-tags")
call_cmd("git push origin {tag}".format(tag=tag))
print "tag done"
# # # start of specific part
# # # end of specific part
methods = {
"version": (get_version, (), {}),
"author": (get_git_val, ('config', 'user.name'), {}),
"author_email": (get_git_val, ('config', 'user.email'), {}),
"name": (get_package_name, (), {}),
"create_tag": (create_tag, (), {}),
"fill_changelog": (fill_changelog, (), {}),
}
if __name__ == "__main__":
if argv[1] in methods.keys():
method, args, kwargs = methods[argv[1]]
print method(*args, **kwargs)
exit(0)
elif argv[1] == "check":
need_push_pull()
edit_version()
check_repo()
fill_changelog()
create_tag()
exit(0)
else:
args = {
"name": name,
"version": get_version(),
"description": desc,
"author": get_git_val("config", "user.name"),
"author_email": get_git_val("config", "user.email"),
"url": "http://www.grandit.cz/",
"packages": find_packages(),
"install_requires": (
"Python >= 2.7",
)
}
setup(**args)