forked from bbaldallaque/Project-Initiator
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathremote.py
More file actions
431 lines (380 loc) · 11.7 KB
/
Copy pathremote.py
File metadata and controls
431 lines (380 loc) · 11.7 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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
import json
import os
import shutil
import sys
import urllib.request
from random import randint
projectsPath = "D:\\Projects\\"
workspacePath = "D:\\Work Spaces"
repo = ""
visibility = ""
projectName = ""
description = ""
tempName = ""
technology = ""
workspaceName = ""
emojis = [":crown:", ":santa:", ":superhero:", ":unicorn:", ":lion:"]
commands = ['git add .',
f'git commit -m "{emojis[randint(0, len(emojis)-1)]} Show Time!"',
'git branch -M main']
def connect():
try:
urllib.request.urlopen("https://kingtechnologies.in")
return True
except:
return False
def flutter():
# Working Fine
os.system(f'flutter create {projectName} --org dev.kingtechnologies')
def php():
os.mkdir(projectName)
os.chdir(projectName)
open("index.php", "w")
os.system("composer self-update")
os.chdir(projectsPath)
def nodejs():
os.mkdir(projectName)
os.chdir(projectName)
os.system("npm init -y")
os.chdir(projectsPath)
def python():
os.mkdir(projectName)
os.chdir(projectName)
open("main.py", "w")
os.chdir(projectsPath)
def web():
os.mkdir(projectName)
os.chdir(projectName)
open("index.html", "w")
open("style.css", "w")
open("script.js", "w")
os.chdir(projectsPath)
def react():
print("Coming Soon...")
exit("Exiting...")
def angular():
print("Coming Soon...")
exit("Exiting...")
def vue():
print("Coming Soon...")
exit("Exiting...")
def rust():
print("Coming Soon...")
exit("Exiting...")
def go():
print("Coming Soon...")
exit("Exiting...")
def laravel():
# Working Fine
os.system("composer self-update")
os.system(f"composer create-project laravel/laravel {projectName}")
def ci():
os.system("composer self-update")
print("Coming Soon...")
exit("Exiting...")
def net():
print("Coming Soon...")
exit("Exiting...")
# Choose repo type i.e. Local, Global or Organization
def chooseRepoType(x=0):
global repo
if(x == 0):
print('''Choose Repository Type:
1. Local Repository
2. Global Repository
3. Organization Repository'''.replace(" ", "").replace("\n", "\n\t"))
x = input("Repository Type: ")
if x == "1":
repo = "local"
elif x == "2":
repo = "global"
elif x == "3":
repo = "organization"
else:
y = input(
"Wrong Input, Wanna Try again! or Exit(y/Y): ")
if (y.lower() == "y"):
exit("Exiting...")
else:
chooseRepoType(y)
# Choose repo visibility i.e. private or public
def chooseVisibility(x=0):
global visibility
if repo == "global" or repo == "organization":
if x == 0:
print('''Choose Project Visibility:
1. Public
2. Private'''.replace(" ", "").replace("\n", "\n\t"))
x = input("Project Visibility: ")
if x == "1":
visibility = "public"
elif x == "2":
visibility = "private"
else:
y = input(
"Wrong Input, Wanna Try again! or Exit(y/Y): ")
if (y.lower() == "y"):
exit("Exiting...")
else:
chooseVisibility(y)
# Choose Technology by Their respective number
def chooseTechnology():
global technology
print('''Choose Technology:
1. Flutter
2. PHP
3. NodeJS
4. Python
5. Basic Web
6. React
7. Angular
8. Vue
9. Rust
10. Go
11. Laravel
12. CodeIgniter
13. .Net'''.replace(" ", "").replace("\n", "\n\t"))
x = input("Technology: ")
if x == "1":
technology = "Flutter"
elif x == "2":
technology = "PHP"
elif x == "3":
technology = "NodeJS"
elif x == "4":
technology = "Python"
elif x == "5":
technology = "Basic Web"
elif x == "6":
technology = "React"
elif x == "7":
technology = "Angular"
elif x == "8":
technology = "Vue"
elif x == "9":
technology = "Rust"
elif x == "10":
technology = "Go"
elif x == "11":
technology = "Laravel"
elif x == "12":
technology = "CodeIgniter"
elif x == "13":
technology = ".Net"
else:
y = input(
"Wrong Input, Wanna Try again! or Exit(y/Y): ")
if (y.lower() == "y"):
exit("Exiting...")
else:
chooseVisibility(y)
# Add Entry to Workspace and Open it
def addEntryToWorkspace():
global workspaceName
if technology == "Flutter":
workspaceName = 'Flutter.code-workspace'
elif technology == "PHP":
workspaceName = 'Php.code-workspace'
elif technology == "NodeJS":
workspaceName = 'Node.code-workspace'
elif technology == "Python":
workspaceName = 'Python.code-workspace'
elif technology == "Basic Web":
workspaceName = 'Web.code-workspace'
elif technology == "React":
workspaceName = 'React.code-workspace'
elif technology == "Angular":
workspaceName = 'Angular.code-workspace'
elif technology == "Vue":
workspaceName = 'Vue.code-workspace'
elif technology == "Rust":
workspaceName = 'Rust.code-workspace'
elif technology == "Go":
workspaceName = 'Go.code-workspace'
elif technology == "Laravel":
workspaceName = 'Php.code-workspace'
elif technology == "CodeIgniter":
workspaceName = 'Php.code-workspace'
elif technology == ".Net":
workspaceName = 'Net.code-workspace'
else:
print("Workspace Not Found")
exit("Exiting...")
os.chdir(workspacePath)
with open(workspaceName) as json_file:
data = json_file.read()
data = json.loads(data.replace("'", "\"").replace("\t", "").replace(
" ", "").replace("\n", "").replace(",}", "}").replace(",]", "]"))
data["folders"].insert(0, {"path": "..\\Projects\\"+projectName})
with open(workspaceName, 'w', encoding='utf-8') as f:
json.dump(data, f, ensure_ascii=False, indent=4)
os.startfile(workspacePath+'\\'+workspaceName)
# Create Local Repo
def localRepo():
_dir = projectsPath + '/' + projectName
os.chdir(_dir)
os.system('git init')
# Create Global Repo or Organization Repo
def globalRepo():
global projectName
global technology
global description
_dir = projectsPath + '/' + projectName
description = input(f"Enter Description for {tempName}: ")
try:
os.chdir(_dir)
os.system('git init')
os.chdir(projectsPath)
if repo == "global":
if visibility == "private":
os.system(
f'gh repo create {projectName} --private --description="{description}" --homepage="https://kingtechnologies.in/" -s {projectName}')
else:
os.system(
f'gh repo create {projectName} --public --description="{description} Project" --homepage="https://kingtechnologies.in/" -s {projectName}')
else:
if visibility == "private":
os.system(
f'gh repo create king-technologies/{projectName} --private --description="{technology} Project" --homepage="https://kingtechnologies.in/" -s {projectName}')
else:
os.system(
f'gh repo create king-technologies/{projectName} --public --description="{technology} Project" --homepage="https://kingtechnologies.in/" -s {projectName}')
commands.append("git push -u origin main")
os.chdir(_dir)
except:
x = input(
f'{projectName} Repo already exist Try another name or exit(y): ')
if (x.lower() == "y"):
exit("Exit")
elif (connect()):
projectName = x
globalRepo(projectName)
else:
y = input(
"No Internet Connection! Want to work locally (y) or exit: ")
if (y.lower() == "y"):
projectName = x
localRepo(x)
else:
exit("Exit")
# Create Repo local or global based on choice
def createRepo():
if repo == "local":
localRepo()
else:
globalRepo()
# Naming Scheme according to the language
def prepareProject():
global projectName
os.chdir(projectsPath)
if technology == "Flutter":
projectName = tempName.lower()
elif technology == "PHP":
projectName = tempName
elif technology == "NodeJS":
projectName = tempName.lower()
elif technology == "Python":
projectName = tempName
elif technology == "Basic Web":
projectName = tempName
elif technology == "React":
projectName = tempName.lower()
elif technology == "Angular":
projectName = tempName.lower()
elif technology == "Vue":
projectName = tempName.lower()
elif technology == "Rust":
projectName = tempName
elif technology == "Go":
projectName = tempName
elif technology == "Laravel":
projectName = tempName.title()
elif technology == "CodeIgniter":
projectName = tempName.title()
elif technology == ".Net":
projectName = tempName
else:
exit("Wrong Technology")
# Call the respective function based on choice
def createProject():
if technology == "Flutter":
os.system(f'flutter upgrade -f')
flutter()
elif technology == "PHP":
php()
elif technology == "NodeJS":
nodejs()
elif technology == "Python":
python()
elif technology == "Basic Web":
web()
elif technology == "React":
react()
elif technology == "Angular":
angular()
elif technology == "Vue":
vue()
elif technology == "Rust":
rust()
elif technology == "Go":
go()
elif technology == "Laravel":
laravel()
commands.append("composer update")
elif technology == "CodeIgniter":
ci()
elif technology == ".Net":
net()
else:
exit("Exiting...")
# Add images folder, Readme File and Github Templates
def addUtilities():
os.makedirs('assets/images')
repoTitle = tempName.capitalize()
repoEmail = tempName.capitalize().replace(" ", "%20")
with open("D:\Projects\Project-Initiator\ReadMeTemplate.md", "r", encoding="utf-8") as f:
d = f.readlines()
with open("README.md", "w", encoding="utf-8") as r:
for i in d:
y = i
if repo == "global":
y = i.replace("<repo-owner>", "Rohit19060")
else:
y = i.replace("<repo-owner>", "king-technologies")
y = y.replace("<repo-name>", projectName)
y = y.replace("<repo-desc>", description)
y = y.replace("<repo-lang>", technology)
y = y.replace("<repo-title>", repoTitle)
y = y.replace("<repo-email>", repoEmail)
r.write(y)
src = "D:\Projects\Project-Initiator\Templates"
import subprocess
proc = subprocess.Popen(["cd"],
stdout=subprocess.PIPE, shell=True)
(out, err) = proc.communicate()
dst = str(out).strip().replace("\\n", "").replace(
"b'", "").replace("'", "").replace("\\r", "")
if not os.path.exists(dst+"\\.github") and os.path.exists(src):
for item in os.listdir(src):
s = os.path.join(src, item)
d = os.path.join(dst, item)
if os.path.isdir(s):
shutil.copytree(s, d)
else:
shutil.copy(s, d)
# Check for the sys argument have -y or not
if "-y" in sys.argv:
repo = "global"
visibility = "public"
else:
chooseRepoType()
chooseVisibility()
tempName = str(sys.argv[1])
chooseTechnology()
prepareProject()
createProject()
createRepo()
addUtilities()
for c in commands:
os.system(c)
addEntryToWorkspace()