From ed88746cd33c0f861e9c45bf05bf9e44d86089ba Mon Sep 17 00:00:00 2001 From: V3n3RiX Date: Sat, 6 Jun 2020 20:37:56 +0100 Subject: filesystem module : gather all the folder and file paths used by sisyphus under one module, and expose them to other modules from there --- src/backend/__init__.py | 2 +- src/backend/branchmaster.py | 29 +++++++++++++--------------- src/backend/branchnext.py | 29 +++++++++++++--------------- src/backend/branchreset.py | 41 +++++++++++++++++++--------------------- src/backend/cache.py | 13 ++++++------- src/backend/check.py | 8 +++----- src/backend/database.py | 20 ++++++++------------ src/backend/filesystem.py | 12 ++++++++++++ src/backend/install.py | 23 +++++++++++----------- src/backend/metadata.py | 23 +++++++++++----------- src/backend/mirror.py | 6 +++--- src/backend/rescue.py | 22 +++++++++------------ src/backend/sync.py | 11 ++++------- src/backend/upgrade.py | 23 +++++++++++----------- src/frontend/gui/sisyphus-gui.py | 26 ++++++++++++------------- 15 files changed, 137 insertions(+), 151 deletions(-) create mode 100644 src/backend/filesystem.py diff --git a/src/backend/__init__.py b/src/backend/__init__.py index c5f8f58..d9fdc29 100644 --- a/src/backend/__init__.py +++ b/src/backend/__init__.py @@ -7,6 +7,7 @@ from .cache import * from .check import * from .csvfiles import * from .database import * +from .filesystem import * from .help import * from .install import * from .killportage import * @@ -24,4 +25,3 @@ from .uninstallforce import * from .uninstall import * from .update import * from .upgrade import * - diff --git a/src/backend/branchmaster.py b/src/backend/branchmaster.py index 6229511..6a114c5 100644 --- a/src/backend/branchmaster.py +++ b/src/backend/branchmaster.py @@ -3,15 +3,12 @@ import animation import os import subprocess - -gentooEbuildDir = '/usr/ports/gentoo' -redcoreEbuildDir = '/usr/ports/redcore' -portageConfigDir = '/opt/redcore-build' +import sisyphus.filesystem @animation.wait('injecting gentoo linux portage tree - branch master') def setGitlabMasterStage1(): - if not os.path.isdir(os.path.join(gentooEbuildDir, '.git')): - os.chdir(gentooEbuildDir) + if not os.path.isdir(os.path.join(sisyphus.filesystem.gentooEbuildDir, '.git')): + os.chdir(sisyphus.filesystem.gentooEbuildDir) subprocess.call(['git', 'init', '-q']) subprocess.call(['git', 'remote', 'add', 'origin', 'https://gitlab.com/redcore/portage.git']) subprocess.call(['git', 'fetch', '--depth=1', 'origin', 'master', '--quiet']) @@ -19,8 +16,8 @@ def setGitlabMasterStage1(): @animation.wait('injecting redcore linux ebuild tree - branch master') def setGitlabMasterStage2(): - if not os.path.isdir(os.path.join(redcoreEbuildDir, '.git')): - os.chdir(redcoreEbuildDir) + if not os.path.isdir(os.path.join(sisyphus.filesystem.redcoreEbuildDir, '.git')): + os.chdir(sisyphus.filesystem.redcoreEbuildDir) subprocess.call(['git', 'init', '-q']) subprocess.call(['git', 'remote', 'add', 'origin', 'https://gitlab.com/redcore/redcore-desktop.git']) subprocess.call(['git', 'fetch', '--depth=1', 'origin', 'master', '--quiet']) @@ -28,8 +25,8 @@ def setGitlabMasterStage2(): @animation.wait('injecting redcore linux portage configuration - branch master') def setGitlabMasterStage3(): - if not os.path.isdir(os.path.join(portageConfigDir, '.git')): - os.chdir(portageConfigDir) + if not os.path.isdir(os.path.join(sisyphus.filesystem.portageConfigDir, '.git')): + os.chdir(sisyphus.filesystem.portageConfigDir) subprocess.call(['git', 'init', '-q']) subprocess.call(['git', 'remote', 'add', 'origin', 'https://gitlab.com/redcore/redcore-build.git']) subprocess.call(['git', 'fetch', '--depth=1', 'origin', 'master', '--quiet']) @@ -42,8 +39,8 @@ def gitlabStart(): @animation.wait('injecting gentoo linux portage tree - branch master') def setPagureMasterStage1(): - if not os.path.isdir(os.path.join(gentooEbuildDir, '.git')): - os.chdir(gentooEbuildDir) + if not os.path.isdir(os.path.join(sisyphus.filesystem.gentooEbuildDir, '.git')): + os.chdir(sisyphus.filesystem.gentooEbuildDir) subprocess.call(['git', 'init', '-q']) subprocess.call(['git', 'remote', 'add', 'origin', 'https://pagure.io/redcore/portage.git']) subprocess.call(['git', 'fetch', '--depth=1', 'origin', 'master', '--quiet']) @@ -51,8 +48,8 @@ def setPagureMasterStage1(): @animation.wait('injecting redcore linux ebuild tree - branch master') def setPagureMasterStage2(): - if not os.path.isdir(os.path.join(redcoreEbuildDir, '.git')): - os.chdir(redcoreEbuildDir) + if not os.path.isdir(os.path.join(sisyphus.filesystem.redcoreEbuildDir, '.git')): + os.chdir(sisyphus.filesystem.redcoreEbuildDir) subprocess.call(['git', 'init', '-q']) subprocess.call(['git', 'remote', 'add', 'origin', 'https://pagure.io/redcore/redcore-desktop.git']) subprocess.call(['git', 'fetch', '--depth=1', 'origin', 'master', '--quiet']) @@ -60,8 +57,8 @@ def setPagureMasterStage2(): @animation.wait('injecting redcore linux portage configuration - branch master') def setPagureMasterStage3(): - if not os.path.isdir(os.path.join(portageConfigDir, '.git')): - os.chdir(portageConfigDir) + if not os.path.isdir(os.path.join(sisyphus.filesystem.portageConfigDir, '.git')): + os.chdir(sisyphus.filesystem.portageConfigDir) subprocess.call(['git', 'init', '-q']) subprocess.call(['git', 'remote', 'add', 'origin', 'https://pagure.io/redcore/redcore-build.git']) subprocess.call(['git', 'fetch', '--depth=1', 'origin', 'master', '--quiet']) diff --git a/src/backend/branchnext.py b/src/backend/branchnext.py index bb29b04..5c9e390 100644 --- a/src/backend/branchnext.py +++ b/src/backend/branchnext.py @@ -3,15 +3,12 @@ import animation import os import subprocess - -gentooEbuildDir = '/usr/ports/gentoo' -redcoreEbuildDir = '/usr/ports/redcore' -portageConfigDir = '/opt/redcore-build' +import sisyphus.filesystem @animation.wait('injecting gentoo linux portage tree - branch next') def setGitlabNextStage1(): - if not os.path.isdir(os.path.join(gentooEbuildDir, '.git')): - os.chdir(gentooEbuildDir) + if not os.path.isdir(os.path.join(sisyphus.filesystem.gentooEbuildDir, '.git')): + os.chdir(sisyphus.filesystem.gentooEbuildDir) subprocess.call(['git', 'init', '-q']) subprocess.call(['git', 'remote', 'add', 'origin', 'https://gitlab.com/redcore/portage.git']) subprocess.call(['git', 'fetch', '--depth=1', 'origin', 'next', '--quiet']) @@ -19,8 +16,8 @@ def setGitlabNextStage1(): @animation.wait('injecting redcore linux ebuild tree - branch next') def setGitlabNextStage2(): - if not os.path.isdir(os.path.join(redcoreEbuildDir, '.git')): - os.chdir(redcoreEbuildDir) + if not os.path.isdir(os.path.join(sisyphus.filesystem.redcoreEbuildDir, '.git')): + os.chdir(sisyphus.filesystem.redcoreEbuildDir) subprocess.call(['git', 'init', '-q']) subprocess.call(['git', 'remote', 'add', 'origin', 'https://gitlab.com/redcore/redcore-desktop.git']) subprocess.call(['git', 'fetch', '--depth=1', 'origin', 'next', '--quiet']) @@ -28,8 +25,8 @@ def setGitlabNextStage2(): @animation.wait('injecting redcore linux portage configuration - branch next') def setGitlabNextStage3(): - if not os.path.isdir(os.path.join(portageConfigDir, '.git')): - os.chdir(portageConfigDir) + if not os.path.isdir(os.path.join(sisyphus.filesystem.portageConfigDir, '.git')): + os.chdir(sisyphus.filesystem.portageConfigDir) subprocess.call(['git', 'init', '-q']) subprocess.call(['git', 'remote', 'add', 'origin', 'https://gitlab.com/redcore/redcore-build.git']) subprocess.call(['git', 'fetch', '--depth=1', 'origin', 'next', '--quiet']) @@ -42,8 +39,8 @@ def startGitlab(): @animation.wait('injecting gentoo linux portage tree - branch next') def setPagureNextStage1(): - if not os.path.isdir(os.path.join(gentooEbuildDir, '.git')): - os.chdir(gentooEbuildDir) + if not os.path.isdir(os.path.join(sisyphus.filesystem.gentooEbuildDir, '.git')): + os.chdir(sisyphus.filesystem.gentooEbuildDir) subprocess.call(['git', 'init', '-q']) subprocess.call(['git', 'remote', 'add', 'origin', 'https://pagure.io/redcore/portage.git']) subprocess.call(['git', 'fetch', '--depth=1', 'origin', 'next', '--quiet']) @@ -51,8 +48,8 @@ def setPagureNextStage1(): @animation.wait('injecting redcore linux ebuild tree - branch next') def setPagureNextStage2(): - if not os.path.isdir(os.path.join(redcoreEbuildDir, '.git')): - os.chdir(redcoreEbuildDir) + if not os.path.isdir(os.path.join(sisyphus.filesystem.redcoreEbuildDir, '.git')): + os.chdir(sisyphus.filesystem.redcoreEbuildDir) subprocess.call(['git', 'init', '-q']) subprocess.call(['git', 'remote', 'add', 'origin', 'https://pagure.io/redcore/redcore-desktop.git']) subprocess.call(['git', 'fetch', '--depth=1', 'origin', 'next', '--quiet']) @@ -60,8 +57,8 @@ def setPagureNextStage2(): @animation.wait('injecting redcore linux portage configuration - branch next') def setPagureNextStage3(): - if not os.path.isdir(os.path.join(portageConfigDir, '.git')): - os.chdir(portageConfigDir) + if not os.path.isdir(os.path.join(sisyphus.filesystem.portageConfigDir, '.git')): + os.chdir(sisyphus.filesystem.portageConfigDir) subprocess.call(['git', 'init', '-q']) subprocess.call(['git', 'remote', 'add', 'origin', 'https://pagure.io/redcore/redcore-build.git']) subprocess.call(['git', 'fetch', '--depth=1', 'origin', 'next', '--quiet']) diff --git a/src/backend/branchreset.py b/src/backend/branchreset.py index 6168a25..def225a 100644 --- a/src/backend/branchreset.py +++ b/src/backend/branchreset.py @@ -3,36 +3,33 @@ import animation import os import shutil - -gentooEbuildDir = '/usr/ports/gentoo' -redcoreEbuildDir = '/usr/ports/redcore' -portageConfigDir = '/opt/redcore-build' +import sisyphus.filesystem @animation.wait('resetting branch configuration') def start(): - if os.path.isdir(gentooEbuildDir): - for files in os.listdir(gentooEbuildDir): - if os.path.isfile(os.path.join(gentooEbuildDir, files)): - os.remove(os.path.join(gentooEbuildDir, files)) + if os.path.isdir(sisyphus.filesystem.gentooEbuildDir): + for files in os.listdir(sisyphus.filesystem.gentooEbuildDir): + if os.path.isfile(os.path.join(sisyphus.filesystem.gentooEbuildDir, files)): + os.remove(os.path.join(sisyphus.filesystem.gentooEbuildDir, files)) else: - shutil.rmtree(os.path.join(gentooEbuildDir, files)) + shutil.rmtree(os.path.join(sisyphus.filesystem.gentooEbuildDir, files)) else: - os.makedirs(gentooEbuildDir) + os.makedirs(sisyphus.filesystem.gentooEbuildDir) - if os.path.isdir(redcoreEbuildDir): - for files in os.listdir(redcoreEbuildDir): - if os.path.isfile(os.path.join(redcoreEbuildDir, files)): - os.remove(os.path.join(redcoreEbuildDir, files)) + if os.path.isdir(sisyphus.filesystem.redcoreEbuildDir): + for files in os.listdir(sisyphus.filesystem.redcoreEbuildDir): + if os.path.isfile(os.path.join(sisyphus.filesystem.redcoreEbuildDir, files)): + os.remove(os.path.join(sisyphus.filesystem.redcoreEbuildDir, files)) else: - shutil.rmtree(os.path.join(redcoreEbuildDir, files)) + shutil.rmtree(os.path.join(sisyphus.filesystem.redcoreEbuildDir, files)) else: - os.makedirs(redcoreEbuildDir) + os.makedirs(sisyphus.filesystem.redcoreEbuildDir) - if os.path.isdir(portageConfigDir): - for files in os.listdir(portageConfigDir): - if os.path.isfile(os.path.join(portageConfigDir, files)): - os.remove(os.path.join(portageConfigDir, files)) + 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(portageConfigDir, files)) + shutil.rmtree(os.path.join(sisyphus.filesystem.portageConfigDir, files)) else: - os.makedirs(portageConfigDir) + os.makedirs(sisyphus.filesystem.portageConfigDir) diff --git a/src/backend/cache.py b/src/backend/cache.py index aaa0a32..b040323 100644 --- a/src/backend/cache.py +++ b/src/backend/cache.py @@ -2,13 +2,12 @@ import os import shutil - -portageCacheDir = '/var/cache/packages' +import sisyphus.filesystem def clean(): - if os.path.isdir(portageCacheDir): - for files in os.listdir(portageCacheDir): - if os.path.isfile(os.path.join(portageCacheDir, files)): - os.remove(os.path.join(portageCacheDir, files)) + 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(portageCacheDir, files)) + shutil.rmtree(os.path.join(sisyphus.filesystem.portageCacheDir, files)) diff --git a/src/backend/check.py b/src/backend/check.py index 2f46357..ee580a2 100644 --- a/src/backend/check.py +++ b/src/backend/check.py @@ -3,16 +3,14 @@ import os import sys import subprocess - -gentooEbuildDir = '/usr/ports/gentoo' -redcoreEbuildDir = '/usr/ports/redcore' +import sisyphus.filesystem def root(): if not os.getuid() == 0: sys.exit("\nYou need root permissions to do this, exiting!\n") def portage(): - os.chdir(gentooEbuildDir) + os.chdir(sisyphus.filesystem.gentooEbuildDir) needsPortageSync = int() localBranch = subprocess.check_output(['git', 'rev-parse', '--abbrev-ref', 'HEAD']) @@ -28,7 +26,7 @@ def portage(): return needsPortageSync def overlay(): - os.chdir(redcoreEbuildDir) + os.chdir(sisyphus.filesystem.redcoreEbuildDir) needsOverlaySync = int() localBranch = subprocess.check_output(['git', 'rev-parse', '--abbrev-ref', 'HEAD']) diff --git a/src/backend/database.py b/src/backend/database.py index 277a265..21db17e 100644 --- a/src/backend/database.py +++ b/src/backend/database.py @@ -6,20 +6,16 @@ import urllib3 import sqlite3 import subprocess import sisyphus.csvfiles - -remotePkgsDB = '/var/lib/sisyphus/csv/remotePackagesPre.csv' -remoteDscsDB = '/var/lib/sisyphus/csv/remoteDescriptionsPre.csv' -localPkgsDB = '/var/lib/sisyphus/csv/localPackagesPre.csv' -sisyphusDB = '/var/lib/sisyphus/db/sisyphus.db' +import sisyphus.filesystem def getRemote(): remotePkgCsv,remoteDescCsv = sisyphus.csvfiles.getURL() http = urllib3.PoolManager() - with http.request('GET', remotePkgCsv, preload_content=False) as tmp_buffer, open(remotePkgsDB, 'wb') as output_file: + with http.request('GET', remotePkgCsv, preload_content=False) as tmp_buffer, open(sisyphus.filesystem.remotePkgsDB, 'wb') as output_file: shutil.copyfileobj(tmp_buffer, output_file) - with http.request('GET', remoteDescCsv, preload_content=False) as tmp_buffer, open(remoteDscsDB, 'wb') as output_file: + with http.request('GET', remoteDescCsv, preload_content=False) as tmp_buffer, open(sisyphus.filesystem.remoteDscsDB, 'wb') as output_file: shutil.copyfileobj(tmp_buffer, output_file) def makeLocal(): @@ -28,17 +24,17 @@ def makeLocal(): def syncRemote(): getRemote() - sisyphusdb = sqlite3.connect(sisyphusDB) + sisyphusdb = sqlite3.connect(sisyphus.filesystem.sisyphusDB) 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(remotePkgsDB) as rmtCsv: + with open(sisyphus.filesystem.remotePkgsDB) as rmtCsv: for row in csv.reader(rmtCsv): sisyphusdb.cursor().execute("insert into remote_packages (category, name, version, slot) values (?, ?, ?, ?);", row) - with open(remoteDscsDB) as rmtCsv: + with open(sisyphus.filesystem.remoteDscsDB) as rmtCsv: for row in csv.reader(rmtCsv): sisyphusdb.cursor().execute("insert into remote_descriptions (category, name, description) values (?, ?, ?);", row) @@ -48,11 +44,11 @@ def syncRemote(): def syncLocal(): makeLocal() - sisyphusdb = sqlite3.connect(sisyphusDB) + sisyphusdb = sqlite3.connect(sisyphus.filesystem.sisyphusDB) 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(localPkgsDB) as lclCsv: + with open(sisyphus.filesystem.localPkgsDB) as lclCsv: for row in csv.reader(lclCsv): sisyphusdb.cursor().execute("insert into local_packages (category, name, version, slot) values (?, ?, ?, ?);", row) diff --git a/src/backend/filesystem.py b/src/backend/filesystem.py new file mode 100644 index 0000000..4338a2a --- /dev/null +++ b/src/backend/filesystem.py @@ -0,0 +1,12 @@ +#!/usr/bin/python3 + +gentooEbuildDir = '/usr/ports/gentoo' +redcoreEbuildDir = '/usr/ports/redcore' +portageConfigDir = '/opt/redcore-build' +portageCacheDir = '/var/cache/packages' +portageMetadataDir = '/var/cache/edb' +remotePkgsDB = '/var/lib/sisyphus/csv/remotePackagesPre.csv' +remoteDscsDB = '/var/lib/sisyphus/csv/remoteDescriptionsPre.csv' +localPkgsDB = '/var/lib/sisyphus/csv/localPackagesPre.csv' +sisyphusDB = '/var/lib/sisyphus/db/sisyphus.db' +mirrorCfg = '/etc/sisyphus/mirrors.conf' diff --git a/src/backend/install.py b/src/backend/install.py index ba1cfa0..cb13849 100644 --- a/src/backend/install.py +++ b/src/backend/install.py @@ -8,11 +8,10 @@ import io import wget import sisyphus.binhost import sisyphus.database +import sisyphus.filesystem import sisyphus.solvedeps import sisyphus.update -portageCacheDir = '/var/cache/packages' - def start(pkgList): sisyphus.update.start() @@ -22,7 +21,7 @@ def start(pkgList): if needsConfig == 0: if len(areSources) == 0: if not len(areBinaries) == 0: - os.chdir(portageCacheDir) + os.chdir(sisyphus.filesystem.portageCacheDir) print("\n" + "These are the binary packages that would be merged, in order:" + "\n\n" + str(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]): @@ -36,11 +35,11 @@ def start(pkgList): if os.path.exists(binary.rstrip().split("/")[1].replace('tbz2', 'xpak')): os.remove(binary.rstrip().split("/")[1].replace('tbz2', 'xpak')) - if os.path.isdir(os.path.join(portageCacheDir, CATEGORY.decode().strip())): - shutil.move(binary.rstrip().split("/")[1], os.path.join(os.path.join(portageCacheDir, CATEGORY.decode().strip()), os.path.basename(binary.rstrip().split("/")[1]))) + if os.path.isdir(os.path.join(sisyphus.filesystem.portageCacheDir, CATEGORY.decode().strip())): + shutil.move(binary.rstrip().split("/")[1], os.path.join(os.path.join(sisyphus.filesystem.portageCacheDir, CATEGORY.decode().strip()), os.path.basename(binary.rstrip().split("/")[1]))) else: - os.makedirs(os.path.join(portageCacheDir, CATEGORY.decode().strip())) - shutil.move(binary.rstrip().split("/")[1], os.path.join(os.path.join(portageCacheDir, CATEGORY.decode().strip()), os.path.basename(binary.rstrip().split("/")[1]))) + os.makedirs(os.path.join(sisyphus.filesystem.portageCacheDir, CATEGORY.decode().strip())) + shutil.move(binary.rstrip().split("/")[1], os.path.join(os.path.join(sisyphus.filesystem.portageCacheDir, CATEGORY.decode().strip()), os.path.basename(binary.rstrip().split("/")[1]))) if os.path.exists(binary.rstrip().split("/")[1]): os.remove(binary.rstrip().split("/")[1]) @@ -60,7 +59,7 @@ def start(pkgList): sys.exit("\n" + "No package found; Quitting." + "\n") else: if not len(areBinaries) == 0: - os.chdir(portageCacheDir) + os.chdir(sisyphus.filesystem.portageCacheDir) print("\n" + "These are the binary packages that would be merged, in order:" + "\n\n" + str(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" + str(areSources) + "\n\n" + "Total:" + " " + str(len(areSources)) + " " + "source package(s)" + "\n") if input("Would you like to proceed?" + " " + "[y/N]" + " ").lower().strip()[:1] == "y": @@ -75,11 +74,11 @@ def start(pkgList): if os.path.exists(binary.rstrip().split("/")[1].replace('tbz2', 'xpak')): os.remove(binary.rstrip().split("/")[1].replace('tbz2', 'xpak')) - if os.path.isdir(os.path.join(portageCacheDir, CATEGORY.decode().strip())): - shutil.move(binary.rstrip().split("/")[1], os.path.join(os.path.join(portageCacheDir, CATEGORY.decode().strip()), os.path.basename(binary.rstrip().split("/")[1]))) + if os.path.isdir(os.path.join(sisyphus.filesystem.portageCacheDir, CATEGORY.decode().strip())): + shutil.move(binary.rstrip().split("/")[1], os.path.join(os.path.join(sisyphus.filesystem.portageCacheDir, CATEGORY.decode().strip()), os.path.basename(binary.rstrip().split("/")[1]))) else: - os.makedirs(os.path.join(portageCacheDir, CATEGORY.decode().strip())) - shutil.move(binary.rstrip().split("/")[1], os.path.join(os.path.join(portageCacheDir, CATEGORY.decode().strip()), os.path.basename(binary.rstrip().split("/")[1]))) + os.makedirs(os.path.join(sisyphus.filesystem.portageCacheDir, CATEGORY.decode().strip())) + shutil.move(binary.rstrip().split("/")[1], os.path.join(os.path.join(sisyphus.filesystem.portageCacheDir, CATEGORY.decode().strip()), os.path.basename(binary.rstrip().split("/")[1]))) if os.path.exists(binary.rstrip().split("/")[1]): os.remove(binary.rstrip().split("/")[1]) diff --git a/src/backend/metadata.py b/src/backend/metadata.py index fc30b15..a27e06a 100644 --- a/src/backend/metadata.py +++ b/src/backend/metadata.py @@ -4,16 +4,15 @@ import animation import os import shutil import subprocess - -portageMetadataDir = '/var/cache/edb' +import sisyphus.filesystem def regenSilent(): - if os.path.isdir(portageMetadataDir): - for files in os.listdir(portageMetadataDir): - if os.path.isfile(os.path.join(portageMetadataDir, files)): - os.remove(os.path.join(portageMetadataDir, files)) + 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(portageMetadataDir, files)) + shutil.rmtree(os.path.join(sisyphus.filesystem.portageMetadataDir, files)) portageExecStage1 = subprocess.Popen(['emerge', '--quiet', '--regen'], stdout=subprocess.PIPE) portageExecStage1.wait() @@ -22,12 +21,12 @@ def regenSilent(): @animation.wait("refreshing metadata") def regenAnimated(): - if os.path.isdir(portageMetadataDir): - for files in os.listdir(portageMetadataDir): - if os.path.isfile(os.path.join(portageMetadataDir, files)): - os.remove(os.path.join(portageMetadataDir, files)) + 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(portageMetadataDir, files)) + shutil.rmtree(os.path.join(sisyphus.filesystem.portageMetadataDir, files)) portageExecStage1 = subprocess.Popen(['emerge', '--quiet', '--regen'], stdout=subprocess.PIPE) portageExecStage1.wait() diff --git a/src/backend/mirror.py b/src/backend/mirror.py index 7d041cf..6843e59 100644 --- a/src/backend/mirror.py +++ b/src/backend/mirror.py @@ -1,11 +1,11 @@ #!/usr/bin/python3 -mirrorCfg = '/etc/sisyphus/mirrors.conf' +import sisyphus.filesystem def getList(): mirrorList = [] - with open(mirrorCfg) as mirrorFile: + with open(sisyphus.filesystem.mirrorCfg) as mirrorFile: for line in mirrorFile.readlines(): if 'PORTAGE_BINHOST=' in line: url = line.split("=")[1].replace('"', '').rstrip() @@ -27,7 +27,7 @@ def printList(): print(i + 1, ' ', line['Url']) def writeList(mirrorList): - with open(mirrorCfg, 'w+') as mirrorFile: + with open(sisyphus.filesystem.mirrorCfg, 'w+') as mirrorFile: mirrorFile.write("#######################################################\n") mirrorFile.write("# Support for multiple mirrors is somewhat incomplete #\n") mirrorFile.write("#######################################################\n") diff --git a/src/backend/rescue.py b/src/backend/rescue.py index 18523d4..96d347f 100644 --- a/src/backend/rescue.py +++ b/src/backend/rescue.py @@ -3,22 +3,18 @@ import animation import os import sisyphus.database - -remotePkgsDB = '/var/lib/sisyphus/csv/remotePackagesPre.csv' -remoteDscsDB = '/var/lib/sisyphus/csv/remoteDescriptionsPre.csv' -localPkgsDB = '/var/lib/sisyphus/csv/localPackagesPre.csv' -sisyphusDB = '/var/lib/sisyphus/db/sisyphus.db' +import sisyphus.filesystem @animation.wait('recovering databases') def start(): - if os.path.exists(remotePkgsDB): - os.remove(remotePkgsDB) - if os.path.exists(remoteDscsDB): - os.remove(remoteDscsDB) - if os.path.exists(localPkgsDB): - os.remove(localPkgsDB) - if os.path.exists(sisyphusDB): - os.remove(sisyphusDB) + if os.path.exists(sisyphus.filesystem.remotePkgsDB): + os.remove(sisyphus.filesystem.remotePkgsDB) + if os.path.exists(sisyphus.filesystem.remoteDscsDB): + os.remove(sisyphus.filesystem.remoteDscsDB) + if os.path.exists(sisyphus.filesystem.localPkgsDB): + os.remove(sisyphus.filesystem.localPkgsDB) + if os.path.exists(sisyphus.filesystem.sisyphusDB): + os.remove(sisyphus.filesystem.sisyphusDB) sisyphus.database.syncRemote() sisyphus.database.syncLocal() diff --git a/src/backend/sync.py b/src/backend/sync.py index b8fd91c..65afd2f 100644 --- a/src/backend/sync.py +++ b/src/backend/sync.py @@ -2,13 +2,10 @@ import os import subprocess - -gentooEbuildDir = '/usr/ports/gentoo' -redcoreEbuildDir = '/usr/ports/redcore' -portageConfigDir = '/opt/redcore-build' +import sisyphus.filesystem def portage(): - os.chdir(gentooEbuildDir) + os.chdir(sisyphus.filesystem.gentooEbuildDir) localBranch = subprocess.check_output(['git', 'rev-parse', '--abbrev-ref', 'HEAD']) remoteBranch = subprocess.check_output(['git', 'rev-parse', '--symbolic-full-name', '@{u}']) @@ -18,7 +15,7 @@ def portage(): gitExecStage2.wait() def overlay(): - os.chdir(redcoreEbuildDir) + os.chdir(sisyphus.filesystem.redcoreEbuildDir) localBranch = subprocess.check_output(['git', 'rev-parse', '--abbrev-ref', 'HEAD']) remoteBranch = subprocess.check_output(['git', 'rev-parse', '--symbolic-full-name', '@{u}']) @@ -28,7 +25,7 @@ def overlay(): gitExecStage2.wait() def portageCfg(): - os.chdir(portageConfigDir) + 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}']) diff --git a/src/backend/upgrade.py b/src/backend/upgrade.py index 0a3762d..d2961d6 100644 --- a/src/backend/upgrade.py +++ b/src/backend/upgrade.py @@ -8,11 +8,10 @@ import io import wget import sisyphus.binhost import sisyphus.database +import sisyphus.filesystem import sisyphus.solvedeps import sisyphus.update -portageCacheDir = '/var/cache/packages' - def start(): sisyphus.update.start() @@ -22,7 +21,7 @@ def start(): if needsConfig == 0: if len(areSources) == 0: if not len(areBinaries) == 0: - os.chdir(portageCacheDir) + os.chdir(sisyphus.filesystem.portageCacheDir) print("\n" + "These are the binary packages that would be merged, in order:" + "\n\n" + str(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]): @@ -36,11 +35,11 @@ def start(): if os.path.exists(binary.rstrip().split("/")[1].replace('tbz2', 'xpak')): os.remove(binary.rstrip().split("/")[1].replace('tbz2', 'xpak')) - if os.path.isdir(os.path.join(portageCacheDir, CATEGORY.decode().strip())): - shutil.move(binary.rstrip().split("/")[1], os.path.join(os.path.join(portageCacheDir, CATEGORY.decode().strip()), os.path.basename(binary.rstrip().split("/")[1]))) + if os.path.isdir(os.path.join(sisyphus.filesystem.portageCacheDir, CATEGORY.decode().strip())): + shutil.move(binary.rstrip().split("/")[1], os.path.join(os.path.join(sisyphus.filesystem.portageCacheDir, CATEGORY.decode().strip()), os.path.basename(binary.rstrip().split("/")[1]))) else: - os.makedirs(os.path.join(portageCacheDir, CATEGORY.decode().strip())) - shutil.move(binary.rstrip().split("/")[1], os.path.join(os.path.join(portageCacheDir, CATEGORY.decode().strip()), os.path.basename(binary.rstrip().split("/")[1]))) + os.makedirs(os.path.join(sisyphus.filesystem.portageCacheDir, CATEGORY.decode().strip())) + shutil.move(binary.rstrip().split("/")[1], os.path.join(os.path.join(sisyphus.filesystem.portageCacheDir, CATEGORY.decode().strip()), os.path.basename(binary.rstrip().split("/")[1]))) if os.path.exists(binary.rstrip().split("/")[1]): os.remove(binary.rstrip().split("/")[1]) @@ -60,7 +59,7 @@ def start(): sys.exit("\n" + "No package upgrades found; Quitting." + "\n") else: if not len(areBinaries) == 0: - os.chdir(portageCacheDir) + os.chdir(sisyphus.filesystem.portageCacheDir) print("\n" + "These are the binary packages that would be merged, in order:" + "\n\n" + str(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" + str(areSources) + "\n\n" + "Total:" + " " + str(len(areSources)) + " " + "source package(s)" + "\n") if input("Would you like to proceed?" + " " + "[y/N]" + " ").lower().strip()[:1] == "y": @@ -75,11 +74,11 @@ def start(): if os.path.exists(binary.rstrip().split("/")[1].replace('tbz2', 'xpak')): os.remove(binary.rstrip().split("/")[1].replace('tbz2', 'xpak')) - if os.path.isdir(os.path.join(portageCacheDir, CATEGORY.decode().strip())): - shutil.move(binary.rstrip().split("/")[1], os.path.join(os.path.join(portageCacheDir, CATEGORY.decode().strip()), os.path.basename(binary.rstrip().split("/")[1]))) + if os.path.isdir(os.path.join(sisyphus.filesystem.portageCacheDir, CATEGORY.decode().strip())): + shutil.move(binary.rstrip().split("/")[1], os.path.join(os.path.join(sisyphus.filesystem.portageCacheDir, CATEGORY.decode().strip()), os.path.basename(binary.rstrip().split("/")[1]))) else: - os.makedirs(os.path.join(portageCacheDir, CATEGORY.decode().strip())) - shutil.move(binary.rstrip().split("/")[1], os.path.join(os.path.join(portageCacheDir, CATEGORY.decode().strip()), os.path.basename(binary.rstrip().split("/")[1]))) + os.makedirs(os.path.join(sisyphus.filesystem.portageCacheDir, CATEGORY.decode().strip())) + shutil.move(binary.rstrip().split("/")[1], os.path.join(os.path.join(sisyphus.filesystem.portageCacheDir, CATEGORY.decode().strip()), os.path.basename(binary.rstrip().split("/")[1]))) if os.path.exists(binary.rstrip().split("/")[1]): os.remove(binary.rstrip().split("/")[1]) diff --git a/src/frontend/gui/sisyphus-gui.py b/src/frontend/gui/sisyphus-gui.py index 12e8da4..15ef316 100644 --- a/src/frontend/gui/sisyphus-gui.py +++ b/src/frontend/gui/sisyphus-gui.py @@ -204,7 +204,7 @@ class Sisyphus(QtWidgets.QMainWindow): AND iv <> av ''' % (Sisyphus.applicationView, Sisyphus.searchTerm, noVirtual)), ]) - with sqlite3.connect(sisyphus.database.sisyphusDB) as db: + with sqlite3.connect(sisyphus.filesystem.sisyphusDB) as db: cursor = db.cursor() cursor.execute('%s' % (self.SELECTS[Sisyphus.databaseView])) rows = cursor.fetchall() @@ -323,7 +323,7 @@ class MirrorConfiguration(QtWidgets.QMainWindow): super(MirrorConfiguration, self).__init__() uic.loadUi('/usr/share/sisyphus/ui/mirrorcfg.ui', self) self.centerOnScreen() - self.MIRRORLIST = getMirrorList() + self.MIRRORLIST = sisyphus.mirror.getList() self.updateMirrorList() self.applyButton.pressed.connect(self.mirrorCfgApply) self.applyButton.released.connect(self.mirrorCfgExit) @@ -352,7 +352,7 @@ class MirrorConfiguration(QtWidgets.QMainWindow): self.MIRRORLIST[self.ACTIVEMIRRORINDEX]['isActive'] = True def mirrorCfgApply(self): - writeMirrorCfg(self.MIRRORLIST) + sisyphus.mirror.writeList(self.MIRRORLIST) def mirrorCfgExit(self): self.close() @@ -402,7 +402,7 @@ class MainWorker(QtCore.QObject): binhostURL = sisyphus.binhost.getURL() areBinaries,areSources,needsConfig = sisyphus.solvedeps.package.__wrapped__(pkgList) #undecorate - os.chdir(sisyphus.cache.portageCacheDir) + os.chdir(sisyphus.filesystem.portageCacheDir) self.workerOutput.emit("\n" + "These are the binary packages that will be merged, in order:" + "\n\n" + str(areBinaries) + "\n\n" + "Total:" + " " + str(len(areBinaries)) + " " + "binary package(s)" + "\n\n") for index, binary in enumerate([package + '.tbz2' for package in areBinaries]): self.workerOutput.emit(">>> Fetching" + " " + binhostURL + binary) @@ -415,11 +415,11 @@ class MainWorker(QtCore.QObject): if os.path.exists(binary.rstrip().split("/")[1].replace('tbz2', 'xpak')): os.remove(binary.rstrip().split("/")[1].replace('tbz2', 'xpak')) - if os.path.isdir(os.path.join(sisyphus.cache.portageCacheDir, CATEGORY.decode().strip())): - shutil.move(binary.rstrip().split("/")[1], os.path.join(os.path.join(sisyphus.cache.portageCacheDir, CATEGORY.decode().strip()), os.path.basename(binary.rstrip().split("/")[1]))) + if os.path.isdir(os.path.join(sisyphus.filesystem.portageCacheDir, CATEGORY.decode().strip())): + shutil.move(binary.rstrip().split("/")[1], os.path.join(os.path.join(sisyphus.filesystem.portageCacheDir, CATEGORY.decode().strip()), os.path.basename(binary.rstrip().split("/")[1]))) else: - os.makedirs(os.path.join(sisyphus.cache.portageCacheDir, CATEGORY.decode().strip())) - shutil.move(binary.rstrip().split("/")[1], os.path.join(os.path.join(sisyphus.cache.portageCacheDir, CATEGORY.decode().strip()), os.path.basename(binary.rstrip().split("/")[1]))) + os.makedirs(os.path.join(sisyphus.filesystem.portageCacheDir, CATEGORY.decode().strip())) + shutil.move(binary.rstrip().split("/")[1], os.path.join(os.path.join(sisyphus.filesystem.portageCacheDir, CATEGORY.decode().strip()), os.path.basename(binary.rstrip().split("/")[1]))) if os.path.exists(binary.rstrip().split("/")[1]): os.remove(binary.rstrip().split("/")[1]) @@ -466,7 +466,7 @@ class MainWorker(QtCore.QObject): else: if not len(areBinaries) == 0: self.workerOutput.emit("\n" + "These are the binary packages that will be merged, in order:" + "\n\n" + str(areBinaries) + "\n\n" + "Total:" + " " + str(len(areBinaries)) + " " + "binary package(s)" + "\n\n") - os.chdir(sisyphus.cache.portageCacheDir) + os.chdir(sisyphus.filesystem.portageCacheDir) for index, binary in enumerate([package + '.tbz2' for package in areBinaries]): self.workerOutput.emit(">>> Fetching" + " " + binhostURL + binary) wget.download(binhostURL + binary) @@ -478,11 +478,11 @@ class MainWorker(QtCore.QObject): if os.path.exists(binary.rstrip().split("/")[1].replace('tbz2', 'xpak')): os.remove(binary.rstrip().split("/")[1].replace('tbz2', 'xpak')) - if os.path.isdir(os.path.join(sisyphus.cache.portageCacheDir, CATEGORY.decode().strip())): - shutil.move(binary.rstrip().split("/")[1], os.path.join(os.path.join(sisyphus.cache.portageCacheDir, CATEGORY.decode().strip()), os.path.basename(binary.rstrip().split("/")[1]))) + if os.path.isdir(os.path.join(sisyphus.filesystem.portageCacheDir, CATEGORY.decode().strip())): + shutil.move(binary.rstrip().split("/")[1], os.path.join(os.path.join(sisyphus.filesystem.portageCacheDir, CATEGORY.decode().strip()), os.path.basename(binary.rstrip().split("/")[1]))) else: - os.makedirs(os.path.join(sisyphus.cache.portageCacheDir, CATEGORY.decode().strip())) - shutil.move(binary.rstrip().split("/")[1], os.path.join(os.path.join(sisyphus.cache.portageCacheDir, CATEGORY.decode().strip()), os.path.basename(binary.rstrip().split("/")[1]))) + os.makedirs(os.path.join(sisyphus.filesystem.portageCacheDir, CATEGORY.decode().strip())) + shutil.move(binary.rstrip().split("/")[1], os.path.join(os.path.join(sisyphus.filesystem.portageCacheDir, CATEGORY.decode().strip()), os.path.basename(binary.rstrip().split("/")[1]))) if os.path.exists(binary.rstrip().split("/")[1]): os.remove(binary.rstrip().split("/")[1]) -- cgit v1.2.3