diff --git a/bin/logtool b/bin/logtool index e9216965148498d933443caf9e81df1f24a7a965..5c8cd372171ae1124735bc9e9a17a3f71bf336be 100755 --- a/bin/logtool +++ b/bin/logtool @@ -150,7 +150,7 @@ following: # not a known command, interpret as file name from os import access, R_OK if access(cmd, R_OK): - logmgr = LogManager(cmd) + logmgr = LogManager(cmd, "r") else: raise IOError, "file '%s' not found" % cmd diff --git a/src/batchjob.py b/src/batchjob.py index 585f5d6a023b2b8cf373741415d9e539ea51c83f..2b568a9e0e5583da42954eecfa1adaf7e6317d04 100644 --- a/src/batchjob.py +++ b/src/batchjob.py @@ -14,13 +14,21 @@ def _cp(src, dest): +def get_timestamp(): + from datetime import datetime + return datetime.now().strftime("%Y-%m-%d-%H%M%S") + + + + class BatchJob(object): - def __init__(self, moniker, main_file, aux_files=[]): - from datetime import datetime + def __init__(self, moniker, main_file, aux_files=[], timestamp=None): import os import os.path - timestamp = datetime.now().strftime("%Y-%m-%d-%H%M") + if timestamp is None: + timestamp = get_timestamp() + self.moniker = ( moniker .replace("-$DATE", "") @@ -30,6 +38,7 @@ class BatchJob(object): self.subdir = os.path.join( os.getcwd(), moniker.replace("$DATE", timestamp)) + os.makedirs(self.subdir) with open("%s/run.sh" % self.subdir, "w") as runscript: diff --git a/src/log.py b/src/log.py index 23182b0d2dac0fbc0354e6174282c30bc50af187..37449710bdd119229b498fd44b1067700888f69a 100644 --- a/src/log.py +++ b/src/log.py @@ -159,14 +159,21 @@ class LogManager(object): data in a saved log. """ - def __init__(self, filename, mpi_comm=None): + def __init__(self, filename, mode, mpi_comm=None): """Initialize this log manager instance. @arg filename: If given, the filename to which this log is bound. If this database exists, the current state is loaded from it. + @arg mode: One of "w", "r" for write, read. "w" assumes that the + database is initially empty. @arg mpi_comm: A C{boost.mpi} communicator. If given, logs are periodically synchronized to the head node, which then writes them out to disk. """ + + assert isinstance(mode, basestring), "mode must be a string" + mode = mode[0] + assert mode in ["w", "r"], "invalid mode" + self.quantity_data = {} self.quantity_table = {} self.gather_descriptors = [] @@ -202,8 +209,13 @@ class LogManager(object): self.db_conn = sqlite3.connect(filename, timeout=30) try: self.db_conn.execute("select * from quantities;") + if mode == "w": + raise RuntimeError, "Log database '%s' already exists" % filename self._load() except sqlite3.OperationalError: + if mode == "r": + raise RuntimeError, "Log database '%s' not found" % filename + # initialize new database self.db_conn.execute(""" create table quantities (