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] [-n|--no-newline] [-o|--old] [-s|--spaces] [-w|--width] [width]\n" % sys.argv[0])
28 from getopt import getopt, GetoptError
31 options, arguments = getopt(sys.argv[1:], "0nosw:",
32 ["null", "no-newline", "old", "spaces", "width="])
42 for option, value in options:
43 if option in ("-h", "--help"):
45 elif option in ("-0", "--null"):
47 elif option in ("-n", "--no-newline"):
49 elif option in ("-o", "--old"):
51 elif option in ("-s", "--spaces"):
53 elif option in ("-w", "--width"):
61 elif len(arguments) > 1:
64 width = int(arguments[0])
66 return print0, newline, old, spaces, width
68 print0, newline, old, spaces, width = get_args()
71 xsetbg_dir = os.path.join(os.environ["HOME"], "lib", "xsetbg")
74 global_db_name = "xsetbg.db"
75 filename_key = "filename"
76 old_filename_key = "old_filename"
79 global_db = shelve.open(global_db_name, flag='r')
81 key = old_filename_key
84 filename = global_db[key]
87 from m_lib.defenc import default_encoding
88 filename = unicode(filename, default_encoding)
93 lines.append("%s%s%s" % (spaces, filename[:width], spaces))
94 filename = filename[width:]
95 filename = u'\n'.join(lines)
97 filename = u"%s%s%s" % (spaces, filename, spaces)
99 sys.stdout.write(filename.encode(default_encoding))
102 sys.stdout.write('\0')