Skip to content

Instantly share code, notes, and snippets.

@rplevka
Last active November 3, 2020 14:54
Show Gist options
  • Save rplevka/36917d4415aa2816433d1162b780b01d to your computer and use it in GitHub Desktop.
Save rplevka/36917d4415aa2816433d1162b780b01d to your computer and use it in GitHub Desktop.

Revisions

  1. rplevka revised this gist Nov 3, 2020. 1 changed file with 2 additions and 0 deletions.
    2 changes: 2 additions & 0 deletions fix_junit_timestamps
    Original file line number Diff line number Diff line change
    @@ -10,6 +10,8 @@ for fi in files:
    foo = xmltodict.parse(f.read())
    t = foo['testsuites']['testsuite']['@timestamp']
    to = time.strptime(t.split('.')[0]+'_+0200', '%Y-%m-%dT%H:%M:%S_%z')
    epoch = time.mktime(to) - 7200
    to = time.gmtime(epoch)
    tn = f'{to.tm_year}-{to.tm_mon}-{to.tm_mday}T{to.tm_hour-2}:{to.tm_min}:{to.tm_sec}'
    foo['testsuites']['testsuite'].update({'properties': [{'property': {'@name': 'start_time', '@value': tn}}]})
    with open(f'new/{fi}', 'w') as g:
  2. rplevka revised this gist Nov 3, 2020. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion fix_junit_timestamps
    Original file line number Diff line number Diff line change
    @@ -11,6 +11,6 @@ for fi in files:
    t = foo['testsuites']['testsuite']['@timestamp']
    to = time.strptime(t.split('.')[0]+'_+0200', '%Y-%m-%dT%H:%M:%S_%z')
    tn = f'{to.tm_year}-{to.tm_mon}-{to.tm_mday}T{to.tm_hour-2}:{to.tm_min}:{to.tm_sec}'
    foo['testsuites']['testsuite']['properties'] = {'property':[{'@name': 'start_time', '@value': tn}]}
    foo['testsuites']['testsuite'].update({'properties': [{'property': {'@name': 'start_time', '@value': tn}}]})
    with open(f'new/{fi}', 'w') as g:
    g.write(xmltodict.unparse(foo))
  3. rplevka revised this gist Oct 22, 2020. 1 changed file with 3 additions and 3 deletions.
    6 changes: 3 additions & 3 deletions fix_junit_timestamps
    Original file line number Diff line number Diff line change
    @@ -3,14 +3,14 @@ import time
    import xmltodict

    files = os.listdir('.')
    for fi in files:
    for fi in files:
    if fi == 'new':
    continue
    with open(fi, 'r') as f:
    with open(fi, 'r') as f:
    foo = xmltodict.parse(f.read())
    t = foo['testsuites']['testsuite']['@timestamp']
    to = time.strptime(t.split('.')[0]+'_+0200', '%Y-%m-%dT%H:%M:%S_%z')
    tn = f'{to.tm_year}-{to.tm_mon}-{to.tm_mday}T{to.tm_hour-2}:{to.tm_min}:{to.tm_sec}'
    foo['testsuites']['testsuite']['properties'] = {'property':[{'@name': 'start_time', '@value': tn}]}
    with open(f'new/{fi}', 'w') as g:
    g.write(xmltodict.unparse(foo))
    g.write(xmltodict.unparse(foo))
  4. rplevka created this gist Oct 22, 2020.
    16 changes: 16 additions & 0 deletions fix_junit_timestamps
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,16 @@
    import os
    import time
    import xmltodict

    files = os.listdir('.')
    for fi in files:
    if fi == 'new':
    continue
    with open(fi, 'r') as f:
    foo = xmltodict.parse(f.read())
    t = foo['testsuites']['testsuite']['@timestamp']
    to = time.strptime(t.split('.')[0]+'_+0200', '%Y-%m-%dT%H:%M:%S_%z')
    tn = f'{to.tm_year}-{to.tm_mon}-{to.tm_mday}T{to.tm_hour-2}:{to.tm_min}:{to.tm_sec}'
    foo['testsuites']['testsuite']['properties'] = {'property':[{'@name': 'start_time', '@value': tn}]}
    with open(f'new/{fi}', 'w') as g:
    g.write(xmltodict.unparse(foo))