-
Notifications
You must be signed in to change notification settings - Fork 0
/
setupproj.py
333 lines (271 loc) · 8.62 KB
/
setupproj.py
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
# SetupProj plots notams on a streetmap.
# Copyright (C) 2023 Jelmer Korten (korty.codes)
# SetupProj is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
# SetupProj is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with SetupProj. If not, see <https://www.gnu.org/licenses/>.
# Contact: korty.codes@gmail.com
# setupproj
# To set up a project
# version 1.0.2
import sys
from os import system, mkdir, makedirs, chdir
from os.path import dirname, realpath, join
import platform
import shutil
import argparse
# To clear the terminal
clear = lambda: system("cls || clear")
def create_folder(full_path):
"""Creates a folder based on the fullpath provided.
The full path is create based on the folder this file is ran in and the new foldername provided.
Should that folder already exist it will ask you before overwriting.
To Run:
copy this file to the folder that holds all your projects / where you want to set up a new project:
In terminal cd to the folder you want to setup the project
python setupproj.py --f PROJECTNAME [--open vscode/pycharm] [--url GITHUB REPO URL]"""
try:
mkdir(full_path)
except FileExistsError as err:
print(err)
print(f"Do you want to OVERWRITE the current information in {full_path}?")
print("Yes/No")
choice = input().lower()
except FileNotFoundError as err:
print(err)
print("Creating folders...")
makedirs(full_path)
print("All folders in the path have been created.")
else:
print("Your folder has been created.")
# finally will be run at the end of a try-except but I only will have choice
# defined if the FileExistsError runs. So we check if choice in locals.
finally:
if "choice" in locals():
if choice == "yes":
clear()
print(f"WARNING, this WILL overwrite all your files in {full_path}")
print("There is no way to return your files")
print("They will not be in the bin, or anywhere, they will be gone..")
print("Type exactly: Understood, OVERWRITE my folder")
x = input()
clear()
if x == "Understood, OVERWRITE my folder":
shutil.rmtree(full_path)
mkdir(full_path)
print("Your folder has been overwritten.")
# TODO: Sort out these continuing prints.
else:
print("Continuing without overwriting.")
else:
print("Continuing without overwriting.")
def use_folder(full_path, folder, openyn, URL, sys_name):
"""Uses the newly created folder to create a new virtual environment, a .gitignore and a README.md
If a --open is specified it will attempt to open the IDE at the end.
If a --url is specified it will attempt to link to that repo."""
print(f"Do you want to continue and use the {folder}")
print("Yes / No")
x = input().lower()
if x!="yes":
sys.exit()
chdir(full_path)
if not URL == None:
system("git init -b main")
system(f"git remote add origin {URL}")
system("git remote -v")
system("echo readme > README.md")
TEXT = f""".{folder}
# Created by https://www.toptal.com/developers/gitignore/api/macos
# Edit at https://www.toptal.com/developers/gitignore?templates=macos
### macOS ###
# General
.DS_Store
.AppleDouble
.LSOverride
# Icon must end with two \r
Icon
# Thumbnails
._*
# Files that might appear in the root of a volume
.DocumentRevisions-V100
.fseventsd
.Spotlight-V100
.TemporaryItems
.Trashes
.VolumeIcon.icns
.com.apple.timemachine.donotpresent
# Directories potentially created on remote AFP share
.AppleDB
.AppleDesktop
Network Trash Folder
Temporary Items
.apdisk
### macOS Patch ###
# iCloud generated files
*.icloud
# End of https://www.toptal.com/developers/gitignore/api/macos
# added from github:
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class
# C extensions
*.so
# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
share/python-wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST
# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec
# Installer logs
pip-log.txt
pip-delete-this-directory.txt
# Unit test / coverage reports
htmlcov/
.tox/
.nox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
*.py,cover
.hypothesis/
.pytest_cache/
cover/
# Translations
*.mo
*.pot
# Django stuff:
*.log
local_settings.py
db.sqlite3
db.sqlite3-journal
# Flask stuff:
instance/
.webassets-cache
# Scrapy stuff:
.scrapy
# Sphinx documentation
docs/_build/
# PyBuilder
.pybuilder/
target/
# Jupyter Notebook
.ipynb_checkpoints
# IPython
profile_default/
ipython_config.py
# pyenv
# For a library or package, you might want to ignore these files since the code is
# intended to run in multiple environments; otherwise, check them in:
# .python-version
# pipenv
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
# However, in case of collaboration, if having platform-specific dependencies or dependencies
# having no cross-platform support, pipenv may install dependencies that don't work, or not
# install all needed dependencies.
#Pipfile.lock
# poetry
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
# This is especially recommended for binary packages to ensure reproducibility, and is more
# commonly ignored for libraries.
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
#poetry.lock
# pdm
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
#pdm.lock
# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
# in version control.
# https://pdm.fming.dev/#use-with-ide
.pdm.toml
# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
__pypackages__/
# Celery stuff
celerybeat-schedule
celerybeat.pid
# SageMath parsed files
*.sage.py
# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/
# Spyder project settings
.spyderproject
.spyproject
# Rope project settings
.ropeproject
# mkdocs documentation
/site
# mypy
.mypy_cache/
.dmypy.json
dmypy.json
# Pyre type checker
.pyre/
# pytype static type analyzer
.pytype/
# Cython debug symbols
cython_debug/
# PyCharm
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
# and can be added to the global gitignore or merged into this file. For a more nuclear
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
#.idea"""
with open('.gitignore','w') as f:
f.write(TEXT)
if not URL == None:
system("git add . && git commit -m 'initial commit'")
system("git push -u origin main")
system(f"{'python' if sys_name=='Windows' else 'python3'} -m venv .{folder}")
if openyn:
if openyn.lower() in ('code','vsc','vscode'):
system("code .")
elif openyn.lower() in ('pycharm','pc'):
system("pycharm .")
if __name__ == "__main__":
parser = argparse.ArgumentParser(description="Setup new project folder")
parser.add_argument("--f", dest="folder", type=str, help="name of folder to be added")
parser.add_argument("--open", dest='openyn', default=False, help="To open VScode/Pycharm when done via 'code/pycharm .'")
parser.add_argument("--url", dest="URL", type=str, help="Use --url URL to provide github url to link to")
args=parser.parse_args()
folder = args.folder
URL = args.URL
openyn = args.openyn
sys_name = platform.system()
dir_path = dirname(realpath(__file__))
full_path = join(dir_path, folder)
clear()
print(f"Trying to create >{folder}< in {dir_path}")
create_folder(full_path)
use_folder(full_path, folder, openyn, URL, sys_name)