Tidy up some formatting

This commit is contained in:
Alexander Wainwright
2025-12-27 12:06:32 +10:00
parent 91cc408d34
commit c1b031f29e
3 changed files with 35 additions and 28 deletions

View File

@@ -71,8 +71,11 @@ class ConfigLoader:
user_config = toml.load(self.path)
self._merge(self.config, user_config)
except Exception as e:
# We might want to let the caller handle this, or just print warning
print(f"Warning: Could not parse config file at {self.path}: {e}")
# We might want to let the caller handle this, or just print
# warning
print(
f'Warning: Could not parse config file at {self.path}: {e}'
)
return self.config
@@ -80,11 +83,12 @@ class ConfigLoader:
"""
Recursively merges 'update' dict into 'base' dict.
"""
# TODO: this is fine, but i do wonder if there is a way to do this with
# a set operation rather than a for-loop. perhaps not in a way that
# maintains the checks...
for key, value in update.items():
if isinstance(value, dict) and key in base and isinstance(base[key], dict):
if (
isinstance(value, dict)
and key in base
and isinstance(base[key], dict)
):
self._merge(base[key], value)
else:
base[key] = value
@@ -103,7 +107,8 @@ class ConfigLoader:
# Ensure directory exists
os.makedirs(os.path.dirname(self.path), exist_ok=True)
# We probably only want to write if it doesn't exist, to avoid clobbering.
# We probably only want to write if it doesn't exist, to avoid
# clobbering.
if os.path.exists(self.path):
return False

View File

@@ -55,7 +55,7 @@ def parse_args():
default=None,
help=(
'Base date or date/time (e.g. 2023-04-10 or 2023-04-10 12:00:00).'
)
),
)
parser.add_argument(
@@ -69,9 +69,8 @@ def parse_args():
'--embed',
action='store_true',
help=(
'Embed EXIF data directly into the image file instead of a '
'sidecar.'
)
'Embed EXIF data directly into the image file instead of a sidecar.'
),
)
parser.add_argument(
@@ -90,7 +89,7 @@ def parse_args():
help=(
'Number of parallel workers to run exiftool; defaults to number '
'of CPUs.'
)
),
)
parser.add_argument(
@@ -112,8 +111,8 @@ def prompt_for_defaults(config):
"""
Prompts the user for default values to populate the initial config.
"""
print("Initializing configuration. Press Enter to skip any field.")
print('Initializing configuration. Press Enter to skip any field.')
# We'll iterate over the 'mappings' to find what fields are available,
# but we'll prioritize the 'core' ones for a better UX order.
core_fields = ['author', 'lab', 'make', 'model', 'lens', 'film']
@@ -124,19 +123,21 @@ def prompt_for_defaults(config):
for field in core_fields:
if field in mappings:
schema = mappings[field]
help_text = schema.get('help', field) if isinstance(schema, dict) else field
val = input(f"Default {help_text} (optional): ").strip()
help_text = (
schema.get('help', field) if isinstance(schema, dict) else field
)
val = input(f'Default {help_text} (optional): ').strip()
if val:
defaults[field] = val
# Time increment
dflt_inc = defaults.get('time_increment', 60)
val = input(f"Default Time Increment [seconds] ({dflt_inc}): ").strip()
val = input(f'Default Time Increment [seconds] ({dflt_inc}): ').strip()
if val:
try:
defaults['time_increment'] = int(val)
except ValueError:
print("Invalid number, keeping default.")
print('Invalid number, keeping default.')
def main():
@@ -151,14 +152,17 @@ def main():
# Handle Initialization
if args.init_config:
if os.path.exists(loader.path):
print(f"Config file already exists at {loader.path}. Not overwriting.")
print(
f'Config file already exists at {loader.path}. Not '
'overwriting.'
)
sys.exit(0)
# Prompt user for initial values
try:
prompt_for_defaults(config)
except KeyboardInterrupt:
print("\nAborted.")
print('\nAborted.')
sys.exit(1)
if loader.save_defaults(config):
@@ -201,7 +205,7 @@ def main():
else:
print(
f"Warning: Invalid format for --field '{item}'. "
"Expected KEY=VALUE."
'Expected KEY=VALUE.'
)
# 4. Resolve Metadata
@@ -229,4 +233,4 @@ def main():
if __name__ == '__main__':
main()
main()

View File

@@ -31,16 +31,14 @@ class ValueResolver:
resolved = self.defaults.copy()
# 2. Overlay CLI Inputs
# cli_args is expected to be a dict of {key: value} provided by the user.
# This merges both --author and --field author=...
# cli_args is expected to be a dict of {key: value} provided by the
# user. This merges both --author and --field author=...
for key, val in cli_args.items():
if val is not None:
resolved[key] = val
# 3. Identify Prompts
# We look at the 'mappings' to see which fields want to be prompted.
# TODO: also here i wonder if there is a cleaner approach with a filter
# or something
if interactive:
fields_to_prompt = []
for field_name, schema in self.mappings.items():