feat(tierCreator): Add show_preview option for dry run mode to display regex patterns and custom formats
This commit is contained in:
parent
166dbb8803
commit
fddc46075f
|
|
@ -18,7 +18,11 @@ def load_template(template_path):
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
|
|
||||||
def create_regex_pattern(group_name, template_dir, output_dir, dry_run=False):
|
def create_regex_pattern(group_name,
|
||||||
|
template_dir,
|
||||||
|
output_dir,
|
||||||
|
dry_run=False,
|
||||||
|
show_preview=False):
|
||||||
"""Create a regex pattern file for a release group if it doesn't exist."""
|
"""Create a regex pattern file for a release group if it doesn't exist."""
|
||||||
output_path = output_dir / f"{group_name}.yml"
|
output_path = output_dir / f"{group_name}.yml"
|
||||||
|
|
||||||
|
|
@ -36,6 +40,17 @@ def create_regex_pattern(group_name, template_dir, output_dir, dry_run=False):
|
||||||
template['name'] = group_name
|
template['name'] = group_name
|
||||||
template['pattern'] = f"(?<=^|[\\s.-]){group_name}\\b"
|
template['pattern'] = f"(?<=^|[\\s.-]){group_name}\\b"
|
||||||
|
|
||||||
|
# Show preview in dry run mode if this is the first pattern
|
||||||
|
if dry_run and show_preview:
|
||||||
|
print("\nPreview of first regex pattern:")
|
||||||
|
print("---")
|
||||||
|
print(
|
||||||
|
yaml.dump(template,
|
||||||
|
sort_keys=False,
|
||||||
|
default_flow_style=False,
|
||||||
|
indent=2))
|
||||||
|
print("---\n")
|
||||||
|
|
||||||
# Create output directory if it doesn't exist
|
# Create output directory if it doesn't exist
|
||||||
output_dir.mkdir(parents=True, exist_ok=True)
|
output_dir.mkdir(parents=True, exist_ok=True)
|
||||||
|
|
||||||
|
|
@ -51,7 +66,8 @@ def create_tier_format(tier,
|
||||||
groups,
|
groups,
|
||||||
template_dir,
|
template_dir,
|
||||||
output_dir,
|
output_dir,
|
||||||
dry_run=False):
|
dry_run=False,
|
||||||
|
show_preview=False):
|
||||||
"""Create a custom format file for a specific tier."""
|
"""Create a custom format file for a specific tier."""
|
||||||
# Get groups for this tier
|
# Get groups for this tier
|
||||||
tier_groups = [group["name"] for group in groups if group["tier"] == tier]
|
tier_groups = [group["name"] for group in groups if group["tier"] == tier]
|
||||||
|
|
@ -96,6 +112,17 @@ def create_tier_format(tier,
|
||||||
f"{'Would ' + existing.lower() if dry_run else existing} custom format: {output_path} (includes {len(tier_groups)} groups)"
|
f"{'Would ' + existing.lower() if dry_run else existing} custom format: {output_path} (includes {len(tier_groups)} groups)"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# Show preview in dry run mode if this is the first format
|
||||||
|
if dry_run and show_preview:
|
||||||
|
print("\nPreview of first custom format:")
|
||||||
|
print("---")
|
||||||
|
print(
|
||||||
|
yaml.dump(template,
|
||||||
|
sort_keys=False,
|
||||||
|
default_flow_style=False,
|
||||||
|
indent=2))
|
||||||
|
print("---\n")
|
||||||
|
|
||||||
if not dry_run:
|
if not dry_run:
|
||||||
with open(output_path, 'w') as f:
|
with open(output_path, 'w') as f:
|
||||||
yaml.dump(template,
|
yaml.dump(template,
|
||||||
|
|
@ -153,18 +180,26 @@ def main():
|
||||||
|
|
||||||
# Create regex patterns for all groups
|
# Create regex patterns for all groups
|
||||||
print("\nProcessing regex patterns:")
|
print("\nProcessing regex patterns:")
|
||||||
for group in data["tiered_groups"]:
|
for i, group in enumerate(data["tiered_groups"]):
|
||||||
create_regex_pattern(group["name"], template_dir, regex_dir,
|
create_regex_pattern(group["name"],
|
||||||
args.dry_run)
|
template_dir,
|
||||||
|
regex_dir,
|
||||||
|
args.dry_run,
|
||||||
|
show_preview=(i == 0))
|
||||||
|
|
||||||
# Create tier formats
|
# Create tier formats
|
||||||
print("\nProcessing custom formats:")
|
print("\nProcessing custom formats:")
|
||||||
unique_tiers = sorted(set(group["tier"]
|
unique_tiers = sorted(set(group["tier"]
|
||||||
for group in data["tiered_groups"]))
|
for group in data["tiered_groups"]))
|
||||||
for tier in unique_tiers:
|
for i, tier in enumerate(unique_tiers):
|
||||||
create_tier_format(tier, args.resolution, args.type,
|
create_tier_format(tier,
|
||||||
data["tiered_groups"], template_dir, format_dir,
|
args.resolution,
|
||||||
args.dry_run)
|
args.type,
|
||||||
|
data["tiered_groups"],
|
||||||
|
template_dir,
|
||||||
|
format_dir,
|
||||||
|
args.dry_run,
|
||||||
|
show_preview=(i == 0))
|
||||||
|
|
||||||
print(
|
print(
|
||||||
f"\nSuccessfully {'simulated' if args.dry_run else 'created'} custom formats for {args.resolution} {args.type}"
|
f"\nSuccessfully {'simulated' if args.dry_run else 'created'} custom formats for {args.resolution} {args.type}"
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue