summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKarsten Loesing <karsten.loesing@gmx.net>2020-06-01 21:51:07 +0200
committerKarsten Loesing <karsten.loesing@gmx.net>2020-06-01 21:51:07 +0200
commit011359d0ed6580bd8cb00f3ce8c510c4948accb7 (patch)
tree26853aca5abb7c26b0599e117fa70f0975174a1a
parentfc498088527083e19122610f5c8c169b5decda76 (diff)
Add size and last_modified fields to index.xml.task-29365
While touching this code: - make sure that the index.xml file itself is not contained and - fix the encoding issue introduced by the Python 3 upgrade. Fixes #29365.
-rw-r--r--onionperf/measurement.py17
1 files changed, 12 insertions, 5 deletions
diff --git a/onionperf/measurement.py b/onionperf/measurement.py
index 3da7445..6046bbd 100644
--- a/onionperf/measurement.py
+++ b/onionperf/measurement.py
@@ -18,11 +18,18 @@ from . import analysis, monitor, model, util
def generate_docroot_index(docroot_path):
root = etree.Element("files")
- filepaths = [f for f in os.listdir(docroot_path) if os.path.isfile(os.path.abspath('/'.join([docroot_path, f])))]
- for filename in filepaths:
- e = etree.SubElement(root, "file")
- e.set("name", filename)
- with open("{0}/index.xml".format(docroot_path), 'wt') as f: print(etree.tostring(root, pretty_print=True, xml_declaration=True), file=f)
+ with os.scandir(docroot_path) as files:
+ for entry in files:
+ if not entry.name == 'index.xml' and entry.is_file():
+ e = etree.SubElement(root, "file")
+ e.set("name", entry.name)
+ stat_result = entry.stat()
+ e.set("size", str(stat_result.st_size))
+ mtime = datetime.datetime.fromtimestamp(stat_result.st_mtime)
+ e.set("last_modified", mtime.replace(microsecond=0).isoformat(sep=' '))
+ with open("{0}/index.xml".format(docroot_path), 'wb') as f:
+ et = etree.ElementTree(root)
+ et.write(f, pretty_print=True, xml_declaration=True)
def readline_thread_task(instream, q):
# wait for lines from stdout until the EOF