From 17f007e8c6a073585462b17492f91382980ea18a Mon Sep 17 00:00:00 2001 From: Kaito Date: Sat, 19 Sep 2026 01:33:47 +0200 Subject: [PATCH 1/4] Create a simple config file; Implement a config system; Improve preset system --- config.json | 6 ++++++ lpp.py | 50 +++++++++++++++++++++++++---------------------- presets/class.py | 3 +++ presets/import.py | 3 +++ presets/print.py | 1 + 5 files changed, 40 insertions(+), 23 deletions(-) create mode 100644 config.json create mode 100644 presets/class.py create mode 100644 presets/import.py create mode 100644 presets/print.py diff --git a/config.json b/config.json new file mode 100644 index 0000000..102c6c0 --- /dev/null +++ b/config.json @@ -0,0 +1,6 @@ +{ + "defaultDirectoryName":"NewProject", + "defaultFileName":"main.py", + "defaultPreset":"", + "presetPath":"./presets" +} \ No newline at end of file diff --git a/lpp.py b/lpp.py index 6bb3bd0..b0f2090 100644 --- a/lpp.py +++ b/lpp.py @@ -1,19 +1,26 @@ -import subprocess -from pathlib import Path -import os -import sys -import argparse - if __name__ == '__main__' : + import subprocess + from pathlib import Path + import os + import sys + import argparse + import json + VERSION = 'v0.1' + configFile = open("config.json",'r') + + config = json.loads(configFile.readall()) + + configFile.close() + 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('-f','--filename',default='main.py',help="Initial file name") - parser.add_argument('--file-preset',default='',help='Choose a preset for the init file: print | class | import') + parser.add_argument('-f','--filename',default=config['defaultFileName'],help="Initial file name") + 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('--version',action='store_true',help='Print the current version') @@ -23,6 +30,14 @@ if __name__ == '__main__' : print(f"Linux Python Preparer {VERSION}") os._exit(0) + presetContent = '' + presetFile = Path().cwd().joinpath(f"{config['presetPath']}/{args.file_preset}.py") + + if not presetFile.exists() and args.file_preset == '' : + raise Exception(f"Preset {args.file_preset} does not exist!") + else : + presetContent = presetFile.read_text() + if not args.path : path = Path().cwd() else : @@ -54,20 +69,9 @@ if __name__ == '__main__' : file.touch(mode=0o750) print('File was created.') - match args.file_preset : - case 'print' : - file.write_text('print("This was made with the Linux Python preparer")') - 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.') + if presetContent : + file.write_text(presetContent) + print(f"Preset {args.file_preset} was implemented.") os.chdir(path.absolute()) if args.git : diff --git a/presets/class.py b/presets/class.py new file mode 100644 index 0000000..6e99c56 --- /dev/null +++ b/presets/class.py @@ -0,0 +1,3 @@ +class NewClass : + def __init__() : + pass \ No newline at end of file diff --git a/presets/import.py b/presets/import.py new file mode 100644 index 0000000..4330255 --- /dev/null +++ b/presets/import.py @@ -0,0 +1,3 @@ +import pathlib +import os +import subprocess \ No newline at end of file diff --git a/presets/print.py b/presets/print.py new file mode 100644 index 0000000..76be2b6 --- /dev/null +++ b/presets/print.py @@ -0,0 +1 @@ +print("This was made with the Linux Python preparer") \ No newline at end of file From ae0f204828225a0c03547c6a77de4ddb978c6d1f Mon Sep 17 00:00:00 2001 From: Kaito Date: Sat, 19 Sep 2026 22:19:55 +0200 Subject: [PATCH 2/4] Fix loading custom presets --- lpp.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lpp.py b/lpp.py index b0f2090..53244fa 100644 --- a/lpp.py +++ b/lpp.py @@ -11,7 +11,7 @@ if __name__ == '__main__' : configFile = open("config.json",'r') - config = json.loads(configFile.readall()) + config = json.loads(configFile.read()) configFile.close() From fb2479c65dee1e39ef86a97a4cdc96f788af077f Mon Sep 17 00:00:00 2001 From: Kaito Date: Sat, 19 Sep 2026 22:23:32 +0200 Subject: [PATCH 3/4] Fix crash if preset flag is not set --- config.json | 2 +- lpp.py | 9 +++++---- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/config.json b/config.json index 102c6c0..3f7a825 100644 --- a/config.json +++ b/config.json @@ -1,5 +1,5 @@ { - "defaultDirectoryName":"NewProject", + "defaultDirectoryName":"NP", "defaultFileName":"main.py", "defaultPreset":"", "presetPath":"./presets" diff --git a/lpp.py b/lpp.py index 53244fa..5fc85ac 100644 --- a/lpp.py +++ b/lpp.py @@ -33,10 +33,11 @@ if __name__ == '__main__' : presetContent = '' presetFile = Path().cwd().joinpath(f"{config['presetPath']}/{args.file_preset}.py") - if not presetFile.exists() and args.file_preset == '' : - raise Exception(f"Preset {args.file_preset} does not exist!") - else : - presetContent = presetFile.read_text() + 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 : path = Path().cwd() From fcee2408694ff22e54ad153e8effa5e64cbdf35b Mon Sep 17 00:00:00 2001 From: Kaito Date: Sat, 19 Sep 2026 22:24:12 +0200 Subject: [PATCH 4/4] Renamed the default dir correctly --- config.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config.json b/config.json index 3f7a825..102c6c0 100644 --- a/config.json +++ b/config.json @@ -1,5 +1,5 @@ { - "defaultDirectoryName":"NP", + "defaultDirectoryName":"NewProject", "defaultFileName":"main.py", "defaultPreset":"", "presetPath":"./presets"