forked from andreatramacere/jetset
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmake_tag.py
executable file
·122 lines (88 loc) · 3.11 KB
/
make_tag.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
#!/usr/bin/env python
from __future__ import absolute_import, division, print_function
from builtins import (bytes, open, super, range,
zip, round, input, pow, object, map, zip)
try:
# Python 2
from __builtin__ import str as builtin_str
except ImportError:
# Python 3
from builtins import str as builtin_str
import yaml,json
import sys
import argparse
import subprocess
from collections import OrderedDict
def ordered_dict_representer(self, value): # can be a lambda if that's what you prefer
return self.represent_mapping('tag:yaml.org,2002:map', value.items())
def update_version_and_label(version):
with open('jetset/pkg_info.json') as fp:
_info = json.load(fp)
if version is not None:
_info['version']=version
label=subprocess.check_output(['git', 'rev-parse', 'HEAD']).decode('ascii').strip()
_info['label']= '%s'%label
print(_info)
with open('jetset/pkg_info.json', 'w') as json_file:
json.dump(_info, json_file)
#with open("conda-pipeline/_template_meta.yaml", 'r') as stream:
# data_loaded = yaml.load(stream)
# data_loaded['package']['version']=version
#yaml.add_representer(OrderedDict, ordered_dict_representer)
#with open('conda-pipeline/meta.yaml', 'w') as yaml_file:
# yaml.dump(data_loaded, yaml_file, default_flow_style=False)
def do_remote_tag(tag):
l=[]
l.append(["git tag -d %s"%tag])
l.append(['git push --delete origin %s'%tag])
l.append(['git push --delete origin-github %s'%tag])
l.append(['''git tag -a %s -m '%s' '''%(tag,tag)])
l.append(['git push origin %s'%tag])
l.append(['git push origin-github %s' % tag])
res = subprocess.call(l[0], shell=True)
for i in l[1::]:
try:
res = subprocess.call(i, shell=True)
except:
pass
print()
def do_remote_push():
l=[]
l.append(['git push origin py23'])
l.append(['git push origin-github py23'])
res = subprocess.call(l[0], shell=True)
for i in l[1::]:
try:
res = subprocess.call(i, shell=True)
except:
pass
print()
def do_commit(message):
l=[]
l.append(["git add . "])
l.append(['''git commit -m '%s' ''' % (message)])
res = subprocess.call(l[0], shell=True)
for i in l[1::]:
try:
res = subprocess.call(i, shell=True)
except:
pass
print()
def main(argv=None):
parser = argparse.ArgumentParser()
parser.add_argument('tag', type=str, )
parser.add_argument('-version', type=str, default=None )
parser.add_argument('-do_remote_tag', action='store_true')
parser.add_argument('-push_message', type=str, default=None)
args = parser.parse_args()
if args.push_message is not None:
do_commit(args.push_message)
update_version_and_label(args.version)
if args.push_message is not None:
do_commit('fixed label in pkg')
if args.push_message is not None:
do_remote_push()
if args.do_remote_tag==True:
do_remote_tag(args.tag)
if __name__ == "__main__":
main(sys.argv)