[tor-commits] [sbws/master] Create symlink to latest v3bw file

pastly at torproject.org pastly at torproject.org
Tue Jun 26 15:36:49 UTC 2018


commit 0db6329319ec9ea2a9486838257d5c1c3e210cc1
Author: juga0 <juga at riseup.net>
Date:   Thu Jun 14 15:54:24 2018 +0000

    Create symlink to latest v3bw file
    
    also lock the directory except when writing to the standard output,
    needed for test_generate.py
---
 sbws/lib/v3bwfile.py | 20 +++++++++++++++-----
 1 file changed, 15 insertions(+), 5 deletions(-)

diff --git a/sbws/lib/v3bwfile.py b/sbws/lib/v3bwfile.py
index ba15d14..1294d99 100644
--- a/sbws/lib/v3bwfile.py
+++ b/sbws/lib/v3bwfile.py
@@ -3,12 +3,13 @@
 (v3bw) used by bandwidth authorities."""
 
 import logging
+import os
 from statistics import median
 
 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.filelock import FileLock, DirectoryLock
 from sbws.util.timestamp import now_isodt_str, unixts_to_isodt_str, now_fname
 
 log = logging.getLogger(__name__)
@@ -401,7 +402,16 @@ class V3BwFile(object):
 
     def write(self, output):
         log.info('Writing v3bw file to %s', output)
-        with open(output, 'wt') as fd:
-            fd.write(str(self.header))
-            for line in self.bw_lines:
-                fd.write(str(line))
+        # to keep test_generate.py working
+        if output != '/dev/stdout':
+            with DirectoryLock(os.path.dirname(output)):
+                with open(output, 'wt') as fd:
+                    fd.write(str(self.header))
+                    for line in self.bw_lines:
+                        fd.write(str(line))
+                os.symlink(output, 'latest.v3bw')
+        else:
+            with open(output, 'wt') as fd:
+                fd.write(str(self.header))
+                for line in self.bw_lines:
+                    fd.write(str(line))





More information about the tor-commits mailing list