[DEV] continue transfer in BDD
This commit is contained in:
parent
7f9c96bf1f
commit
d79ec42220
@ -113,7 +113,7 @@ default_values_type = [
|
|||||||
|
|
||||||
|
|
||||||
def add_interface(_name, _default_value = None):
|
def add_interface(_name, _default_value = None):
|
||||||
interface = data_interface.DataInterface(_name, os.path.join(tools.get_run_path(), app.config['REST_DATA'], "bdd_" + _name + ".json"))
|
interface = data_interface.DataInterface(_name, os.path.join(tools.get_run_path(), app.config['REST_DATA'], "bdd_" + _name + ".db3"))
|
||||||
if _default_value != None:
|
if _default_value != None:
|
||||||
if interface.count() == 0:
|
if interface.count() == 0:
|
||||||
interface.reset_with_value(_default_value);
|
interface.reset_with_value(_default_value);
|
||||||
|
@ -15,6 +15,20 @@ import random
|
|||||||
import copy
|
import copy
|
||||||
from sanic.exceptions import ServerError
|
from sanic.exceptions import ServerError
|
||||||
import sqlite3
|
import sqlite3
|
||||||
|
|
||||||
|
|
||||||
|
def dict_factory(cursor, row):
|
||||||
|
d = {}
|
||||||
|
for idx, col in enumerate(cursor.description):
|
||||||
|
if col[0] == "covers":
|
||||||
|
if row[idx] != None:
|
||||||
|
d[col[0]] = row[idx].split("/")
|
||||||
|
else:
|
||||||
|
d[col[0]] = None
|
||||||
|
else:
|
||||||
|
d[col[0]] = row[idx]
|
||||||
|
return d
|
||||||
|
|
||||||
##
|
##
|
||||||
## @breif Generic interface to access to the BDD (no BDD, direct file IO)
|
## @breif Generic interface to access to the BDD (no BDD, direct file IO)
|
||||||
##
|
##
|
||||||
@ -30,8 +44,9 @@ class DataInterface():
|
|||||||
self.mark_to_store()
|
self.mark_to_store()
|
||||||
else:
|
else:
|
||||||
self.conn = sqlite3.connect(self.file)
|
self.conn = sqlite3.connect(self.file)
|
||||||
self.cursor = self.conn.cursor()
|
self.conn.row_factory = dict_factory
|
||||||
self.upgrade_global_bdd_id();
|
#self.cursor = self.conn.cursor()
|
||||||
|
##self.upgrade_global_bdd_id();
|
||||||
|
|
||||||
def set_data_model(self, _data_model):
|
def set_data_model(self, _data_model):
|
||||||
self.model = _data_model
|
self.model = _data_model
|
||||||
@ -40,9 +55,11 @@ class DataInterface():
|
|||||||
self.bdd = _data
|
self.bdd = _data
|
||||||
self.last_id = 0
|
self.last_id = 0
|
||||||
self.mark_to_store()
|
self.mark_to_store()
|
||||||
self.upgrade_global_bdd_id();
|
##self.upgrade_global_bdd_id();
|
||||||
|
|
||||||
def check_with_model(self, _data):
|
def check_with_model(self, _data):
|
||||||
|
return True
|
||||||
|
"""
|
||||||
if self.model == None:
|
if self.model == None:
|
||||||
return True
|
return True
|
||||||
values = []
|
values = []
|
||||||
@ -85,8 +102,10 @@ class DataInterface():
|
|||||||
debug.warning("[key='" + key + "'] try to add wrong type in BDD " + type(_data[key]).__name__ + " is not: " + getattr(self.model, key).__name__)
|
debug.warning("[key='" + key + "'] try to add wrong type in BDD " + type(_data[key]).__name__ + " is not: " + getattr(self.model, key).__name__)
|
||||||
return False
|
return False
|
||||||
return True
|
return True
|
||||||
|
"""
|
||||||
|
|
||||||
def upgrade_global_bdd_id(self):
|
def upgrade_global_bdd_id(self):
|
||||||
|
"""
|
||||||
self.last_id = 0
|
self.last_id = 0
|
||||||
for elem in self.bdd:
|
for elem in self.bdd:
|
||||||
if 'id' not in elem.keys():
|
if 'id' not in elem.keys():
|
||||||
@ -96,8 +115,10 @@ class DataInterface():
|
|||||||
# start at a random value permit to vaidate the basis inctance test
|
# start at a random value permit to vaidate the basis inctance test
|
||||||
if self.last_id == 0:
|
if self.last_id == 0:
|
||||||
self.last_id = random.randint(20, 100)
|
self.last_id = random.randint(20, 100)
|
||||||
|
"""
|
||||||
|
|
||||||
def get_table_index(self, _id):
|
def get_table_index(self, _id):
|
||||||
|
"""
|
||||||
id_in_bdd = 0
|
id_in_bdd = 0
|
||||||
for elem in self.bdd:
|
for elem in self.bdd:
|
||||||
if 'id' in elem.keys() \
|
if 'id' in elem.keys() \
|
||||||
@ -105,6 +126,7 @@ class DataInterface():
|
|||||||
return id_in_bdd
|
return id_in_bdd
|
||||||
id_in_bdd += 1
|
id_in_bdd += 1
|
||||||
return None
|
return None
|
||||||
|
"""
|
||||||
|
|
||||||
##
|
##
|
||||||
## @brief Mark the current BDD to store all in File system (sync)
|
## @brief Mark the current BDD to store all in File system (sync)
|
||||||
@ -124,28 +146,39 @@ class DataInterface():
|
|||||||
|
|
||||||
def gets(self, filter=None):
|
def gets(self, filter=None):
|
||||||
debug.info("gets " + self.name)
|
debug.info("gets " + self.name)
|
||||||
|
cursor = self.conn.cursor()
|
||||||
|
cursor.execute('SELECT * FROM data WHERE deleted=0')
|
||||||
|
results = cursor.fetchall()
|
||||||
|
#debug.info("gets data = " + json.dumps(results, indent=4))
|
||||||
if filter == None:
|
if filter == None:
|
||||||
return self.bdd
|
return results
|
||||||
return self.filter_object_values(self.bdd, filter)
|
debug.warning("BDD does not suppor filter now ...");
|
||||||
|
return results
|
||||||
|
|
||||||
def gets_where(self, select, filter=None, order_by=None):
|
def gets_where(self, select, filter=None, order_by=None):
|
||||||
debug.info("gets " + self.name)
|
debug.info("gets " + self.name)
|
||||||
|
"""
|
||||||
tmp_list = self.get_sub_list(self.bdd, select)
|
tmp_list = self.get_sub_list(self.bdd, select)
|
||||||
tmp_list = self.order_by(tmp_list, order_by)
|
tmp_list = self.order_by(tmp_list, order_by)
|
||||||
return self.filter_object_values(tmp_list, filter);
|
return self.filter_object_values(tmp_list, filter);
|
||||||
|
"""
|
||||||
|
|
||||||
def get(self, _id):
|
def get(self, _id):
|
||||||
if type(_id) != int:
|
if type(_id) != int:
|
||||||
debug.warning("get wrong input type...")
|
debug.warning("get wrong input type...")
|
||||||
debug.info("get " + self.name + ": " + str(_id))
|
debug.info("get " + self.name + ": " + str(_id))
|
||||||
for elem in self.bdd:
|
cursor = self.conn.cursor()
|
||||||
if 'id' in elem.keys() \
|
#cursor.execute('SELECT * FROM data WHERE deleted=0')
|
||||||
and elem["id"] == _id:
|
#results = cursor.fetchall()
|
||||||
return elem
|
#debug.info("display data = " + json.dumps(results, indent=4))
|
||||||
debug.warning("not found element: " + str(len(self.bdd)))
|
req = (_id,)
|
||||||
return None
|
cursor.execute('SELECT * FROM data WHERE deleted=0 AND id=?', req)
|
||||||
|
results = cursor.fetchone()
|
||||||
|
#debug.info("get specific data = " + json.dumps(results))
|
||||||
|
return results;
|
||||||
|
|
||||||
def set(self, _id, _value):
|
def set(self, _id, _value):
|
||||||
|
"""
|
||||||
if type(_id) != int:
|
if type(_id) != int:
|
||||||
debug.warning("get wrong input type...")
|
debug.warning("get wrong input type...")
|
||||||
for elem in self.bdd:
|
for elem in self.bdd:
|
||||||
@ -155,18 +188,26 @@ class DataInterface():
|
|||||||
self.mark_to_store()
|
self.mark_to_store()
|
||||||
return elem
|
return elem
|
||||||
debug.warning("not found element: " + str(len(self.bdd)))
|
debug.warning("not found element: " + str(len(self.bdd)))
|
||||||
|
"""
|
||||||
return None
|
return None
|
||||||
|
|
||||||
def delete(self, _id):
|
def delete(self, _id):
|
||||||
debug.info("delete " + self.name + ": " + str(_id))
|
debug.info("delete " + self.name + ": " + str(_id))
|
||||||
id_in_bdd = self.get_table_index(_id)
|
req = (_id,)
|
||||||
if id_in_bdd == None:
|
cursor.execute('UPDATE data SET deleted=1 WHERE id=?', req)
|
||||||
return False
|
|
||||||
del self.bdd[id_in_bdd]
|
|
||||||
self.mark_to_store()
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def put(self, _id, _value):
|
def put(self, _id, _value):
|
||||||
|
request = 'UPDATE data WHERE id=? SET'
|
||||||
|
list_data = [_id]
|
||||||
|
for elem in _value.keys():
|
||||||
|
if elem == "id":
|
||||||
|
continue
|
||||||
|
list_data.append(_value[elem])
|
||||||
|
request += " '" + elem + "' = ?"
|
||||||
|
cursor.execute(request, list_data)
|
||||||
|
|
||||||
|
"""
|
||||||
debug.info("put " + self.name + ": " + str(_id))
|
debug.info("put " + self.name + ": " + str(_id))
|
||||||
id_in_bdd = self.get_table_index(_id)
|
id_in_bdd = self.get_table_index(_id)
|
||||||
if id_in_bdd == None:
|
if id_in_bdd == None:
|
||||||
@ -182,9 +223,11 @@ class DataInterface():
|
|||||||
self.bdd[id_in_bdd] = value_bdd
|
self.bdd[id_in_bdd] = value_bdd
|
||||||
debug.warning(" ==> " + str(self.bdd[id_in_bdd]))
|
debug.warning(" ==> " + str(self.bdd[id_in_bdd]))
|
||||||
self.mark_to_store()
|
self.mark_to_store()
|
||||||
|
"""
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def post(self, _value):
|
def post(self, _value):
|
||||||
|
"""
|
||||||
debug.info("post " + self.name)
|
debug.info("post " + self.name)
|
||||||
_value["id"] = self.last_id
|
_value["id"] = self.last_id
|
||||||
self.last_id += 1
|
self.last_id += 1
|
||||||
@ -192,10 +235,12 @@ class DataInterface():
|
|||||||
raise ServerError("Corelation with BDD error", status_code=404)
|
raise ServerError("Corelation with BDD error", status_code=404)
|
||||||
self.bdd.append(_value)
|
self.bdd.append(_value)
|
||||||
self.mark_to_store()
|
self.mark_to_store()
|
||||||
|
"""
|
||||||
return _value
|
return _value
|
||||||
|
|
||||||
# TODO : rework this
|
# TODO : rework this
|
||||||
def find(self, _list_token, _values):
|
def find(self, _list_token, _values):
|
||||||
|
"""
|
||||||
out = []
|
out = []
|
||||||
for elem in self.bdd:
|
for elem in self.bdd:
|
||||||
find = True
|
find = True
|
||||||
@ -206,14 +251,19 @@ class DataInterface():
|
|||||||
if find == True:
|
if find == True:
|
||||||
out.append(elem)
|
out.append(elem)
|
||||||
return out
|
return out
|
||||||
|
"""
|
||||||
|
pass
|
||||||
|
|
||||||
def count(self, select = None):
|
def count(self, select = None):
|
||||||
if select == None:
|
"""if select == None:
|
||||||
return len(self.bdd)
|
return len(self.bdd)
|
||||||
tmp = self.get_sub_list(self.bdd, select)
|
tmp = self.get_sub_list(self.bdd, select)
|
||||||
return len(tmp)
|
return len(tmp)
|
||||||
|
"""
|
||||||
|
pass
|
||||||
|
|
||||||
def get_sub_list(self, _values, _select):
|
def get_sub_list(self, _values, _select):
|
||||||
|
"""
|
||||||
out = []
|
out = []
|
||||||
for elem in _values:
|
for elem in _values:
|
||||||
find = True
|
find = True
|
||||||
@ -274,8 +324,11 @@ class DataInterface():
|
|||||||
if find == True:
|
if find == True:
|
||||||
out.append(elem)
|
out.append(elem)
|
||||||
return out
|
return out
|
||||||
|
"""
|
||||||
|
pass
|
||||||
|
|
||||||
def order_by(self, _values, _order):
|
def order_by(self, _values, _order):
|
||||||
|
"""
|
||||||
if _order == None:
|
if _order == None:
|
||||||
return _values
|
return _values
|
||||||
if len(_order) == 0:
|
if len(_order) == 0:
|
||||||
@ -297,8 +350,11 @@ class DataInterface():
|
|||||||
for elem in out_unclassable:
|
for elem in out_unclassable:
|
||||||
out.append(elem);
|
out.append(elem);
|
||||||
return out;
|
return out;
|
||||||
|
"""
|
||||||
|
pass
|
||||||
|
|
||||||
def filter_object_values(self, _values, _filter):
|
def filter_object_values(self, _values, _filter):
|
||||||
|
"""
|
||||||
out = []
|
out = []
|
||||||
if _filter == None:
|
if _filter == None:
|
||||||
return _values
|
return _values
|
||||||
@ -318,5 +374,6 @@ class DataInterface():
|
|||||||
element_out[token] = elem[token]
|
element_out[token] = elem[token]
|
||||||
out.append(element_out)
|
out.append(element_out)
|
||||||
return out
|
return out
|
||||||
|
"""
|
||||||
|
|
||||||
|
|
||||||
|
@ -40,7 +40,8 @@ c = conn.cursor()
|
|||||||
# Create table
|
# Create table
|
||||||
c.execute('''
|
c.execute('''
|
||||||
CREATE TABLE data(
|
CREATE TABLE data(
|
||||||
id INTEGER PRIMARY KEY ,
|
id INTEGER PRIMARY KEY,
|
||||||
|
deleted INTEGER,
|
||||||
sha512 TEXT NOT NULL,
|
sha512 TEXT NOT NULL,
|
||||||
mime_type TEXT NOT NULL,
|
mime_type TEXT NOT NULL,
|
||||||
size INTEGER NOT NULL,
|
size INTEGER NOT NULL,
|
||||||
@ -63,7 +64,7 @@ for elem in my_old_bdd:
|
|||||||
sha512 = elem["sha512"]
|
sha512 = elem["sha512"]
|
||||||
size = elem["size"]
|
size = elem["size"]
|
||||||
request_insert = (id, sha512, mime_type, size, new_time, original_name)
|
request_insert = (id, sha512, mime_type, size, new_time, original_name)
|
||||||
c.execute('INSERT INTO data VALUES (?,?,?,?,?,?)', request_insert)
|
c.execute('INSERT INTO data VALUES (?,0,?,?,?,?,?)', request_insert)
|
||||||
|
|
||||||
# Save (commit) the changes
|
# Save (commit) the changes
|
||||||
conn.commit()
|
conn.commit()
|
||||||
|
@ -41,7 +41,8 @@ c = conn.cursor()
|
|||||||
# Create table
|
# Create table
|
||||||
c.execute('''
|
c.execute('''
|
||||||
CREATE TABLE data (
|
CREATE TABLE data (
|
||||||
id INTEGER PRIMARY KEY ,
|
id INTEGER PRIMARY KEY,
|
||||||
|
deleted INTEGER,
|
||||||
create_date INTEGER NOT NULL,
|
create_date INTEGER NOT NULL,
|
||||||
modify_date INTEGER NOT NULL,
|
modify_date INTEGER NOT NULL,
|
||||||
name TEXT NOT NULL,
|
name TEXT NOT NULL,
|
||||||
@ -78,7 +79,7 @@ for elem in my_old_bdd:
|
|||||||
if covers == None:
|
if covers == None:
|
||||||
covers = [];
|
covers = [];
|
||||||
request_insert = (id, new_time, new_time, name, description, list_to_string(covers))
|
request_insert = (id, new_time, new_time, name, description, list_to_string(covers))
|
||||||
c.execute('INSERT INTO data VALUES (?,?,?,?,?,?)', request_insert)
|
c.execute('INSERT INTO data VALUES (?,0,?,?,?,?,?)', request_insert)
|
||||||
|
|
||||||
# Save (commit) the changes
|
# Save (commit) the changes
|
||||||
conn.commit()
|
conn.commit()
|
||||||
|
@ -41,7 +41,8 @@ c = conn.cursor()
|
|||||||
# Create table
|
# Create table
|
||||||
c.execute('''
|
c.execute('''
|
||||||
CREATE TABLE data (
|
CREATE TABLE data (
|
||||||
id INTEGER PRIMARY KEY ,
|
id INTEGER PRIMARY KEY,
|
||||||
|
deleted INTEGER,
|
||||||
create_date INTEGER NOT NULL,
|
create_date INTEGER NOT NULL,
|
||||||
modify_date INTEGER NOT NULL,
|
modify_date INTEGER NOT NULL,
|
||||||
number INTEGER NOT NULL,
|
number INTEGER NOT NULL,
|
||||||
@ -83,7 +84,7 @@ for elem in my_old_bdd:
|
|||||||
if covers == None:
|
if covers == None:
|
||||||
covers = [];
|
covers = [];
|
||||||
request_insert = (id, new_time, new_time, name, description, group_id, list_to_string(covers))
|
request_insert = (id, new_time, new_time, name, description, group_id, list_to_string(covers))
|
||||||
c.execute('INSERT INTO data VALUES (?,?,?,?,?,?)', request_insert)
|
c.execute('INSERT INTO data VALUES (?,0,?,?,?,?,?,?)', request_insert)
|
||||||
|
|
||||||
# Save (commit) the changes
|
# Save (commit) the changes
|
||||||
conn.commit()
|
conn.commit()
|
||||||
|
@ -41,7 +41,8 @@ c = conn.cursor()
|
|||||||
# Create table
|
# Create table
|
||||||
c.execute('''
|
c.execute('''
|
||||||
CREATE TABLE data (
|
CREATE TABLE data (
|
||||||
id INTEGER PRIMARY KEY ,
|
id INTEGER PRIMARY KEY,
|
||||||
|
deleted INTEGER,
|
||||||
create_date INTEGER NOT NULL,
|
create_date INTEGER NOT NULL,
|
||||||
modify_date INTEGER NOT NULL,
|
modify_date INTEGER NOT NULL,
|
||||||
name TEXT NOT NULL,
|
name TEXT NOT NULL,
|
||||||
@ -78,7 +79,7 @@ for elem in my_old_bdd:
|
|||||||
if covers == None:
|
if covers == None:
|
||||||
covers = [];
|
covers = [];
|
||||||
request_insert = (id, new_time, new_time, name, description, list_to_string(covers))
|
request_insert = (id, new_time, new_time, name, description, list_to_string(covers))
|
||||||
c.execute('INSERT INTO data VALUES (?,?,?,?,?,?)', request_insert)
|
c.execute('INSERT INTO data VALUES (?,0,?,?,?,?,?)', request_insert)
|
||||||
|
|
||||||
# Save (commit) the changes
|
# Save (commit) the changes
|
||||||
conn.commit()
|
conn.commit()
|
||||||
|
@ -41,7 +41,8 @@ c = conn.cursor()
|
|||||||
# Create table
|
# Create table
|
||||||
c.execute('''
|
c.execute('''
|
||||||
CREATE TABLE data (
|
CREATE TABLE data (
|
||||||
id INTEGER PRIMARY KEY ,
|
id INTEGER PRIMARY KEY,
|
||||||
|
deleted INTEGER,
|
||||||
create_date INTEGER NOT NULL,
|
create_date INTEGER NOT NULL,
|
||||||
modify_date INTEGER NOT NULL,
|
modify_date INTEGER NOT NULL,
|
||||||
name TEXT NOT NULL,
|
name TEXT NOT NULL,
|
||||||
@ -78,7 +79,7 @@ for elem in my_old_bdd:
|
|||||||
if covers == None:
|
if covers == None:
|
||||||
covers = [];
|
covers = [];
|
||||||
request_insert = (id, new_time, new_time, name, description, list_to_string(covers))
|
request_insert = (id, new_time, new_time, name, description, list_to_string(covers))
|
||||||
c.execute('INSERT INTO data VALUES (?,?,?,?,?,?)', request_insert)
|
c.execute('INSERT INTO data VALUES (?,0,?,?,?,?,?)', request_insert)
|
||||||
|
|
||||||
# Save (commit) the changes
|
# Save (commit) the changes
|
||||||
conn.commit()
|
conn.commit()
|
||||||
|
@ -41,7 +41,8 @@ c = conn.cursor()
|
|||||||
# Create table
|
# Create table
|
||||||
c.execute('''
|
c.execute('''
|
||||||
CREATE TABLE data (
|
CREATE TABLE data (
|
||||||
id INTEGER PRIMARY KEY ,
|
id INTEGER PRIMARY KEY,
|
||||||
|
deleted INTEGER,
|
||||||
create_date INTEGER NOT NULL,
|
create_date INTEGER NOT NULL,
|
||||||
modify_date INTEGER NOT NULL,
|
modify_date INTEGER NOT NULL,
|
||||||
name TEXT NOT NULL,
|
name TEXT NOT NULL,
|
||||||
@ -122,11 +123,23 @@ for elem in my_old_bdd:
|
|||||||
else:
|
else:
|
||||||
time = elem["time"]
|
time = elem["time"]
|
||||||
request_insert = (id, new_time, modify_time, name, description, list_to_string(covers), data_id, type_id, univers_id, group_id, saison_id, date, episode, time)
|
request_insert = (id, new_time, modify_time, name, description, list_to_string(covers), data_id, type_id, univers_id, group_id, saison_id, date, episode, time)
|
||||||
c.execute('INSERT INTO data VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?)', request_insert)
|
c.execute('INSERT INTO data VALUES (?,0,?,?,?,?,?,?,?,?,?,?,?,?,?)', request_insert)
|
||||||
|
|
||||||
# Save (commit) the changes
|
# Save (commit) the changes
|
||||||
conn.commit()
|
conn.commit()
|
||||||
|
|
||||||
|
def dict_factory(cursor, row):
|
||||||
|
d = {}
|
||||||
|
for idx, col in enumerate(cursor.description):
|
||||||
|
d[col[0]] = row[idx]
|
||||||
|
return d
|
||||||
|
|
||||||
|
conn.row_factory = dict_factory
|
||||||
|
c = conn.cursor()
|
||||||
|
c.execute('SELECT * FROM data WHERE deleted=false')
|
||||||
|
results = c.fetchall()
|
||||||
|
print(results)
|
||||||
|
|
||||||
# We can also close the connection if we are done with it.
|
# We can also close the connection if we are done with it.
|
||||||
# Just be sure any changes have been committed or they will be lost.
|
# Just be sure any changes have been committed or they will be lost.
|
||||||
conn.close()
|
conn.close()
|
||||||
|
@ -6,8 +6,8 @@
|
|||||||
export const environment = {
|
export const environment = {
|
||||||
production: false,
|
production: false,
|
||||||
// URL of development API
|
// URL of development API
|
||||||
//apiUrl: 'http://localhost:15080',
|
apiUrl: 'http://localhost:15080',
|
||||||
apiUrl: 'http://192.168.1.157/karideo/api',
|
//apiUrl: 'http://192.168.1.157/karideo/api',
|
||||||
frontBaseUrl: '',
|
frontBaseUrl: '',
|
||||||
//apiMode: "QUERRY"
|
//apiMode: "QUERRY"
|
||||||
apiMode: "REWRITE",
|
apiMode: "REWRITE",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user