8
8
def main ():
9
9
parser = argparse .ArgumentParser (description = 'Creates a git repository in current directory for RPM spec file and sources' )
10
10
parser .add_argument ('name' , help = 'name of repository' )
11
+ parser .add_argument ('--local' ,
12
+ help = 'do not create github repository' ,
13
+ action = 'store_true' )
11
14
parser .add_argument ('token_file' ,
12
15
help = 'file containing github authentication token' ,
13
16
nargs = '?' ,
14
17
default = os .path .join (os .path .dirname (os .path .realpath (__file__ )), 'github.txt' ))
15
18
args = parser .parse_args ()
16
19
17
- # authenticate to Github
18
- token = open (args .token_file ).read ().strip ()
19
- g = Github (token )
20
+ if not args .local :
21
+ # authenticate to Github
22
+ token = open (args .token_file ).read ().strip ()
23
+ g = Github (token )
20
24
21
- # create repository
22
- org = g .get_organization ('xcp-ng-rpms' )
23
- org .create_repo (args .name , "RPM sources for %s" % args .name )
25
+ # create repository
26
+ org = g .get_organization ('xcp-ng-rpms' )
27
+ org .create_repo (args .name , "RPM sources for %s" % args .name )
24
28
25
29
# initial commit to master
26
30
gitignore = """BUILD
@@ -39,7 +43,13 @@ def main():
39
43
40
44
Built RPMs and source RPMs are available on https://updates.xcp-ng.org.
41
45
""" % args .name
42
- subprocess .check_call (['git' , 'clone' , 'https://github.com/xcp-ng-rpms/%s.git' % args .name ])
46
+ if args .local :
47
+ subprocess .check_call (['git' , 'init' , args .name ])
48
+ subprocess .check_call (['git' , '-C' , args .name ,
49
+ 'remote' , 'add' , 'origin' ,
50
+ 'https://github.com/xcp-ng-rpms/%s.git' % args .name ])
51
+ else :
52
+ subprocess .check_call (['git' , 'clone' , 'https://github.com/xcp-ng-rpms/%s.git' % args .name ])
43
53
os .chdir (args .name )
44
54
if "git@github.com" not in subprocess .check_output (
45
55
['git' , 'remote' , 'get-url' , '--push' , 'origin' ],
@@ -61,7 +71,8 @@ def main():
61
71
subprocess .check_call (['git' , 'lfs' , 'track' , '*.tbz' ])
62
72
subprocess .check_call (['git' , 'add' , '.gitattributes' ])
63
73
subprocess .check_call (['git' , 'commit' , '-s' , '-m' , 'Initial commit' ])
64
- subprocess .check_call (['git' , 'push' ])
74
+ if not args .local :
75
+ subprocess .check_call (['git' , 'push' ])
65
76
66
77
if __name__ == "__main__" :
67
78
main ()
0 commit comments