Skip to content

Instantly share code, notes, and snippets.

@somini
Last active August 29, 2015 14:15
Show Gist options
  • Save somini/f309d761290fe36e2dc6 to your computer and use it in GitHub Desktop.
Save somini/f309d761290fe36e2dc6 to your computer and use it in GitHub Desktop.
Python Script to update the XML for Linux Mint Background Slideshow
#!/usr/bin/env python
import os,sys,re
from lxml import etree as ET
folders = sys.argv[1:]
if len(folders) == 0:
sys.stderr.write("No folders given\n")
sys.exit()
files = []
for folder in folders:
for basepath,_,newfiles in os.walk(folder):
files.extend(os.path.abspath(os.path.join(basepath, f)) for f in newfiles)
root = ET.Element('wallpapers')
for f in files:
e_e = ET.SubElement(root,'wallpaper',{'deleted': 'false'})
ET.SubElement(e_e,'filename').text = f
ET.SubElement(e_e,'title').text = re.match(".+/(.+)/.+$",f).group(1)
ET.SubElement(e_e,'author').text = os.environ['USER']
sys.stdout.write(ET.tostring(root, encoding="UTF-8", pretty_print=False, xml_declaration=True, doctype='<!DOCTYPE wallpapers SYSTEM "cinnamon-wp-list.dtd">', with_tail=False))
python mint_update_background.py ~/Documents/Pictures/Screenshots/ | sudo tee /usr/share/cinnamon-background-properties/screenshots.xml | xmllint --format -
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment