Skip to content

Commit

Permalink
Feat/add subdir system (#7)
Browse files Browse the repository at this point in the history
* feat: add pretty cli and messages

* feat: add main process for cli commands

* feat: add subdir process
  • Loading branch information
andreasbaumgartner committed Apr 27, 2024
1 parent d7cb883 commit 60f72c9
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 8 deletions.
56 changes: 49 additions & 7 deletions src/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,15 @@ def main():
question = BaseQuestion()
s_template = question.multiple_choice_questions(
choices=templates,
message="Which Plugin you want do use?",
message="Which Template you wana use?",
)
# print the selected template
msg.warning_msg(f"Selected Template: {s_template}")
msg.warning_msg(f"Selected Template: {s_template['choice'][0]}")

# selected plugin
template.read_template("base.json")
# TODO: Dynamic
template.read_template(s_template["choice"][0])


# convert the plugin into actions
result = template.convert_template()
Expand All @@ -42,9 +44,15 @@ def main():
msg.success_msg(f"Base: {template.base_files}")

# process the service for the base files
struct = BaseStructureGenerator()

struct = BaseStructureGenerator(project_name)
struct.create_dir()
struct.return_project_dir()
project_path = struct.return_project_dir()

file = FileService(project_path)
file.create_file(template.base_files)
file.create_file_with_subdir(template.subdir)


# basic generation
# ------------ #
Expand Down Expand Up @@ -333,6 +341,32 @@ def create_setup_nox(self):
return sys.exit(1)


class FileService(Messages):
"""Class to create file as a service"""

def __init__(self, project_path: str):
self.services = []
self.project_path = project_path
self.req_dir = "requirements"

def create_file(self, files):
"""create file based on the files provided"""
for file in files:
open(os.path.join(self.project_path, file), "w").close() # noqa: E501
self.services.append(file)

def create_file_with_subdir(self, files):
"""create file with subdir necessary"""

for file in files:
if "requirements" in file:
os.makedirs(os.path.join(self.project_path, self.req_dir)) # noqa: E501
open(os.path.join(self.project_path, self.req_dir, file), "w").close()
self.services.append(file)
else:
Messages.error_msg("File for Subdir not supported")


class Template:
"""Base class for templates."""

Expand All @@ -341,6 +375,7 @@ def __init__(self):
self.templates = []
self.template = None
self.base_files = []
self.subdir = []
self.services = []
self.python_version = None
self.config = None
Expand All @@ -360,13 +395,20 @@ def convert_template(self) -> str:
"""Convert a selected .json template"""
if self.template is not None:
data = json.loads(self.template)

self.base_files = data["base"]
self.subdir = data["subdir_files"]
self.services = data["services"]
self.python_version = data["python"]
self.config = data["config"]

return (self.base_files, self.services, self.python_version, self.config)
return (
self.base_files,
self.subdir,
self.services,
self.python_version,
self.config,
)



if __name__ == "__main__":
Expand Down
2 changes: 1 addition & 1 deletion src/templates/base.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"base": [
"README.md",
"README.md",
"LICENSE"
],

Expand Down
6 changes: 6 additions & 0 deletions src/templates/test.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@
"README.md"
],


"subdir_files": [
"requirements.txt"
],


"services": [
"pip"
],
Expand Down

0 comments on commit 60f72c9

Please sign in to comment.