summaryrefslogtreecommitdiff
path: root/src/verbs/sync.py
diff options
context:
space:
mode:
authordavidovski <git@davidovski.xyz>2021-11-17 12:20:12 +0000
committerdavidovski <git@davidovski.xyz>2021-11-17 12:20:12 +0000
commit0ff24f5611f8a30f01ae08d866b5276c020a8665 (patch)
tree8c0a67e5f11e5622d9a46df2b7a1bd08cb66eddb /src/verbs/sync.py
parent0313176c9fe35fcca0f53b99ce1e636af0bc9e4e (diff)
added server pinging to determine best mirror to use
Diffstat (limited to 'src/verbs/sync.py')
-rw-r--r--src/verbs/sync.py34
1 files changed, 33 insertions, 1 deletions
diff --git a/src/verbs/sync.py b/src/verbs/sync.py
index 443a698..e9cc7b3 100644
--- a/src/verbs/sync.py
+++ b/src/verbs/sync.py
@@ -86,12 +86,44 @@ def import_key(source, url, verbose=False):
elif verbose:
print(colors.BG_RED + f"" + colors.RESET)
+
+def test_source(source, url):
+ start = time.time()
+ util.curl(util.add_path(url, "index.html"))
+ duration = time.time() - start
+ return int(duration * 1000)
+
+def test_sources(sources, file_path, test_count=10):
+ if test_count > 0:
+ pings = {}
+ checked = 0
+ for source,url in sources.items():
+ total = 0
+ for i in range(test_count):
+ total += test_source(source, url)
+ util.loading_bar(checked, len(sources) * test_count, f"Pinging Sources")
+ checked += 1
+ pings[source] = total / test_count if total > 0 else 0
+
+
+ sorted(pings, reverse=True)
+
+ with open(file_path, "w") as file:
+ for source,ping in pings.items():
+ file.write(f"{source} {ping}\n")
+
+ util.loading_bar(checked, len(sources) * test_count, f"Pinged Sources")
+ print()
+
+
def sync(args, options, config):
sources = config["sources"]
repos = config["repos"]
v = options["v"]
+ test_sources(sources, config["dir"]["sources"], test_count=int(config["pings"]))
+
for repo in repos:
packages = sync_packages(repo, sources, verbose=v)
@@ -103,7 +135,7 @@ def sync(args, options, config):
num_packages = len(validated)
util.loading_bar(num_packages, num_packages, f"Synced {repo}")
print(colors.RESET)
-
+
#total = len(sources)
#completed = 0