X-Git-Url: https://git.phdru.name/?p=xsetbg.git;a=blobdiff_plain;f=dump_db.py;h=ea6b0f16ea8e7254dbc2bca9dc1f9fe3cde4bb5b;hp=9c4954d31370826356bb8b72d0a37b800d659caa;hb=HEAD;hpb=9f11c26113add5270ade4da28c7a2adb84194b1b diff --git a/dump_db.py b/dump_db.py index 9c4954d..ca3c6a7 100755 --- a/dump_db.py +++ b/dump_db.py @@ -1,24 +1,20 @@ -#! /usr/bin/env python +#! /usr/bin/env python3 """Dump the DB sorted by date This file is a part of XSetBg. """ -__author__ = "Oleg Broytman " -__copyright__ = "Copyright (C) 2006-2012 PhiloSoft Design" -__license__ = "GNU GPL" +import sys +from xsetbg_conf import xsetbg_conf +from xsetbg_db import xsetbg_db -import os, shelve -from operator import itemgetter +if not xsetbg_db: + sys.exit("Error: no database found") -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): - if key.startswith('/'): - print value, key -global_db.close() +fs_encoding = xsetbg_conf.get("images", "fs_encoding") +for row in xsetbg_db.select(orderBy='-last_shown'): + sys.stdout.buffer.write( + ('%d %s %s\n' % (row.id, row.last_shown, row.full_name + )).encode(fs_encoding) + )