2 """Print background filename
4 Print the filename of the current or previous background image.
6 This file is a part of XSetBg.
11 from xsetbg_db import xsetbg_db
14 sys.exit("Error: no database found")
18 sys.stderr.write("Usage: %s [index]\n" % sys.argv[0])
23 from getopt import getopt, GetoptError
26 options, arguments = getopt(sys.argv[1:], "he:",
27 ["help", "output-encoding="])
32 output_encoding = None
34 for option, value in options:
35 if option in ("-h", "--help"):
37 elif option in ("-e", "--output-encoding"):
38 output_encoding = value
43 if len(arguments) == 1:
45 index = int(arguments[0])
51 if output_encoding is None:
52 from m_lib.defenc import default_encoding
53 output_encoding = default_encoding
54 return index, output_encoding
56 index, output_encoding = get_args()
58 filename = xsetbg_db.select('last_shown IS NOT NULL',
59 orderBy='-last_shown')[index].full_name
61 print filename.encode(output_encoding)