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
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ ruamel.yaml
tenacity~=9.0.0
requests~=2.32.3
pydantic~=2.9.2
javaproperties~=0.8.2
31 changes: 3 additions & 28 deletions scripts/parse_and_validate_properties_txt.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import os
from typing import Optional, Union
from pydantic import BaseModel, Field, ConfigDict, field_validator
import javaproperties as jp


class PropertiesBase(BaseModel):
Expand Down Expand Up @@ -71,32 +72,6 @@ def read_properties_txt(properties_url):

return r.text

def parse_text(properties_raw):
field_pattern = re.compile(r"^([a-zA-z]+)\s*=(.*)")

properties_dict = {}
field_name = ""
field_value = ""
properties_lines = properties_raw.split('\n')
for line in properties_lines:
if line.startswith('#') or not line.strip():
continue
if line_match := field_pattern.match(line):
# store previous key-value pair
if field_name:
properties_dict[field_name] = field_value
# process current line
field_name = line_match[1].strip()
field_value = line_match[2].strip()
field_value = field_value.split('#')[0].strip()
else:
field_value += " " + line.strip()
# store last key-pair
if field_name:
properties_dict[field_name] = field_value

return properties_dict

def validate_existing(properties_dict):
# validation on existing contribution is weaker
properties = PropertiesExisting.model_validate(properties_dict)
Expand Down Expand Up @@ -151,9 +126,9 @@ def set_output_error(msg):

try:
if type_ == 'library':
props = validate_new_library(parse_text(properties_raw))
props = validate_new_library(jp.loads(properties_raw))
else:
props = validate_new(parse_text(properties_raw))
props = validate_new(jp.loads(properties_raw))
except Exception as e:
set_output_error(f'Errors when parsing file. Please check all required fields, and file format.\n\n{e}')
raise e
Expand Down