2 """Print background filename
4 Print the filename of the current or previous background image.
6 This file is a part of XSetBg.
10 __author__ = "Oleg Broytman <phd@phdru.name>"
11 __copyright__ = "Copyright (C) 2004-2015 PhiloSoft Design"
12 __license__ = "GNU GPL"
16 from xsetbg_db import xsetbg_db
19 sys.exit("Error: no database found")
23 sys.stderr.write("Usage: %s [index]\n" % sys.argv[0])
28 from getopt import getopt, GetoptError
31 options, arguments = getopt(sys.argv[1:], "he:",
32 ["help", "output-encoding="])
37 output_encoding = None
39 for option, value in options:
40 if option in ("-h", "--help"):
42 elif option in ("-e", "--output-encoding"):
43 output_encoding = value
48 if len(arguments) == 1:
50 index = int(arguments[0])
56 if output_encoding is None:
57 from m_lib.defenc import default_encoding
58 output_encoding = default_encoding
59 return index, output_encoding
61 index, output_encoding = get_args()
63 filename = xsetbg_db.select('last_shown IS NOT NULL',
64 orderBy='-last_shown')[index].full_name
66 print filename.encode(output_encoding)