7
7
update: Updates a repo.
8
8
print: Prints a tracked repo.
9
9
glorify: Generate the hall of fame.
10
+ code: Generate MD or RST integration code.
10
11
"""
11
12
12
13
__copyright__ = '2018 Sourcerer, Inc.'
19
20
20
21
import fame .storage
21
22
import fame .ssl_hack
23
+ from fame .code_gen import make_md_code , make_rst_code
22
24
from fame .github_tracker import RepoTracker
23
25
from fame .glory import Glory
24
26
25
27
26
- def is_repo_command (command ):
27
- return command in ['add' , 'remove' , 'update' , 'print' , 'glorify' ]
28
+ class Command :
29
+ ADD = 'add'
30
+ REMOVE = 'remove'
31
+ UPDATE = 'update'
32
+ LIST = 'list'
33
+ PRINT = 'print'
34
+ GLORIFY = 'glorify'
35
+ CODE = 'code'
36
+
37
+ @staticmethod
38
+ def is_repo_command (command ):
39
+ return command in [
40
+ Command .ADD , Command .REMOVE , Command .UPDATE ,
41
+ Command .PRINT , Command .GLORIFY ]
42
+
43
+ @staticmethod
44
+ def get_all ():
45
+ return [
46
+ Command .ADD , Command .REMOVE , Command .UPDATE ,
47
+ Command .LIST , Command .PRINT , Command .GLORIFY , Command .CODE ]
28
48
29
49
30
50
def parse_args ():
31
51
parser = argparse .ArgumentParser ()
32
52
parser .add_argument ('command' , type = str ,
33
- choices = ['add' , 'remove' , 'list' ,
34
- 'update' , 'print' , 'glorify' ],
53
+ choices = Command .get_all (),
35
54
help = 'Command to execute' )
36
55
parser .add_argument ('--user' , type = str ,
37
56
help = 'Github user that tracks a repo' )
@@ -43,6 +62,8 @@ def parse_args():
43
62
help = 'Working directory to store data' )
44
63
parser .add_argument ('--gcloud_bucket' , type = str ,
45
64
help = 'Google cloud bucket to store data' )
65
+ parser .add_argument ('--format' , type = str , choices = ['md' , 'rst' ],
66
+ default = 'md' , help = 'Code format to generate' )
46
67
parser .add_argument ('--token' , type = str , help = 'Github API token' )
47
68
parser .add_argument ('--sourcerer_origin' , type = str ,
48
69
default = 'https://sourcerer.io' ,
@@ -56,15 +77,16 @@ def parse_args():
56
77
help = 'Disable SSL host checks, useful for debugging' )
57
78
args = parser .parse_args ()
58
79
59
- if is_repo_command (args .command ):
80
+ if Command . is_repo_command (args .command ) or args . command == Command . CODE :
60
81
if not args .user :
61
82
parser .error ('Must provide repo user' )
62
83
if not args .owner :
63
84
parser .error ('Must provide repo owner' )
64
85
if not args .repo :
65
86
parser .error ('Must provide repo name' )
66
- if not args .sourcerer_origin :
67
- parser .error ('Must provide Sourcerer origin' )
87
+
88
+ if Command .is_repo_command (args .command ) and not args .sourcerer_origin :
89
+ parser .error ('Must provide Sourcerer origin' )
68
90
69
91
if args .work_dir and not os .path .isdir (args .work_dir ):
70
92
parser .error ('--work_dir must be an existing directory' )
@@ -88,19 +110,19 @@ def main():
88
110
89
111
try :
90
112
tracker = RepoTracker ()
91
- if is_repo_command (args .command ):
113
+ if Command . is_repo_command (args .command ):
92
114
tracker .configure (args .user , args .owner , args .repo ,
93
115
args .sourcerer_api_origin ,
94
116
args .sourcerer_api_secret ,
95
117
args .token )
96
118
97
- if args .command == 'add' :
119
+ if args .command == Command . ADD :
98
120
tracker .add ()
99
- elif args .command == 'remove' :
121
+ elif args .command == Command . REMOVE :
100
122
tracker .remove ()
101
- elif args .command == 'update' :
123
+ elif args .command == Command . UPDATE :
102
124
tracker .update ()
103
- elif args .command == 'list' :
125
+ elif args .command == Command . LIST :
104
126
table = []
105
127
for result in RepoTracker .list (args .user ):
106
128
user , owner , repo , status , modified , error = result
@@ -109,13 +131,19 @@ def main():
109
131
'%s:%s/%s' % (user , owner , repo ),
110
132
status , modified , error ])
111
133
print (tabulate (table ))
112
- elif args .command == 'print' :
134
+ elif args .command == Command . PRINT :
113
135
repo = tracker .load ()
114
136
print (repo )
115
- elif args .command == 'glorify' :
137
+ elif args .command == Command . GLORIFY :
116
138
repo = tracker .load ()
117
139
glory = Glory (args .sourcerer_origin , args .sourcerer_api_origin )
118
140
glory .make (repo )
141
+ elif args .command == Command .CODE :
142
+ if args .format == 'md' :
143
+ print (make_md_code (args .user , args .owner , args .repo ))
144
+ elif args .format == 'rst' :
145
+ print (make_rst_code (args .user , args .owner , args .repo ))
146
+
119
147
except Exception as e :
120
148
print ('e %s' % str (e ))
121
149
0 commit comments