summaryrefslogtreecommitdiff
path: root/src/backend/syncDatabase.py
diff options
context:
space:
mode:
authorV3n3RiX <venerix@koprulu.sector>2022-09-17 19:12:53 +0100
committerV3n3RiX <venerix@koprulu.sector>2022-09-17 19:12:53 +0100
commite1562a71d6483021d332bccbfc5a3086688bc58c (patch)
tree6be3d468e0aadd6c4de6c4dbd7a58ebe9fd59cbb /src/backend/syncDatabase.py
parent0cf2c9f8ec52b1ae276c1573210d252ab0c4577b (diff)
rearrange the backend
Diffstat (limited to 'src/backend/syncDatabase.py')
-rw-r--r--src/backend/syncDatabase.py57
1 files changed, 57 insertions, 0 deletions
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()
+