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 [-o|--old]\n" % sys.argv[0])
28 from getopt import getopt, GetoptError
31 options, arguments = getopt(sys.argv[1:], "he:o",
32 ["help", "output-encoding=", "old"])
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
44 elif option in ("-o", "--old"):
52 if output_encoding is None:
53 from m_lib.defenc import default_encoding
54 output_encoding = default_encoding
55 return old, output_encoding
57 old, output_encoding = get_args()
65 filename = xsetbg_db.select('last_shown IS NOT NULL',
66 orderBy='-last_shown')[index].full_name
68 print filename.encode(output_encoding)