From 76c9a423c497a1b7c2831087e02e6d8dbda5cb58 Mon Sep 17 00:00:00 2001 From: Oleg Broytman Date: Tue, 7 Jan 2014 14:33:08 +0400 Subject: [PATCH] Configure path to the database --- dump_db.py | 14 ++++---------- find_oldest.py | 18 ++++++------------ print_all.py | 14 ++++---------- reload_db.py | 15 ++++++--------- xsetbg.conf.pat | 2 ++ xsetbg.py | 10 +++++----- xsetbg_db.py | 7 +++---- 7 files changed, 30 insertions(+), 50 deletions(-) diff --git a/dump_db.py b/dump_db.py index 9c4954d..8c80932 100755 --- a/dump_db.py +++ b/dump_db.py @@ -6,19 +6,13 @@ This file is a part of XSetBg. """ __author__ = "Oleg Broytman " -__copyright__ = "Copyright (C) 2006-2012 PhiloSoft Design" +__copyright__ = "Copyright (C) 2006-2014 PhiloSoft Design" __license__ = "GNU GPL" -import os, shelve from operator import itemgetter +from xsetbg_db import xsetbg_db -xsetbg_dir = os.path.join(os.environ["HOME"], "lib", "xsetbg") -os.chdir(xsetbg_dir) - -global_db_name = "xsetbg.db" - -global_db = shelve.open(global_db_name, flag='r') -for key, value in sorted(global_db.items(), key=itemgetter(1), reverse=1): +for key, value in sorted(xsetbg_db.items(), key=itemgetter(1), reverse=1): if key.startswith('/'): print value, key -global_db.close() +xsetbg_db.close() diff --git a/find_oldest.py b/find_oldest.py index 444abe7..f98b4e6 100755 --- a/find_oldest.py +++ b/find_oldest.py @@ -6,26 +6,20 @@ This file is a part of XSetBg. """ __author__ = "Oleg Broytman " -__copyright__ = "Copyright (C) 2006-2012 PhiloSoft Design" +__copyright__ = "Copyright (C) 2006-2014 PhiloSoft Design" __license__ = "GNU GPL" -import os, shelve from time import localtime, asctime - -xsetbg_dir = os.path.join(os.environ["HOME"], "lib", "xsetbg") -os.chdir(xsetbg_dir) - -global_db_name = "xsetbg.db" +from xsetbg_db import xsetbg_db count = 0 oldest = None -global_db = shelve.open(global_db_name, flag='r') -for key in global_db.keys(): +for key in xsetbg_db.keys(): count += 1 - if key.startswith('/') and ((oldest is None) or (global_db[key] < oldest)): - oldest = global_db[key] -global_db.close() + if key.startswith('/') and ((oldest is None) or (xsetbg_db[key] < oldest)): + oldest = xsetbg_db[key] +xsetbg_db.close() print count, "files" print "Oldest:", asctime(localtime(oldest)) diff --git a/print_all.py b/print_all.py index 64bc3f4..e67c642 100755 --- a/print_all.py +++ b/print_all.py @@ -6,19 +6,13 @@ This file is a part of XSetBg. """ __author__ = "Oleg Broytman " -__copyright__ = "Copyright (C) 2006-2012 PhiloSoft Design" +__copyright__ = "Copyright (C) 2006-2014 PhiloSoft Design" __license__ = "GNU GPL" -import os, shelve from operator import itemgetter +from xsetbg_db import xsetbg_db -xsetbg_dir = os.path.join(os.environ["HOME"], "lib", "xsetbg") -os.chdir(xsetbg_dir) - -global_db_name = "xsetbg.db" - -global_db = shelve.open(global_db_name, flag='r') -for key, value in sorted(global_db.items(), key=itemgetter(1), reverse=1): +for key, value in sorted(xsetbg_db.items(), key=itemgetter(1), reverse=1): if key.startswith('/'): print key -global_db.close() +xsetbg_db.close() diff --git a/reload_db.py b/reload_db.py index af03710..1bee46e 100755 --- a/reload_db.py +++ b/reload_db.py @@ -6,20 +6,17 @@ This file is a part of XSetBg. """ __author__ = "Oleg Broytman " -__copyright__ = "Copyright (C) 2007-2012 PhiloSoft Design" +__copyright__ = "Copyright (C) 2007-2014 PhiloSoft Design" __license__ = "GNU GPL" -import sys, os, shelve +import sys, shelve +from xsetbg_db import xsetbg_db_path -xsetbg_dir = os.path.join(os.environ["HOME"], "lib", "xsetbg") -os.chdir(xsetbg_dir) - -global_db_name = "xsetbg.db" dump_file = open(sys.argv[1], 'rU') -global_db = shelve.open(global_db_name, flag='n') +xsetbg_db = shelve.open(xsetbg_db_path, flag='n') for line in dump_file: timestamp, filename = line.strip().split(None, 1) - global_db[filename] = float(timestamp) -global_db.close() + xsetbg_db[filename] = float(timestamp) +xsetbg_db.close() dump_file.close() diff --git a/xsetbg.conf.pat b/xsetbg.conf.pat index 3dd1bf5..d515443 100644 --- a/xsetbg.conf.pat +++ b/xsetbg.conf.pat @@ -7,6 +7,8 @@ host = localhost port = 7999 [xsetbg] +database = ~/lib/xsetbg/xsetbg.db + ; minimum time in seconds between background image changes min_pause = 300 ; (5 minutes) diff --git a/xsetbg.py b/xsetbg.py index f4426ee..ac55e25 100755 --- a/xsetbg.py +++ b/xsetbg.py @@ -26,7 +26,7 @@ import sys from time import time from xsetbg_conf import xsetbg_dir, xsetbg_conf -from xsetbg_db import xsetbg_db_name, xsetbg_db +from xsetbg_db import xsetbg_db def error(error_str, error_code=1): @@ -116,11 +116,11 @@ os.umask(0066) # octal; -rw-------; make the global persistent dictionary # readable only by the user try: - xsetbg_db = shelve.open(os.path.join(xsetbg_dir, xsetbg_db_name), flag='c') + xsetbg_db = shelve.open(xsetbg_db_path, flag='c') except anydbm.error, msg: if str(msg) == "db type could not be determined": - os.remove(xsetbg_db_name) - xsetbg_db = shelve.open(os.path.join(xsetbg_dir, xsetbg_db_name), flag='c') + os.remove(xsetbg_db_path) + xsetbg_db = shelve.open(xsetbg_db_path, flag='c') # Remove old filenames old_time = time() - min_delay @@ -164,7 +164,7 @@ def change(force=False): xsetbg_db = None try: # Reopen the global persistent dictionary - xsetbg_db = shelve.open(os.path.join(xsetbg_dir, xsetbg_db_name), 'w') + xsetbg_db = shelve.open(xsetbg_db_path, 'w') timestamp = xsetbg_db.get(timestamp_key) current_time = time() diff --git a/xsetbg_db.py b/xsetbg_db.py index 4853afb..d98e1b5 100755 --- a/xsetbg_db.py +++ b/xsetbg_db.py @@ -10,13 +10,12 @@ __license__ = "GNU GPL" __all__ = ['xsetbg_db'] import anydbm -import os import shelve -from xsetbg_conf import xsetbg_dir, xsetbg_conf +from xsetbg_conf import xsetbg_conf -xsetbg_db_name = "xsetbg.db" +xsetbg_db_path = xsetbg_conf.get('xsetbg', 'database') try: - xsetbg_db = shelve.open(os.path.join(xsetbg_dir, xsetbg_db_name), 'r') + xsetbg_db = shelve.open(xsetbg_db_path, 'r') except anydbm.error: xsetbg_db = None -- 2.39.2