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/database.py | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) (limited to 'src/backend/database.py') 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) -- cgit v1.2.3