wireplumber/split-config-file.py

49 lines
1.6 KiB
Python

#!/usr/bin/python3
import hashlib
import sys
def sha256_from_data(data):
hash_sha256 = hashlib.sha256()
hash_sha256.update(data)
return hash_sha256.hexdigest()
contents = open('90-enable-all.lua', 'r', encoding='utf-8').read()
sha256sum = sha256_from_data(contents.encode('utf-8'))
expected_sha256sum = '86888e9d3fcc952c41e778ab4edae4a0eb1f9f51b62ae0772befa9f0fdef611d'
if sha256sum != expected_sha256sum:
print('The script has to be updated for new changes in 90-enable-all.lua')
print(f'File sha256sum: {sha256sum}')
print(f'expected sha256sum: {expected_sha256sum}')
sys.exit(1)
content_sections = contents.split('\n\n')
sections = ['enable-metadata',
'default-access-policy',
'load-devices',
'track-user-choices-devices',
'track-user-choices-streams',
'link-nodes-by-roles',
'suspend-idle-nodes',
'allow-loading-objects-on-demand']
if len(content_sections) != len(sections):
print('The script has to be updated for new changes in 90-enable-all.lua')
sys.exit(1)
for i, (content, sec) in enumerate(zip(content_sections, sections)):
if sec == 'load-devices':
lines = content.split('\n')
open(f'90-{i}-1-enable-alsa.lua', 'w',
encoding='utf-8').write(lines[1])
open(f'90-{i}-2-enable-v4l2.lua', 'w',
encoding='utf-8').write(lines[2])
open(f'90-{i}-3-enable-libcamera.lua', 'w',
encoding='utf-8').write(lines[3])
continue
filename = f'90-{i}-{sec}.lua'
open(filename, 'w', encoding='utf-8').write(content)