-
Notifications
You must be signed in to change notification settings - Fork 6
/
build_updated_packages.py
executable file
·170 lines (146 loc) · 4.11 KB
/
build_updated_packages.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
#!/usr/bin/env python
import glob
import argparse
import os
import sys
import subprocess
import shlex
parser = argparse.ArgumentParser(
description='Build changed packages',
formatter_class=argparse.ArgumentDefaultsHelpFormatter)
parser.add_argument("-g", "--git-sources", default="/git/uvcdat")
parser.add_argument(
"-d",
"--delta",
help="delta to look back in git history to figure out Packages to update",
default=1,
)
parser.add_argument(
"-u",
"--units",
help="units for delta",
choices=[
"days",
"hours",
"months",
"years",
"tag",
"date"],
default="days")
parser.add_argument(
"-v",
"--version",
help="name of version to use, default to today's date",
default=None)
parser.add_argument(
"-b",
"--branch",
help="git branch to use, default to current",
default=None)
parser.add_argument(
"-V",
"--verbose",
action="store_true",
default=False,
help="verbose output")
try:
user_login = os.getlogin()
except:
print "COULD NOT figure out your username"
user_login = "some_user"
parser.add_argument(
"-c",
"--channel",
default=user_login,
help="channel to cleanup")
parser.add_argument("-B", "--build", default=None, help="Build to use")
parser.add_argument("-l", "--label", default=None, help="Label to use")
files = glob.glob("*/meta.yaml.in")
args = parser.parse_args(sys.argv[1:])
def run_cmd(cmd, cwd=None):
if cwd is None:
cwd = args.git_sources
if args.verbose:
print "running:", cmd, "in directory", cwd
sub = subprocess.Popen(
shlex.split(cmd),
cwd=cwd,
stderr=subprocess.PIPE,
stdout=subprocess.PIPE)
sub.wait()
try:
o = sub.stdout.readlines()
except:
o = "No output"
try:
e = sub.stderr.readlines()
except:
e = "no err"
if args.verbose:
if len(o) == 0:
print "OUT OK"
else:
print "OUT:", o
if args.verbose:
if len(e) == 0:
print "ERR OK"
else:
print "ERR:", e
return len(o), len(e)
if not os.path.exists(args.git_sources):
raise RuntimeError(
"git repo directory does not exists: %s" %
args.git_sources)
cmd = "git fetch --all"
run_cmd(cmd)
# Preping the meta files
cmd = "./prep_for_build.py"
if args.branch is not None:
cmd += " -b %s" % args.branch
if args.build is not None:
cmd += "-B %s" % args.build
if args.version is not None:
cmd += "-v %s" % args.version
run_cmd(cmd, os.getcwd())
if args.branch is not None:
cmd = "git checkout %s" % args.branch
run_cmd(cmd)
run_cmd("git pull")
changed = False
for f in files:
sp = f.split("/")
bnm = "/".join(sp[:-1] + ["build.sh"])
bld = open(bnm)
try:
b = bld.read().split("cd Packages")[1].split()[0][1:]
except:
b = sp[0]
print "package:", b
p = f.split("/")[0]
last_commit_format = "'origin@{%s}'"
if args.units not in ["tag", "date"]:
last_commit_format = last_commit_format % ( "%%s %s ago" % args.units )
elif args.units == "tag":
last_commit_format = "%s"
last_commit = last_commit_format % args.delta
cmd = "git diff --dirstat origin %s -- Packages/%s" % (
last_commit, b)
if args.verbose:
print "CMD:", cmd
changes, errors = run_cmd(cmd)
if changes > 0:
changed = True
print "\tChanged"
cmd = "conda build %s" % sp[0]
run_cmd(cmd,os.getcwd())
cmd = "python manage_anaconda_packages.py -l %s -c %s -p %s" % (args.label, args.channel, sp[0])
run_cmd(cmd,os.getcwd())
cmd = "python manage_anaconda_packages.py -u -l %s -c %s -p %s" % (args.label, args.channel, sp[0])
run_cmd(cmd,os.getcwd())
if changed:
cmd = "conda build cdat_info"
run_cmd(cmd,os.getcwd())
cmd = "python manage_anaconda_packages.py -l %s -c %s -p cdat_info" % (args.label, args.channel)
run_cmd(cmd,os.getcwd())
cmd = "python manage_anaconda_packages.py -u -l %s -c %s -p cdat_info" % (args.label, args.channel)
run_cmd(cmd,os.getcwd())