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-2012 PhiloSoft Design"
12 __license__ = "GNU GPL"
15 import sys, os, shelve
19 sys.stderr.write("Usage: %s [-o|--old]\n" % sys.argv[0])
24 from getopt import getopt, GetoptError
27 options, arguments = getopt(sys.argv[1:], "he:o",
28 ["help", "output-encoding=", "old"])
33 output_encoding = None
35 for option, value in options:
36 if option in ("-h", "--help"):
38 elif option in ("-e", "--output-encoding"):
39 output_encoding = value
40 elif option in ("-o", "--old"):
48 if output_encoding is None:
49 from m_lib.defenc import default_encoding
50 output_encoding = default_encoding
51 return old, output_encoding
53 old, output_encoding = get_args()
56 xsetbg_dir = os.path.join(os.environ["HOME"], "lib", "xsetbg")
59 global_db_name = "xsetbg.db"
60 filename_key = "filename"
61 old_filename_key = "old_filename"
64 global_db = shelve.open(global_db_name, flag='r')
66 key = old_filename_key
69 filename = global_db[key]
72 from ConfigParser import SafeConfigParser
73 config = SafeConfigParser()
74 config.read("xsetbg.conf")
76 fs_encoding = config.get("images", "fs_encoding")
77 filename = unicode(filename, fs_encoding)
79 print filename.encode(output_encoding)