46 lines
1.4 KiB
Python
Executable File
46 lines
1.4 KiB
Python
Executable File
#!/usr/bin/env python3
|
|
|
|
import glob
|
|
import os
|
|
import re
|
|
|
|
import yaml
|
|
|
|
os.chdir(os.path.dirname(__file__) + '/../')
|
|
|
|
exitvalue = 0
|
|
|
|
for f in glob.glob('metadata/*.yml'):
|
|
with open(f) as fp:
|
|
raw = fp.read()
|
|
data = yaml.safe_load(raw)
|
|
archive_policy = data.get('ArchivePolicy', 3)
|
|
if (
|
|
'Disabled' not in data
|
|
and 'Summary' in data
|
|
and archive_policy > 0
|
|
):
|
|
en_US_dir = f[:-4] + '/en-US/'
|
|
os.makedirs(en_US_dir, exist_ok=True)
|
|
with open(en_US_dir + '/summary.txt', 'w') as fp:
|
|
fp.write(data['Summary'].strip().rstrip() + '\n')
|
|
with open(f, 'w') as out:
|
|
out.write(re.sub(r'Summary:[^\n]+\n', r'', raw))
|
|
exitvalue += 1
|
|
|
|
# if you want to pull in translations from another source:
|
|
packageName = f[9:-4]
|
|
scraped_glob = os.path.join(
|
|
'/path/to/scraper/metadata/', packageName, '[a-z]*', 'short_description.txt'
|
|
)
|
|
for df in glob.glob(scraped_glob):
|
|
locale = os.path.basename(os.path.dirname(df))
|
|
with open(df) as fp:
|
|
text = fp.read()
|
|
outfile = 'metadata/' + packageName + '/' + locale + '/summary.txt'
|
|
os.makedirs(os.path.dirname(outfile), exist_ok=True)
|
|
with open(outfile, 'w') as fp:
|
|
fp.write(text.strip().rstrip() + '\n')
|
|
|
|
exit(exitvalue)
|