Fix regex generation
This commit is contained in:
parent
62d593136a
commit
6d5284a887
399 changed files with 679 additions and 879 deletions
|
|
@ -40,7 +40,7 @@ def collect_custom_format(service, file_name, input_json, output_dir):
|
|||
if implementation in ['ReleaseTitleSpecification', 'ReleaseGroupSpecification']:
|
||||
condition['pattern'] = spec.get('name', '')
|
||||
elif implementation in ['ResolutionSpecification']:
|
||||
condition['resolution'] = spec.get('fields', {}).get('value')
|
||||
condition['resolution'] = f"{spec.get('fields', {}).get('value')}p"
|
||||
elif implementation in ['SourceSpecification']:
|
||||
condition['source'] = spec.get('fields', {}).get('value')
|
||||
elif implementation in ['LanguageSpecification']:
|
||||
|
|
@ -64,7 +64,10 @@ def collect_custom_format(service, file_name, input_json, output_dir):
|
|||
'trash_scores': input_json.get('trash_scores', {}),
|
||||
'description': f"""[Custom format from TRaSH-Guides.](https://trash-guides.info/{service.capitalize()}/{service.capitalize()}-collection-of-custom-formats/#{file_name})
|
||||
|
||||
{markdownify(input_json.get('description', ''))}""",
|
||||
{markdownify(input_json.get('description', ''))}""".strip(),
|
||||
'metadata': {
|
||||
'includeInRename': input_json.get('includeCustomFormatWhenRenaming', False),
|
||||
},
|
||||
'tags': IMPLEMENTATION_TO_TAG_MAPPING[implementation],
|
||||
'conditions': conditions,
|
||||
'tests': []
|
||||
|
|
|
|||
|
|
@ -90,7 +90,7 @@ def collect_profile(service, input_json, output_dir):
|
|||
'name': name,
|
||||
'description': f"""[Profile from TRaSH-Guides.](https://trash-guides.info/{service.capitalize()}/{service}-setup-quality-profiles)
|
||||
|
||||
{markdownify(input_json.get('trash_description', ''))}""",
|
||||
{markdownify(input_json.get('trash_description', ''))}""".strip(),
|
||||
'trash_id': trash_id,
|
||||
'tags': [],
|
||||
'upgradesAllowed': input_json.get('upgradeAllowed', True),
|
||||
|
|
|
|||
|
|
@ -2,42 +2,47 @@ import os
|
|||
import json
|
||||
import yaml
|
||||
|
||||
|
||||
def collect_regex_pattern(service, file_name, input_json, output_dir):
|
||||
# Find the first pattern in specifications
|
||||
pattern = None
|
||||
|
||||
for spec in input_json.get('specifications', []):
|
||||
implementation = spec.get('implementation')
|
||||
if implementation not in ['ReleaseTitleSpecification', 'ReleaseGroupSpecification']:
|
||||
continue
|
||||
for spec in input_json.get("specifications", []):
|
||||
implementation = spec.get("implementation")
|
||||
if implementation not in [
|
||||
"ReleaseTitleSpecification",
|
||||
"ReleaseGroupSpecification",
|
||||
]:
|
||||
continue
|
||||
|
||||
pattern = spec.get('fields', {}).get('value')
|
||||
if not pattern:
|
||||
continue
|
||||
# Compose YAML structure
|
||||
name = input_json.get('name', '')
|
||||
yml_data = {
|
||||
'name': name,
|
||||
'pattern': pattern,
|
||||
'description': "",
|
||||
'tags': [],
|
||||
}
|
||||
pattern = spec.get("fields", {}).get("value")
|
||||
if not pattern:
|
||||
print(f"No pattern found in {file_name} for {implementation}")
|
||||
continue
|
||||
# Compose YAML structure
|
||||
name = input_json.get("name", "")
|
||||
yml_data = {
|
||||
"name": name,
|
||||
"pattern": pattern,
|
||||
"description": "",
|
||||
"tags": [],
|
||||
}
|
||||
|
||||
# Output path
|
||||
output_path = os.path.join(output_dir, f"{file_name}.yml")
|
||||
with open(output_path, 'w', encoding='utf-8') as f:
|
||||
yaml.dump(yml_data, f, sort_keys=False, allow_unicode=True)
|
||||
print(f"Generated: {output_path}")
|
||||
# Output path
|
||||
output_path = os.path.join(output_dir, f"{name.replace('/', '-')}.yml")
|
||||
with open(output_path, "w", encoding="utf-8") as f:
|
||||
yaml.dump(yml_data, f, sort_keys=False, allow_unicode=True)
|
||||
print(f"Generated: {output_path}")
|
||||
|
||||
|
||||
def collect_regex_patterns(service, input_dir, output_dir):
|
||||
for root, _, files in os.walk(input_dir):
|
||||
for filename in files:
|
||||
if not filename.endswith('.json'):
|
||||
if not filename.endswith(".json"):
|
||||
continue
|
||||
|
||||
file_path = os.path.join(root, filename)
|
||||
file_stem = os.path.splitext(filename)[0] # Filename without extension
|
||||
with open(file_path, 'r', encoding='utf-8') as f:
|
||||
with open(file_path, "r", encoding="utf-8") as f:
|
||||
data = json.load(f)
|
||||
collect_regex_pattern(service, file_stem, data, output_dir)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue