From 1dc3bbe378ae39b10765c9e0f2a0ef995b4a287c Mon Sep 17 00:00:00 2001 From: V3n3RiX Date: Sun, 30 Oct 2022 20:11:44 +0000 Subject: move setMirror -> mirrors --- src/backend/__init__.py | 2 +- src/backend/mirrors.py | 59 ++++++++++++++++++++++++++++++++++++++++ src/backend/setMirror.py | 59 ---------------------------------------- src/frontend/cli/sisyphus-cli.py | 4 +-- src/frontend/gui/sisyphus-gui.py | 4 +-- 5 files changed, 64 insertions(+), 64 deletions(-) create mode 100644 src/backend/mirrors.py delete mode 100644 src/backend/setMirror.py diff --git a/src/backend/__init__.py b/src/backend/__init__.py index 3cd1b2e..19276cc 100644 --- a/src/backend/__init__.py +++ b/src/backend/__init__.py @@ -4,13 +4,13 @@ from .getenv import * from .getfs import * from .install import * from .killemerge import * +from .mirrors import * from .purgeenv import * from .recoverdb import * from .solvedeps import * from .search import * from .setbranch import * from .setjobs import * -from .setMirror import * from .setprofile import * from .syncdb import * from .syncenv import * diff --git a/src/backend/mirrors.py b/src/backend/mirrors.py new file mode 100644 index 0000000..ad02f58 --- /dev/null +++ b/src/backend/mirrors.py @@ -0,0 +1,59 @@ +#!/usr/bin/python3 + +import sisyphus.getfs + +def getList(): + mirrorList = [] + + with open(sisyphus.getfs.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.getfs.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/setMirror.py b/src/backend/setMirror.py deleted file mode 100644 index ad02f58..0000000 --- a/src/backend/setMirror.py +++ /dev/null @@ -1,59 +0,0 @@ -#!/usr/bin/python3 - -import sisyphus.getfs - -def getList(): - mirrorList = [] - - with open(sisyphus.getfs.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.getfs.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/frontend/cli/sisyphus-cli.py b/src/frontend/cli/sisyphus-cli.py index 3124fd0..4a514c8 100755 --- a/src/frontend/cli/sisyphus-cli.py +++ b/src/frontend/cli/sisyphus-cli.py @@ -277,12 +277,12 @@ def sysinfo(): @mirrorSetup.command("list") def mirrorlist(): """List available binary package repository mirrors (the active one is marked with *).""" - sisyphus.setMirror.printList() + sisyphus.mirrors.printList() @mirrorSetup.command("set") def mirrorset(index: int): """Change the binary package repository to the selected mirror.""" - sisyphus.setMirror.setActive(index) + sisyphus.mirrors.setActive(index) if __name__ == "__main__": if len(sys.argv) > 1 and not '--help' in sys.argv: diff --git a/src/frontend/gui/sisyphus-gui.py b/src/frontend/gui/sisyphus-gui.py index 020c47c..5b054e4 100644 --- a/src/frontend/gui/sisyphus-gui.py +++ b/src/frontend/gui/sisyphus-gui.py @@ -320,7 +320,7 @@ class MirrorConfiguration(QtWidgets.QMainWindow): super(MirrorConfiguration, self).__init__() uic.loadUi('/usr/share/sisyphus/ui/mirrorcfg.ui', self) self.centerOnScreen() - self.MIRRORLIST = sisyphus.setMirror.getList() + self.MIRRORLIST = sisyphus.mirrors.getList() self.updateMirrorList() self.applyButton.pressed.connect(self.mirrorCfgApply) self.applyButton.released.connect(self.mirrorCfgExit) @@ -351,7 +351,7 @@ class MirrorConfiguration(QtWidgets.QMainWindow): self.MIRRORLIST[self.ACTIVEMIRRORINDEX]['isActive'] = True def mirrorCfgApply(self): - sisyphus.setMirror.writeList(self.MIRRORLIST) + sisyphus.mirrors.writeList(self.MIRRORLIST) def mirrorCfgExit(self): self.close() -- cgit v1.2.3