File: fvwm-crystal.wallpaper

package info (click to toggle)
fvwm-crystal 3.4.1%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: buster, stretch
  • size: 21,700 kB
  • ctags: 1,494
  • sloc: sh: 3,265; cs: 1,335; python: 875; makefile: 214
file content (32 lines) | stat: -rwxr-xr-x 927 bytes parent folder | download | duplicates (3)
1
2
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)