"""Restrict the agent's XFCE desktop to Friction and the captioned tutorial."""
from pathlib import Path
import xml.etree.ElementTree as ET
ALLOWED = {"friction.desktop", "tutorial.desktop"}
root = Path("/etc/xdg/xfce4/xfconf/xfce-perchannel-xml")
keyboard = root / "xfce4-keyboard-shortcuts.xml"
tree = ET.parse(keyboard)
tree.getroot().set("locked", "root")
commands = tree.getroot().find("property[@name='commands']")
if commands is not None:
for child in list(commands):
commands.remove(child)
ET.SubElement(commands, "property", name="default", type="empty")
tree.write(keyboard, encoding="UTF-8", xml_declaration=True)
panel = '''
'''
(Path("/etc/xdg/xfce4/panel/default.xml")).write_text(panel)
(root / "xfce4-panel.xml").write_text(panel)
(root / "xfce4-desktop.xml").write_text('''
''')
user = Path("/root/.config/xfce4/xfconf/xfce-perchannel-xml")
user.mkdir(parents=True, exist_ok=True)
for name in ("xfce4-keyboard-shortcuts.xml", "xfce4-panel.xml", "xfce4-desktop.xml"):
(user / name).write_bytes((root / name).read_bytes())
for folder in ("/usr/share/applications", "/usr/local/share/applications", "/root/Desktop"):
for file in Path(folder).glob("*.desktop"):
if file.name not in ALLOWED:
file.unlink()
for folder in ("/opt/autostart", "/root/.config/autostart"):
for file in Path(folder).glob("*.desktop"):
if "friction" not in file.name:
file.unlink()