49 lines
1.3 KiB
Python
49 lines
1.3 KiB
Python
#!/usr/bin/env python3
|
|
"""
|
|
Run this from the kodi-repo directory after dropping a new addon zip in place.
|
|
Example: python3 update_repo.py
|
|
"""
|
|
import glob
|
|
import hashlib
|
|
import os
|
|
|
|
REPO_DIR = os.path.dirname(os.path.abspath(__file__))
|
|
|
|
|
|
def read_addon_xml(path):
|
|
with open(path, encoding='utf-8') as f:
|
|
content = f.read()
|
|
lines = [l for l in content.splitlines() if not l.strip().startswith('<?xml')]
|
|
return '\n'.join(lines).strip()
|
|
|
|
|
|
def build_addons_xml():
|
|
parts = []
|
|
for entry in sorted(os.listdir(REPO_DIR)):
|
|
xml_path = os.path.join(REPO_DIR, entry, 'addon.xml')
|
|
if os.path.isfile(xml_path):
|
|
parts.append(read_addon_xml(xml_path))
|
|
addons_xml = '<?xml version="1.0" encoding="UTF-8"?>\n<addons>\n'
|
|
addons_xml += '\n'.join(parts) + '\n'
|
|
addons_xml += '</addons>\n'
|
|
return addons_xml
|
|
|
|
|
|
def main():
|
|
addons_xml = build_addons_xml()
|
|
with open(os.path.join(REPO_DIR, 'addons.xml'), 'w', encoding='utf-8') as f:
|
|
f.write(addons_xml)
|
|
|
|
md5 = hashlib.md5(addons_xml.encode('utf-8')).hexdigest()
|
|
with open(os.path.join(REPO_DIR, 'addons.xml.md5'), 'w') as f:
|
|
f.write(md5)
|
|
|
|
print('addons.xml updated')
|
|
print(f'addons.xml.md5: {md5}')
|
|
print('\nNext steps:')
|
|
print(' git add -A && git commit -m "Update repo" && git push')
|
|
|
|
|
|
if __name__ == '__main__':
|
|
main()
|