Add missing glance functions
[kamaki] / build
1 #!/usr/bin/env python
2
3 import os
4 import shutil
5 import stat
6
7 from os.path import exists, join
8
9
10 SRCDIR = 'kamaki'
11 DSTDIR = 'bin'
12 DST = 'kamaki'
13
14 FILES = ('config.py', 'utils.py', 'client.py', 'cli.py')
15
16
17 def cat(path, dst, skipheader=True):
18     dst.write('\n')
19     
20     in_header = True
21     for line in open(path):
22         if in_header and line.strip() and not line.startswith('#'):
23             in_header = False
24         
25         if line.startswith('from kamaki.'):
26             continue    # Skip local imports
27         
28         if skipheader and in_header:
29             continue
30         
31         dst.write(line)
32
33
34 def main():
35     if not exists(DSTDIR):
36         os.makedirs(DSTDIR)
37     dstpath = join(DSTDIR, DST)
38     
39     dst = open(dstpath, 'w')
40     
41     dst.write('#!/usr/bin/env python\n')
42     
43     cat(join(SRCDIR, '__init__.py'), dst, skipheader=False)
44     
45     for file in FILES:
46         cat(join(SRCDIR, file), dst)
47     
48     dst.close()
49     
50     # Make file executable
51     mode = stat.S_IMODE(os.stat(dstpath).st_mode)
52     mode |= 0111
53     os.chmod(dstpath, mode)
54
55
56 if __name__ == '__main__':
57     main()