move load_locale() and file_entry() to be accessible by all modules

* load_locale -> common.load_localized_config() since common handles config
* file_entry -> metadata.file_entry() since metadata handles data format
This commit is contained in:
Hans-Christoph Steiner 2023-04-24 17:34:47 +02:00
parent f9864dc3a2
commit 49362b5fd1
3 changed files with 54 additions and 46 deletions

View file

@ -487,6 +487,42 @@ def read_config(opts=None):
return config
def file_entry(filename, hash_value=None):
meta = {}
meta["name"] = "/" + filename.split("/", 1)[1]
meta["sha256"] = hash_value or common.sha256sum(filename)
meta["size"] = os.stat(filename).st_size
return meta
def load_localized_config(name, repodir):
lst = {}
for f in Path().glob("config/**/{name}.yml".format(name=name)):
locale = f.parts[1]
if len(f.parts) == 2:
locale = "en-US"
with open(f, encoding="utf-8") as fp:
elem = yaml.safe_load(fp)
for akey, avalue in elem.items():
if akey not in lst:
lst[akey] = {}
for key, value in avalue.items():
if key not in lst[akey]:
lst[akey][key] = {}
if key == "icon":
shutil.copy(
os.path.join("config", value),
os.path.join(repodir, "icons")
)
lst[akey][key][locale] = file_entry(
os.path.join(repodir, "icons", value)
)
else:
lst[akey][key][locale] = value
return lst
def parse_human_readable_size(size):
units = {
'b': 1,