Skip to content

Commit 513c92c

Browse files
authored
use javaproperties library to parse (#77)
1 parent 188f6e8 commit 513c92c

File tree

2 files changed

+4
-28
lines changed

2 files changed

+4
-28
lines changed

requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@ ruamel.yaml
22
tenacity~=9.0.0
33
requests~=2.32.3
44
pydantic~=2.9.2
5+
javaproperties~=0.8.2

scripts/parse_and_validate_properties_txt.py

Lines changed: 3 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import os
1515
from typing import Optional, Union
1616
from pydantic import BaseModel, Field, ConfigDict, field_validator
17+
import javaproperties as jp
1718

1819

1920
class PropertiesBase(BaseModel):
@@ -71,32 +72,6 @@ def read_properties_txt(properties_url):
7172

7273
return r.text
7374

74-
def parse_text(properties_raw):
75-
field_pattern = re.compile(r"^([a-zA-z]+)\s*=(.*)")
76-
77-
properties_dict = {}
78-
field_name = ""
79-
field_value = ""
80-
properties_lines = properties_raw.split('\n')
81-
for line in properties_lines:
82-
if line.startswith('#') or not line.strip():
83-
continue
84-
if line_match := field_pattern.match(line):
85-
# store previous key-value pair
86-
if field_name:
87-
properties_dict[field_name] = field_value
88-
# process current line
89-
field_name = line_match[1].strip()
90-
field_value = line_match[2].strip()
91-
field_value = field_value.split('#')[0].strip()
92-
else:
93-
field_value += " " + line.strip()
94-
# store last key-pair
95-
if field_name:
96-
properties_dict[field_name] = field_value
97-
98-
return properties_dict
99-
10075
def validate_existing(properties_dict):
10176
# validation on existing contribution is weaker
10277
properties = PropertiesExisting.model_validate(properties_dict)
@@ -151,9 +126,9 @@ def set_output_error(msg):
151126

152127
try:
153128
if type_ == 'library':
154-
props = validate_new_library(parse_text(properties_raw))
129+
props = validate_new_library(jp.loads(properties_raw))
155130
else:
156-
props = validate_new(parse_text(properties_raw))
131+
props = validate_new(jp.loads(properties_raw))
157132
except Exception as e:
158133
set_output_error(f'Errors when parsing file. Please check all required fields, and file format.\n\n{e}')
159134
raise e

0 commit comments

Comments
 (0)