Commit 9fa3d173 authored by juga's avatar juga
Browse files

Change Unix Epoch by ISO 8601 in header keyvalues

timestamps
parent f459dabb
from sbws.globals import (fail_hard, is_initted)
from datetime import datetime
from sbws.globals import (fail_hard, is_initted, TIMESTAMP_DT_FRMT)
from sbws.lib.v3bwfile import V3BwHeader
from sbws.lib.resultdump import ResultSuccess
from sbws.lib.resultdump import load_recent_results_in_datadir
......@@ -101,9 +103,11 @@ def log_stats(data_lines):
def read_started_ts(conf):
"""Write timestamp in Unix Epoch seconds.microsecs when scanner started.
"""Read ISO formated timestamp which represents the date and time
when scanner started.
:param ConfigParser conf: configuration
:returns: str, ISO formated timestamp
"""
filepath = conf['paths']['started_filepath']
with FileLock(filepath):
......@@ -126,7 +130,11 @@ def main(args, conf):
results = load_recent_results_in_datadir(
fresh_days, datadir, success_only=True)
if results:
earliest_bandwidth = min([r.time for r in results])
# Using naive datetime object without timezone, assumed utc
# Not using .isoformat() since that does not include 'T'
earliest_bandwidth = datetime.utcfromtimestamp(
min([r.time for r in results])) \
.strftime(TIMESTAMP_DT_FRMT)
if len(results) < 1:
log.warning('No recent results, so not generating anything. (Have you '
'ran sbws scanner recently?)')
......
''' Measure the relays. '''
from datetime import datetime
from ..lib.circuitbuilder import GapsCircuitBuilder as CB
from ..lib.resultdump import ResultDump
from ..lib.resultdump import ResultSuccess, ResultErrorCircuit
......@@ -10,7 +12,7 @@ from ..lib.destination import DestinationList
from ..util.filelock import FileLock
# from ..util.simpleauth import authenticate_to_server
# from ..util.sockio import (make_socket, close_socket)
from sbws.globals import (fail_hard, is_initted)
from sbws.globals import (fail_hard, is_initted, TIMESTAMP_DT_FRMT)
import sbws.util.stem as stem_utils
import sbws.util.requests as requests_utils
from argparse import ArgumentDefaultsHelpFormatter
......@@ -280,11 +282,15 @@ def result_putter_error(target):
def write_start_ts(conf):
"""Write timestamp in Unix Epoch seconds.microsecs when scanner started.
"""Write ISO formated timestamp which represents the date and time
when scanner started.
:param ConfigParser conf: configuration
"""
generator_started = str(time.time())
# Using naive object, without timezone, since all datetimes are assumed
# to be always in UTC.
# Not using .isoformat() since that does not include 'T'
generator_started = datetime.utcnow().strftime(TIMESTAMP_DT_FRMT)
log.info('Scanner started at {}'.format(generator_started))
filepath = conf['paths']['started_filepath']
with FileLock(filepath):
......
......@@ -24,6 +24,8 @@ TORRC_STARTING_POINT = {
'UseEntryGuards': '0',
}
TIMESTAMP_DT_FRMT = "%d-%b-%Y %H:%M:%S"
def is_initted(d):
if not os.path.isdir(d):
......
Supports Markdown
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