2 """Print background filename
4 Print the filename of the current or previous background image.
6 This file is a part of XSetBg.
10 __version__ = "$Revision$"[11:-2]
11 __revision__ = "$Id$"[5:-2]
12 __date__ = "$Date$"[7:-2]
14 __author__ = "Oleg BroytMann <phd@phd.pp.ru>"
15 __copyright__ = "Copyright (C) 2004-2007 PhiloSoft Design"
16 __license__ = "GNU GPL"
19 import sys, os, shelve
23 sys.stderr.write("Usage: %s [-0|--null] [-o|--old] [-s|--spaces] [-w|--width] [width]\n" % sys.argv[0])
28 from getopt import getopt, GetoptError
31 options, arguments = getopt(sys.argv[1:], "0osw:",
32 ["null", "old", "spaces", "width="])
41 for option, value in options:
42 if option in ("-h", "--help"):
44 elif option in ("-0", "--null"):
46 elif option in ("-o", "--old"):
48 elif option in ("-s", "--spaces"):
50 elif option in ("-w", "--width"):
58 elif len(arguments) > 1:
61 width = int(arguments[0])
63 return print0, old, spaces, width
65 print0, old, spaces, width = get_args()
68 xsetbg_dir = os.path.join(os.environ["HOME"], "lib", "xsetbg")
71 global_db_name = "xsetbg.db"
72 filename_key = "filename"
73 old_filename_key = "old_filename"
76 global_db = shelve.open(global_db_name, flag='r')
78 key = old_filename_key
81 filename = global_db[key]
84 from m_lib.defenc import default_encoding
85 filename = unicode(filename, default_encoding)
90 lines.append("%s%s%s" % (spaces, filename[:width], spaces))
91 filename = filename[width:]
92 filename = u'\n'.join(lines)
94 filename = u"%s%s%s" % (spaces, filename, spaces)
96 sys.stdout.write(filename.encode(default_encoding))
99 sys.stdout.write('\0')