summaryrefslogtreecommitdiff
path: root/src/backend/download.py
diff options
context:
space:
mode:
authorV3n3RiX <venerix@koprulu.sector>2023-04-07 17:47:46 +0100
committerV3n3RiX <venerix@koprulu.sector>2023-04-07 17:47:46 +0100
commit5a3414863014bec7f901cb04b9afd49834e181f4 (patch)
treed5efa6c68fd41907a77043c12a38a60c87a6b9c6 /src/backend/download.py
parenta9d87ee5bd0c98b6daae9ddf307c634da9c35551 (diff)
backend : rewrite download in a more efficient way
Diffstat (limited to 'src/backend/download.py')
-rw-r--r--src/backend/download.py122
1 files changed, 36 insertions, 86 deletions
diff --git a/src/backend/download.py b/src/backend/download.py
index 32e27a6..7e2d4ec 100644
--- a/src/backend/download.py
+++ b/src/backend/download.py
@@ -4,96 +4,46 @@ import atexit
import io
import os
import subprocess
+import sys
import pickle
import sisyphus.getfs
import sisyphus.killemerge
-def dl_pbin_only():
+def start(redir_out=False, dl_world=False):
dl_list = []
- bin_list, src_list, need_cfg = pickle.load(
- open(os.path.join(sisyphus.getfs.p_mtd_dir, "sisyphus_pkgdeps.pickle"), "rb"))
- for index, pbin in enumerate(['=' + package for package in bin_list]):
- dl_list.append(pbin)
-
- p_exe = subprocess.Popen(['emerge', '--nodeps', '--quiet', '--verbose', '--getbinpkg', '--getbinpkgonly', '--fetchonly',
- '--rebuilt-binaries', '--with-bdeps=y', '--misspell-suggestion=n', '--fuzzy-search=n'] + list(dl_list))
- p_exe.wait()
-
-
-def dl_pbin():
- dl_list = []
- bin_list, src_list, need_cfg = pickle.load(
- open(os.path.join(sisyphus.getfs.p_mtd_dir, "sisyphus_pkgdeps.pickle"), "rb"))
-
- for index, pbin in enumerate(['=' + package for package in bin_list]):
- dl_list.append(pbin)
-
- p_exe = subprocess.Popen(['emerge', '--nodeps', '--quiet', '--verbose', '--getbinpkg', '--fetchonly',
- '--rebuilt-binaries', '--with-bdeps=y', '--misspell-suggestion=n', '--fuzzy-search=n'] + list(dl_list))
- p_exe.wait()
-
-
-def xdl_pbin_only():
- dl_list = []
- bin_list, src_list, need_cfg = pickle.load(
- open(os.path.join(sisyphus.getfs.p_mtd_dir, "sisyphus_pkgdeps.pickle"), "rb"))
-
- for index, pbin in enumerate(['=' + package for package in bin_list]):
- dl_list.append(pbin)
-
- p_exe = subprocess.Popen(['emerge', '--nodeps', '--quiet', '--verbose', '--getbinpkg', '--getbinpkgonly', '--fetchonly', '--rebuilt-binaries',
- '--with-bdeps=y', '--misspell-suggestion=n', '--fuzzy-search=n'] + list(dl_list), stdout=subprocess.PIPE, stderr=subprocess.PIPE)
- # kill portage if the program dies or it's terminated by the user
- atexit.register(sisyphus.killemerge.start, p_exe)
-
- for p_out in io.TextIOWrapper(p_exe.stdout, encoding="utf-8"):
- print(p_out.rstrip())
-
- p_exe.wait()
-
-
-def dl_wpbin_only():
- dl_list = []
- bin_list, src_list, need_cfg = pickle.load(
- open(os.path.join(sisyphus.getfs.p_mtd_dir, "sisyphus_worlddeps.pickle"), "rb"))
-
- for index, pbin in enumerate(['=' + package for package in bin_list]):
- dl_list.append(pbin)
-
- p_exe = subprocess.Popen(['emerge', '--nodeps', '--quiet', '--verbose', '--getbinpkg', '--getbinpkgonly', '--fetchonly',
- '--rebuilt-binaries', '--with-bdeps=y', '--misspell-suggestion=n', '--fuzzy-search=n'] + list(dl_list))
- p_exe.wait()
-
-
-def dl_wpbin():
- dl_list = []
- bin_list, src_list, need_cfg = pickle.load(
- open(os.path.join(sisyphus.getfs.p_mtd_dir, "sisyphus_worlddeps.pickle"), "rb"))
-
- for index, pbin in enumerate(['=' + package for package in bin_list]):
- dl_list.append(pbin)
-
- p_exe = subprocess.Popen(['emerge', '--nodeps', '--quiet', '--verbose', '--getbinpkg', '--fetchonly',
- '--rebuilt-binaries', '--with-bdeps=y', '--misspell-suggestion=n', '--fuzzy-search=n'] + list(dl_list))
- p_exe.wait()
-
-
-def xdl_wpbin_only():
- dl_list = []
- bin_list, src_list, need_cfg = pickle.load(
- open(os.path.join(sisyphus.getfs.p_mtd_dir, "sisyphus_worlddeps.pickle"), "rb"))
-
- for index, pbin in enumerate(['=' + package for package in bin_list]):
- dl_list.append(pbin)
-
- p_exe = subprocess.Popen(['emerge', '--nodeps', '--quiet', '--verbose', '--getbinpkg', '--getbinpkgonly', '--fetchonly', '--rebuilt-binaries',
- '--with-bdeps=y', '--misspell-suggestion=n', '--fuzzy-search=n'] + list(dl_list), stdout=subprocess.PIPE, stderr=subprocess.PIPE)
- # kill portage if the program dies or it's terminated by the user
- atexit.register(sisyphus.killemerge.start, p_exe)
-
- for p_out in io.TextIOWrapper(p_exe.stdout, encoding="utf-8"):
- print(p_out.rstrip())
-
- p_exe.wait()
+ if dl_world:
+ file_path = os.path.join(
+ sisyphus.getfs.p_mtd_dir, "sisyphus_worlddeps.pickle")
+ else:
+ file_path = os.path.join(
+ sisyphus.getfs.p_mtd_dir, "sisyphus_pkgdeps.pickle")
+
+ with open(file_path, "rb") as f:
+ bin_list, src_list, need_cfg = pickle.load(f)
+
+ dl_list = [f'={package}' for package in bin_list]
+
+ if redir_out:
+ p_exe = subprocess.Popen(['emerge', '--nodeps', '--quiet', '--verbose', '--getbinpkg', '--fetchonly', '--rebuilt-binaries',
+ '--with-bdeps=y', '--misspell-suggestion=n', '--fuzzy-search=n'] + list(dl_list), stdout=subprocess.PIPE, stderr=subprocess.PIPE)
+ # kill portage if the program dies or it's terminated by the user
+ atexit.register(sisyphus.killemerge.start, p_exe)
+
+ for p_out in io.TextIOWrapper(p_exe.stdout, encoding="utf-8"):
+ print(p_out.rstrip())
+
+ p_exe.wait()
+ else:
+ p_exe = subprocess.Popen(['emerge', '--nodeps', '--quiet', '--verbose', '--getbinpkg', '--fetchonly',
+ '--rebuilt-binaries', '--with-bdeps=y', '--misspell-suggestion=n', '--fuzzy-search=n'] + list(dl_list))
+ try:
+ p_exe.wait()
+ except KeyboardInterrupt:
+ p_exe.terminate()
+ try:
+ p_exe.wait(1)
+ except subprocess.TimeoutExpired:
+ p_exe.kill()
+ sys.exit()