From e1562a71d6483021d332bccbfc5a3086688bc58c Mon Sep 17 00:00:00 2001 From: V3n3RiX Date: Sat, 17 Sep 2022 19:12:53 +0100 Subject: rearrange the backend --- src/backend/__init__.py | 52 +++++++-------- src/backend/autoRemoveAll.py | 28 +++++++++ src/backend/autoremove.py | 28 --------- src/backend/binhost.py | 15 ----- src/backend/branchsetup.py | 94 --------------------------- src/backend/check.py | 42 ------------- src/backend/checkEnvironment.py | 42 +++++++++++++ src/backend/csvfiles.py | 17 ----- src/backend/database.py | 57 ----------------- src/backend/ebuildinstall.py | 113 --------------------------------- src/backend/ebuildsearch.py | 6 -- src/backend/ebuildupgrade.py | 114 --------------------------------- src/backend/filesystem.py | 28 --------- src/backend/forceuninstall.py | 14 ----- src/backend/getBinhost.py | 15 +++++ src/backend/getCSV.py | 17 +++++ src/backend/getFilesystem.py | 28 +++++++++ src/backend/install.py | 96 ---------------------------- src/backend/installPkg.py | 96 ++++++++++++++++++++++++++++ src/backend/installSrc.py | 113 +++++++++++++++++++++++++++++++++ src/backend/killPortage.py | 4 ++ src/backend/killportage.py | 4 -- src/backend/mirror.py | 59 ----------------- src/backend/purge.py | 51 --------------- src/backend/purgeEnvironment.py | 51 +++++++++++++++ src/backend/recoverDatabase.py | 20 ++++++ src/backend/rescue.py | 20 ------ src/backend/resolveDeps.py | 69 ++++++++++++++++++++ src/backend/search.py | 133 --------------------------------------- src/backend/searchPkg.py | 133 +++++++++++++++++++++++++++++++++++++++ src/backend/searchSrc.py | 6 ++ src/backend/setBranch.py | 94 +++++++++++++++++++++++++++ src/backend/setJobs.py | 6 ++ src/backend/setMirror.py | 59 +++++++++++++++++ src/backend/setProfile.py | 18 ++++++ src/backend/setjobs.py | 6 -- src/backend/setprofile.py | 18 ------ src/backend/solvedeps.py | 69 -------------------- src/backend/spmsync.py | 8 --- src/backend/sync.py | 45 ------------- src/backend/syncDatabase.py | 57 +++++++++++++++++ src/backend/syncEnvironment.py | 45 +++++++++++++ src/backend/syncSPM.py | 8 +++ src/backend/sysInfo.py | 7 +++ src/backend/sysinfo.py | 7 --- src/backend/uninstall.py | 28 --------- src/backend/uninstallAll.py | 28 +++++++++ src/backend/uninstallForceAll.py | 14 +++++ src/backend/update.py | 55 ---------------- src/backend/updateAll.py | 55 ++++++++++++++++ src/backend/upgrade.py | 102 ------------------------------ src/backend/upgradePkg.py | 102 ++++++++++++++++++++++++++++++ src/backend/upgradeSrc.py | 114 +++++++++++++++++++++++++++++++++ 53 files changed, 1255 insertions(+), 1255 deletions(-) create mode 100644 src/backend/autoRemoveAll.py delete mode 100644 src/backend/autoremove.py delete mode 100644 src/backend/binhost.py delete mode 100644 src/backend/branchsetup.py delete mode 100644 src/backend/check.py create mode 100644 src/backend/checkEnvironment.py delete mode 100644 src/backend/csvfiles.py delete mode 100644 src/backend/database.py delete mode 100644 src/backend/ebuildinstall.py delete mode 100644 src/backend/ebuildsearch.py delete mode 100644 src/backend/ebuildupgrade.py delete mode 100644 src/backend/filesystem.py delete mode 100644 src/backend/forceuninstall.py create mode 100644 src/backend/getBinhost.py create mode 100644 src/backend/getCSV.py create mode 100644 src/backend/getFilesystem.py delete mode 100644 src/backend/install.py create mode 100644 src/backend/installPkg.py create mode 100644 src/backend/installSrc.py create mode 100644 src/backend/killPortage.py delete mode 100644 src/backend/killportage.py delete mode 100644 src/backend/mirror.py delete mode 100644 src/backend/purge.py create mode 100644 src/backend/purgeEnvironment.py create mode 100644 src/backend/recoverDatabase.py delete mode 100644 src/backend/rescue.py create mode 100644 src/backend/resolveDeps.py delete mode 100644 src/backend/search.py create mode 100644 src/backend/searchPkg.py create mode 100644 src/backend/searchSrc.py create mode 100644 src/backend/setBranch.py create mode 100644 src/backend/setJobs.py create mode 100644 src/backend/setMirror.py create mode 100644 src/backend/setProfile.py delete mode 100644 src/backend/setjobs.py delete mode 100644 src/backend/setprofile.py delete mode 100644 src/backend/solvedeps.py delete mode 100644 src/backend/spmsync.py delete mode 100644 src/backend/sync.py create mode 100644 src/backend/syncDatabase.py create mode 100644 src/backend/syncEnvironment.py create mode 100644 src/backend/syncSPM.py create mode 100644 src/backend/sysInfo.py delete mode 100644 src/backend/sysinfo.py delete mode 100644 src/backend/uninstall.py create mode 100644 src/backend/uninstallAll.py create mode 100644 src/backend/uninstallForceAll.py delete mode 100644 src/backend/update.py create mode 100644 src/backend/updateAll.py delete mode 100644 src/backend/upgrade.py create mode 100644 src/backend/upgradePkg.py create mode 100644 src/backend/upgradeSrc.py (limited to 'src/backend') diff --git a/src/backend/__init__.py b/src/backend/__init__.py index 7833aba..bf350e1 100644 --- a/src/backend/__init__.py +++ b/src/backend/__init__.py @@ -1,26 +1,26 @@ -from .autoremove import * -from .binhost import * -from .branchsetup import * -from .check import * -from .csvfiles import * -from .database import * -from .ebuildinstall import * -from .ebuildsearch import * -from .ebuildupgrade import * -from .filesystem import * -from .forceuninstall import * -from .install import * -from .killportage import * -from .mirror import * -from .purge import * -from .rescue import * -from .search import * -from .setjobs import * -from .setprofile import * -from .solvedeps import * -from .spmsync import * -from .sync import * -from .sysinfo import * -from .uninstall import * -from .update import * -from .upgrade import * +from .autoRemoveAll import * +from .checkEnvironment import * +from .getBinhost import * +from .getCSV import * +from .getFilesystem import * +from .installPkg import * +from .installSrc import * +from .killPortage import * +from .purgeEnvironment import * +from .recoverDatabase import * +from .resolveDeps import * +from .searchPkg import * +from .searchSrc import * +from .setBranch import * +from .setJobs import * +from .setMirror import * +from .setProfile import * +from .syncDatabase import * +from .syncEnvironment import * +from .syncSPM import * +from .sysInfo import * +from .uninstallAll import * +from .uninstallForceAll import * +from .updateAll import * +from .upgradePkg import * +from .upgradeSrc import * diff --git a/src/backend/autoRemoveAll.py b/src/backend/autoRemoveAll.py new file mode 100644 index 0000000..bcf5760 --- /dev/null +++ b/src/backend/autoRemoveAll.py @@ -0,0 +1,28 @@ +#!/usr/bin/python3 + +import atexit +import io +import subprocess +import sys +import sisyphus.checkEnvironment +import sisyphus.syncDatabase +import sisyphus.killPortage + +def start(): + if sisyphus.checkEnvironment.root(): + portageExec = subprocess.Popen(['emerge', '--quiet', '--depclean', '--ask'], stdout=subprocess.PIPE, stderr=subprocess.PIPE) + stdout, stderr = portageExec.communicate() + sisyphus.syncDatabase.syncLocal() + else: + sys.exit("\nYou need root permissions to do this, exiting!\n") + +def startqt(): + portageExec = subprocess.Popen(['emerge', '--depclean'], stdout=subprocess.PIPE, stderr=subprocess.PIPE) + stdout, stderr = portageExec.communicate() + # kill portage if the program dies or it's terminated by the user + atexit.register(sisyphus.killPortage.start, portageExec) + + for portageOutput in io.TextIOWrapper(portageExec.stdout, encoding="utf-8"): + print(portageOutput.rstrip()) + + sisyphus.syncDatabase.syncLocal() diff --git a/src/backend/autoremove.py b/src/backend/autoremove.py deleted file mode 100644 index 37ae7ee..0000000 --- a/src/backend/autoremove.py +++ /dev/null @@ -1,28 +0,0 @@ -#!/usr/bin/python3 - -import atexit -import io -import subprocess -import sys -import sisyphus.check -import sisyphus.database -import sisyphus.killportage - -def start(): - if sisyphus.check.root(): - portageExec = subprocess.Popen(['emerge', '--quiet', '--depclean', '--ask'], stdout=subprocess.PIPE, stderr=subprocess.PIPE) - stdout, stderr = portageExec.communicate() - sisyphus.database.syncLocal() - else: - sys.exit("\nYou need root permissions to do this, exiting!\n") - -def startqt(): - portageExec = subprocess.Popen(['emerge', '--depclean'], stdout=subprocess.PIPE, stderr=subprocess.PIPE) - stdout, stderr = portageExec.communicate() - # kill portage if the program dies or it's terminated by the user - atexit.register(sisyphus.killportage.start, portageExec) - - for portageOutput in io.TextIOWrapper(portageExec.stdout, encoding="utf-8"): - print(portageOutput.rstrip()) - - sisyphus.database.syncLocal() diff --git a/src/backend/binhost.py b/src/backend/binhost.py deleted file mode 100644 index 3de4fca..0000000 --- a/src/backend/binhost.py +++ /dev/null @@ -1,15 +0,0 @@ -#!/usr/bin/python3 - -import io -import subprocess - -def start(): - isBinhost = [] - portageExec = subprocess.Popen(['emerge', '--info', '--verbose'], stdout=subprocess.PIPE, stderr=subprocess.PIPE) - stdout, stderr = portageExec.communicate() - - for portageOutput in io.TextIOWrapper(portageExec.stdout, encoding="utf-8"): - if "PORTAGE_BINHOST" in portageOutput.rstrip(): - isBinhost = str(portageOutput.rstrip().split("=")[1].strip('\"')) - - return isBinhost diff --git a/src/backend/branchsetup.py b/src/backend/branchsetup.py deleted file mode 100644 index 4ac3b84..0000000 --- a/src/backend/branchsetup.py +++ /dev/null @@ -1,94 +0,0 @@ -#!/usr/bin/python3 - -import animation -import git -import os -import sys -import sisyphus.check -import sisyphus.filesystem -import sisyphus.purge -import sisyphus.setjobs -import sisyphus.setprofile - -def getBranchRemote(branch,remote): - portageRemote = [] - redcoreRemote = [] - portageConfigRemote = [] - if "master" in branch: - if "gitlab" in remote: - remote = sisyphus.filesystem.remoteGitlab - elif "pagure" in remote: - remote = sisyphus.filesystem.remotePagure - else: - sys.exit("Usage: sisyphus-cli.py branch [OPTIONS] BRANCH" + "\n" + - "Try 'sisyphus-cli.py branch --help' for help." + "\n\n" + - "Error: Invalid remote" + " " + "'" + str(remote) + "'" + " " + "(options : gitlab, pagure)" - ) - elif "next" in branch: - if "gitlab" in remote: - remote = sisyphus.filesystem.remoteGitlab - elif "pagure" in remote: - remote = sisyphus.filesystem.remotePagure - else: - sys.exit("Usage: sisyphus-cli.py branch [OPTIONS] BRANCH" + "\n" + - "Try 'sisyphus-cli.py branch --help' for help." + "\n\n" + - "Error: Invalid remote" + " " + "'" + str(remote) + "'" + " " + "(options : gitlab, pagure)" - ) - else: - sys.exit("Usage: sisyphus-cli.py branch [OPTIONS] BRANCH" + "\n" + - "Try 'sisyphus-cli.py branch --help' for help." + "\n\n" + - "Error: Invalid branch" + " " + "'" + str(branch) + "'" +" " + "(options : master, next)" - ) - - portageRemote = [remote, sisyphus.filesystem.portageRepo] - redcoreRemote = [remote, sisyphus.filesystem.redcoreRepo] - portageConfigRemote = [remote, sisyphus.filesystem.portageConfigRepo] - - return portageRemote,redcoreRemote,portageConfigRemote - -@animation.wait('injecting Gentoo Linux portage tree') -def injectGentooPortageTree(branch,remote): - portageRemote,redcoreRemote,portageConfigRemote = getBranchRemote(branch,remote) - - if not os.path.isdir(os.path.join(sisyphus.filesystem.portageRepoDir, '.git')): - git.Repo.clone_from("/".join(portageRemote), sisyphus.filesystem.portageRepoDir, depth=1, branch=branch) - -@animation.wait('injecting Redcore Linux ebuild overlay') -def injectRedcoreEbuildOverlay(branch,remote): - portageRemote,redcoreRemote,portageConfigRemote = getBranchRemote(branch,remote) - - if not os.path.isdir(os.path.join(sisyphus.filesystem.redcoreRepoDir, '.git')): - git.Repo.clone_from("/".join(redcoreRemote), sisyphus.filesystem.redcoreRepoDir, depth=1, branch=branch) - -@animation.wait('injecting Redcore Linux portage config') -def injectRedcorePortageConfig(branch,remote): - portageRemote,redcoreRemote,portageConfigRemote = getBranchRemote(branch,remote) - - if not os.path.isdir(os.path.join(sisyphus.filesystem.portageConfigDir, '.git')): - git.Repo.clone_from("/".join(portageConfigRemote), sisyphus.filesystem.portageConfigDir, depth=1, branch=branch) - -def warnAboutBinaryRepository(branch,remote): - if "master" in branch: - print("\nThe switch to branch" + " " + "'" + branch + "'" + " " + "from remote" + " " + "'" + remote + "'" + " " + "is now complete") - print("You must pair this branch with the stable binhost (binary repository)") - print("Hint : Use the odd numbers (1,3,5,7) from 'sisyphus mirror list'") - print("Examples : 'sisyphus mirror set 1' or 'sisyphus mirror set 5'\n") - elif "next" in branch: - print("\nThe switch to branch" + " " + "'" + branch + "'" + " " + "from remote" + " " + "'" + remote + "'" + " " + "is now complete") - print("You must pair this branch with the testing binhost (binary repository)") - print("Hint : Use the even numbers (2,4,6,8) from 'sisyphus mirror list'") - print("Examples : 'sisyphus mirror set 4' or 'sisyphus mirror set 8'\n") - - -def start(branch,remote): - if sisyphus.check.root(): - sisyphus.purge.branch() - sisyphus.purge.metadata() - injectGentooPortageTree(branch,remote) - injectRedcoreEbuildOverlay(branch,remote) - injectRedcorePortageConfig(branch,remote) - sisyphus.setjobs.start() - sisyphus.setprofile.start() - warnAboutBinaryRepository(branch,remote) - else: - sys.exit("\nYou need root permissions to do this, exiting!\n") diff --git a/src/backend/check.py b/src/backend/check.py deleted file mode 100644 index 7f23338..0000000 --- a/src/backend/check.py +++ /dev/null @@ -1,42 +0,0 @@ -#!/usr/bin/python3 - -import os -import subprocess -import sisyphus.binhost -import sisyphus.filesystem - -def root(): - return True if os.getuid() == 0 else False - -def branch(): - activeBranch = None - - if os.path.isdir(os.path.join(sisyphus.filesystem.portageRepoDir, '.git')): - os.chdir(sisyphus.filesystem.portageRepoDir) - localBranch = subprocess.check_output(['git', 'rev-parse', '--abbrev-ref', 'HEAD']) - - if localBranch.decode().strip() == 'master': - activeBranch = str('master') - - if localBranch.decode().strip() == 'next': - activeBranch = str('next') - - return activeBranch - -def sanity(): - activeBranch = branch() - isBinhost = sisyphus.binhost.start() - isSane = int() - - if "packages-next" in isBinhost: - if activeBranch == "next": - isSane = int(1) - else: - isSane = int(0) - else: - if activeBranch == "master": - isSane = int(1) - else: - isSane = int(0) - - return isSane diff --git a/src/backend/checkEnvironment.py b/src/backend/checkEnvironment.py new file mode 100644 index 0000000..5a43780 --- /dev/null +++ b/src/backend/checkEnvironment.py @@ -0,0 +1,42 @@ +#!/usr/bin/python3 + +import os +import subprocess +import sisyphus.getBinhost +import sisyphus.getFilesystem + +def root(): + return True if os.getuid() == 0 else False + +def branch(): + activeBranch = None + + if os.path.isdir(os.path.join(sisyphus.getFilesystem.portageRepoDir, '.git')): + os.chdir(sisyphus.getFilesystem.portageRepoDir) + localBranch = subprocess.check_output(['git', 'rev-parse', '--abbrev-ref', 'HEAD']) + + if localBranch.decode().strip() == 'master': + activeBranch = str('master') + + if localBranch.decode().strip() == 'next': + activeBranch = str('next') + + return activeBranch + +def sanity(): + activeBranch = branch() + isBinhost = sisyphus.getBinhost.start() + isSane = int() + + if "packages-next" in isBinhost: + if activeBranch == "next": + isSane = int(1) + else: + isSane = int(0) + else: + if activeBranch == "master": + isSane = int(1) + else: + isSane = int(0) + + return isSane diff --git a/src/backend/csvfiles.py b/src/backend/csvfiles.py deleted file mode 100644 index 503ee84..0000000 --- a/src/backend/csvfiles.py +++ /dev/null @@ -1,17 +0,0 @@ -#!/usr/bin/python3 - -import sisyphus.binhost - -def start(): - isPackageCsv = [] - isDescriptionCsv = [] - isBinhost = sisyphus.binhost.start() - - if "packages-next" in isBinhost: - isPackageCsv = isBinhost.replace('packages-next', 'csv-next') + 'remotePackagesPre.csv' - isDescriptionCsv = isBinhost.replace('packages-next', 'csv-next') + 'remoteDescriptionsPre.csv' - else: - isPackageCsv = isBinhost.replace('packages', 'csv') + 'remotePackagesPre.csv' - isDescriptionCsv = isBinhost.replace('packages', 'csv') + 'remoteDescriptionsPre.csv' - - return isPackageCsv,isDescriptionCsv diff --git a/src/backend/database.py b/src/backend/database.py deleted file mode 100644 index e2ad380..0000000 --- a/src/backend/database.py +++ /dev/null @@ -1,57 +0,0 @@ -#!/usr/bin/python3 - -import csv -import shutil -import urllib3 -import sqlite3 -import subprocess -import sisyphus.csvfiles -import sisyphus.filesystem - -def getRemote(): - isPackageCsv,isDescriptionCsv = sisyphus.csvfiles.start() - http = urllib3.PoolManager() - - with http.request('GET', isPackageCsv, preload_content=False) as tmp_buffer, open(sisyphus.filesystem.remotePackagesCsv, 'wb') as output_file: - shutil.copyfileobj(tmp_buffer, output_file) - - with http.request('GET', isDescriptionCsv, preload_content=False) as tmp_buffer, open(sisyphus.filesystem.remoteDescriptionsCsv, 'wb') as output_file: - shutil.copyfileobj(tmp_buffer, output_file) - -def makeLocal(): - subprocess.call(['/usr/share/sisyphus/helpers/make_local_csv']) - -def syncRemote(): - getRemote() - - sisyphusdb = sqlite3.connect(sisyphus.filesystem.localDatabase) - sisyphusdb.cursor().execute('''drop table if exists remote_packages''') - sisyphusdb.cursor().execute('''drop table if exists remote_descriptions''') - sisyphusdb.cursor().execute('''create table remote_packages (category TEXT,name TEXT,version TEXT,slot TEXT)''') - sisyphusdb.cursor().execute('''create table remote_descriptions (category TEXT,name TEXT,description TEXT)''') - - with open(sisyphus.filesystem.remotePackagesCsv) as input_file: - for row in csv.reader(input_file): - sisyphusdb.cursor().execute("insert into remote_packages (category, name, version, slot) values (?, ?, ?, ?);", row) - - with open(sisyphus.filesystem.remoteDescriptionsCsv) as input_file: - for row in csv.reader(input_file): - sisyphusdb.cursor().execute("insert into remote_descriptions (category, name, description) values (?, ?, ?);", row) - - sisyphusdb.commit() - sisyphusdb.close() - -def syncLocal(): - makeLocal() - - sisyphusdb = sqlite3.connect(sisyphus.filesystem.localDatabase) - sisyphusdb.cursor().execute('''drop table if exists local_packages''') - sisyphusdb.cursor().execute('''create table local_packages (category TEXT,name TEXT,version TEXT,slot TEXT)''') - - with open(sisyphus.filesystem.localPackagesCsv) as input_file: - for row in csv.reader(input_file): - sisyphusdb.cursor().execute("insert into local_packages (category, name, version, slot) values (?, ?, ?, ?);", row) - - sisyphusdb.commit() - sisyphusdb.close() - diff --git a/src/backend/ebuildinstall.py b/src/backend/ebuildinstall.py deleted file mode 100644 index d194ac2..0000000 --- a/src/backend/ebuildinstall.py +++ /dev/null @@ -1,113 +0,0 @@ -#!/usr/bin/python3 - -import io -import os -import shutil -import subprocess -import sys -import wget -import sisyphus.binhost -import sisyphus.check -import sisyphus.database -import sisyphus.filesystem -import sisyphus.solvedeps -import sisyphus.update - -def start(pkgname): - if sisyphus.check.root(): - sisyphus.update.start() - - isBinhost = sisyphus.binhost.start() - areBinaries,areSources,needsConfig = sisyphus.solvedeps.package(pkgname) - - if needsConfig == 0: - if len(areSources) == 0: - if not len(areBinaries) == 0: - os.chdir(sisyphus.filesystem.portageCacheDir) - print("\n" + "These are the binary packages that would be merged, in order:" + "\n\n" + " ".join(areBinaries) + "\n\n" + "Total:" + " " + str(len(areBinaries)) + " " + "binary package(s)" + "\n") - if input("Would you like to proceed?" + " " + "[y/N]" + " ").lower().strip()[:1] == "y": - for index, binary in enumerate([package + '.tbz2' for package in areBinaries], start=1): - print(">>> Downloading binary ({}".format(index) + " " + "of" + " " + str(len(areBinaries)) + ")" + " " + binary) - wget.download(isBinhost + binary) - print("\n") - - if os.path.isdir(os.path.join(sisyphus.filesystem.portageCacheDir, binary.rstrip().split("/")[0])): - shutil.move(binary.rstrip().split("/")[1], os.path.join(os.path.join(sisyphus.filesystem.portageCacheDir, binary.rstrip().split("/")[0]), os.path.basename(binary.rstrip().split("/")[1]))) - else: - os.makedirs(os.path.join(sisyphus.filesystem.portageCacheDir, binary.rstrip().split("/")[0])) - shutil.move(binary.rstrip().split("/")[1], os.path.join(os.path.join(sisyphus.filesystem.portageCacheDir, binary.rstrip().split("/")[0]), os.path.basename(binary.rstrip().split("/")[1]))) - - if os.path.exists(binary.rstrip().split("/")[1]): - os.remove(binary.rstrip().split("/")[1]) - - portageExec = subprocess.Popen(['emerge', '--usepkg', '--usepkgonly', '--rebuilt-binaries', '--with-bdeps=y', '--misspell-suggestion=n', '--fuzzy-search=n'] + list(pkgname), stdout=subprocess.PIPE, stderr=subprocess.PIPE) - stdout, stderr = portageExec.communicate() - - for portageOutput in io.TextIOWrapper(portageExec.stdout, encoding="utf-8"): - if not "These are the packages that would be merged, in order:" in portageOutput.rstrip(): - if not "Calculating dependencies" in portageOutput.rstrip(): - print(portageOutput.rstrip()) - - sisyphus.database.syncLocal() - else: - sys.exit("\n" + "Ok; Quitting." + "\n") - else: - sys.exit("\n" + "No package found; Quitting." + "\n") - else: - if not len(areBinaries) == 0: - os.chdir(sisyphus.filesystem.portageCacheDir) - print("\n" + "These are the binary packages that would be merged, in order:" + "\n\n" + " ".join(areBinaries) + "\n\n" + "Total:" + " " + str(len(areBinaries)) + " " + "binary package(s)" + "\n") - print("\n" + "These are the source packages that would be merged, in order:" + "\n\n" + " ".join(areSources) + "\n\n" + "Total:" + " " + str(len(areSources)) + " " + "source package(s)" + "\n") - if input("Would you like to proceed?" + " " + "[y/N]" + " ").lower().strip()[:1] == "y": - for index, binary in enumerate([package + '.tbz2' for package in areBinaries], start=1): - print(">>> Downloading binary ({}".format(index) + " " + "of" + " " + str(len(areBinaries)) + ")" + " " + binary) - wget.download(isBinhost + binary) - print("\n") - - if os.path.isdir(os.path.join(sisyphus.filesystem.portageCacheDir, binary.rstrip().split("/")[0])): - shutil.move(binary.rstrip().split("/")[1], os.path.join(os.path.join(sisyphus.filesystem.portageCacheDir, binary.rstrip().split("/")[0]), os.path.basename(binary.rstrip().split("/")[1]))) - else: - os.makedirs(os.path.join(sisyphus.filesystem.portageCacheDir, binary.rstrip().split("/")[0])) - shutil.move(binary.rstrip().split("/")[1], os.path.join(os.path.join(sisyphus.filesystem.portageCacheDir, binary.rstrip().split("/")[0]), os.path.basename(binary.rstrip().split("/")[1]))) - - if os.path.exists(binary.rstrip().split("/")[1]): - os.remove(binary.rstrip().split("/")[1]) - - portageExec = subprocess.Popen(['emerge', '--usepkg', '--rebuilt-binaries', '--with-bdeps=y', '--misspell-suggestion=n', '--fuzzy-search=n'] + list(pkgname), stdout=subprocess.PIPE, stderr=subprocess.PIPE) - stdout, stderr = portageExec.communicate() - - for portageOutput in io.TextIOWrapper(portageExec.stdout, encoding="utf-8"): - if not "These are the packages that would be merged, in order:" in portageOutput.rstrip(): - if not "Calculating dependencies" in portageOutput.rstrip(): - print(portageOutput.rstrip()) - - sisyphus.database.syncLocal() - else: - sys.exit("\n" + "Ok; Quitting." + "\n") - else: - print("\n" + "These are the source packages that would be merged, in order:" + "\n\n" + " ".join(areSources) + "\n\n" + "Total:" + " " + str(len(areSources)) + " " + "source package(s)" + "\n") - if input("Would you like to proceed?" + " " + "[y/N]" + " ").lower().strip()[:1] == "y": - portageExec = subprocess.Popen(['emerge', '--with-bdeps=y', '--misspell-suggestion=n', '--fuzzy-search=n'] + list(pkgname), stdout=subprocess.PIPE, stderr=subprocess.PIPE) - stdout, stderr = portageExec.communicate() - - for portageOutput in io.TextIOWrapper(portageExec.stdout, encoding="utf-8"): - if not "These are the packages that would be merged, in order:" in portageOutput.rstrip(): - if not "Calculating dependencies" in portageOutput.rstrip(): - print(portageOutput.rstrip()) - - sisyphus.database.syncLocal() - else: - sys.exit("\n" + "Ok; Quitting." + "\n") - else: - portageExec = subprocess.Popen(['emerge', '--quiet', '--pretend', '--getbinpkg', '--rebuilt-binaries', '--with-bdeps=y', '--misspell-suggestion=n', '--fuzzy-search=n'] + list(pkgname), stdout=subprocess.PIPE, stderr=subprocess.PIPE) - stdout, stderr = portageExec.communicate() - - for portageOutput in io.TextIOWrapper(portageExec.stdout, encoding="utf-8"): - if not "Local copy of remote index is up-to-date and will be used." in portageOutput.rstrip(): - if not "ebuild" in portageOutput.rstrip(): - if not "binary" in portageOutput.rstrip(): - print(portageOutput.rstrip()) - - sys.exit("\n" + "Cannot proceed; Apply the above changes to your portage configuration files and try again; Quitting." + "\n") - else: - sys.exit("\nYou need root permissions to do this, exiting!\n") diff --git a/src/backend/ebuildsearch.py b/src/backend/ebuildsearch.py deleted file mode 100644 index c9b5862..0000000 --- a/src/backend/ebuildsearch.py +++ /dev/null @@ -1,6 +0,0 @@ -#!/usr/bin/python3 - -import subprocess - -def start(pkgname): - subprocess.call(['emerge', '--search', '--getbinpkg'] + list(pkgname)) diff --git a/src/backend/ebuildupgrade.py b/src/backend/ebuildupgrade.py deleted file mode 100644 index ae5d39b..0000000 --- a/src/backend/ebuildupgrade.py +++ /dev/null @@ -1,114 +0,0 @@ -#!/usr/bin/python3 - -import io -import os -import shutil -import subprocess -import sys -import wget -import sisyphus.binhost -import sisyphus.check -import sisyphus.database -import sisyphus.filesystem -import sisyphus.solvedeps -import sisyphus.update - -def start(): - if sisyphus.check.root(): - sisyphus.update.start() - - binhostURL = sisyphus.binhost.start() - areBinaries,areSources,needsConfig = sisyphus.solvedeps.world() - - if needsConfig == 0: - if len(areSources) == 0: - if not len(areBinaries) == 0: - os.chdir(sisyphus.filesystem.portageCacheDir) - print("\n" + "These are the binary packages that would be merged, in order:" + "\n\n" + " ".join(areBinaries) + "\n\n" + "Total:" + " " + str(len(areBinaries)) + " " + "binary package(s)" + "\n") - if input("Would you like to proceed?" + " " + "[y/N]" + " ").lower().strip()[:1] == "y": - for index, binary in enumerate([package + '.tbz2' for package in areBinaries], start=1): - print(">>> Downloading binary ({}".format(index) + " " + "of" + " " + str(len(areBinaries)) + ")" + " " + binary) - wget.download(binhostURL + binary) - print("\n") - - if os.path.isdir(os.path.join(sisyphus.filesystem.portageCacheDir, binary.rstrip().split("/")[0])): - shutil.move(binary.rstrip().split("/")[1], os.path.join(os.path.join(sisyphus.filesystem.portageCacheDir, binary.rstrip().split("/")[0]), os.path.basename(binary.rstrip().split("/")[1]))) - else: - os.makedirs(os.path.join(sisyphus.filesystem.portageCacheDir, binary.rstrip().split("/")[0])) - shutil.move(binary.rstrip().split("/")[1], os.path.join(os.path.join(sisyphus.filesystem.portageCacheDir, binary.rstrip().split("/")[0]), os.path.basename(binary.rstrip().split("/")[1]))) - - if os.path.exists(binary.rstrip().split("/")[1]): - os.remove(binary.rstrip().split("/")[1]) - - portageExec = subprocess.Popen(['emerge', '--update', '--deep', '--newuse', '--usepkg', '--usepkgonly', '--rebuilt-binaries', '--backtrack=100', '--with-bdeps=y', '--misspell-suggestion=n', '--fuzzy-search=n', '@world'], stdout=subprocess.PIPE, stderr=subprocess.PIPE) - stdout, stderr = portageExec.communicate() - - for portageOutput in io.TextIOWrapper(portageExec.stdout, encoding="utf-8"): - if not "These are the packages that would be merged, in order:" in portageOutput.rstrip(): - if not "Calculating dependencies" in portageOutput.rstrip(): - print(portageOutput.rstrip()) - - sisyphus.database.syncLocal() - else: - sys.exit("\n" + "Ok; Quitting." + "\n") - else: - sys.exit("\n" + "No package upgrades found; Quitting." + "\n") - else: - if not len(areBinaries) == 0: - os.chdir(sisyphus.filesystem.portageCacheDir) - print("\n" + "These are the binary packages that would be merged, in order:" + "\n\n" + " ".join(areBinaries) + "\n\n" + "Total:" + " " + str(len(areBinaries)) + " " + "binary package(s)" + "\n") - print("\n" + "These are the source packages that would be merged, in order:" + "\n\n" + " ".join(areSources) + "\n\n" + "Total:" + " " + str(len(areSources)) + " " + "source package(s)" + "\n") - if input("Would you like to proceed?" + " " + "[y/N]" + " ").lower().strip()[:1] == "y": - for index, binary in enumerate([package + '.tbz2' for package in areBinaries], start=1): - print(">>> Downloading binary ({}".format(index) + " " + "of" + " " + str(len(areBinaries)) + ")" + " " + binary) - wget.download(binhostURL + binary) - print("\n") - - if os.path.isdir(os.path.join(sisyphus.filesystem.portageCacheDir, binary.rstrip().split("/")[0])): - shutil.move(binary.rstrip().split("/")[1], os.path.join(os.path.join(sisyphus.filesystem.portageCacheDir, binary.rstrip().split("/")[0]), os.path.basename(binary.rstrip().split("/")[1]))) - else: - os.makedirs(os.path.join(sisyphus.filesystem.portageCacheDir, binary.rstrip().split("/")[0])) - shutil.move(binary.rstrip().split("/")[1], os.path.join(os.path.join(sisyphus.filesystem.portageCacheDir, binary.rstrip().split("/")[0]), os.path.basename(binary.rstrip().split("/")[1]))) - - if os.path.exists(binary.rstrip().split("/")[1]): - os.remove(binary.rstrip().split("/")[1]) - - portageExec = subprocess.Popen(['emerge', '--update', '--deep', '--newuse', '--usepkg', '--rebuilt-binaries', '--backtrack=100', '--with-bdeps=y', '--misspell-suggestion=n', '--fuzzy-search=n', '@world'], stdout=subprocess.PIPE, stderr=subprocess.PIPE) - stdout, stderr = portageExec.communicate() - - for portageOutput in io.TextIOWrapper(portageExec.stdout, encoding="utf-8"): - if not "These are the packages that would be merged, in order:" in portageOutput.rstrip(): - if not "Calculating dependencies" in portageOutput.rstrip(): - print(portageOutput.rstrip()) - - sisyphus.database.syncLocal() - else: - sys.exit("\n" + "Ok; Quitting." + "\n") - else: - print("\n" + "These are the source packages that would be merged, in order:" + "\n\n" + " ".join(areSources) + "\n\n" + "Total:" + " " + str(len(areSources)) + " " + "source package(s)" + "\n") - if input("Would you like to proceed?" + " " + "[y/N]" + " ").lower().strip()[:1] == "y": - portageExec = subprocess.Popen(['emerge', '--update', '--deep', '--newuse', '--backtrack=100', '--with-bdeps=y', '--misspell-suggestion=n', '--fuzzy-search=n', '@world'], stdout=subprocess.PIPE, stderr=subprocess.PIPE) - stdout, stderr = portageExec.communicate() - - for portageOutput in io.TextIOWrapper(portageExec.stdout, encoding="utf-8"): - if not "These are the packages that would be merged, in order:" in portageOutput.rstrip(): - if not "Calculating dependencies" in portageOutput.rstrip(): - print(portageOutput.rstrip()) - - sisyphus.database.syncLocal() - else: - sys.exit("\n" + "Ok; Quitting." + "\n") - else: - portageExec = subprocess.Popen(['emerge', '--quiet', '--update', '--deep', '--newuse', '--pretend', '--getbinpkg', '--rebuilt-binaries', '--backtrack=100', '--with-bdeps=y', '--misspell-suggestion=n', '--fuzzy-search=n', '@world'], stdout=subprocess.PIPE, stderr=subprocess.PIPE) - stdout, stderr = portageExec.communicate() - - for portageOutput in io.TextIOWrapper(portageExec.stdout, encoding="utf-8"): - if not "Local copy of remote index is up-to-date and will be used." in portageOutput.rstrip(): - if not "ebuild" in portageOutput.rstrip(): - if not "binary" in portageOutput.rstrip(): - print(portageOutput.rstrip()) - - sys.exit("\n" + "Cannot proceed; Apply the above changes to your portage configuration files and try again; Quitting." + "\n") - else: - sys.exit("\nYou need root permissions to do this, exiting!\n") - diff --git a/src/backend/filesystem.py b/src/backend/filesystem.py deleted file mode 100644 index 4934108..0000000 --- a/src/backend/filesystem.py +++ /dev/null @@ -1,28 +0,0 @@ -#!/usr/bin/python3 - -import platform - -remoteGitlab = 'https://gitlab.com/redcore' -remotePagure = 'https://pagure.io/redcore' - -portageRepo = 'portage.git' -redcoreRepo = 'redcore-desktop.git' -portageConfigRepo = 'redcore-build.git' - -portageRepoDir = '/usr/ports/gentoo' -redcoreRepoDir = '/usr/ports/redcore' -portageConfigDir = '/opt/redcore-build' -portageCacheDir = '/var/cache/packages' -portageMetadataDir = '/var/cache/edb' - -remotePackagesCsv = '/var/lib/sisyphus/csv/remotePackagesPre.csv' -remoteDescriptionsCsv = '/var/lib/sisyphus/csv/remoteDescriptionsPre.csv' -localPackagesCsv = '/var/lib/sisyphus/csv/localPackagesPre.csv' - -localDatabase = '/var/lib/sisyphus/db/sisyphus.db' - -if platform.uname()[4] == 'x86_64': - mirrorCfg = '/etc/sisyphus/sisyphus-mirrors-amd64.conf' - -if platform.uname()[4] == 'aarch64': - mirrorCfg = '/etc/sisyphus/sisyphus-mirrors-arm64.conf' diff --git a/src/backend/forceuninstall.py b/src/backend/forceuninstall.py deleted file mode 100644 index 9329695..0000000 --- a/src/backend/forceuninstall.py +++ /dev/null @@ -1,14 +0,0 @@ -#!/usr/bin/python3 - -import subprocess -import sys -import sisyphus.check -import sisyphus.database - -def start(pkgname): - if sisyphus.check.root(): - portageExec = subprocess.Popen(['emerge', '--quiet', '--unmerge', '--ask'] + list(pkgname), stdout=subprocess.PIPE, stderr=subprocess.PIPE) - stdout, stderr = portageExec.communicate() - sisyphus.database.syncLocal() - else: - sys.exit("\nYou need root permissions to do this, exiting!\n") diff --git a/src/backend/getBinhost.py b/src/backend/getBinhost.py new file mode 100644 index 0000000..3de4fca --- /dev/null +++ b/src/backend/getBinhost.py @@ -0,0 +1,15 @@ +#!/usr/bin/python3 + +import io +import subprocess + +def start(): + isBinhost = [] + portageExec = subprocess.Popen(['emerge', '--info', '--verbose'], stdout=subprocess.PIPE, stderr=subprocess.PIPE) + stdout, stderr = portageExec.communicate() + + for portageOutput in io.TextIOWrapper(portageExec.stdout, encoding="utf-8"): + if "PORTAGE_BINHOST" in portageOutput.rstrip(): + isBinhost = str(portageOutput.rstrip().split("=")[1].strip('\"')) + + return isBinhost diff --git a/src/backend/getCSV.py b/src/backend/getCSV.py new file mode 100644 index 0000000..798f163 --- /dev/null +++ b/src/backend/getCSV.py @@ -0,0 +1,17 @@ +#!/usr/bin/python3 + +import sisyphus.getBinhost + +def start(): + isPackageCsv = [] + isDescriptionCsv = [] + isBinhost = sisyphus.getBinhost.start() + + if "packages-next" in isBinhost: + isPackageCsv = isBinhost.replace('packages-next', 'csv-next') + 'remotePackagesPre.csv' + isDescriptionCsv = isBinhost.replace('packages-next', 'csv-next') + 'remoteDescriptionsPre.csv' + else: + isPackageCsv = isBinhost.replace('packages', 'csv') + 'remotePackagesPre.csv' + isDescriptionCsv = isBinhost.replace('packages', 'csv') + 'remoteDescriptionsPre.csv' + + return isPackageCsv,isDescriptionCsv diff --git a/src/backend/getFilesystem.py b/src/backend/getFilesystem.py new file mode 100644 index 0000000..4934108 --- /dev/null +++ b/src/backend/getFilesystem.py @@ -0,0 +1,28 @@ +#!/usr/bin/python3 + +import platform + +remoteGitlab = 'https://gitlab.com/redcore' +remotePagure = 'https://pagure.io/redcore' + +portageRepo = 'portage.git' +redcoreRepo = 'redcore-desktop.git' +portageConfigRepo = 'redcore-build.git' + +portageRepoDir = '/usr/ports/gentoo' +redcoreRepoDir = '/usr/ports/redcore' +portageConfigDir = '/opt/redcore-build' +portageCacheDir = '/var/cache/packages' +portageMetadataDir = '/var/cache/edb' + +remotePackagesCsv = '/var/lib/sisyphus/csv/remotePackagesPre.csv' +remoteDescriptionsCsv = '/var/lib/sisyphus/csv/remoteDescriptionsPre.csv' +localPackagesCsv = '/var/lib/sisyphus/csv/localPackagesPre.csv' + +localDatabase = '/var/lib/sisyphus/db/sisyphus.db' + +if platform.uname()[4] == 'x86_64': + mirrorCfg = '/etc/sisyphus/sisyphus-mirrors-amd64.conf' + +if platform.uname()[4] == 'aarch64': + mirrorCfg = '/etc/sisyphus/sisyphus-mirrors-arm64.conf' diff --git a/src/backend/install.py b/src/backend/install.py deleted file mode 100644 index c9b2d67..0000000 --- a/src/backend/install.py +++ /dev/null @@ -1,96 +0,0 @@ -#!/usr/bin/python3 - -import atexit -import io -import os -import shutil -import subprocess -import sys -import wget -import sisyphus.binhost -import sisyphus.check -import sisyphus.database -import sisyphus.filesystem -import sisyphus.killportage -import sisyphus.solvedeps -import sisyphus.update - -def start(pkgname): - if sisyphus.check.root(): - sisyphus.update.start() - - isBinhost = sisyphus.binhost.start() - areBinaries,areSources,needsConfig = sisyphus.solvedeps.package(pkgname) - - if needsConfig == 0: - if len(areSources) == 0: - if not len(areBinaries) == 0: - os.chdir(sisyphus.filesystem.portageCacheDir) - print("\n" + "These are the binary packages that would be merged, in order:" + "\n\n" + " ".join(areBinaries) + "\n\n" + "Total:" + " " + str(len(areBinaries)) + " " + "binary package(s)" + "\n") - if input("Would you like to proceed?" + " " + "[y/N]" + " ").lower().strip()[:1] == "y": - for index, binary in enumerate([package + '.tbz2' for package in areBinaries], start=1): - print(">>> Downloading binary ({}".format(index) + " " + "of" + " " + str(len(areBinaries)) + ")" + " " + binary) - wget.download(isBinhost + binary) - print("\n") - - if os.path.isdir(os.path.join(sisyphus.filesystem.portageCacheDir, binary.rstrip().split("/")[0])): - shutil.move(binary.rstrip().split("/")[1], os.path.join(os.path.join(sisyphus.filesystem.portageCacheDir, binary.rstrip().split("/")[0]), os.path.basename(binary.rstrip().split("/")[1]))) - else: - os.makedirs(os.path.join(sisyphus.filesystem.portageCacheDir, binary.rstrip().split("/")[0])) - shutil.move(binary.rstrip().split("/")[1], os.path.join(os.path.join(sisyphus.filesystem.portageCacheDir, binary.rstrip().split("/")[0]), os.path.basename(binary.rstrip().split("/")[1]))) - - if os.path.exists(binary.rstrip().split("/")[1]): - os.remove(binary.rstrip().split("/")[1]) - - portageExec = subprocess.Popen(['emerge', '--usepkg', '--usepkgonly', '--rebuilt-binaries', '--with-bdeps=y', '--misspell-suggestion=n', '--fuzzy-search=n'] + list(pkgname), stdout=subprocess.PIPE, stderr=subprocess.PIPE) - stdout, stderr = portageExec.communicate() - - for portageOutput in io.TextIOWrapper(portageExec.stdout, encoding="utf-8"): - if not "These are the packages that would be merged, in order:" in portageOutput.rstrip(): - if not "Calculating dependencies" in portageOutput.rstrip(): - print(portageOutput.rstrip()) - - sisyphus.database.syncLocal() - else: - sys.exit("\n" + "Ok; Quitting." + "\n") - else: - sys.exit("\n" + "No package found; Quitting." + "\n") - else: - sys.exit("\n" + "Source package(s) found in the mix;" + " " + "Use" + " " + "'" + "sisyphus install" + " " + " ".join(pkgname) + " " + "--ebuild" + "'" + ";" + " " + "Quitting." + "\n") - else: - # don't silently fail if a source package requested without the --ebuild option needs a keyword, mask, REQUIRED_USE or USE change - sys.exit("\n" + "Invalid request;" " " + "Use" + " " + "'" + "sisyphus install" + " " + " ".join(pkgname) + " " + "--ebuild" + "'" + ";" + " " + "Quitting." + "\n") - else: - sys.exit("\nYou need root permissions to do this, exiting!\n") - -def startqt(pkgname): - isBinhost = sisyphus.binhost.start() - areBinaries,areSources,needsConfig = sisyphus.solvedeps.package.__wrapped__(pkgname) #undecorate - - os.chdir(sisyphus.filesystem.portageCacheDir) - print("\n" + "These are the binary packages that will be merged, in order:" + "\n\n" + " ".join(areBinaries) + "\n\n" + "Total:" + " " + str(len(areBinaries)) + " " + "binary package(s)" + "\n\n") - for index, binary in enumerate([package + '.tbz2' for package in areBinaries], start=1): - print(">>> Downloading binary ({}".format(index) + " " + "of" + " " + str(len(areBinaries)) + ")" + " " + binary) - wget.download(isBinhost + binary) - print("\n") - - if os.path.isdir(os.path.join(sisyphus.filesystem.portageCacheDir, binary.rstrip().split("/")[0])): - shutil.move(binary.rstrip().split("/")[1], os.path.join(os.path.join(sisyphus.filesystem.portageCacheDir, binary.rstrip().split("/")[0]), os.path.basename(binary.rstrip().split("/")[1]))) - else: - os.makedirs(os.path.join(sisyphus.filesystem.portageCacheDir, binary.rstrip().split("/")[0])) - shutil.move(binary.rstrip().split("/")[1], os.path.join(os.path.join(sisyphus.filesystem.portageCacheDir, binary.rstrip().split("/")[0]), os.path.basename(binary.rstrip().split("/")[1]))) - - if os.path.exists(binary.rstrip().split("/")[1]): - os.remove(binary.rstrip().split("/")[1]) - - portageExec = subprocess.Popen(['emerge', '--usepkg', '--usepkgonly', '--rebuilt-binaries', '--with-bdeps=y', '--misspell-suggestion=n', '--fuzzy-search=n'] + pkgname, stdout=subprocess.PIPE, stderr=subprocess.PIPE) - stdout, stderr = portageExec.communicate() - # kill portage if the program dies or it's terminated by the user - atexit.register(sisyphus.killportage.start, portageExec) - - for portageOutput in io.TextIOWrapper(portageExec.stdout, encoding="utf-8"): - if not "These are the packages that would be merged, in order:" in portageOutput.rstrip(): - if not "Calculating dependencies" in portageOutput.rstrip(): - print(portageOutput.rstrip()) - - sisyphus.database.syncLocal() diff --git a/src/backend/installPkg.py b/src/backend/installPkg.py new file mode 100644 index 0000000..480e346 --- /dev/null +++ b/src/backend/installPkg.py @@ -0,0 +1,96 @@ +#!/usr/bin/python3 + +import atexit +import io +import os +import shutil +import subprocess +import sys +import wget +import sisyphus.getBinhost +import sisyphus.checkEnvironment +import sisyphus.syncDatabase +import sisyphus.getFilesystem +import sisyphus.killPortage +import sisyphus.resolveDeps +import sisyphus.updateAll + +def start(pkgname): + if sisyphus.checkEnvironment.root(): + sisyphus.updateAll.start() + + isBinhost = sisyphus.getBinhost.start() + areBinaries,areSources,needsConfig = sisyphus.resolveDeps.package(pkgname) + + if needsConfig == 0: + if len(areSources) == 0: + if not len(areBinaries) == 0: + os.chdir(sisyphus.getFilesystem.portageCacheDir) + print("\n" + "These are the binary packages that would be merged, in order:" + "\n\n" + " ".join(areBinaries) + "\n\n" + "Total:" + " " + str(len(areBinaries)) + " " + "binary package(s)" + "\n") + if input("Would you like to proceed?" + " " + "[y/N]" + " ").lower().strip()[:1] == "y": + for index, binary in enumerate([package + '.tbz2' for package in areBinaries], start=1): + print(">>> Downloading binary ({}".format(index) + " " + "of" + " " + str(len(areBinaries)) + ")" + " " + binary) + wget.download(isBinhost + binary) + print("\n") + + if os.path.isdir(os.path.join(sisyphus.getFilesystem.portageCacheDir, binary.rstrip().split("/")[0])): + shutil.move(binary.rstrip().split("/")[1], os.path.join(os.path.join(sisyphus.getFilesystem.portageCacheDir, binary.rstrip().split("/")[0]), os.path.basename(binary.rstrip().split("/")[1]))) + else: + os.makedirs(os.path.join(sisyphus.getFilesystem.portageCacheDir, binary.rstrip().split("/")[0])) + shutil.move(binary.rstrip().split("/")[1], os.path.join(os.path.join(sisyphus.getFilesystem.portageCacheDir, binary.rstrip().split("/")[0]), os.path.basename(binary.rstrip().split("/")[1]))) + + if os.path.exists(binary.rstrip().split("/")[1]): + os.remove(binary.rstrip().split("/")[1]) + + portageExec = subprocess.Popen(['emerge', '--usepkg', '--usepkgonly', '--rebuilt-binaries', '--with-bdeps=y', '--misspell-suggestion=n', '--fuzzy-search=n'] + list(pkgname), stdout=subprocess.PIPE, stderr=subprocess.PIPE) + stdout, stderr = portageExec.communicate() + + for portageOutput in io.TextIOWrapper(portageExec.stdout, encoding="utf-8"): + if not "These are the packages that would be merged, in order:" in portageOutput.rstrip(): + if not "Calculating dependencies" in portageOutput.rstrip(): + print(portageOutput.rstrip()) + + sisyphus.syncDatabase.syncLocal() + else: + sys.exit("\n" + "Ok; Quitting." + "\n") + else: + sys.exit("\n" + "No package found; Quitting." + "\n") + else: + sys.exit("\n" + "Source package(s) found in the mix;" + " " + "Use" + " " + "'" + "sisyphus install" + " " + " ".join(pkgname) + " " + "--ebuild" + "'" + ";" + " " + "Quitting." + "\n") + else: + # don't silently fail if a source package requested without the --ebuild option needs a keyword, mask, REQUIRED_USE or USE change + sys.exit("\n" + "Invalid request;" " " + "Use" + " " + "'" + "sisyphus install" + " " + " ".join(pkgname) + " " + "--ebuild" + "'" + ";" + " " + "Quitting." + "\n") + else: + sys.exit("\nYou need root permissions to do this, exiting!\n") + +def startqt(pkgname): + isBinhost = sisyphus.getBinhost.start() + areBinaries,areSources,needsConfig = sisyphus.resolveDeps.package.__wrapped__(pkgname) #undecorate + + os.chdir(sisyphus.getFilesystem.portageCacheDir) + print("\n" + "These are the binary packages that will be merged, in order:" + "\n\n" + " ".join(areBinaries) + "\n\n" + "Total:" + " " + str(len(areBinaries)) + " " + "binary package(s)" + "\n\n") + for index, binary in enumerate([package + '.tbz2' for package in areBinaries], start=1): + print(">>> Downloading binary ({}".format(index) + " " + "of" + " " + str(len(areBinaries)) + ")" + " " + binary) + wget.download(isBinhost + binary) + print("\n") + + if os.path.isdir(os.path.join(sisyphus.getFilesystem.portageCacheDir, binary.rstrip().split("/")[0])): + shutil.move(binary.rstrip().split("/")[1], os.path.join(os.path.join(sisyphus.getFilesystem.portageCacheDir, binary.rstrip().split("/")[0]), os.path.basename(binary.rstrip().split("/")[1]))) + else: + os.makedirs(os.path.join(sisyphus.getFilesystem.portageCacheDir, binary.rstrip().split("/")[0])) + shutil.move(binary.rstrip().split("/")[1], os.path.join(os.path.join(sisyphus.getFilesystem.portageCacheDir, binary.rstrip().split("/")[0]), os.path.basename(binary.rstrip().split("/")[1]))) + + if os.path.exists(binary.rstrip().split("/")[1]): + os.remove(binary.rstrip().split("/")[1]) + + portageExec = subprocess.Popen(['emerge', '--usepkg', '--usepkgonly', '--rebuilt-binaries', '--with-bdeps=y', '--misspell-suggestion=n', '--fuzzy-search=n'] + pkgname, stdout=subprocess.PIPE, stderr=subprocess.PIPE) + stdout, stderr = portageExec.communicate() + # kill portage if the program dies or it's terminated by the user + atexit.register(sisyphus.killPortage.start, portageExec) + + for portageOutput in io.TextIOWrapper(portageExec.stdout, encoding="utf-8"): + if not "These are the packages that would be merged, in order:" in portageOutput.rstrip(): + if not "Calculating dependencies" in portageOutput.rstrip(): + print(portageOutput.rstrip()) + + sisyphus.syncDatabase.syncLocal() diff --git a/src/backend/installSrc.py b/src/backend/installSrc.py new file mode 100644 index 0000000..5ff5958 --- /dev/null +++ b/src/backend/installSrc.py @@ -0,0 +1,113 @@ +#!/usr/bin/python3 + +import io +import os +import shutil +import subprocess +import sys +import wget +import sisyphus.getBinhost +import sisyphus.checkEnvironment +import sisyphus.syncDatabase +import sisyphus.getFilesystem +import sisyphus.resolveDeps +import sisyphus.updateAll + +def start(pkgname): + if sisyphus.checkEnvironment.root(): + sisyphus.updateAll.start() + + isBinhost = sisyphus.getBinhost.start() + areBinaries,areSources,needsConfig = sisyphus.resolveDeps.package(pkgname) + + if needsConfig == 0: + if len(areSources) == 0: + if not len(areBinaries) == 0: + os.chdir(sisyphus.getFilesystem.portageCacheDir) + print("\n" + "These are the binary packages that would be merged, in order:" + "\n\n" + " ".join(areBinaries) + "\n\n" + "Total:" + " " + str(len(areBinaries)) + " " + "binary package(s)" + "\n") + if input("Would you like to proceed?" + " " + "[y/N]" + " ").lower().strip()[:1] == "y": + for index, binary in enumerate([package + '.tbz2' for package in areBinaries], start=1): + print(">>> Downloading binary ({}".format(index) + " " + "of" + " " + str(len(areBinaries)) + ")" + " " + binary) + wget.download(isBinhost + binary) + print("\n") + + if os.path.isdir(os.path.join(sisyphus.getFilesystem.portageCacheDir, binary.rstrip().split("/")[0])): + shutil.move(binary.rstrip().split("/")[1], os.path.join(os.path.join(sisyphus.getFilesystem.portageCacheDir, binary.rstrip().split("/")[0]), os.path.basename(binary.rstrip().split("/")[1]))) + else: + os.makedirs(os.path.join(sisyphus.getFilesystem.portageCacheDir, binary.rstrip().split("/")[0])) + shutil.move(binary.rstrip().split("/")[1], os.path.join(os.path.join(sisyphus.getFilesystem.portageCacheDir, binary.rstrip().split("/")[0]), os.path.basename(binary.rstrip().split("/")[1]))) + + if os.path.exists(binary.rstrip().split("/")[1]): + os.remove(binary.rstrip().split("/")[1]) + + portageExec = subprocess.Popen(['emerge', '--usepkg', '--usepkgonly', '--rebuilt-binaries', '--with-bdeps=y', '--misspell-suggestion=n', '--fuzzy-search=n'] + list(pkgname), stdout=subprocess.PIPE, stderr=subprocess.PIPE) + stdout, stderr = portageExec.communicate() + + for portageOutput in io.TextIOWrapper(portageExec.stdout, encoding="utf-8"): + if not "These are the packages that would be merged, in order:" in portageOutput.rstrip(): + if not "Calculating dependencies" in portageOutput.rstrip(): + print(portageOutput.rstrip()) + + sisyphus.syncDatabase.syncLocal() + else: + sys.exit("\n" + "Ok; Quitting." + "\n") + else: + sys.exit("\n" + "No package found; Quitting." + "\n") + else: + if not len(areBinaries) == 0: + os.chdir(sisyphus.getFilesystem.portageCacheDir) + print("\n" + "These are the binary packages that would be merged, in order:" + "\n\n" + " ".join(areBinaries) + "\n\n" + "Total:" + " " + str(len(areBinaries)) + " " + "binary package(s)" + "\n") + print("\n" + "These are the source packages that would be merged, in order:" + "\n\n" + " ".join(areSources) + "\n\n" + "Total:" + " " + str(len(areSources)) + " " + "source package(s)" + "\n") + if input("Would you like to proceed?" + " " + "[y/N]" + " ").lower().strip()[:1] == "y": + for index, binary in enumerate([package + '.tbz2' for package in areBinaries], start=1): + print(">>> Downloading binary ({}".format(index) + " " + "of" + " " + str(len(areBinaries)) + ")" + " " + binary) + wget.download(isBinhost + binary) + print("\n") + + if os.path.isdir(os.path.join(sisyphus.getFilesystem.portageCacheDir, binary.rstrip().split("/")[0])): + shutil.move(binary.rstrip().split("/")[1], os.path.join(os.path.join(sisyphus.getFilesystem.portageCacheDir, binary.rstrip().split("/")[0]), os.path.basename(binary.rstrip().split("/")[1]))) + else: + os.makedirs(os.path.join(sisyphus.getFilesystem.portageCacheDir, binary.rstrip().split("/")[0])) + shutil.move(binary.rstrip().split("/")[1], os.path.join(os.path.join(sisyphus.getFilesystem.portageCacheDir, binary.rstrip().split("/")[0]), os.path.basename(binary.rstrip().split("/")[1]))) + + if os.path.exists(binary.rstrip().split("/")[1]): + os.remove(binary.rstrip().split("/")[1]) + + portageExec = subprocess.Popen(['emerge', '--usepkg', '--rebuilt-binaries', '--with-bdeps=y', '--misspell-suggestion=n', '--fuzzy-search=n'] + list(pkgname), stdout=subprocess.PIPE, stderr=subprocess.PIPE) + stdout, stderr = portageExec.communicate() + + for portageOutput in io.TextIOWrapper(portageExec.stdout, encoding="utf-8"): + if not "These are the packages that would be merged, in order:" in portageOutput.rstrip(): + if not "Calculating dependencies" in portageOutput.rstrip(): + print(portageOutput.rstrip()) + + sisyphus.syncDatabase.syncLocal() + else: + sys.exit("\n" + "Ok; Quitting." + "\n") + else: + print("\n" + "These are the source packages that would be merged, in order:" + "\n\n" + " ".join(areSources) + "\n\n" + "Total:" + " " + str(len(areSources)) + " " + "source package(s)" + "\n") + if input("Would you like to proceed?" + " " + "[y/N]" + " ").lower().strip()[:1] == "y": + portageExec = subprocess.Popen(['emerge', '--with-bdeps=y', '--misspell-suggestion=n', '--fuzzy-search=n'] + list(pkgname), stdout=subprocess.PIPE, stderr=subprocess.PIPE) + stdout, stderr = portageExec.communicate() + + for portageOutput in io.TextIOWrapper(portageExec.stdout, encoding="utf-8"): + if not "These are the packages that would be merged, in order:" in portageOutput.rstrip(): + if not "Calculating dependencies" in portageOutput.rstrip(): + print(portageOutput.rstrip()) + + sisyphus.syncDatabase.syncLocal() + else: + sys.exit("\n" + "Ok; Quitting." + "\n") + else: + portageExec = subprocess.Popen(['emerge', '--quiet', '--pretend', '--getbinpkg', '--rebuilt-binaries', '--with-bdeps=y', '--misspell-suggestion=n', '--fuzzy-search=n'] + list(pkgname), stdout=subprocess.PIPE, stderr=subprocess.PIPE) + stdout, stderr = portageExec.communicate() + + for portageOutput in io.TextIOWrapper(portageExec.stdout, encoding="utf-8"): + if not "Local copy of remote index is up-to-date and will be used." in portageOutput.rstrip(): + if not "ebuild" in portageOutput.rstrip(): + if not "binary" in portageOutput.rstrip(): + print(portageOutput.rstrip()) + + sys.exit("\n" + "Cannot proceed; Apply the above changes to your portage configuration files and try again; Quitting." + "\n") + else: + sys.exit("\nYou need root permissions to do this, exiting!\n") diff --git a/src/backend/killPortage.py b/src/backend/killPortage.py new file mode 100644 index 0000000..f01af6b --- /dev/null +++ b/src/backend/killPortage.py @@ -0,0 +1,4 @@ +#!/usr/bin/python3 + +def start(portageCmd): + portageCmd.terminate() diff --git a/src/backend/killportage.py b/src/backend/killportage.py deleted file mode 100644 index f01af6b..0000000 --- a/src/backend/killportage.py +++ /dev/null @@ -1,4 +0,0 @@ -#!/usr/bin/python3 - -def start(portageCmd): - portageCmd.terminate() diff --git a/src/backend/mirror.py b/src/backend/mirror.py deleted file mode 100644 index e2b7f26..0000000 --- a/src/backend/mirror.py +++ /dev/null @@ -1,59 +0,0 @@ -#!/usr/bin/python3 - -import sisyphus.filesystem - -def getList(): - mirrorList = [] - - with open(sisyphus.filesystem.mirrorCfg) as mirrorFile: - for line in mirrorFile.readlines(): - if 'PORTAGE_BINHOST=' in line: - url = line.split("=")[1].replace('"', '').rstrip() - mirror = {'isActive': True, 'Url': url} - if line.startswith('#'): - mirror['isActive'] = False - mirrorList.append(mirror) - mirrorFile.close() - - return mirrorList - -def printList(): - mirrorList = getList() - - for i, line in enumerate(mirrorList): - if line['isActive']: - print(i + 1, '*', line['Url']) - else: - print(i + 1, ' ', line['Url']) - -def writeList(mirrorList): - with open(sisyphus.filesystem.mirrorCfg, 'w+') as mirrorFile: - mirrorFile.write("#######################################################\n") - mirrorFile.write("# Support for multiple mirrors is somewhat incomplete #\n") - mirrorFile.write("#######################################################\n") - mirrorFile.write("# Please avoid using the Main Repository #\n") - mirrorFile.write("# http://mirrors.redcorelinux.org/redcorelinux #\n") - mirrorFile.write("# as the bandwidth is limited, use mirrors instead #\n") - mirrorFile.write("#######################################################\n") - mirrorFile.write("# Uncomment only one mirror from the list bellow #\n") - mirrorFile.write("#######################################################\n") - mirrorFile.write("\n") - for line in mirrorList: - mirror = 'PORTAGE_BINHOST=' + '"' + line['Url'] + '"' - if not line['isActive']: - mirror = '# ' + mirror - mirrorFile.write(mirror + "\n") - mirrorFile.write("\n") - -def setActive(mirror): - mirrorList = getList() - if mirror not in range(1, len(mirrorList) + 1): - print("\n" + "Mirror index is wrong, please check with sisyphus mirror list" + "\n") - else: - for i in range(0, len(mirrorList)): - indx = i + 1 - if indx == mirror: - mirrorList[i]['isActive'] = True - else: - mirrorList[i]['isActive'] = False - writeList(mirrorList) diff --git a/src/backend/purge.py b/src/backend/purge.py deleted file mode 100644 index 3a94cff..0000000 --- a/src/backend/purge.py +++ /dev/null @@ -1,51 +0,0 @@ -#!/usr/bin/python3 - -import animation -import os -import shutil -import sisyphus.filesystem - -@animation.wait('purging branch configuration') -def branch(): - if os.path.isdir(sisyphus.filesystem.portageRepoDir): - for files in os.listdir(sisyphus.filesystem.portageRepoDir): - if os.path.isfile(os.path.join(sisyphus.filesystem.portageRepoDir, files)): - os.remove(os.path.join(sisyphus.filesystem.portageRepoDir, files)) - else: - shutil.rmtree(os.path.join(sisyphus.filesystem.portageRepoDir, files)) - else: - os.makedirs(sisyphus.filesystem.portageRepoDir) - - if os.path.isdir(sisyphus.filesystem.redcoreRepoDir): - for files in os.listdir(sisyphus.filesystem.redcoreRepoDir): - if os.path.isfile(os.path.join(sisyphus.filesystem.redcoreRepoDir, files)): - os.remove(os.path.join(sisyphus.filesystem.redcoreRepoDir, files)) - else: - shutil.rmtree(os.path.join(sisyphus.filesystem.redcoreRepoDir, files)) - else: - os.makedirs(sisyphus.filesystem.redcoreRepoDir) - - if os.path.isdir(sisyphus.filesystem.portageConfigDir): - for files in os.listdir(sisyphus.filesystem.portageConfigDir): - if os.path.isfile(os.path.join(sisyphus.filesystem.portageConfigDir, files)): - os.remove(os.path.join(sisyphus.filesystem.portageConfigDir, files)) - else: - shutil.rmtree(os.path.join(sisyphus.filesystem.portageConfigDir, files)) - else: - os.makedirs(sisyphus.filesystem.portageConfigDir) - -def cache(): - if os.path.isdir(sisyphus.filesystem.portageCacheDir): - for files in os.listdir(sisyphus.filesystem.portageCacheDir): - if os.path.isfile(os.path.join(sisyphus.filesystem.portageCacheDir, files)): - os.remove(os.path.join(sisyphus.filesystem.portageCacheDir, files)) - else: - shutil.rmtree(os.path.join(sisyphus.filesystem.portageCacheDir, files)) - -def metadata(): - if os.path.isdir(sisyphus.filesystem.portageMetadataDir): - for files in os.listdir(sisyphus.filesystem.portageMetadataDir): - if os.path.isfile(os.path.join(sisyphus.filesystem.portageMetadataDir, files)): - os.remove(os.path.join(sisyphus.filesystem.portageMetadataDir, files)) - else: - shutil.rmtree(os.path.join(sisyphus.filesystem.portageMetadataDir, files)) diff --git a/src/backend/purgeEnvironment.py b/src/backend/purgeEnvironment.py new file mode 100644 index 0000000..0eba801 --- /dev/null +++ b/src/backend/purgeEnvironment.py @@ -0,0 +1,51 @@ +#!/usr/bin/python3 + +import animation +import os +import shutil +import sisyphus.getFilesystem + +@animation.wait('purging branch configuration') +def branch(): + if os.path.isdir(sisyphus.getFilesystem.portageRepoDir): + for files in os.listdir(sisyphus.getFilesystem.portageRepoDir): + if os.path.isfile(os.path.join(sisyphus.getFilesystem.portageRepoDir, files)): + os.remove(os.path.join(sisyphus.getFilesystem.portageRepoDir, files)) + else: + shutil.rmtree(os.path.join(sisyphus.getFilesystem.portageRepoDir, files)) + else: + os.makedirs(sisyphus.getFilesystem.portageRepoDir) + + if os.path.isdir(sisyphus.getFilesystem.redcoreRepoDir): + for files in os.listdir(sisyphus.getFilesystem.redcoreRepoDir): + if os.path.isfile(os.path.join(sisyphus.getFilesystem.redcoreRepoDir, files)): + os.remove(os.path.join(sisyphus.getFilesystem.redcoreRepoDir, files)) + else: + shutil.rmtree(os.path.join(sisyphus.getFilesystem.redcoreRepoDir, files)) + else: + os.makedirs(sisyphus.getFilesystem.redcoreRepoDir) + + if os.path.isdir(sisyphus.getFilesystem.portageConfigDir): + for files in os.listdir(sisyphus.getFilesystem.portageConfigDir): + if os.path.isfile(os.path.join(sisyphus.getFilesystem.portageConfigDir, files)): + os.remove(os.path.join(sisyphus.getFilesystem.portageConfigDir, files)) + else: + shutil.rmtree(os.path.join(sisyphus.getFilesystem.portageConfigDir, files)) + else: + os.makedirs(sisyphus.getFilesystem.portageConfigDir) + +def cache(): + if os.path.isdir(sisyphus.getFilesystem.portageCacheDir): + for files in os.listdir(sisyphus.getFilesystem.portageCacheDir): + if os.path.isfile(os.path.join(sisyphus.getFilesystem.portageCacheDir, files)): + os.remove(os.path.join(sisyphus.getFilesystem.portageCacheDir, files)) + else: + shutil.rmtree(os.path.join(sisyphus.getFilesystem.portageCacheDir, files)) + +def metadata(): + if os.path.isdir(sisyphus.getFilesystem.portageMetadataDir): + for files in os.listdir(sisyphus.getFilesystem.portageMetadataDir): + if os.path.isfile(os.path.join(sisyphus.getFilesystem.portageMetadataDir, files)): + os.remove(os.path.join(sisyphus.getFilesystem.portageMetadataDir, files)) + else: + shutil.rmtree(os.path.join(sisyphus.getFilesystem.portageMetadataDir, files)) diff --git a/src/backend/recoverDatabase.py b/src/backend/recoverDatabase.py new file mode 100644 index 0000000..c067815 --- /dev/null +++ b/src/backend/recoverDatabase.py @@ -0,0 +1,20 @@ +#!/usr/bin/python3 + +import animation +import os +import sisyphus.syncDatabase +import sisyphus.getFilesystem + +@animation.wait('recovering databases') +def start(): + if os.path.exists(sisyphus.getFilesystem.remotePackagesCsv): + os.remove(sisyphus.getFilesystem.remotePackagesCsv) + if os.path.exists(sisyphus.getFilesystem.remoteDescriptionsCsv): + os.remove(sisyphus.getFilesystem.remoteDescriptionsCsv) + if os.path.exists(sisyphus.getFilesystem.localPackagesCsv): + os.remove(sisyphus.getFilesystem.localPackagesCsv) + if os.path.exists(sisyphus.getFilesystem.localDatabase): + os.remove(sisyphus.getFilesystem.localDatabase) + + sisyphus.syncDatabase.syncRemote() + sisyphus.syncDatabase.syncLocal() diff --git a/src/backend/rescue.py b/src/backend/rescue.py deleted file mode 100644 index 26e7c68..0000000 --- a/src/backend/rescue.py +++ /dev/null @@ -1,20 +0,0 @@ -#!/usr/bin/python3 - -import animation -import os -import sisyphus.database -import sisyphus.filesystem - -@animation.wait('recovering databases') -def start(): - if os.path.exists(sisyphus.filesystem.remotePackagesCsv): - os.remove(sisyphus.filesystem.remotePackagesCsv) - if os.path.exists(sisyphus.filesystem.remoteDescriptionsCsv): - os.remove(sisyphus.filesystem.remoteDescriptionsCsv) - if os.path.exists(sisyphus.filesystem.localPackagesCsv): - os.remove(sisyphus.filesystem.localPackagesCsv) - if os.path.exists(sisyphus.filesystem.localDatabase): - os.remove(sisyphus.filesystem.localDatabase) - - sisyphus.database.syncRemote() - sisyphus.database.syncLocal() diff --git a/src/backend/resolveDeps.py b/src/backend/resolveDeps.py new file mode 100644 index 0000000..f0af4c0 --- /dev/null +++ b/src/backend/resolveDeps.py @@ -0,0 +1,69 @@ +#!/usr/bin/python3 + +import animation +import io +import subprocess + +@animation.wait('resolving dependencies') +def package(pkgname): + areBinaries = [] + areSources = [] + needsConfig = int() + portageExec = subprocess.Popen(['emerge', '--quiet', '--pretend', '--getbinpkg', '--rebuilt-binaries', '--with-bdeps=y', '--misspell-suggestion=n', '--fuzzy-search=n'] + list(pkgname), stdout=subprocess.PIPE, stderr=subprocess.PIPE) + stdout, stderr = portageExec.communicate() + + for portageOutput in io.TextIOWrapper(portageExec.stderr, encoding="utf-8"): + if "The following keyword changes are necessary to proceed:" in portageOutput.rstrip(): + needsConfig = int(1) + + if "The following mask changes are necessary to proceed:" in portageOutput.rstrip(): + needsConfig = int(1) + + if "The following USE changes are necessary to proceed:" in portageOutput.rstrip(): + needsConfig = int(1) + + if "The following REQUIRED_USE flag constraints are unsatisfied:" in portageOutput.rstrip(): + needsConfig = int(1) + + for portageOutput in io.TextIOWrapper(portageExec.stdout, encoding="utf-8"): + if "[binary" in portageOutput.rstrip(): + isBinary = str(portageOutput.rstrip().split("]")[1].split("[")[0].strip("\ ")) + areBinaries.append(isBinary) + + if "[ebuild" in portageOutput.rstrip(): + isSource = str(portageOutput.rstrip().split("]")[1].split("[")[0].strip("\ ")) + areSources.append(isSource) + + return areBinaries,areSources,needsConfig + +@animation.wait('resolving dependencies') +def world(): + areBinaries = [] + areSources = [] + needsConfig = int() + portageExec = subprocess.Popen(['emerge', '--quiet', '--update', '--deep', '--newuse', '--pretend', '--getbinpkg', '--rebuilt-binaries', '--backtrack=100', '--with-bdeps=y', '--misspell-suggestion=n', '--fuzzy-search=n', '@world'], stdout=subprocess.PIPE, stderr=subprocess.PIPE) + stdout, stderr = portageExec.communicate() + + for portageOutput in io.TextIOWrapper(portageExec.stderr, encoding="utf-8"): + if "The following keyword changes are necessary to proceed:" in portageOutput.rstrip(): + needsConfig = int(1) + + if "The following mask changes are necessary to proceed:" in portageOutput.rstrip(): + needsConfig = int(1) + + if "The following USE changes are necessary to proceed:" in portageOutput.rstrip(): + needsConfig = int(1) + + if "The following REQUIRED_USE flag constraints are unsatisfied:" in portageOutput.rstrip(): + needsConfig = int(1) + + for portageOutput in io.TextIOWrapper(portageExec.stdout, encoding="utf-8"): + if "[binary" in portageOutput.rstrip(): + isBinary = str(portageOutput.rstrip().split("]")[1].split("[")[0].strip("\ ")) + areBinaries.append(isBinary) + + if "[ebuild" in portageOutput.rstrip(): + isSource = str(portageOutput.rstrip().split("]")[1].split("[")[0].strip("\ ")) + areSources.append(isSource) + + return areBinaries,areSources,needsConfig diff --git a/src/backend/search.py b/src/backend/search.py deleted file mode 100644 index 18eeb82..0000000 --- a/src/backend/search.py +++ /dev/null @@ -1,133 +0,0 @@ -#!/usr/bin/python3 - -import sqlite3 -import sisyphus.check -import sisyphus.filesystem -import sisyphus.update - -def searchDB(filter, cat = '', pn = '', desc = ''): - NOVIRT = "AND cat NOT LIKE 'virtual'" - SELECTS = { - 'all': f'''SELECT - i.category AS cat, - i.name as pn, - i.version as iv, - IFNULL(a.version, 'alien') AS av, - d.description AS desc - FROM local_packages AS i LEFT OUTER JOIN remote_packages as a - ON i.category = a.category - AND i.name = a.name - AND i.slot = a.slot - LEFT JOIN remote_descriptions AS d ON i.name = d.name AND i.category = d.category - WHERE cat LIKE '%{cat}%' AND pn LIKE '%{pn}%' AND desc LIKE '%{desc}%' {NOVIRT} - UNION - SELECT - a.category AS cat, - a.name as pn, - IFNULL(i.version, 'None') AS iv, - a.version as av, - d.description AS desc - FROM remote_packages AS a LEFT OUTER JOIN local_packages AS i - ON a.category = i.category - AND a.name = i.name - AND a.slot = i.slot - LEFT JOIN remote_descriptions AS d ON a.name = d.name AND a.category = d.category - WHERE cat LIKE '%{cat}%' AND pn LIKE '%{pn}%' AND desc LIKE '%{desc}%' {NOVIRT}''', - 'installed': f'''SELECT - i.category AS cat, - i.name AS pn, - i.version AS iv, - a.version as av, - d.description AS desc - FROM local_packages AS i - LEFT JOIN remote_packages AS a - ON i.category = a.category - AND i.name = a.name - AND i.slot = a.slot - LEFT JOIN remote_descriptions AS d ON i.name = d.name AND i.category = d.category - WHERE cat LIKE '%{cat}%' AND pn LIKE '%{pn}%' AND desc LIKE '%{desc}%' {NOVIRT}''', - 'alien': f'''SELECT - i.category AS cat, - i.name AS pn, - i.version as iv, - IFNULL(a.version, 'alien') AS av, - d.description AS desc - FROM local_packages AS i - LEFT JOIN remote_packages AS a - ON a.category = i.category - AND a.name = i.name - AND a.slot = i.slot - LEFT JOIN remote_descriptions AS d ON i.name = d.name AND i.category = d.category - WHERE cat LIKE '%{cat}%' AND pn LIKE '%{pn}%' AND desc LIKE '%{desc}%' {NOVIRT} - AND av IS 'alien' ''', - 'available': f'''SELECT - a.category AS cat, - a.name AS pn, - i.version as iv, - a.version AS av, - d.description AS desc - FROM remote_packages AS a - LEFT JOIN local_packages AS i - ON a.category = i.category - AND a.name = i.name - AND a.slot = i.slot - LEFT JOIN remote_descriptions AS d ON a.name = d.name AND a.category = d.category - WHERE cat LIKE '%{cat}%' AND pn LIKE '%{pn}%' AND desc LIKE '%{desc}%' {NOVIRT} - AND iv IS NULL''', - 'upgradeable': f'''SELECT - i.category AS cat, - i.name AS pn, - i.version as iv, - a.version AS av, - d.description AS desc - FROM local_packages AS i - INNER JOIN remote_packages AS a - ON i.category = a.category - AND i.name = a.name - AND i.slot = a.slot - LEFT JOIN remote_descriptions AS d ON i.name = d.name AND i.category = d.category - WHERE cat LIKE '%{cat}%' AND pn LIKE '%{pn}%' AND desc LIKE '%{desc}%' {NOVIRT} - AND iv <> av''' - } - - with sqlite3.connect(sisyphus.filesystem.localDatabase) as db: - db.row_factory = sqlite3.Row - cursor = db.cursor() - cursor.execute(SELECTS[filter]) - rows = cursor.fetchall() - - return rows - -def tosql(string): - return '%%' if string == '' else string.replace('*', '%').replace('?', '_') - -def showSearch(filter, cat, pn, desc, single): - print(f"Searching {filter} packages ... \n") - pkglist = searchDB(filter, tosql(cat), tosql(pn), tosql(desc)) - - if len(pkglist) == 0: - print("No package found!\nUse the '--ebuild' option to search for source packages!") - else: - if single: - print(f"{'Package':45} {'Installed':20} Available") - for pkg in pkglist: - if not single: - print(f"* {pkg['cat']}/{pkg['pn']}") - print(f"\tInstalled version: {pkg['iv']}") - if pkg['av'] != 'alien': - print(f"\tLatest available version: {pkg['av']}") - else: - print(f"\tAlien package: Use `sisyphus search --ebuild {pkg['pn']}` for available version!") - print(f"\tDescription: {pkg['desc']}\n") - else: - cpn = f"{pkg['cat']}/{pkg['pn']}" - print(f"{cpn:45} {str(pkg['iv']):20} {str(pkg['av'])}") - print(f"\nFound {len(pkglist)} matching package(s) ...") - -def start(filter, cat, pn, desc, single): - if sisyphus.check.root(): - sisyphus.update.start() - else: - print("\nYou are not root, cannot fetch updates.\nSearch result may be inaccurate!\n") - - showSearch(filter, cat, pn, desc, single) diff --git a/src/backend/searchPkg.py b/src/backend/searchPkg.py new file mode 100644 index 0000000..6f227f9 --- /dev/null +++ b/src/backend/searchPkg.py @@ -0,0 +1,133 @@ +#!/usr/bin/python3 + +import sqlite3 +import sisyphus.checkEnvironment +import sisyphus.getFilesystem +import sisyphus.updateAll + +def searchDB(filter, cat = '', pn = '', desc = ''): + NOVIRT = "AND cat NOT LIKE 'virtual'" + SELECTS = { + 'all': f'''SELECT + i.category AS cat, + i.name as pn, + i.version as iv, + IFNULL(a.version, 'alien') AS av, + d.description AS desc + FROM local_packages AS i LEFT OUTER JOIN remote_packages as a + ON i.category = a.category + AND i.name = a.name + AND i.slot = a.slot + LEFT JOIN remote_descriptions AS d ON i.name = d.name AND i.category = d.category + WHERE cat LIKE '%{cat}%' AND pn LIKE '%{pn}%' AND desc LIKE '%{desc}%' {NOVIRT} + UNION + SELECT + a.category AS cat, + a.name as pn, + IFNULL(i.version, 'None') AS iv, + a.version as av, + d.description AS desc + FROM remote_packages AS a LEFT OUTER JOIN local_packages AS i + ON a.category = i.category + AND a.name = i.name + AND a.slot = i.slot + LEFT JOIN remote_descriptions AS d ON a.name = d.name AND a.category = d.category + WHERE cat LIKE '%{cat}%' AND pn LIKE '%{pn}%' AND desc LIKE '%{desc}%' {NOVIRT}''', + 'installed': f'''SELECT + i.category AS cat, + i.name AS pn, + i.version AS iv, + a.version as av, + d.description AS desc + FROM local_packages AS i + LEFT JOIN remote_packages AS a + ON i.category = a.category + AND i.name = a.name + AND i.slot = a.slot + LEFT JOIN remote_descriptions AS d ON i.name = d.name AND i.category = d.category + WHERE cat LIKE '%{cat}%' AND pn LIKE '%{pn}%' AND desc LIKE '%{desc}%' {NOVIRT}''', + 'alien': f'''SELECT + i.category AS cat, + i.name AS pn, + i.version as iv, + IFNULL(a.version, 'alien') AS av, + d.description AS desc + FROM local_packages AS i + LEFT JOIN remote_packages AS a + ON a.category = i.category + AND a.name = i.name + AND a.slot = i.slot + LEFT JOIN remote_descriptions AS d ON i.name = d.name AND i.category = d.category + WHERE cat LIKE '%{cat}%' AND pn LIKE '%{pn}%' AND desc LIKE '%{desc}%' {NOVIRT} + AND av IS 'alien' ''', + 'available': f'''SELECT + a.category AS cat, + a.name AS pn, + i.version as iv, + a.version AS av, + d.description AS desc + FROM remote_packages AS a + LEFT JOIN local_packages AS i + ON a.category = i.category + AND a.name = i.name + AND a.slot = i.slot + LEFT JOIN remote_descriptions AS d ON a.name = d.name AND a.category = d.category + WHERE cat LIKE '%{cat}%' AND pn LIKE '%{pn}%' AND desc LIKE '%{desc}%' {NOVIRT} + AND iv IS NULL''', + 'upgradeable': f'''SELECT + i.category AS cat, + i.name AS pn, + i.version as iv, + a.version AS av, + d.description AS desc + FROM local_packages AS i + INNER JOIN remote_packages AS a + ON i.category = a.category + AND i.name = a.name + AND i.slot = a.slot + LEFT JOIN remote_descriptions AS d ON i.name = d.name AND i.category = d.category + WHERE cat LIKE '%{cat}%' AND pn LIKE '%{pn}%' AND desc LIKE '%{desc}%' {NOVIRT} + AND iv <> av''' + } + + with sqlite3.connect(sisyphus.getFilesystem.localDatabase) as db: + db.row_factory = sqlite3.Row + cursor = db.cursor() + cursor.execute(SELECTS[filter]) + rows = cursor.fetchall() + + return rows + +def tosql(string): + return '%%' if string == '' else string.replace('*', '%').replace('?', '_') + +def showSearch(filter, cat, pn, desc, single): + print(f"Searching {filter} packages ... \n") + pkglist = searchDB(filter, tosql(cat), tosql(pn), tosql(desc)) + + if len(pkglist) == 0: + print("No package found!\nUse the '--ebuild' option to search for source packages!") + else: + if single: + print(f"{'Package':45} {'Installed':20} Available") + for pkg in pkglist: + if not single: + print(f"* {pkg['cat']}/{pkg['pn']}") + print(f"\tInstalled version: {pkg['iv']}") + if pkg['av'] != 'alien': + print(f"\tLatest available version: {pkg['av']}") + else: + print(f"\tAlien package: Use `sisyphus search --ebuild {pkg['pn']}` for available version!") + print(f"\tDescription: {pkg['desc']}\n") + else: + cpn = f"{pkg['cat']}/{pkg['pn']}" + print(f"{cpn:45} {str(pkg['iv']):20} {str(pkg['av'])}") + print(f"\nFound {len(pkglist)} matching package(s) ...") + +def start(filter, cat, pn, desc, single): + if sisyphus.checkEnvironment.root(): + sisyphus.updateAll.start() + else: + print("\nYou are not root, cannot fetch updates.\nSearch result may be inaccurate!\n") + + showSearch(filter, cat, pn, desc, single) diff --git a/src/backend/searchSrc.py b/src/backend/searchSrc.py new file mode 100644 index 0000000..c9b5862 --- /dev/null +++ b/src/backend/searchSrc.py @@ -0,0 +1,6 @@ +#!/usr/bin/python3 + +import subprocess + +def start(pkgname): + subprocess.call(['emerge', '--search', '--getbinpkg'] + list(pkgname)) diff --git a/src/backend/setBranch.py b/src/backend/setBranch.py new file mode 100644 index 0000000..d0fa834 --- /dev/null +++ b/src/backend/setBranch.py @@ -0,0 +1,94 @@ +#!/usr/bin/python3 + +import animation +import git +import os +import sys +import sisyphus.checkEnvironment +import sisyphus.getFilesystem +import sisyphus.purgeEnvironment +import sisyphus.setJobs +import sisyphus.setProfile + +def getBranchRemote(branch,remote): + portageRemote = [] + redcoreRemote = [] + portageConfigRemote = [] + if "master" in branch: + if "gitlab" in remote: + remote = sisyphus.getFilesystem.remoteGitlab + elif "pagure" in remote: + remote = sisyphus.getFilesystem.remotePagure + else: + sys.exit("Usage: sisyphus-cli.py branch [OPTIONS] BRANCH" + "\n" + + "Try 'sisyphus-cli.py branch --help' for help." + "\n\n" + + "Error: Invalid remote" + " " + "'" + str(remote) + "'" + " " + "(options : gitlab, pagure)" + ) + elif "next" in branch: + if "gitlab" in remote: + remote = sisyphus.getFilesystem.remoteGitlab + elif "pagure" in remote: + remote = sisyphus.getFilesystem.remotePagure + else: + sys.exit("Usage: sisyphus-cli.py branch [OPTIONS] BRANCH" + "\n" + + "Try 'sisyphus-cli.py branch --help' for help." + "\n\n" + + "Error: Invalid remote" + " " + "'" + str(remote) + "'" + " " + "(options : gitlab, pagure)" + ) + else: + sys.exit("Usage: sisyphus-cli.py branch [OPTIONS] BRANCH" + "\n" + + "Try 'sisyphus-cli.py branch --help' for help." + "\n\n" + + "Error: Invalid branch" + " " + "'" + str(branch) + "'" +" " + "(options : master, next)" + ) + + portageRemote = [remote, sisyphus.getFilesystem.portageRepo] + redcoreRemote = [remote, sisyphus.getFilesystem.redcoreRepo] + portageConfigRemote = [remote, sisyphus.getFilesystem.portageConfigRepo] + + return portageRemote,redcoreRemote,portageConfigRemote + +@animation.wait('injecting Gentoo Linux portage tree') +def injectStage1(branch,remote): + portageRemote,redcoreRemote,portageConfigRemote = getBranchRemote(branch,remote) + + if not os.path.isdir(os.path.join(sisyphus.getFilesystem.portageRepoDir, '.git')): + git.Repo.clone_from("/".join(portageRemote), sisyphus.getFilesystem.portageRepoDir, depth=1, branch=branch) + +@animation.wait('injecting Redcore Linux ebuild overlay') +def injectStage2(branch,remote): + portageRemote,redcoreRemote,portageConfigRemote = getBranchRemote(branch,remote) + + if not os.path.isdir(os.path.join(sisyphus.getFilesystem.redcoreRepoDir, '.git')): + git.Repo.clone_from("/".join(redcoreRemote), sisyphus.getFilesystem.redcoreRepoDir, depth=1, branch=branch) + +@animation.wait('injecting Redcore Linux portage config') +def injectStage3(branch,remote): + portageRemote,redcoreRemote,portageConfigRemote = getBranchRemote(branch,remote) + + if not os.path.isdir(os.path.join(sisyphus.getFilesystem.portageConfigDir, '.git')): + git.Repo.clone_from("/".join(portageConfigRemote), sisyphus.getFilesystem.portageConfigDir, depth=1, branch=branch) + +def giveWarning(branch,remote): + if "master" in branch: + print("\nThe switch to branch" + " " + "'" + branch + "'" + " " + "from remote" + " " + "'" + remote + "'" + " " + "is now complete") + print("You must pair this branch with the stable binhost (binary repository)") + print("Hint : Use the odd numbers (1,3,5,7) from 'sisyphus mirror list'") + print("Examples : 'sisyphus mirror set 1' or 'sisyphus mirror set 5'\n") + elif "next" in branch: + print("\nThe switch to branch" + " " + "'" + branch + "'" + " " + "from remote" + " " + "'" + remote + "'" + " " + "is now complete") + print("You must pair this branch with the testing binhost (binary repository)") + print("Hint : Use the even numbers (2,4,6,8) from 'sisyphus mirror list'") + print("Examples : 'sisyphus mirror set 4' or 'sisyphus mirror set 8'\n") + + +def start(branch,remote): + if sisyphus.checkEnvironment.root(): + sisyphus.purgeEnvironment.branch() + sisyphus.purgeEnvironment.metadata() + injectStage1(branch,remote) + injectStage2(branch,remote) + injectStage3(branch,remote) + sisyphus.setJobs.start() + sisyphus.setProfile.start() + giveWarning(branch,remote) + else: + sys.exit("\nYou need root permissions to do this, exiting!\n") diff --git a/src/backend/setJobs.py b/src/backend/setJobs.py new file mode 100644 index 0000000..5a22b10 --- /dev/null +++ b/src/backend/setJobs.py @@ -0,0 +1,6 @@ +#!/usr/bin/python3 + +import subprocess + +def start(): + subprocess.call(['/usr/share/sisyphus/helpers/set_jobs']) diff --git a/src/backend/setMirror.py b/src/backend/setMirror.py new file mode 100644 index 0000000..b2d4f1f --- /dev/null +++ b/src/backend/setMirror.py @@ -0,0 +1,59 @@ +#!/usr/bin/python3 + +import sisyphus.getFilesystem + +def getList(): + mirrorList = [] + + with open(sisyphus.getFilesystem.mirrorCfg) as mirrorFile: + for line in mirrorFile.readlines(): + if 'PORTAGE_BINHOST=' in line: + url = line.split("=")[1].replace('"', '').rstrip() + mirror = {'isActive': True, 'Url': url} + if line.startswith('#'): + mirror['isActive'] = False + mirrorList.append(mirror) + mirrorFile.close() + + return mirrorList + +def printList(): + mirrorList = getList() + + for i, line in enumerate(mirrorList): + if line['isActive']: + print(i + 1, '*', line['Url']) + else: + print(i + 1, ' ', line['Url']) + +def writeList(mirrorList): + with open(sisyphus.getFilesystem.mirrorCfg, 'w+') as mirrorFile: + mirrorFile.write("#######################################################\n") + mirrorFile.write("# Support for multiple mirrors is somewhat incomplete #\n") + mirrorFile.write("#######################################################\n") + mirrorFile.write("# Please avoid using the Main Repository #\n") + mirrorFile.write("# http://mirrors.redcorelinux.org/redcorelinux #\n") + mirrorFile.write("# as the bandwidth is limited, use mirrors instead #\n") + mirrorFile.write("#######################################################\n") + mirrorFile.write("# Uncomment only one mirror from the list bellow #\n") + mirrorFile.write("#######################################################\n") + mirrorFile.write("\n") + for line in mirrorList: + mirror = 'PORTAGE_BINHOST=' + '"' + line['Url'] + '"' + if not line['isActive']: + mirror = '# ' + mirror + mirrorFile.write(mirror + "\n") + mirrorFile.write("\n") + +def setActive(mirror): + mirrorList = getList() + if mirror not in range(1, len(mirrorList) + 1): + print("\n" + "Mirror index is wrong, please check with sisyphus mirror list" + "\n") + else: + for i in range(0, len(mirrorList)): + indx = i + 1 + if indx == mirror: + mirrorList[i]['isActive'] = True + else: + mirrorList[i]['isActive'] = False + writeList(mirrorList) diff --git a/src/backend/setProfile.py b/src/backend/setProfile.py new file mode 100644 index 0000000..87d5437 --- /dev/null +++ b/src/backend/setProfile.py @@ -0,0 +1,18 @@ +#!/usr/bin/python3 + +import animation +import platform +import subprocess + +@animation.wait('setting up profile') +def start(): + if platform.uname()[4] == 'x86_64': + eselectExec = subprocess.Popen(['eselect', 'profile', 'set', 'default/linux/amd64/17.1/hardened'], stdout=subprocess.PIPE, stderr=subprocess.PIPE) + stdout, stderr = eselectExec.communicate() + + if platform.uname()[4] == 'aarch64': + eselectExec = subprocess.Popen(['eselect', 'profile', 'set', 'default/linux/arm64/17.0'], stdout=subprocess.PIPE, stderr=subprocess.PIPE) + stdout, stderr = eselectExec.communicate() + + envExec = subprocess.Popen(['env-update'], stdout=subprocess.DEVNULL) + envExec.wait() diff --git a/src/backend/setjobs.py b/src/backend/setjobs.py deleted file mode 100644 index 5a22b10..0000000 --- a/src/backend/setjobs.py +++ /dev/null @@ -1,6 +0,0 @@ -#!/usr/bin/python3 - -import subprocess - -def start(): - subprocess.call(['/usr/share/sisyphus/helpers/set_jobs']) diff --git a/src/backend/setprofile.py b/src/backend/setprofile.py deleted file mode 100644 index 87d5437..0000000 --- a/src/backend/setprofile.py +++ /dev/null @@ -1,18 +0,0 @@ -#!/usr/bin/python3 - -import animation -import platform -import subprocess - -@animation.wait('setting up profile') -def start(): - if platform.uname()[4] == 'x86_64': - eselectExec = subprocess.Popen(['eselect', 'profile', 'set', 'default/linux/amd64/17.1/hardened'], stdout=subprocess.PIPE, stderr=subprocess.PIPE) - stdout, stderr = eselectExec.communicate() - - if platform.uname()[4] == 'aarch64': - eselectExec = subprocess.Popen(['eselect', 'profile', 'set', 'default/linux/arm64/17.0'], stdout=subprocess.PIPE, stderr=subprocess.PIPE) - stdout, stderr = eselectExec.communicate() - - envExec = subprocess.Popen(['env-update'], stdout=subprocess.DEVNULL) - envExec.wait() diff --git a/src/backend/solvedeps.py b/src/backend/solvedeps.py deleted file mode 100644 index f0af4c0..0000000 --- a/src/backend/solvedeps.py +++ /dev/null @@ -1,69 +0,0 @@ -#!/usr/bin/python3 - -import animation -import io -import subprocess - -@animation.wait('resolving dependencies') -def package(pkgname): - areBinaries = [] - areSources = [] - needsConfig = int() - portageExec = subprocess.Popen(['emerge', '--quiet', '--pretend', '--getbinpkg', '--rebuilt-binaries', '--with-bdeps=y', '--misspell-suggestion=n', '--fuzzy-search=n'] + list(pkgname), stdout=subprocess.PIPE, stderr=subprocess.PIPE) - stdout, stderr = portageExec.communicate() - - for portageOutput in io.TextIOWrapper(portageExec.stderr, encoding="utf-8"): - if "The following keyword changes are necessary to proceed:" in portageOutput.rstrip(): - needsConfig = int(1) - - if "The following mask changes are necessary to proceed:" in portageOutput.rstrip(): - needsConfig = int(1) - - if "The following USE changes are necessary to proceed:" in portageOutput.rstrip(): - needsConfig = int(1) - - if "The following REQUIRED_USE flag constraints are unsatisfied:" in portageOutput.rstrip(): - needsConfig = int(1) - - for portageOutput in io.TextIOWrapper(portageExec.stdout, encoding="utf-8"): - if "[binary" in portageOutput.rstrip(): - isBinary = str(portageOutput.rstrip().split("]")[1].split("[")[0].strip("\ ")) - areBinaries.append(isBinary) - - if "[ebuild" in portageOutput.rstrip(): - isSource = str(portageOutput.rstrip().split("]")[1].split("[")[0].strip("\ ")) - areSources.append(isSource) - - return areBinaries,areSources,needsConfig - -@animation.wait('resolving dependencies') -def world(): - areBinaries = [] - areSources = [] - needsConfig = int() - portageExec = subprocess.Popen(['emerge', '--quiet', '--update', '--deep', '--newuse', '--pretend', '--getbinpkg', '--rebuilt-binaries', '--backtrack=100', '--with-bdeps=y', '--misspell-suggestion=n', '--fuzzy-search=n', '@world'], stdout=subprocess.PIPE, stderr=subprocess.PIPE) - stdout, stderr = portageExec.communicate() - - for portageOutput in io.TextIOWrapper(portageExec.stderr, encoding="utf-8"): - if "The following keyword changes are necessary to proceed:" in portageOutput.rstrip(): - needsConfig = int(1) - - if "The following mask changes are necessary to proceed:" in portageOutput.rstrip(): - needsConfig = int(1) - - if "The following USE changes are necessary to proceed:" in portageOutput.rstrip(): - needsConfig = int(1) - - if "The following REQUIRED_USE flag constraints are unsatisfied:" in portageOutput.rstrip(): - needsConfig = int(1) - - for portageOutput in io.TextIOWrapper(portageExec.stdout, encoding="utf-8"): - if "[binary" in portageOutput.rstrip(): - isBinary = str(portageOutput.rstrip().split("]")[1].split("[")[0].strip("\ ")) - areBinaries.append(isBinary) - - if "[ebuild" in portageOutput.rstrip(): - isSource = str(portageOutput.rstrip().split("]")[1].split("[")[0].strip("\ ")) - areSources.append(isSource) - - return areBinaries,areSources,needsConfig diff --git a/src/backend/spmsync.py b/src/backend/spmsync.py deleted file mode 100644 index 2c388f1..0000000 --- a/src/backend/spmsync.py +++ /dev/null @@ -1,8 +0,0 @@ -#!/usr/bin/python3 - -import animation -import sisyphus.database - -@animation.wait('syncing spm changes') -def start(): - sisyphus.database.syncLocal() diff --git a/src/backend/sync.py b/src/backend/sync.py deleted file mode 100644 index 0f28823..0000000 --- a/src/backend/sync.py +++ /dev/null @@ -1,45 +0,0 @@ -#!/usr/bin/python3 - -import os -import subprocess -import sisyphus.filesystem - -def portage(): - os.chdir(sisyphus.filesystem.portageRepoDir) - localBranch = subprocess.check_output(['git', 'rev-parse', '--abbrev-ref', 'HEAD']) - remoteBranch = subprocess.check_output(['git', 'rev-parse', '--symbolic-full-name', '@{u}']) - - gitExecStage1 = subprocess.Popen(['git', 'fetch', '--depth=1', 'origin'] + localBranch.decode().strip().split() + ['--quiet'], stdout=subprocess.PIPE, stderr=subprocess.PIPE) - stdout, stderr = gitExecStage1.communicate() - - gitExecStage2 = subprocess.Popen(['git', 'reset', '--hard'] + remoteBranch.decode().strip().replace('refs/remotes/','').split() + ['--quiet'], stdout=subprocess.PIPE, stderr=subprocess.PIPE) - stdout, stderr = gitExecStage2.communicate() - -def overlay(): - os.chdir(sisyphus.filesystem.redcoreRepoDir) - localBranch = subprocess.check_output(['git', 'rev-parse', '--abbrev-ref', 'HEAD']) - remoteBranch = subprocess.check_output(['git', 'rev-parse', '--symbolic-full-name', '@{u}']) - - gitExecStage1 = subprocess.Popen(['git', 'fetch', '--depth=1', 'origin'] + localBranch.decode().strip().split() + ['--quiet'], stdout=subprocess.PIPE, stderr=subprocess.PIPE) - stdout, stderr = gitExecStage1.communicate() - - gitExecStage2 = subprocess.Popen(['git', 'reset', '--hard'] + remoteBranch.decode().strip().replace('refs/remotes/','').split() + ['--quiet'], stdout=subprocess.PIPE, stderr=subprocess.PIPE) - stdout, stderr = gitExecStage2.communicate() - -def portageCfg(): - os.chdir(sisyphus.filesystem.portageConfigDir) - localBranch = subprocess.check_output(['git', 'rev-parse', '--abbrev-ref', 'HEAD']) - remoteBranch = subprocess.check_output(['git', 'rev-parse', '--symbolic-full-name', '@{u}']) - - gitExecStage1 = subprocess.Popen(['git', 'stash'], stdout=subprocess.PIPE, stderr=subprocess.PIPE) - stdout, stderr = gitExecStage1.communicate() - gitExecStage2 = subprocess.Popen(['git', 'fetch', '--depth=1', 'origin'] + localBranch.decode().strip().split() + ['--quiet'], stdout=subprocess.PIPE, stderr=subprocess.PIPE) - stdout, stderr = gitExecStage2.communicate() - gitExecStage3 = subprocess.Popen(['git', 'reset', '--hard'] + remoteBranch.decode().strip().replace('refs/remotes/','').split() + ['--quiet'], stdout=subprocess.PIPE, stderr=subprocess.PIPE) - stdout, stderr = gitExecStage3.communicate() - gitExecStage4 = subprocess.Popen(['git', 'stash', 'apply'], stdout=subprocess.PIPE, stderr=subprocess.PIPE) - stdout, stderr = gitExecStage4.communicate() - gitExecStage5 = subprocess.Popen(['git', 'stash', 'clear'], stdout=subprocess.PIPE, stderr=subprocess.PIPE) - stdout, stderr = gitExecStage5.communicate() - gitExecStage6 = subprocess.Popen(['git', 'gc', '--prune=now', '--quiet'], stdout=subprocess.PIPE, stderr=subprocess.PIPE) - stdout, stderr = gitExecStage6.communicate() diff --git a/src/backend/syncDatabase.py b/src/backend/syncDatabase.py new file mode 100644 index 0000000..9aa72d6 --- /dev/null +++ b/src/backend/syncDatabase.py @@ -0,0 +1,57 @@ +#!/usr/bin/python3 + +import csv +import shutil +import urllib3 +import sqlite3 +import subprocess +import sisyphus.getCSV +import sisyphus.getFilesystem + +def getRemote(): + isPackageCsv,isDescriptionCsv = sisyphus.getCSV.start() + http = urllib3.PoolManager() + + with http.request('GET', isPackageCsv, preload_content=False) as tmp_buffer, open(sisyphus.getFilesystem.remotePackagesCsv, 'wb') as output_file: + shutil.copyfileobj(tmp_buffer, output_file) + + with http.request('GET', isDescriptionCsv, preload_content=False) as tmp_buffer, open(sisyphus.getFilesystem.remoteDescriptionsCsv, 'wb') as output_file: + shutil.copyfileobj(tmp_buffer, output_file) + +def makeLocal(): + subprocess.call(['/usr/share/sisyphus/helpers/make_local_csv']) + +def syncRemote(): + getRemote() + + sisyphusdb = sqlite3.connect(sisyphus.getFilesystem.localDatabase) + sisyphusdb.cursor().execute('''drop table if exists remote_packages''') + sisyphusdb.cursor().execute('''drop table if exists remote_descriptions''') + sisyphusdb.cursor().execute('''create table remote_packages (category TEXT,name TEXT,version TEXT,slot TEXT)''') + sisyphusdb.cursor().execute('''create table remote_descriptions (category TEXT,name TEXT,description TEXT)''') + + with open(sisyphus.getFilesystem.remotePackagesCsv) as input_file: + for row in csv.reader(input_file): + sisyphusdb.cursor().execute("insert into remote_packages (category, name, version, slot) values (?, ?, ?, ?);", row) + + with open(sisyphus.getFilesystem.remoteDescriptionsCsv) as input_file: + for row in csv.reader(input_file): + sisyphusdb.cursor().execute("insert into remote_descriptions (category, name, description) values (?, ?, ?);", row) + + sisyphusdb.commit() + sisyphusdb.close() + +def syncLocal(): + makeLocal() + + sisyphusdb = sqlite3.connect(sisyphus.getFilesystem.localDatabase) + sisyphusdb.cursor().execute('''drop table if exists local_packages''') + sisyphusdb.cursor().execute('''create table local_packages (category TEXT,name TEXT,version TEXT,slot TEXT)''') + + with open(sisyphus.getFilesystem.localPackagesCsv) as input_file: + for row in csv.reader(input_file): + sisyphusdb.cursor().execute("insert into local_packages (category, name, version, slot) values (?, ?, ?, ?);", row) + + sisyphusdb.commit() + sisyphusdb.close() + diff --git a/src/backend/syncEnvironment.py b/src/backend/syncEnvironment.py new file mode 100644 index 0000000..04b662a --- /dev/null +++ b/src/backend/syncEnvironment.py @@ -0,0 +1,45 @@ +#!/usr/bin/python3 + +import os +import subprocess +import sisyphus.getFilesystem + +def syncStage1(): + os.chdir(sisyphus.getFilesystem.portageRepoDir) + localBranch = subprocess.check_output(['git', 'rev-parse', '--abbrev-ref', 'HEAD']) + remoteBranch = subprocess.check_output(['git', 'rev-parse', '--symbolic-full-name', '@{u}']) + + gitExecStage1 = subprocess.Popen(['git', 'fetch', '--depth=1', 'origin'] + localBranch.decode().strip().split() + ['--quiet'], stdout=subprocess.PIPE, stderr=subprocess.PIPE) + stdout, stderr = gitExecStage1.communicate() + + gitExecStage2 = subprocess.Popen(['git', 'reset', '--hard'] + remoteBranch.decode().strip().replace('refs/remotes/','').split() + ['--quiet'], stdout=subprocess.PIPE, stderr=subprocess.PIPE) + stdout, stderr = gitExecStage2.communicate() + +def syncStage2(): + os.chdir(sisyphus.getFilesystem.redcoreRepoDir) + localBranch = subprocess.check_output(['git', 'rev-parse', '--abbrev-ref', 'HEAD']) + remoteBranch = subprocess.check_output(['git', 'rev-parse', '--symbolic-full-name', '@{u}']) + + gitExecStage1 = subprocess.Popen(['git', 'fetch', '--depth=1', 'origin'] + localBranch.decode().strip().split() + ['--quiet'], stdout=subprocess.PIPE, stderr=subprocess.PIPE) + stdout, stderr = gitExecStage1.communicate() + + gitExecStage2 = subprocess.Popen(['git', 'reset', '--hard'] + remoteBranch.decode().strip().replace('refs/remotes/','').split() + ['--quiet'], stdout=subprocess.PIPE, stderr=subprocess.PIPE) + stdout, stderr = gitExecStage2.communicate() + +def syncStage3(): + os.chdir(sisyphus.getFilesystem.portageConfigDir) + localBranch = subprocess.check_output(['git', 'rev-parse', '--abbrev-ref', 'HEAD']) + remoteBranch = subprocess.check_output(['git', 'rev-parse', '--symbolic-full-name', '@{u}']) + + gitExecStage1 = subprocess.Popen(['git', 'stash'], stdout=subprocess.PIPE, stderr=subprocess.PIPE) + stdout, stderr = gitExecStage1.communicate() + gitExecStage2 = subprocess.Popen(['git', 'fetch', '--depth=1', 'origin'] + localBranch.decode().strip().split() + ['--quiet'], stdout=subprocess.PIPE, stderr=subprocess.PIPE) + stdout, stderr = gitExecStage2.communicate() + gitExecStage3 = subprocess.Popen(['git', 'reset', '--hard'] + remoteBranch.decode().strip().replace('refs/remotes/','').split() + ['--quiet'], stdout=subprocess.PIPE, stderr=subprocess.PIPE) + stdout, stderr = gitExecStage3.communicate() + gitExecStage4 = subprocess.Popen(['git', 'stash', 'apply'], stdout=subprocess.PIPE, stderr=subprocess.PIPE) + stdout, stderr = gitExecStage4.communicate() + gitExecStage5 = subprocess.Popen(['git', 'stash', 'clear'], stdout=subprocess.PIPE, stderr=subprocess.PIPE) + stdout, stderr = gitExecStage5.communicate() + gitExecStage6 = subprocess.Popen(['git', 'gc', '--prune=now', '--quiet'], stdout=subprocess.PIPE, stderr=subprocess.PIPE) + stdout, stderr = gitExecStage6.communicate() diff --git a/src/backend/syncSPM.py b/src/backend/syncSPM.py new file mode 100644 index 0000000..89cc5df --- /dev/null +++ b/src/backend/syncSPM.py @@ -0,0 +1,8 @@ +#!/usr/bin/python3 + +import animation +import sisyphus.syncDatabase + +@animation.wait('syncing spm changes') +def start(): + sisyphus.syncDatabase.syncLocal() diff --git a/src/backend/sysInfo.py b/src/backend/sysInfo.py new file mode 100644 index 0000000..5ae29c2 --- /dev/null +++ b/src/backend/sysInfo.py @@ -0,0 +1,7 @@ +#!/usr/bin/python3 + +import subprocess + +def show(): + subprocess.call(['emerge', '--info']) + diff --git a/src/backend/sysinfo.py b/src/backend/sysinfo.py deleted file mode 100644 index 5ae29c2..0000000 --- a/src/backend/sysinfo.py +++ /dev/null @@ -1,7 +0,0 @@ -#!/usr/bin/python3 - -import subprocess - -def show(): - subprocess.call(['emerge', '--info']) - diff --git a/src/backend/uninstall.py b/src/backend/uninstall.py deleted file mode 100644 index b8981ca..0000000 --- a/src/backend/uninstall.py +++ /dev/null @@ -1,28 +0,0 @@ -#!/usr/bin/python3 - -import atexit -import io -import subprocess -import sys -import sisyphus.check -import sisyphus.database -import sisyphus.killportage - -def start(pkgname): - if sisyphus.check.root(): - portageExec = subprocess.Popen(['emerge', '--quiet', '--depclean', '--ask'] + list(pkgname), stdout=subprocess.PIPE, stderr=subprocess.PIPE) - stdout, stderr = portageExec.communicate() - sisyphus.database.syncLocal() - else: - sys.exit("\nYou need root permissions to do this, exiting!\n") - -def startqt(pkgname): - portageExec = subprocess.Popen(['emerge', '--depclean'] + pkgname, stdout=subprocess.PIPE, stderr=subprocess.PIPE) - stdout, stderr = portageExec.communicate() - # kill portage if the program dies or it's terminated by the user - atexit.register(sisyphus.killportage.start, portageExec) - - for portageOutput in io.TextIOWrapper(portageExec.stdout, encoding="utf-8"): - print(portageOutput.rstrip()) - - sisyphus.database.syncLocal() diff --git a/src/backend/uninstallAll.py b/src/backend/uninstallAll.py new file mode 100644 index 0000000..4d0c050 --- /dev/null +++ b/src/backend/uninstallAll.py @@ -0,0 +1,28 @@ +#!/usr/bin/python3 + +import atexit +import io +import subprocess +import sys +import sisyphus.checkEnvironment +import sisyphus.syncDatabase +import sisyphus.killPortage + +def start(pkgname): + if sisyphus.checkEnvironment.root(): + portageExec = subprocess.Popen(['emerge', '--quiet', '--depclean', '--ask'] + list(pkgname), stdout=subprocess.PIPE, stderr=subprocess.PIPE) + stdout, stderr = portageExec.communicate() + sisyphus.syncDatabase.syncLocal() + else: + sys.exit("\nYou need root permissions to do this, exiting!\n") + +def startqt(pkgname): + portageExec = subprocess.Popen(['emerge', '--depclean'] + pkgname, stdout=subprocess.PIPE, stderr=subprocess.PIPE) + stdout, stderr = portageExec.communicate() + # kill portage if the program dies or it's terminated by the user + atexit.register(sisyphus.killPortage.start, portageExec) + + for portageOutput in io.TextIOWrapper(portageExec.stdout, encoding="utf-8"): + print(portageOutput.rstrip()) + + sisyphus.syncDatabase.syncLocal() diff --git a/src/backend/uninstallForceAll.py b/src/backend/uninstallForceAll.py new file mode 100644 index 0000000..8a952c6 --- /dev/null +++ b/src/backend/uninstallForceAll.py @@ -0,0 +1,14 @@ +#!/usr/bin/python3 + +import subprocess +import sys +import sisyphus.checkEnvironment +import sisyphus.syncDatabase + +def start(pkgname): + if sisyphus.checkEnvironment.root(): + portageExec = subprocess.Popen(['emerge', '--quiet', '--unmerge', '--ask'] + list(pkgname), stdout=subprocess.PIPE, stderr=subprocess.PIPE) + stdout, stderr = portageExec.communicate() + sisyphus.syncDatabase.syncLocal() + else: + sys.exit("\nYou need root permissions to do this, exiting!\n") diff --git a/src/backend/update.py b/src/backend/update.py deleted file mode 100644 index 0fe1fde..0000000 --- a/src/backend/update.py +++ /dev/null @@ -1,55 +0,0 @@ -#!/usr/bin/python3 - -import animation -import sys -import time -import sisyphus.binhost -import sisyphus.check -import sisyphus.database -import sisyphus.purge -import sisyphus.sync - -def syncAll(): - sisyphus.purge.cache() - sisyphus.sync.portage() - sisyphus.sync.overlay() - sisyphus.sync.portageCfg() - sisyphus.database.syncRemote() - -@animation.wait('fetching updates') -def start(): - activeBranch = sisyphus.check.branch() - isBinhost = sisyphus.binhost.start() - isSane = sisyphus.check.sanity() - - if isSane == 1: - syncAll() - else: - if "packages-next" in isBinhost: - print("\nCurrent branch: '" + activeBranch + "' (stable)" + "\nCurrent binhost: '" + isBinhost + "' (testing)") - else: - print("\nCurrent branch: '" + activeBranch + "' (testing)" + "\nCurrent binhost: '" + isBinhost + "' (stable)") - sys.exit("\nInvalid branch - binhost pairing; Use 'sisyphus branch --help' for help; Quitting.") - -def startqt(): - activeBranch = sisyphus.check.branch() - isBinhost = sisyphus.binhost.start() - isSane = sisyphus.check.sanity() - - if isSane == 1: - syncAll() - else: - if "packages-next" in isBinhost: - print("\nCurrent branch: '" + activeBranch + "' (stable)" + "\nCurrent binhost: '" + isBinhost + "' (testing)") - else: - print("\nCurrent branch: '" + activeBranch + "' (testing)" + "\nCurrent binhost: '" + isBinhost + "' (stable)") - print("\nInvalid branch - binhost pairing; Use 'sisyphus branch --help' for help; Quitting in 10 seconds.\n") - t = int(10) - while t: - mins, secs = divmod(t, 60) - timer = '{:02d}:{:02d}'.format(mins, secs) - print(timer, end="\r") - time.sleep(1) - t -= 1 - - sys.exit() diff --git a/src/backend/updateAll.py b/src/backend/updateAll.py new file mode 100644 index 0000000..e981da2 --- /dev/null +++ b/src/backend/updateAll.py @@ -0,0 +1,55 @@ +#!/usr/bin/python3 + +import animation +import sys +import time +import sisyphus.getBinhost +import sisyphus.checkEnvironment +import sisyphus.syncDatabase +import sisyphus.purgeEnvironment +import sisyphus.syncEnvironment + +def syncAll(): + sisyphus.purgeEnvironment.cache() + sisyphus.syncEnvironment.syncStage1() + sisyphus.syncEnvironment.syncStage2() + sisyphus.syncEnvironment.syncStage3() + sisyphus.syncDatabase.syncRemote() + +@animation.wait('fetching updates') +def start(): + activeBranch = sisyphus.checkEnvironment.branch() + isBinhost = sisyphus.getBinhost.start() + isSane = sisyphus.checkEnvironment.sanity() + + if isSane == 1: + syncAll() + else: + if "packages-next" in isBinhost: + print("\nCurrent branch: '" + activeBranch + "' (stable)" + "\nCurrent binhost: '" + isBinhost + "' (testing)") + else: + print("\nCurrent branch: '" + activeBranch + "' (testing)" + "\nCurrent binhost: '" + isBinhost + "' (stable)") + sys.exit("\nInvalid branch - binhost pairing; Use 'sisyphus branch --help' for help; Quitting.") + +def startqt(): + activeBranch = sisyphus.checkEnvironment.branch() + isBinhost = sisyphus.getBinhost.start() + isSane = sisyphus.checkEnvironment.sanity() + + if isSane == 1: + syncAll() + else: + if "packages-next" in isBinhost: + print("\nCurrent branch: '" + activeBranch + "' (stable)" + "\nCurrent binhost: '" + isBinhost + "' (testing)") + else: + print("\nCurrent branch: '" + activeBranch + "' (testing)" + "\nCurrent binhost: '" + isBinhost + "' (stable)") + print("\nInvalid branch - binhost pairing; Use 'sisyphus branch --help' for help; Quitting in 10 seconds.\n") + t = int(10) + while t: + mins, secs = divmod(t, 60) + timer = '{:02d}:{:02d}'.format(mins, secs) + print(timer, end="\r") + time.sleep(1) + t -= 1 + + sys.exit() diff --git a/src/backend/upgrade.py b/src/backend/upgrade.py deleted file mode 100644 index 54fcd5c..0000000 --- a/src/backend/upgrade.py +++ /dev/null @@ -1,102 +0,0 @@ -#!/usr/bin/python3 - -import atexit -import io -import os -import shutil -import subprocess -import sys -import wget -import sisyphus.binhost -import sisyphus.check -import sisyphus.database -import sisyphus.filesystem -import sisyphus.killportage -import sisyphus.solvedeps -import sisyphus.update - -def start(): - if sisyphus.check.root(): - sisyphus.update.start() - - isBinhost = sisyphus.binhost.start() - areBinaries,areSources,needsConfig = sisyphus.solvedeps.world() - - if needsConfig == 0: - if len(areSources) == 0: - if not len(areBinaries) == 0: - os.chdir(sisyphus.filesystem.portageCacheDir) - print("\n" + "These are the binary packages that would be merged, in order:" + "\n\n" + " ".join(areBinaries) + "\n\n" + "Total:" + " " + str(len(areBinaries)) + " " + "binary package(s)" + "\n") - if input("Would you like to proceed?" + " " + "[y/N]" + " ").lower().strip()[:1] == "y": - for index, binary in enumerate([package + '.tbz2' for package in areBinaries], start=1): - print(">>> Downloading binary ({}".format(index) + " " + "of" + " " + str(len(areBinaries)) + ")" + " " + binary) - wget.download(isBinhost + binary) - print("\n") - - if os.path.isdir(os.path.join(sisyphus.filesystem.portageCacheDir, binary.rstrip().split("/")[0])): - shutil.move(binary.rstrip().split("/")[1], os.path.join(os.path.join(sisyphus.filesystem.portageCacheDir, binary.rstrip().split("/")[0]), os.path.basename(binary.rstrip().split("/")[1]))) - else: - os.makedirs(os.path.join(sisyphus.filesystem.portageCacheDir, binary.rstrip().split("/")[0])) - shutil.move(binary.rstrip().split("/")[1], os.path.join(os.path.join(sisyphus.filesystem.portageCacheDir, binary.rstrip().split("/")[0]), os.path.basename(binary.rstrip().split("/")[1]))) - - if os.path.exists(binary.rstrip().split("/")[1]): - os.remove(binary.rstrip().split("/")[1]) - - portageExec = subprocess.Popen(['emerge', '--update', '--deep', '--newuse', '--usepkg', '--usepkgonly', '--rebuilt-binaries', '--backtrack=100', '--with-bdeps=y', '--misspell-suggestion=n', '--fuzzy-search=n', '@world'], stdout=subprocess.PIPE, stderr=subprocess.PIPE) - stdout, stderr = portageExec.communicate() - - for portageOutput in io.TextIOWrapper(portageExec.stdout, encoding="utf-8"): - if not "These are the packages that would be merged, in order:" in portageOutput.rstrip(): - if not "Calculating dependencies" in portageOutput.rstrip(): - print(portageOutput.rstrip()) - - sisyphus.database.syncLocal() - else: - sys.exit("\n" + "Ok; Quitting." + "\n") - else: - sys.exit("\n" + "No package upgrades found; Quitting." + "\n") - else: - sys.exit("\n" + "Source package(s) found in the mix;" + " " + "Use" + " " + "'" + "sisyphus upgrade --ebuild" + "'" + ";" + " " + "Quitting." + "\n") - else: - # don't silently fail if a source package requested without the --ebuild option needs a keyword, mask, REQUIRED_USE or USE change - sys.exit("\n" + "Invalid request;" " " + "Use" + " " + "'" + "sisyphus upgrade --ebuild" + "'" + ";" + " " + "Quitting." + "\n") - else: - sys.exit("\nYou need root permissions to do this, exiting!\n") - -def startqt(): - isBinhost = sisyphus.binhost.start() - areBinaries,areSources,needsConfig = sisyphus.solvedeps.world.__wrapped__() #undecorate - - if not len(areSources) == 0: - print("\n" + "Source package(s) found in the mix;" + " " + "Use sisyphus CLI:" + " " + "'" + "sisyphus upgrade --ebuild" + "'" + " " + "to perform the upgrade;" + " " + "Aborting." + "\n") - else: - if not len(areBinaries) == 0: - os.chdir(sisyphus.filesystem.portageCacheDir) - print("\n" + "These are the binary packages that will be merged, in order:" + "\n\n" + " ".join(areBinaries) + "\n\n" + "Total:" + " " + str(len(areBinaries)) + " " + "binary package(s)" + "\n\n") - for index, binary in enumerate([package + '.tbz2' for package in areBinaries], start=1): - print(">>> Downloading binary ({}".format(index) + " " + "of" + " " + str(len(areBinaries)) + ")" + " " + binary) - wget.download(isBinhost + binary) - print("\n") - - if os.path.isdir(os.path.join(sisyphus.filesystem.portageCacheDir, binary.rstrip().split("/")[0])): - shutil.move(binary.rstrip().split("/")[1], os.path.join(os.path.join(sisyphus.filesystem.portageCacheDir, binary.rstrip().split("/")[0]), os.path.basename(binary.rstrip().split("/")[1]))) - else: - os.makedirs(os.path.join(sisyphus.filesystem.portageCacheDir, binary.rstrip().split("/")[0])) - shutil.move(binary.rstrip().split("/")[1], os.path.join(os.path.join(sisyphus.filesystem.portageCacheDir, binary.rstrip().split("/")[0]), os.path.basename(binary.rstrip().split("/")[1]))) - - if os.path.exists(binary.rstrip().split("/")[1]): - os.remove(binary.rstrip().split("/")[1]) - - portageExec = subprocess.Popen(['emerge', '--update', '--deep', '--newuse', '--usepkg', '--usepkgonly', '--rebuilt-binaries', '--backtrack=100', '--with-bdeps=y', '--misspell-suggestion=n', '--fuzzy-search=n', '@world'], stdout=subprocess.PIPE, stderr=subprocess.PIPE) - stdout, stderr = portageExec.communicate() - # kill portage if the program dies or it's terminated by the user - atexit.register(sisyphus.killportage.start, portageExec) - - for portageOutput in io.TextIOWrapper(portageExec.stdout, encoding="utf-8"): - if not "These are the packages that would be merged, in order:" in portageOutput.rstrip(): - if not "Calculating dependencies" in portageOutput.rstrip(): - print(portageOutput.rstrip()) - - sisyphus.database.syncLocal() - else: - print("\n" + "No package upgrades found; Quitting." + "\n") diff --git a/src/backend/upgradePkg.py b/src/backend/upgradePkg.py new file mode 100644 index 0000000..1121747 --- /dev/null +++ b/src/backend/upgradePkg.py @@ -0,0 +1,102 @@ +#!/usr/bin/python3 + +import atexit +import io +import os +import shutil +import subprocess +import sys +import wget +import sisyphus.getBinhost +import sisyphus.checkEnvironment +import sisyphus.syncDatabase +import sisyphus.getFilesystem +import sisyphus.killPortage +import sisyphus.resolveDeps +import sisyphus.updateAll + +def start(): + if sisyphus.checkEnvironment.root(): + sisyphus.updateAll.start() + + isBinhost = sisyphus.getBinhost.start() + areBinaries,areSources,needsConfig = sisyphus.resolveDeps.world() + + if needsConfig == 0: + if len(areSources) == 0: + if not len(areBinaries) == 0: + os.chdir(sisyphus.getFilesystem.portageCacheDir) + print("\n" + "These are the binary packages that would be merged, in order:" + "\n\n" + " ".join(areBinaries) + "\n\n" + "Total:" + " " + str(len(areBinaries)) + " " + "binary package(s)" + "\n") + if input("Would you like to proceed?" + " " + "[y/N]" + " ").lower().strip()[:1] == "y": + for index, binary in enumerate([package + '.tbz2' for package in areBinaries], start=1): + print(">>> Downloading binary ({}".format(index) + " " + "of" + " " + str(len(areBinaries)) + ")" + " " + binary) + wget.download(isBinhost + binary) + print("\n") + + if os.path.isdir(os.path.join(sisyphus.getFilesystem.portageCacheDir, binary.rstrip().split("/")[0])): + shutil.move(binary.rstrip().split("/")[1], os.path.join(os.path.join(sisyphus.getFilesystem.portageCacheDir, binary.rstrip().split("/")[0]), os.path.basename(binary.rstrip().split("/")[1]))) + else: + os.makedirs(os.path.join(sisyphus.getFilesystem.portageCacheDir, binary.rstrip().split("/")[0])) + shutil.move(binary.rstrip().split("/")[1], os.path.join(os.path.join(sisyphus.getFilesystem.portageCacheDir, binary.rstrip().split("/")[0]), os.path.basename(binary.rstrip().split("/")[1]))) + + if os.path.exists(binary.rstrip().split("/")[1]): + os.remove(binary.rstrip().split("/")[1]) + + portageExec = subprocess.Popen(['emerge', '--update', '--deep', '--newuse', '--usepkg', '--usepkgonly', '--rebuilt-binaries', '--backtrack=100', '--with-bdeps=y', '--misspell-suggestion=n', '--fuzzy-search=n', '@world'], stdout=subprocess.PIPE, stderr=subprocess.PIPE) + stdout, stderr = portageExec.communicate() + + for portageOutput in io.TextIOWrapper(portageExec.stdout, encoding="utf-8"): + if not "These are the packages that would be merged, in order:" in portageOutput.rstrip(): + if not "Calculating dependencies" in portageOutput.rstrip(): + print(portageOutput.rstrip()) + + sisyphus.syncDatabase.syncLocal() + else: + sys.exit("\n" + "Ok; Quitting." + "\n") + else: + sys.exit("\n" + "No package upgrades found; Quitting." + "\n") + else: + sys.exit("\n" + "Source package(s) found in the mix;" + " " + "Use" + " " + "'" + "sisyphus upgrade --ebuild" + "'" + ";" + " " + "Quitting." + "\n") + else: + # don't silently fail if a source package requested without the --ebuild option needs a keyword, mask, REQUIRED_USE or USE change + sys.exit("\n" + "Invalid request;" " " + "Use" + " " + "'" + "sisyphus upgrade --ebuild" + "'" + ";" + " " + "Quitting." + "\n") + else: + sys.exit("\nYou need root permissions to do this, exiting!\n") + +def startqt(): + isBinhost = sisyphus.getBinhost.start() + areBinaries,areSources,needsConfig = sisyphus.resolveDeps.world.__wrapped__() #undecorate + + if not len(areSources) == 0: + print("\n" + "Source package(s) found in the mix;" + " " + "Use sisyphus CLI:" + " " + "'" + "sisyphus upgrade --ebuild" + "'" + " " + "to perform the upgrade;" + " " + "Aborting." + "\n") + else: + if not len(areBinaries) == 0: + os.chdir(sisyphus.getFilesystem.portageCacheDir) + print("\n" + "These are the binary packages that will be merged, in order:" + "\n\n" + " ".join(areBinaries) + "\n\n" + "Total:" + " " + str(len(areBinaries)) + " " + "binary package(s)" + "\n\n") + for index, binary in enumerate([package + '.tbz2' for package in areBinaries], start=1): + print(">>> Downloading binary ({}".format(index) + " " + "of" + " " + str(len(areBinaries)) + ")" + " " + binary) + wget.download(isBinhost + binary) + print("\n") + + if os.path.isdir(os.path.join(sisyphus.getFilesystem.portageCacheDir, binary.rstrip().split("/")[0])): + shutil.move(binary.rstrip().split("/")[1], os.path.join(os.path.join(sisyphus.getFilesystem.portageCacheDir, binary.rstrip().split("/")[0]), os.path.basename(binary.rstrip().split("/")[1]))) + else: + os.makedirs(os.path.join(sisyphus.getFilesystem.portageCacheDir, binary.rstrip().split("/")[0])) + shutil.move(binary.rstrip().split("/")[1], os.path.join(os.path.join(sisyphus.getFilesystem.portageCacheDir, binary.rstrip().split("/")[0]), os.path.basename(binary.rstrip().split("/")[1]))) + + if os.path.exists(binary.rstrip().split("/")[1]): + os.remove(binary.rstrip().split("/")[1]) + + portageExec = subprocess.Popen(['emerge', '--update', '--deep', '--newuse', '--usepkg', '--usepkgonly', '--rebuilt-binaries', '--backtrack=100', '--with-bdeps=y', '--misspell-suggestion=n', '--fuzzy-search=n', '@world'], stdout=subprocess.PIPE, stderr=subprocess.PIPE) + stdout, stderr = portageExec.communicate() + # kill portage if the program dies or it's terminated by the user + atexit.register(sisyphus.killPortage.start, portageExec) + + for portageOutput in io.TextIOWrapper(portageExec.stdout, encoding="utf-8"): + if not "These are the packages that would be merged, in order:" in portageOutput.rstrip(): + if not "Calculating dependencies" in portageOutput.rstrip(): + print(portageOutput.rstrip()) + + sisyphus.syncDatabase.syncLocal() + else: + print("\n" + "No package upgrades found; Quitting." + "\n") diff --git a/src/backend/upgradeSrc.py b/src/backend/upgradeSrc.py new file mode 100644 index 0000000..161a7c4 --- /dev/null +++ b/src/backend/upgradeSrc.py @@ -0,0 +1,114 @@ +#!/usr/bin/python3 + +import io +import os +import shutil +import subprocess +import sys +import wget +import sisyphus.getBinhost +import sisyphus.checkEnvironment +import sisyphus.syncDatabase +import sisyphus.getFilesystem +import sisyphus.resolveDeps +import sisyphus.updateAll + +def start(): + if sisyphus.checkEnvironment.root(): + sisyphus.updateAll.start() + + binhostURL = sisyphus.getBinhost.start() + areBinaries,areSources,needsConfig = sisyphus.resolveDeps.world() + + if needsConfig == 0: + if len(areSources) == 0: + if not len(areBinaries) == 0: + os.chdir(sisyphus.getFilesystem.portageCacheDir) + print("\n" + "These are the binary packages that would be merged, in order:" + "\n\n" + " ".join(areBinaries) + "\n\n" + "Total:" + " " + str(len(areBinaries)) + " " + "binary package(s)" + "\n") + if input("Would you like to proceed?" + " " + "[y/N]" + " ").lower().strip()[:1] == "y": + for index, binary in enumerate([package + '.tbz2' for package in areBinaries], start=1): + print(">>> Downloading binary ({}".format(index) + " " + "of" + " " + str(len(areBinaries)) + ")" + " " + binary) + wget.download(binhostURL + binary) + print("\n") + + if os.path.isdir(os.path.join(sisyphus.getFilesystem.portageCacheDir, binary.rstrip().split("/")[0])): + shutil.move(binary.rstrip().split("/")[1], os.path.join(os.path.join(sisyphus.getFilesystem.portageCacheDir, binary.rstrip().split("/")[0]), os.path.basename(binary.rstrip().split("/")[1]))) + else: + os.makedirs(os.path.join(sisyphus.getFilesystem.portageCacheDir, binary.rstrip().split("/")[0])) + shutil.move(binary.rstrip().split("/")[1], os.path.join(os.path.join(sisyphus.getFilesystem.portageCacheDir, binary.rstrip().split("/")[0]), os.path.basename(binary.rstrip().split("/")[1]))) + + if os.path.exists(binary.rstrip().split("/")[1]): + os.remove(binary.rstrip().split("/")[1]) + + portageExec = subprocess.Popen(['emerge', '--update', '--deep', '--newuse', '--usepkg', '--usepkgonly', '--rebuilt-binaries', '--backtrack=100', '--with-bdeps=y', '--misspell-suggestion=n', '--fuzzy-search=n', '@world'], stdout=subprocess.PIPE, stderr=subprocess.PIPE) + stdout, stderr = portageExec.communicate() + + for portageOutput in io.TextIOWrapper(portageExec.stdout, encoding="utf-8"): + if not "These are the packages that would be merged, in order:" in portageOutput.rstrip(): + if not "Calculating dependencies" in portageOutput.rstrip(): + print(portageOutput.rstrip()) + + sisyphus.syncDatabase.syncLocal() + else: + sys.exit("\n" + "Ok; Quitting." + "\n") + else: + sys.exit("\n" + "No package upgrades found; Quitting." + "\n") + else: + if not len(areBinaries) == 0: + os.chdir(sisyphus.getFilesystem.portageCacheDir) + print("\n" + "These are the binary packages that would be merged, in order:" + "\n\n" + " ".join(areBinaries) + "\n\n" + "Total:" + " " + str(len(areBinaries)) + " " + "binary package(s)" + "\n") + print("\n" + "These are the source packages that would be merged, in order:" + "\n\n" + " ".join(areSources) + "\n\n" + "Total:" + " " + str(len(areSources)) + " " + "source package(s)" + "\n") + if input("Would you like to proceed?" + " " + "[y/N]" + " ").lower().strip()[:1] == "y": + for index, binary in enumerate([package + '.tbz2' for package in areBinaries], start=1): + print(">>> Downloading binary ({}".format(index) + " " + "of" + " " + str(len(areBinaries)) + ")" + " " + binary) + wget.download(binhostURL + binary) + print("\n") + + if os.path.isdir(os.path.join(sisyphus.getFilesystem.portageCacheDir, binary.rstrip().split("/")[0])): + shutil.move(binary.rstrip().split("/")[1], os.path.join(os.path.join(sisyphus.getFilesystem.portageCacheDir, binary.rstrip().split("/")[0]), os.path.basename(binary.rstrip().split("/")[1]))) + else: + os.makedirs(os.path.join(sisyphus.getFilesystem.portageCacheDir, binary.rstrip().split("/")[0])) + shutil.move(binary.rstrip().split("/")[1], os.path.join(os.path.join(sisyphus.getFilesystem.portageCacheDir, binary.rstrip().split("/")[0]), os.path.basename(binary.rstrip().split("/")[1]))) + + if os.path.exists(binary.rstrip().split("/")[1]): + os.remove(binary.rstrip().split("/")[1]) + + portageExec = subprocess.Popen(['emerge', '--update', '--deep', '--newuse', '--usepkg', '--rebuilt-binaries', '--backtrack=100', '--with-bdeps=y', '--misspell-suggestion=n', '--fuzzy-search=n', '@world'], stdout=subprocess.PIPE, stderr=subprocess.PIPE) + stdout, stderr = portageExec.communicate() + + for portageOutput in io.TextIOWrapper(portageExec.stdout, encoding="utf-8"): + if not "These are the packages that would be merged, in order:" in portageOutput.rstrip(): + if not "Calculating dependencies" in portageOutput.rstrip(): + print(portageOutput.rstrip()) + + sisyphus.syncDatabase.syncLocal() + else: + sys.exit("\n" + "Ok; Quitting." + "\n") + else: + print("\n" + "These are the source packages that would be merged, in order:" + "\n\n" + " ".join(areSources) + "\n\n" + "Total:" + " " + str(len(areSources)) + " " + "source package(s)" + "\n") + if input("Would you like to proceed?" + " " + "[y/N]" + " ").lower().strip()[:1] == "y": + portageExec = subprocess.Popen(['emerge', '--update', '--deep', '--newuse', '--backtrack=100', '--with-bdeps=y', '--misspell-suggestion=n', '--fuzzy-search=n', '@world'], stdout=subprocess.PIPE, stderr=subprocess.PIPE) + stdout, stderr = portageExec.communicate() + + for portageOutput in io.TextIOWrapper(portageExec.stdout, encoding="utf-8"): + if not "These are the packages that would be merged, in order:" in portageOutput.rstrip(): + if not "Calculating dependencies" in portageOutput.rstrip(): + print(portageOutput.rstrip()) + + sisyphus.syncDatabase.syncLocal() + else: + sys.exit("\n" + "Ok; Quitting." + "\n") + else: + portageExec = subprocess.Popen(['emerge', '--quiet', '--update', '--deep', '--newuse', '--pretend', '--getbinpkg', '--rebuilt-binaries', '--backtrack=100', '--with-bdeps=y', '--misspell-suggestion=n', '--fuzzy-search=n', '@world'], stdout=subprocess.PIPE, stderr=subprocess.PIPE) + stdout, stderr = portageExec.communicate() + + for portageOutput in io.TextIOWrapper(portageExec.stdout, encoding="utf-8"): + if not "Local copy of remote index is up-to-date and will be used." in portageOutput.rstrip(): + if not "ebuild" in portageOutput.rstrip(): + if not "binary" in portageOutput.rstrip(): + print(portageOutput.rstrip()) + + sys.exit("\n" + "Cannot proceed; Apply the above changes to your portage configuration files and try again; Quitting." + "\n") + else: + sys.exit("\nYou need root permissions to do this, exiting!\n") + -- cgit v1.2.3