summaryrefslogtreecommitdiff
path: root/src/backend/database.py
diff options
context:
space:
mode:
authorV3n3RiX <venerix@redcorelinux.org>2020-06-06 16:22:04 +0100
committerV3n3RiX <venerix@redcorelinux.org>2020-06-06 16:22:04 +0100
commitac0efd1bd6c703147bd8d3caedf489fab87d6131 (patch)
treee6af981b6e90be35447dbb88dd276a4d8ff2d47e /src/backend/database.py
parent49e6ab19aa461151132dfb4f1cf962d4ef403c66 (diff)
big rewrite : split the backend in smaller pieces, rework the cli frontend to work with the new backend ... gui frontend wip
Diffstat (limited to 'src/backend/database.py')
-rw-r--r--src/backend/database.py61
1 files changed, 61 insertions, 0 deletions
diff --git a/src/backend/database.py b/src/backend/database.py
new file mode 100644
index 0000000..277a265
--- /dev/null
+++ b/src/backend/database.py
@@ -0,0 +1,61 @@
+#!/usr/bin/python3
+
+import csv
+import shutil
+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'
+
+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:
+ shutil.copyfileobj(tmp_buffer, output_file)
+
+ with http.request('GET', remoteDescCsv, preload_content=False) as tmp_buffer, open(remoteDscsDB, '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(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:
+ for row in csv.reader(rmtCsv):
+ sisyphusdb.cursor().execute("insert into remote_packages (category, name, version, slot) values (?, ?, ?, ?);", row)
+
+ with open(remoteDscsDB) as rmtCsv:
+ for row in csv.reader(rmtCsv):
+ sisyphusdb.cursor().execute("insert into remote_descriptions (category, name, description) values (?, ?, ?);", row)
+
+ sisyphusdb.commit()
+ sisyphusdb.close()
+
+def syncLocal():
+ makeLocal()
+
+ sisyphusdb = sqlite3.connect(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:
+ for row in csv.reader(lclCsv):
+ sisyphusdb.cursor().execute("insert into local_packages (category, name, version, slot) values (?, ?, ?, ?);", row)
+
+ sisyphusdb.commit()
+ sisyphusdb.close()
+