Skip to content

Instantly share code, notes, and snippets.

@ehazlett
Created May 17, 2011 04:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ehazlett/975950 to your computer and use it in GitHub Desktop.
Save ehazlett/975950 to your computer and use it in GitHub Desktop.
Gnome wallpaper slideshow creator
#!/usr/bin/env python
import os
import sys
import logging
from datetime import date
from optparse import OptionParser
IMAGE_TYPES = [
'png',
'jpg',
'jpeg',
'gif',
]
logging.basicConfig(level=logging.DEBUG,
format='%(levelname)-6s %(message)s',
datefmt='%m-%d %H:%M')
def create_config(path=None, duration=600, transition=5.0):
if not path:
logging.error('You must specify a path')
return None
d = date.today()
cfg = '<background>\n'
cfg += '\t<starttime>\n'
cfg += '\t\t<year>{0}</year>\n'.format(d.year)
cfg += '\t\t<month>{0}</month>\n'.format(d.month)
cfg += '\t\t<day>{0}</day>\n'.format(d.day)
cfg += '\t\t<hour>00</hour>\n'
cfg += '\t\t<minute>00</minute>\n'
cfg += '\t\t<second>00</second>\n'
cfg += '\t</starttime>\n'
prev_file = None
for f in os.listdir(path):
fpath = os.path.join(path, f)
fname, ext = os.path.splitext(f)
# check image type
if ext.lower().replace('.', '') in IMAGE_TYPES:
if prev_file:
cfg += '\t<transition>\n'
cfg += '\t\t<duration>{0}</duration>\n'.format(transition)
cfg += '\t\t<from>{0}</from>\n'.format(prev_file)
cfg += '\t\t<to>{0}</to>\n'.format(fpath)
cfg += '\t</transition>\n'
cfg += '\t<static>\n'
cfg += '\t\t<duration>{0}</duration>\n'.format(duration)
cfg += '\t\t<file>{0}</file>\n'.format(fpath)
cfg += '\t</static>\n'
prev_file = fpath
cfg += '</background>\n'
return cfg
if __name__ == '__main__':
op = OptionParser()
op.add_option('-p', '--path', dest='path', help='Path to images')
op.add_option('-d', '--duration', dest='duration', default='600', help='Duration of images')
op.add_option('-t', '--transition', dest='transition', default='5', help='Duration of transition')
opts, args = op.parse_args()
if not opts.path:
op.print_help()
sys.exit(1)
cfg = create_config(opts.path, opts.duration, opts.transition)
cfg_file = os.path.join(opts.path, 'background-1.xml')
f = open(cfg_file, 'w')
f.write(cfg)
f.close()
logging.info('Configuration file created: {0}'.format(cfg_file))
logging.info('Done.')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment