[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[tor-commits] [sbws/master] destination: add function to parse countries
commit fe281909a5705cd9ab17daf57ae4ec179719572f
Author: juga0 <juga@xxxxxxxxxx>
Date: Mon Feb 11 10:50:04 2019 +0000
destination: add function to parse countries
so that they can be reported in the bandwidth file headers.
---
sbws/lib/destination.py | 20 ++++++++++++++++++++
1 file changed, 20 insertions(+)
diff --git a/sbws/lib/destination.py b/sbws/lib/destination.py
index c0e6b03..a92df61 100644
--- a/sbws/lib/destination.py
+++ b/sbws/lib/destination.py
@@ -12,6 +12,26 @@ from ..globals import MAXIMUM_NUMBER_DESTINATION_FAILURES
log = logging.getLogger(__name__)
+# Duplicate some code from DestinationList.from_config,
+# it should be refactored.
+def parse_destinations_countries(conf):
+ """Returns the destinations' country as string separated by comma.
+
+ """
+ destinations_countries = []
+ for key in conf['destinations'].keys():
+ # Not a destination key
+ if key in ['usability_test_interval']:
+ continue
+ # The destination is not enabled
+ if not conf['destinations'].getboolean(key):
+ continue
+ destination_section = 'destinations.{}'.format(key)
+ destination_country = conf[destination_section].get('country', None)
+ destinations_countries.append(destination_country)
+ return ','.join(destinations_countries)
+
+
def _parse_verify_option(conf_section):
if 'verify' not in conf_section:
return DESTINATION_VERIFY_CERTIFICATE
_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits