| 12
 3
 4
 5
 6
 7
 8
 9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 
 | #!/usr/bin/env python2
# Select random wallpaper from given directory or directories
# Written by: Maciej Delmanowski <harnir@post.pl>
# Derived from: pjbackground
# Usage: <wallpaper-program> `fvwm-crystal.wallpaper <directory> [directory] ...
import sys, os, string, random
# This function looks for image files in specified directory and it's
# subdirectories and returns the list of absolute names
def find_images(root):
	for path, dirs, files in os.walk(root):
		for filename in files:
			extension = os.path.splitext(filename)
			if string.lower(extension[1]) in ('.jpg','.jpeg','.png'):
				yield os.path.join(path, filename)
# Exit with no arguments
if len(sys.argv) == 1:
	sys.exit()
# Find images in all directories specified in the command line
images=[]
for argument in sys.argv:
	for image in find_images(argument):
		images.append(image)
# Select random wallpaper and print it
print random.choice(images)
 |