1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
|
#!/usr/bin/env python """ Script to delete zdab files which have all been successfully fit. """ from sddm.logger import Logger log = Logger() if __name__ == '__main__': import argparse import sqlite3 import os from os.path import join, split, exists import numpy as np parser = argparse.ArgumentParser("delete zdab files which have all been successfully fit") parser.add_argument("--db", type=str, help="database file", default=None) parser.add_argument('--loglevel', help="logging level (debug, verbose, notice, warning)", default='notice') parser.add_argument('--logfile', default=None, help="filename for log file") args = parser.parse_args() log.set_verbosity(args.loglevel) if args.logfile: log.set_logfile(args.logfile) home = os.path.expanduser("~") if args.db is None: args.db = join(home,'state.db') conn = sqlite3.connect(args.db) c = conn.cursor() results = c.execute('SELECT filename, state FROM state').fetchall() unique_filenames = set(row[0] for row in results) for filename in unique_filenames: if not exists(filename): continue head, tail = split(filename) success = [row[1] == 'SUCCESS' for row in results if row[0] == filename] if all(success): log.notice("deleting %s because all %i jobs were successfull" % (tail, len(success))) os.remove(filename) else: log.debug("skipping %s because %i/%i jobs haven't finished" % (tail, len(success) - np.count_nonzero(success), len(success))) conn.close() /sddm/log/utils/delete-zdabs'>