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
|
# TODO:
# - Check if inside a virtualenv, and warn before doing anything
# - Build everything that we are currently expecting as a binary
# - Create complete bundle changelog
import argparse
import json
import os
import tempfile
from contextlib import contextmanager
from distutils import dir_util
from actions import GitCloneAll, GitCheckout, PythonSetupAll
from actions import CollectAllDeps, CopyBinaries, PLister, SeededConfig
from actions import DarwinLauncher, CopyAssets, CopyMisc, FixDylibs
from actions import DmgIt, PycRemover, TarballIt, MtEmAll, ZipIt, SignIt
from actions import RemoveUnused, CreateDirStructure
from utils import IS_MAC, IS_WIN
sorted_repos = [
"leap_assets",
"leap_pycommon",
"keymanager",
"soledad",
"leap_mail",
"bitmask_client",
"bitmask_launcher",
]
@contextmanager
def new_build_dir(default=None):
bd = default
if bd is None:
bd = tempfile.mkdtemp(prefix="bundler-")
yield bd
# Only remove if created a temp dir
if default is None:
dir_util.remove_tree(bd)
def _get_dict_from_json(json_file):
data = {}
try:
with open(json_file, 'r') as f:
data = json.load(f)
except Exception as e:
print "Problem loading json: {0!r}".format(e)
pass
return data
def get_version(versions_file):
"""
Return the "version" data on the json file given as parameter.
:param versions_file: the file name of the json to parse.
:type versions_file: str
:rtype: str or None
"""
versions = _get_dict_from_json(versions_file)
return versions.get('version')
def get_tuf_repo(versions_file):
"""
Return the "tuf_repo" data on the json file given as parameter.
:param versions_file: the file name of the json to parse.
:type versions_file: str
:rtype: str or None
"""
versions = _get_dict_from_json(versions_file)
return versions.get('tuf_repo')
def main():
parser = argparse.ArgumentParser(description='Bundle creation tool.')
parser.add_argument('--workon', help="")
parser.add_argument('--skip', nargs="*", default=[], help="")
parser.add_argument('--do', nargs="*", default=[], help="")
parser.add_argument('--paths-file', help="")
parser.add_argument('--versions-file', help="")
parser.add_argument('--binaries', help="")
parser.add_argument('--seeded-config', help="")
parser.add_argument('--codesign', default="", help="")
args = parser.parse_args()
assert args.paths_file is not None, \
"We need a paths file, otherwise you'll get " \
"problems with distutils and site"
paths_file = os.path.realpath(args.paths_file)
assert args.binaries is not None, \
"We don't support building from source, so you'll need to " \
"specify a binaries path"
binaries_path = os.path.realpath(args.binaries)
assert args.versions_file is not None, \
"You need to specify a versions file with the versions to use " \
"for each package."
versions_path = os.path.realpath(args.versions_file)
seeded_config = None
if args.seeded_config is not None:
seeded_config = os.path.realpath(args.seeded_config)
with new_build_dir(os.path.realpath(args.workon)) as bd:
print "Doing it all in", bd
def init(t, bd=bd):
return t(bd, args.skip, args.do)
gc = init(GitCloneAll)
gc.run(sorted_repos)
# NOTE: NEW...
gco = init(GitCheckout)
gco.run(sorted_repos, versions_path)
ps = init(PythonSetupAll)
ps.run(sorted_repos, binaries_path)
cd = init(CreateDirStructure, os.path.join(bd, "Bitmask"))
cd.run()
dp = init(CollectAllDeps)
dp.run(paths_file)
if binaries_path is not None:
cb = init(CopyBinaries)
cb.run(binaries_path)
if IS_MAC:
pl = init(PLister)
pl.run()
dl = init(DarwinLauncher)
dl.run()
ca = init(CopyAssets)
ca.run()
fd = init(FixDylibs)
fd.run()
cm = init(CopyMisc)
cm.run(binaries_path, get_tuf_repo(versions_path))
pyc = init(PycRemover)
pyc.run()
if IS_WIN:
mt = init(MtEmAll)
mt.run()
if IS_MAC:
si = init(SignIt)
si.run(args.codesign)
if seeded_config is not None:
sc = init(SeededConfig)
sc.run(seeded_config)
version = get_version(versions_path)
if IS_MAC:
dm = init(DmgIt)
dm.run(sorted_repos, version)
elif IS_WIN:
zi = init(ZipIt)
zi.run(sorted_repos, version)
else:
ru = init(RemoveUnused)
ru.run()
ti = init(TarballIt)
ti.run(sorted_repos, version)
# do manifest on windows
if __name__ == "__main__":
main()
|