|
|
@@ -1,19 +1,26 @@
|
|
|
|
import subprocess
|
|
|
|
|
|
|
|
from pathlib import Path
|
|
|
|
|
|
|
|
import os
|
|
|
|
|
|
|
|
import sys
|
|
|
|
|
|
|
|
import argparse
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__' :
|
|
|
|
if __name__ == '__main__' :
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import subprocess
|
|
|
|
|
|
|
|
from pathlib import Path
|
|
|
|
|
|
|
|
import os
|
|
|
|
|
|
|
|
import sys
|
|
|
|
|
|
|
|
import argparse
|
|
|
|
|
|
|
|
import json
|
|
|
|
|
|
|
|
|
|
|
|
VERSION = 'v0.1'
|
|
|
|
VERSION = 'v0.1'
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
configFile = open("config.json",'r')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
config = json.loads(configFile.read())
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
configFile.close()
|
|
|
|
|
|
|
|
|
|
|
|
parser = argparse.ArgumentParser(description="A Python project preparer for Linux")
|
|
|
|
parser = argparse.ArgumentParser(description="A Python project preparer for Linux")
|
|
|
|
|
|
|
|
|
|
|
|
parser.add_argument('-n','--name',default='NewProject',help='The project name')
|
|
|
|
parser.add_argument('-n','--name',default=config['defaultDirectoryName'],help='The project name')
|
|
|
|
parser.add_argument('-p','--path',default=False,help='The path to create the project in')
|
|
|
|
parser.add_argument('-p','--path',default=False,help='The path to create the project in')
|
|
|
|
parser.add_argument('-f','--filename',default='main.py',help="Initial file name")
|
|
|
|
parser.add_argument('-f','--filename',default=config['defaultFileName'],help="Initial file name")
|
|
|
|
parser.add_argument('--file-preset',default='',help='Choose a preset for the init file: print | class | import')
|
|
|
|
parser.add_argument('--file-preset',default=config['defaultPreset'],help='Choose a preset for the init file: print | class | import')
|
|
|
|
parser.add_argument('-g','--git',action='store_true',help='If "git init" should be used')
|
|
|
|
parser.add_argument('-g','--git',action='store_true',help='If "git init" should be used')
|
|
|
|
parser.add_argument('--version',action='store_true',help='Print the current version')
|
|
|
|
parser.add_argument('--version',action='store_true',help='Print the current version')
|
|
|
|
|
|
|
|
|
|
|
@@ -23,6 +30,15 @@ if __name__ == '__main__' :
|
|
|
|
print(f"Linux Python Preparer {VERSION}")
|
|
|
|
print(f"Linux Python Preparer {VERSION}")
|
|
|
|
os._exit(0)
|
|
|
|
os._exit(0)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
presetContent = ''
|
|
|
|
|
|
|
|
presetFile = Path().cwd().joinpath(f"{config['presetPath']}/{args.file_preset}.py")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if args.file_preset != '' :
|
|
|
|
|
|
|
|
if not presetFile.exists() :
|
|
|
|
|
|
|
|
raise Exception(f"Preset {args.file_preset} does not exist!")
|
|
|
|
|
|
|
|
else :
|
|
|
|
|
|
|
|
presetContent = presetFile.read_text()
|
|
|
|
|
|
|
|
|
|
|
|
if not args.path :
|
|
|
|
if not args.path :
|
|
|
|
path = Path().cwd()
|
|
|
|
path = Path().cwd()
|
|
|
|
else :
|
|
|
|
else :
|
|
|
@@ -54,20 +70,9 @@ if __name__ == '__main__' :
|
|
|
|
file.touch(mode=0o750)
|
|
|
|
file.touch(mode=0o750)
|
|
|
|
print('File was created.')
|
|
|
|
print('File was created.')
|
|
|
|
|
|
|
|
|
|
|
|
match args.file_preset :
|
|
|
|
if presetContent :
|
|
|
|
case 'print' :
|
|
|
|
file.write_text(presetContent)
|
|
|
|
file.write_text('print("This was made with the Linux Python preparer")')
|
|
|
|
|
|
|
|
print(f"Preset {args.file_preset} was implemented.")
|
|
|
|
print(f"Preset {args.file_preset} was implemented.")
|
|
|
|
case 'class' :
|
|
|
|
|
|
|
|
file.write_text('class NewClass :\n\t\n\tdef __init__() :\n\t\tpass')
|
|
|
|
|
|
|
|
print(f"Preset {args.file_preset} was implemented.")
|
|
|
|
|
|
|
|
case 'import' :
|
|
|
|
|
|
|
|
file.write_text('import pathlib\nimport os\nimport subprocess')
|
|
|
|
|
|
|
|
print(f"Preset {args.file_preset} was implemented.")
|
|
|
|
|
|
|
|
case '' :
|
|
|
|
|
|
|
|
pass
|
|
|
|
|
|
|
|
case _:
|
|
|
|
|
|
|
|
print('Preset does not exist.')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
os.chdir(path.absolute())
|
|
|
|
os.chdir(path.absolute())
|
|
|
|
if args.git :
|
|
|
|
if args.git :
|
|
|
|