Commit b94f7ae0 authored by juga's avatar juga
Browse files

Generate v3bw files in a dir and named with timestamp

parent c8009072
datadir = ${sbws_home}/datadir
v3bw_fname = ${sbws_home}/v3bw.txt
v3bw_dname = ${sbws_home}/v3bw
v3bw_fname = ${v3bw_dname}/{}.v3bw
started_filepath = ${sbws_home}/started_at
log_filepath = ${sbws_home}/sbws.log
......@@ -35,6 +35,8 @@ def main(args, conf):
if not is_initted(
fail_hard('Sbws isn\'t initialized. Try sbws init')
os.makedirs(conf['paths']['v3bw_dname'], exist_ok=True)
datadir = conf['paths']['datadir']
if not os.path.isdir(datadir):
fail_hard('%s does not exist', datadir)
......@@ -9,7 +9,7 @@ from sbws import __version__
from sbws.globals import SPEC_VERSION, BW_LINE_SIZE
from sbws.lib.resultdump import ResultSuccess, _ResultType
from sbws.util.filelock import FileLock
from sbws.util.timestamp import now_isodt_str, unixts_to_isodt_str
from sbws.util.timestamp import now_isodt_str, unixts_to_isodt_str, now_fname
log = logging.getLogger(__name__)
......@@ -395,7 +395,7 @@ class V3BwFile(object):
bw_lines = scale_lines(bw_lines, args.scale_constant)
header = V3BwHeader.from_results(conf, results)
f = cls(header, bw_lines)
output = args.output or conf['paths']['v3bw_fname']
output = args.output or conf['paths']['v3bw_fname'].format(now_fname())
return f
......@@ -149,7 +149,7 @@ def _validate_paths(conf):
sec = 'paths'
err_tmpl = Template('$sec/$key ($val): $e')
unvalidated_keys = [
'datadir', 'sbws_home', 'v3bw_fname',
'datadir', 'sbws_home', 'v3bw_fname', 'v3bw_dname',
'started_filepath', 'log_filepath']
all_valid_keys = unvalidated_keys
allow_missing = ['sbws_home']
......@@ -47,6 +47,16 @@ def now_isodt_str():
return dt_obj_to_isodt_str(datetime.utcnow())
def now_fname():
Return now timestamp in UTC formatted as %Y%m%d_%H%M%S string for file
:returns: now timestamp in UTC formatted as %Y%m%d_%H%M%S string
return datetime.utcnow().strftime("%Y%m%d_%H%M%S")
def unixts_to_str(unixts):
"""Convert unix timestamp integer or float to string"""
# even if it is only converting to str, ensure that input is nothing else
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment