summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordavidovski <david@davidovski.xyz>2021-11-21 01:42:54 +0000
committerdavidovski <david@davidovski.xyz>2021-11-21 01:42:54 +0000
commit05ab891879f9d3e466d6d563a545ab22f4b258a1 (patch)
treeaa0715633cbec9ceacbc8ee0872727468cb3f1f9
parent49b1fddbbd961889b2048437c22fa819c1da17df (diff)
added more "mirrors"
-rw-r--r--Makefile5
-rw-r--r--src/util.py5
-rw-r--r--src/verbs/sync.py44
-rw-r--r--xipkg.conf6
4 files changed, 43 insertions, 17 deletions
diff --git a/Makefile b/Makefile
index 6617955..8948fda 100644
--- a/Makefile
+++ b/Makefile
@@ -8,10 +8,11 @@ xi: src/xi.py
rm src/xi.zip
chmod +x ${XI_BINARY}
-install: xi xipkg.conf default.conf bin/xi
+install: clean xi xipkg.conf default.conf bin/xi
mkdir -p /etc/xipkg.d/
cp default.conf /etc/xipkg.d/
cp xipkg.conf /etc/xipkg.conf
cp bin/xi /usr/bin/xi
-
+clean:
+ rm -rf bin
diff --git a/src/util.py b/src/util.py
index 2411f1d..99bb82e 100644
--- a/src/util.py
+++ b/src/util.py
@@ -30,7 +30,10 @@ def print_reset(text):
print(colors.RESET + text)
def curl(url):
- r = requests.get(url)
+ try:
+ r = requests.get(url)
+ except:
+ return 500, ""
return r.status_code, r.text
def mkdir(path):
diff --git a/src/verbs/sync.py b/src/verbs/sync.py
index c534f4d..0d47ddf 100644
--- a/src/verbs/sync.py
+++ b/src/verbs/sync.py
@@ -6,22 +6,31 @@ import time
CACHE_DIR = "/var/cache/xipkg"
def list_packages(url):
+ start = time.time()
status, response = util.curl(url + "/packages.list")
+ duration = (time.time() - start) * 1000
if status != 200:
- return {}
+ return {}, -1
else:
+ duration /= len(response)
return {
line.split()[0].split(".")[0]: line.split()[1]
for line in response.split("\n") if len(line.split()) > 0
- }
+ }, duration
def sync_packages(repo, sources, verbose=False):
packages = {}
total = 0
completed = 0
+
+ speeds = {}
for source,url in sources.items():
- listed = list_packages(url + repo if url[-1] == "/" else f"/{repo}")
+ listed, speed = list_packages(url + repo if url[-1] == "/" else f"/{repo}")
+
+ if speed > 0:
+ speeds[source] = speed
+
if len(listed) == 0 and verbose:
print(colors.BG_RED + f"No packages found in {source}/{repo}" + colors.RESET)
@@ -33,7 +42,8 @@ def sync_packages(repo, sources, verbose=False):
packages[p].append((listed[p], source))
completed += 1
util.loading_bar(completed, total, f"Syncing {repo}")
- return packages
+
+ return packages, speeds
def validate_packages(packages, repo, verbose=False):
output = {}
@@ -68,7 +78,6 @@ def save_package_list(validated, location):
with open(package_file, "w") as file:
file.write("checksum=" + info["checksum"] + "\n")
file.write("sources=" + " ".join([source for source in info["sources"]]))
- file.write("deps=" + " ".join([source for source in info["sources"]]))
###### !!! #######
@@ -90,10 +99,13 @@ def import_key(source, url, verbose=False):
def test_source(source, url):
+ # requesting a resource may not be the best way to do this, caching etc
start = time.time()
- util.curl(util.add_path(url, "index.html"))
- duration = time.time() - start
- return int(duration * 1000)
+ code, reponse = util.curl(util.add_path(url, "index.html"))
+ if code == 200:
+ return int((time.time() - start) * 1000)
+ else:
+ return -1
def test_sources(sources, file_path, test_count=10):
if test_count > 0:
@@ -105,10 +117,11 @@ def test_sources(sources, file_path, test_count=10):
total += test_source(source, url)
util.loading_bar(checked, len(sources) * test_count, f"Pinging Sources")
checked += 1
- pings[source] = int(total / test_count) if total > 0 else 0
+ if total > 0:
+ pings[source] = int(total / test_count) if total > 0 else 0
- sorted(pings, reverse=True)
+ sorted(pings)
with open(file_path, "w") as file:
for source,ping in pings.items():
@@ -124,10 +137,15 @@ def sync(args, options, config):
v = options["v"]
- test_sources(sources, config["dir"]["sources"], test_count=int(config["pings"]))
-
+ # test_sources(sources, config["dir"]["sources"], test_count=int(config["pings"]))
+
for repo in repos:
- packages = sync_packages(repo, sources, verbose=v)
+ packages, speeds = sync_packages(repo, sources, verbose=v)
+
+ sorted(speeds)
+ with open(config["dir"]["sources"], "w") as file:
+ for source,ping in speeds.items():
+ file.write(f"{source} {ping}\n")
# find the most popular hash to use
validated = validate_packages(packages, repo, verbose=v)
diff --git a/xipkg.conf b/xipkg.conf
index 07d1801..705c30d 100644
--- a/xipkg.conf
+++ b/xipkg.conf
@@ -4,7 +4,11 @@ include /etc/xipkg.d/default.conf
sources {
davidovski https://xi.davidovski.xyz/repo/
- codeberg https://xi.codeberg.page/repo/
+ codeberg https://xi.codeberg.page/repo/
+ ftp https://xilinux.ftp.sh/repo/
+ ix https://xilinux.ix.tc/repo/
+ ro https://xilinux.ro.lt/repo/
+ invalid https://xilinux.invalid/repo/
}
repos [