-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCreate.py
More file actions
executable file
·58 lines (43 loc) · 1.25 KB
/
Copy pathCreate.py
File metadata and controls
executable file
·58 lines (43 loc) · 1.25 KB
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
#!/usr/bin/env python3
import os, git, requests, json, sys
f = open('Config.txt', 'r')
data = f.readlines()
homeDir = data[0].rstrip()
user = data[1].rstrip()
token = data[2].rstrip()
f.close()
dirName = sys.argv[1]
payload = {'name': dirName, 'auto_init': 'true'}
def createDir():
path = f'{homeDir}{dirName}'
print(path)
try:
os.mkdir(path)
print(f'Directory {dirName} created')
except FileExistsError:
print(f'Directory {dirName} already exists')
def createReadMe():
path = homeDir + "readme.txt"
f = open(path, 'w+')
print('readme file created')
f.close()
def createGitRepo():
requests.post('https://api.github.com/' + 'user/repos', auth=(user,token), data=json.dumps(payload))
def gitInitCommit():
path = homeDir + dirName
r = git.Repo.init(path)
r.index.add('*')
r.index.commit('first commit')
remote = r.create_remote(dirName, url = f'https://github.com/{user}/{dirName}.git')
remote.push(refspec='master:master')
r.close()
def main():
createDir()
createReadMe()
print('Creating Github Repo...')
createGitRepo()
print('Initialise Git and push to master....')
gitInitCommit()
print('Done!')
if __name__ == "__main__":
main()