Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/add subdir system #7

Merged
merged 4 commits into from
Apr 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading