Skip to content
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
12 changes: 9 additions & 3 deletions struct_module/commands/generate.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def _load_yaml_config(self, structure_definition, structures_path):
if not os.path.exists(file_path):
file_path = os.path.join(contribs_path, f"{structure_definition}.yaml")
if not os.path.exists(file_path):
self.logger.error(f"File not found: {file_path}")
self.logger.error(f"File not found: {file_path}")
return None
with open(file_path, 'r') as f:
return yaml.safe_load(f)
Expand Down Expand Up @@ -138,7 +138,7 @@ def _create_structure(self, args):
file_path_to_create = os.path.join(args.base_path, name)
existing_content = None
if os.path.exists(file_path_to_create):
self.logger.info(f"File already exists: {file_path_to_create}")
self.logger.warning(f"⚠️ File already exists: {file_path_to_create}")
with open(file_path_to_create, 'r') as existing_file:
existing_content = existing_file.read()

Expand Down Expand Up @@ -169,7 +169,13 @@ def _create_structure(self, args):
if 'struct' in content:
self.logger.info(f"Generating structure")
self.logger.info(f" Folder: {folder}")
self.logger.info(f" Struct: {content['struct']}")
self.logger.info(f" Struct:")
if isinstance(content['struct'], list):
# iterate over the list of structures
for struct in content['struct']:
self.logger.info(f" - {struct}")
if isinstance(content['struct'], str):
self.logger.info(f" - {content['struct']}")

# get vars from with param. this will be a dict of key value pairs
merged_vars = ""
Expand Down
2 changes: 1 addition & 1 deletion struct_module/commands/info.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def _get_info(self, args):
file_path = os.path.join(args.structures_path, f"{args.structure_definition}.yaml")
# show error if file is not found
if not os.path.exists(file_path):
self.logger.error(f"File not found: {file_path}")
self.logger.error(f"File not found: {file_path}")
return
with open(file_path, 'r') as f:
config = yaml.safe_load(f)
Expand Down
22 changes: 10 additions & 12 deletions struct_module/file_item.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ def fetch_content(self):
self.content = self.content_fetcher.fetch_content(self.content_location)
self.logger.debug(f"Fetched content: {self.content}")
except Exception as e:
self.logger.error(f"Failed to fetch content from {self.content_location}: {e}")
self.logger.error(f"Failed to fetch content from {self.content_location}: {e}")

def _merge_default_template_vars(self, template_vars):
default_vars = {
Expand All @@ -125,17 +125,15 @@ def create(self, base_path, dry_run=False, backup_path=None, file_strategy='over
file_path = os.path.join(base_path, self.name)

if self.skip:
self.logger.info(f"Skipping file creation")
self.logger.info(f" File path: {file_path}")
self.logger.info(f"skip is set to true. skipping creation.")
return

if dry_run:
self.logger.info(f"[DRY RUN] Would create file: {file_path} with content: \n\n{self.content}")
return

if self.skip_if_exists and os.path.exists(file_path):
self.logger.info(f"Skipping file creation as file exists")
self.logger.info(f" File path: {file_path}")
self.logger.info(f" skip_if_exists is set to true and file already exists. skipping creation.")
return

# Create the directory if it does not exist
Expand All @@ -152,7 +150,7 @@ def create(self, base_path, dry_run=False, backup_path=None, file_strategy='over
elif file_strategy == 'append':
with open(file_path, 'a') as f:
f.write(f"{self.content}\n")
self.logger.info(f"Appended to existing file: {file_path}")
self.logger.info(f"Appended to existing file: {file_path}")
return
elif file_strategy == 'rename':
new_name = f"{file_path}.{int(time.time())}"
Expand All @@ -161,12 +159,12 @@ def create(self, base_path, dry_run=False, backup_path=None, file_strategy='over

with open(file_path, 'w') as f:
f.write(f"{self.content}\n")
self.logger.debug(f"Created file with content")
self.logger.debug(f" File path: {file_path}")
self.logger.debug(f" Content: \n\n{self.content}")
self.logger.info(f"Created file with content")
self.logger.info(f" File path: {file_path}")
self.logger.debug(f" Content: \n\n{self.content}")

if self.permissions:
os.chmod(file_path, int(self.permissions, 8))
self.logger.info(f"Set permissions to file")
self.logger.info(f" File path: {file_path}")
self.logger.info(f" Permissions: {self.permissions}")
self.logger.info(f"🔐 Set permissions to file")
self.logger.info(f" File path: {file_path}")
self.logger.info(f" Permissions: {self.permissions}")
2 changes: 1 addition & 1 deletion struct_module/logging_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ def configure_logging(level=logging.INFO, log_file=None):
"""Configure logging with colorlog."""
handler = colorlog.StreamHandler()

line_format = "%(log_color)s[%(levelname)s] >> %(message)s"
line_format = "%(log_color)s%(message)s"
if level == logging.DEBUG:
line_format = "%(log_color)s[%(asctime)s][%(levelname)s][%(filename)s:%(lineno)d] >> %(message)s"

Expand Down
2 changes: 1 addition & 1 deletion struct_module/template_renderer.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ def prompt_for_missing_vars(self, content, vars):
if self.non_interactive:
user_input = default if default else "NEEDS_TO_BE_SET"
else:
user_input = input(f"Enter value for {var} [{default}]: ") or default
user_input = input(f"Enter value for {var} [{default}]: ") or default
self.input_store.set_value(var, user_input)
vars[var] = user_input
self.input_store.save()
Expand Down
Loading