Remove unused code
[bitmask_bundler.git] / bundler / main.py
1 # TODO:
2 #  - Check if inside a virtualenv, and warn before doing anything
3 #  - Build everything that we are currently expecting as a binary
4 #  - Create complete bundle changelog
5
6 import argparse
7 import os
8 import tempfile
9
10 from contextlib import contextmanager
11 from distutils import dir_util
12
13 from actions import GitCloneAll, PythonSetupAll, CreateDirStructure
14 from actions import CollectAllDeps, CopyBinaries, PLister, SeededConfig
15 from actions import DarwinLauncher, CopyAssets, CopyMisc, FixDylibs
16 from actions import DmgIt, PycRemover, TarballIt, MtEmAll, ZipIt, SignIt
17 from actions import RemoveUnused
18
19 from utils import IS_MAC, IS_WIN
20
21 sorted_repos = [
22     "leap_assets",
23     "leap_pycommon",
24     "keymanager",
25     "soledad",
26     "leap_mail",
27     "bitmask_client",
28     "bitmask_launcher",
29     "thandy"
30 ]
31
32
33 @contextmanager
34 def new_build_dir(default=None):
35     bd = default
36     if bd is None:
37         bd = tempfile.mkdtemp(prefix="bundler-")
38     yield bd
39     # Only remove if created a temp dir
40     if default is None:
41         dir_util.remove_tree(bd)
42
43
44 def main():
45     parser = argparse.ArgumentParser(description='Bundle creation tool.')
46     parser.add_argument('--workon', help="")
47     parser.add_argument('--skip', nargs="*", default=[], help="")
48     parser.add_argument('--do', nargs="*", default=[], help="")
49     parser.add_argument('--paths-file', help="")
50     parser.add_argument('--binaries', help="")
51     parser.add_argument('--seeded-config', help="")
52     parser.add_argument('--nightly', action="store_true", help="")
53     parser.add_argument('--codesign', default="", help="")
54
55     args = parser.parse_args()
56
57     assert args.paths_file is not None, \
58         "We need a paths file, otherwise you'll get " \
59         "problems with distutils and site"
60     paths_file = os.path.realpath(args.paths_file)
61
62     assert args.binaries is not None, \
63         "We don't support building from source, so you'll need to " \
64         "specify a binaries path"
65     binaries_path = os.path.realpath(args.binaries)
66
67     seeded_config = None
68     if args.seeded_config is not None:
69         seeded_config = os.path.realpath(args.seeded_config)
70
71     with new_build_dir(os.path.realpath(args.workon)) as bd:
72         print "Doing it all in", bd
73
74         def init(t, bd=bd):
75             return t(bd, args.skip, args.do)
76
77         gc = init(GitCloneAll)
78         gc.run(sorted_repos, args.nightly)
79
80         ps = init(PythonSetupAll)
81         ps.run(sorted_repos, binaries_path)
82
83         cd = init(CreateDirStructure, os.path.join(bd, "Bitmask"))
84         cd.run()
85
86         dp = init(CollectAllDeps)
87         dp.run(paths_file)
88
89         if binaries_path is not None:
90             cb = init(CopyBinaries)
91             cb.run(binaries_path)
92
93         if IS_MAC:
94             pl = init(PLister)
95             pl.run()
96             dl = init(DarwinLauncher)
97             dl.run()
98             ca = init(CopyAssets)
99             ca.run()
100             fd = init(FixDylibs)
101             fd.run()
102
103         cm = init(CopyMisc)
104         cm.run()
105
106         pyc = init(PycRemover)
107         pyc.run()
108
109         if IS_WIN:
110             mt = init(MtEmAll)
111             mt.run()
112
113         if IS_MAC:
114             si = init(SignIt)
115             si.run(args.codesign)
116
117         if seeded_config is not None:
118             sc = init(SeededConfig)
119             sc.run(seeded_config)
120
121         if IS_MAC:
122             dm = init(DmgIt)
123             dm.run(sorted_repos, args.nightly)
124         elif IS_WIN:
125             zi = init(ZipIt)
126             zi.run(sorted_repos, args.nightly)
127         else:
128             ru = init(RemoveUnused)
129             ru.run()
130             ti = init(TarballIt)
131             ti.run(sorted_repos, args.nightly)
132
133         # do manifest on windows
134
135 if __name__ == "__main__":
136     main()