-
Notifications
You must be signed in to change notification settings - Fork 1
/
castor
executable file
·73 lines (49 loc) · 1.85 KB
/
castor
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
#!/usr/bin/env python3
# vim: fileencoding=utf-8 tw=100 expandtab ts=4 sw=4 :
#
# Castor
# (c) 2015 ActivKonnect
# Rémy Sanchez <remy.sanchez@activkonnect.com>
import argparse
import sys
from castor.repo import CastorException, init, find_repo, Castor
def parse_cli():
p = argparse.ArgumentParser(description='Castor is a tool to manage assembly of various Git '
'repositories into a single deployable source tree.')
s = p.add_subparsers(help='Action', dest='action')
a_init = s.add_parser('init', help='Initializes a directory')
a_init.add_argument('directory', type=str, default='.', nargs='?', help='Directory to '
'initialize (defaults '
'to current directory)')
s.add_parser('apply', help='Apply the Castorfile')
s.add_parser('freeze', help='Report current Git commits to Castorfile, assemble all files in '
'the dam directory and add them to the Git index.')
r = p.parse_args()
if r.action is None:
p.print_help()
sys.exit(1)
return r
def make_castor():
root = find_repo('.')
if root is None:
raise CastorException('You are not in a Castor repository')
return Castor(root)
def do_init(directory):
init(directory)
def do_apply():
make_castor().apply()
def do_freeze():
make_castor().freeze()
def main():
parsed = vars(parse_cli())
action = parsed.pop('action')
try:
globals()['do_{}'.format(action)](**parsed)
except KeyboardInterrupt:
print('kthx, bye')
sys.exit(1)
except CastorException as e:
sys.stderr.write('Error: {}\n'.format(e))
sys.exit(1)
if __name__ == '__main__':
main()