Commit 754d65ff authored by wanli's avatar wanli

feat(资源监视器): 资源监视器表增加两个字段

parent 8c4fd68a
''' '''
Author: your name Author: your name
Date: 2021-06-29 19:24:32 Date: 2021-06-29 19:24:32
LastEditTime: 2021-07-05 20:41:32 LastEditTime: 2021-07-21 10:27:25
LastEditors: Please set LastEditors LastEditors: Please set LastEditors
Description: In User Settings Edit Description: In User Settings Edit
FilePath: \evm-store\backend\controller\monitor.py FilePath: \evm-store\backend\controller\monitor.py
...@@ -15,7 +15,11 @@ class SystemResource(object): ...@@ -15,7 +15,11 @@ class SystemResource(object):
return result return result
def post(self, params): def post(self, params):
result = System(**params) data = dict()
for k in params:
if hasattr(System, k):
data[k] = params[k]
result = System(**data)
session.add(result) session.add(result)
return session.commit() return session.commit()
...@@ -32,7 +36,11 @@ class LvglResource(object): ...@@ -32,7 +36,11 @@ class LvglResource(object):
return result return result
def post(self, params): def post(self, params):
result = Lvgl(**params) data = dict()
for k in params:
if hasattr(Lvgl, k):
data[k] = params[k]
result = Lvgl(**data)
session.add(result) session.add(result)
return session.commit() return session.commit()
...@@ -49,7 +57,11 @@ class EvmResource(object): ...@@ -49,7 +57,11 @@ class EvmResource(object):
return result return result
def post(self, params): def post(self, params):
result = Evm(**params) data = dict()
for k in params:
if hasattr(Evm, k):
data[k] = params[k]
result = Evm(**data)
session.add(result) session.add(result)
return session.commit() return session.commit()
...@@ -66,7 +78,11 @@ class ImageResource(object): ...@@ -66,7 +78,11 @@ class ImageResource(object):
return result return result
def post(self, params): def post(self, params):
result = Image(**params) data = dict()
for k in params:
if hasattr(Image, k):
data[k] = params[k]
result = Image(**data)
session.add(result) session.add(result)
return session.commit() return session.commit()
...@@ -74,7 +90,11 @@ class ImageResource(object): ...@@ -74,7 +90,11 @@ class ImageResource(object):
t = [] t = []
for a in array: for a in array:
a.update({ "watch": watch }) a.update({ "watch": watch })
t.append(Image(**a)) data = dict()
for k in a:
if hasattr(Image, k):
data[k] = a[k]
t.append(Image(**data))
session.add_all(t) session.add_all(t)
return session.commit() return session.commit()
......
...@@ -58,6 +58,8 @@ class System(Base): ...@@ -58,6 +58,8 @@ class System(Base):
id = Column(Integer, primary_key=True, autoincrement=True) id = Column(Integer, primary_key=True, autoincrement=True)
watch = Column(Integer) # 手表ID watch = Column(Integer) # 手表ID
free_size = Column(Integer) # 单位:字节 free_size = Column(Integer) # 单位:字节
free_space_size = Column(Integer) # 单位:字节
used_space_size = Column(Integer) # 单位:字节
timestamp = Column(DateTime(timezone=True), default=get_current_datetime, server_default=func.now(), onupdate=func.now()) timestamp = Column(DateTime(timezone=True), default=get_current_datetime, server_default=func.now(), onupdate=func.now())
def to_dict(self): def to_dict(self):
......
...@@ -3,135 +3,157 @@ ...@@ -3,135 +3,157 @@
''' '''
Author: your name Author: your name
Date: 2021-07-20 19:04:27 Date: 2021-07-20 19:04:27
LastEditTime: 2021-07-21 01:10:53 LastEditTime: 2021-07-21 10:05:11
LastEditors: Please set LastEditors LastEditors: Please set LastEditors
Description: In User Settings Edit Description: In User Settings Edit
FilePath: \evm-store\tools\database_migration.py FilePath: \evm-store\tools\database_migration.py
''' '''
import os
import sqlite3 import sqlite3
import uuid import uuid
source_conn = sqlite3.connect('/mnt/d/projects/scriptiot/evm-store/tools/app-store.db') BASE_DIR = os.path.dirname(os.path.abspath(__file__))
print("####>>>", BASE_DIR)
source_conn = sqlite3.connect(os.path.join(BASE_DIR, "app-store.db"))
source_cur = source_conn.cursor() source_cur = source_conn.cursor()
target_conn = sqlite3.connect('/mnt/d/projects/scriptiot/evm-store/tools/evue-store.db') target_db = os.path.join(BASE_DIR, "evue_store.db")
target_conn = sqlite3.connect(target_db)
target_cur = source_conn.cursor() target_cur = source_conn.cursor()
# 更新user表 with open("database_migration.sql", "w+") as fd:
opts = [ # 更新user表
[2, 39], opts = [
[3, 40], [2, 39],
[4, 41] [3, 40],
] [4, 41]
]
sqls = [
"update evm_store_annex set create_by = {a} where create_by = {b};", sqls = [
"update evm_store_annex set update_by = {a} where update_by = {b};", "update evm_store_annex set create_by = {a} where create_by = {b};",
"update evm_store_app_logs set create_by = {a} where create_by = {b};", "update evm_store_annex set update_by = {a} where update_by = {b};",
"update evm_store_build_logs set create_by = {a} where create_by = {b};", "update evm_store_app_logs set create_by = {a} where create_by = {b};",
"update evm_store_build_logs set update_by = {a} where update_by = {b};", "update evm_store_build_logs set create_by = {a} where create_by = {b};",
"update evm_store_device set create_by = {a} where create_by = {b};", "update evm_store_build_logs set update_by = {a} where update_by = {b};",
"update evm_store_device set update_by = {a} where update_by = {b};", "update evm_store_device set create_by = {a} where create_by = {b};",
"update evm_store_login_logs set create_by = {a} where create_by = {b};", "update evm_store_device set update_by = {a} where update_by = {b};",
] "update evm_store_login_logs set create_by = {a} where create_by = {b};",
]
for s in sqls:
for o in opts: for s in sqls:
string = s.format(a=o[0], b=o[1]) for o in opts:
source_cur.execute(string) sql_str = s.format(a=o[0], b=o[1])
source_conn.commit() source_cur.execute(sql_str)
source_conn.commit()
# 先插入user表
source_cur.execute('SELECT account, username, password, email, phone, create_at, create_by, update_at, update_by FROM evm_store_user') # 先插入user表
sql = "insert evm_user (id, uuid, account, username, password, email, phone, create_at, create_by, update_at, update_byis_delete, is_delete) values ({a}, {b}, {c}, {d}, {e}, {f}, {g}, {h}, {i}, {j}, {k}, 0);" source_cur.execute('SELECT account, username, password, email, phone, create_at, create_by, update_at, update_by FROM evm_store_user')
res = source_cur.fetchall() sql = "insert into evm_user (id, uuid, account, username, password, email, phone, create_at, create_by, update_at, update_by, is_delete) values ({a}, '{b}', '{c}', '{d}', '{e}', '{f}', '{g}', '{h}', {i}, '{j}', {k}, 0);"
i = 0 res = source_cur.fetchall()
for line in res: i = 0
i += 1 for line in res:
sql.format(a=i, b=uuid.uuid1().hex, c=line[0], d=line[1], e=line[2], f=line[3], g=line[4], h=line[5], i=line[6], j=line[7], k=line[8]) i += 1
target_cur.execute(string) sql_str = sql.format(a=i, b=uuid.uuid1().hex, c=line[0], d=line[1], e=line[2], f=line[3], g=line[4], h=line[5], i=line[6], j=line[7], k=line[8])
target_conn.commit() print("sql:", sql_str)
# target_cur.execute(sql_str)
# login logs fd.write(sql_str + "\n")
source_cur.execute('SELECT id, username, ip, address, create_at, create_by, remarks FROM evm_store_login_logs') target_conn.commit()
res = source_cur.fetchall()
sql = "insert into evm_login (id, uuid, user, login_at, user_agent, ip, geo_location, operator, create_at, create_by, update_at, update_by, is_delete) values ({a}, {b}, {c}, {d}, {e}, {f}, {g}, {h}, {i}, {j}, {k}, {l}, 0);" # login logs
for line in res: source_cur.execute('SELECT id, username, ip, address, create_at, create_by, remarks FROM evm_store_login_logs')
sql.format(a=line[0], b=uuid.uuid1().hex, c=line[5], d=line[6], e="", f=line[2], g=line[3], h="", i=line[4], j=line[5], k=line[4], l=line[5]) res = source_cur.fetchall()
target_cur.execute(string) sql = "insert into evm_login (id, uuid, user, login_at, user_agent, ip, geo_location, operator, create_at, create_by, update_at, update_by, is_delete) values ({a}, '{b}', {c}, '{d}', '{e}', '{f}', '{g}', '{h}', '{i}', {j}, '{k}', {l}, 0);"
target_conn.commit() for line in res:
sql_str = sql.format(a=line[0], b=uuid.uuid1().hex, c=line[5], d=line[6], e="", f=line[2], g=line[3], h="", i=line[4], j=line[5], k=line[4], l=line[5])
# 更新app_url字段 # target_cur.execute(sql_str)
sql = "select app, app_path from evm_store_build_logs" fd.write(sql_str + "\n")
source_cur.execute(sql) target_conn.commit()
res = source_cur.fetchall()
for line in res: # 更新app_url字段
string = "update evm_store_apps set app_url = '{u}' where id = {a}".format(u=line[1], a=line[0]) sql = "select app, app_path from evm_store_build_logs"
target_cur.execute(string) source_cur.execute(sql)
target_conn.commit() res = source_cur.fetchall()
for line in res:
# annex sql_str = string = "update evm_store_apps set app_url = '{u}' where id = {a}".format(u=line[1], a=line[0])
source_cur.execute('SELECT id, uuid, app, title, path, size, create_by, create_at, update_by, update_at, is_delete FROM evm_store_annex') # target_cur.execute(sql_str)
res = source_cur.fetchall() fd.write(sql_str + "\n")
sql = "insert into evm_annex (id, uuid, app, title, path, size, create_at, create_by, update_at, update_by, is_delete) values ({a}, {b}, {c}, {d}, {e}, {f}, {g}, {h}, {i}, {j}, 0);" target_conn.commit()
for line in res:
sql.format(a=line[0], b=uuid.uuid1().hex, c=line[2], d=line[3], e=line[4], f=line[5], g=line[6], h=line[7], i=line[8], j=line[9]) # annex
target_cur.execute(string) source_cur.execute('SELECT id, uuid, app, title, path, size, create_by, create_at, update_by, update_at, is_delete FROM evm_store_annex')
target_conn.commit() res = source_cur.fetchall()
sql = "insert into evm_annex (id, uuid, app, title, path, size, create_at, create_by, update_at, update_by, is_delete) values ({a}, '{b}', {c}, '{d}', '{e}', {f}, '{g}', {h}, '{i}', {j}, 0);"
# app for line in res:
source_cur.execute('SELECT id, app_name, app_icon, app_version, category, app_url, app_desc, create_at, create_by ,update_at, update_by, is_delete FROM evm_store_apps') sql_str = sql.format(a=line[0], b=uuid.uuid1().hex, c=line[2], d=line[3], e=line[4], f=line[5], g=line[6], h=line[7], i=line[8], j=line[9])
res = source_cur.fetchall() # target_cur.execute(sql_str)
sql = "insert into evm_app (id, uuid, app_name, app_icon, app_version, category, download_url, app_screen_size, app_arch, app_review, meta_data, remarks, create_at, create_by, update_at, update_by, is_delete) values ({a}, {b}, {c}, {d}, {e}, {f}, {g}, {h}, {i}, {j}, {k}, {l}, {m}, {n}, {o}, {p} 0);" fd.write(sql_str + "\n")
for line in res: target_conn.commit()
sql.format(a=line[0], b=uuid.uuid1().hex, c=line[1], d=line[2], e=line[3], f=line[4], g=line[5], h="240 * 240", i="ASR3601", j=0, k='{}', l=line[6], m=line[7], n=line[8], o=line[9], p=line[10])
target_cur.execute(string) # app
target_conn.commit() source_cur.execute('SELECT id, app_name, app_icon, app_version, category, app_url, app_desc, create_at, create_by ,update_at, update_by, is_delete FROM evm_store_apps')
res = source_cur.fetchall()
# device sql = "insert into evm_app (id, uuid, app_name, app_icon, app_version, category, download_url, app_screen_size, app_arch, app_review, meta_data, remarks, create_at, create_by, update_at, update_by, is_delete) values ({a}, '{b}', '{c}', '{d}', '{e}', '{f}', '{g}', '{h}', '{i}', '{j}', '{k}', '{l}', '{m}', {n}, '{o}', {p} 0);"
source_cur.execute('SELECT id, name, imei, desc, type, create_at, create_by, update_at, update_by, is_delete FROM evm_store_device') for line in res:
res = source_cur.fetchall() sql_str = sql.format(a=line[0], b=uuid.uuid1().hex, c=line[1], d=line[2], e=line[3], f=line[4], g=line[5], h="240 * 240", i="ASR3601", j=0, k='{}', l=line[6], m=line[7], n=line[8], o=line[9], p=line[10])
sql = "insert into evm_device (id, uuid, name, imei, desc, type, create_at, create_by, update_at, update_by, is_delete) values ({a}, {b}, {c}, {d}, {e}, {f}, {g}, {h}, {i}, {j}, {k});" # target_cur.execute(sql_str)
for line in res: fd.write(sql_str + "\n")
sql.format(a=line[0], b=uuid.uuid1().hex, c=line[1], d=line[2], e=line[3], f=line[4], g=line[5], h=line[6], i=line[7], j=line[8], k=line[9]) target_conn.commit()
target_cur.execute(string)
target_conn.commit() # device
source_cur.execute('SELECT id, name, imei, desc, type, create_at, create_by, update_at, update_by, is_delete FROM evm_store_device')
# app log & build log res = source_cur.fetchall()
# 先插入app log sql = "insert into evm_device (id, uuid, name, imei, desc, type, create_at, create_by, update_at, update_by, is_delete) values ({a}, '{b}', '{c}', '{d}', '{e}', '{f}', '{g}', {h}, '{i}', {j}, {k});"
source_cur.execute('SELECT id, uuid, app_name, app_path, app_version, app_info, create_at, create_by FROM evm_store_app_logs') for line in res:
res = source_cur.fetchall() sql_str = sql.format(a=line[0], b=uuid.uuid1().hex, c=line[1], d=line[2], e=line[3], f=line[4], g=line[5], h=line[6], i=line[7], j=line[8], k=line[9])
sql = "insert into evm_package (id, uuid, app_name, app_path, app_version, app_info, create_at, create_by, update_at, update_by, is_delete, source) values ({a}, {b}, {c}, {d}, {e}, {f}, {g}, {h}, {i}, {j}, {k}, {l});" # target_cur.execute(sql_str)
for line in res: fd.write(sql_str + "\n")
s = 1 if line[3].find("evueapps") > -1 else 0 target_conn.commit()
sql.format(a=line[0], b=uuid.uuid1().hex, c=line[2], d=line[3], e=line[4], f=line[5], g=line[6], h=line[7], i=line[6], j=line[7], k=0, l=s)
target_cur.execute(string) # app log & build log
target_conn.commit() # 先插入app log
source_cur.execute('SELECT id, uuid, app_name, app_path, app_version, app_info, create_at, create_by FROM evm_store_app_logs')
# 然后查询出所有build log记录,遍历这些记录 res = source_cur.fetchall()
# 在循环里,查询这一条记录是否已经存在(根据app_path),不存在则插入 sql = "insert into evm_package (id, uuid, app_name, app_path, app_version, app_info, create_at, create_by, update_at, update_by, is_delete, source) values ({a}, '{b}', '{c}', '{d}', '{e}', '{f}', '{g}', {h}, '{i}', {j}, {k}, {l});"
source_cur.execute('SELECT id, uuid, app, app_path, app_info, source, create_at, create_by, update_at, update_by, is_delete FROM evm_store_build_logs') for line in res:
res = source_cur.fetchall() s = 1 if line[3].find("evueapps") > -1 else 0
sql = "insert into evm_package (id, uuid, app_name, app_path, app_version, app_info, source, create_at, create_by, update_at, update_by, is_delete) values ({a}, {b}, {c}, {d}, {e}, {f}, {g}, {h}, {i}, {j}, {k}, {l});" sql_str = sql.format(a=line[0], b=uuid.uuid1().hex, c=line[2], d=line[3], e=line[4], f=line[5], g=line[6], h=line[7], i=line[6], j=line[7], k=0, l=s)
for line in res: # target_cur.execute(sql_str)
string = "select id, uuid, app_path from evm_store_app_logs where app_path = '{}'".format(line[3]) fd.write(sql_str + "\n")
source_cur.execute(string) target_conn.commit()
tmp = source_cur.fetchone()
if tmp: # 然后查询出所有build log记录,遍历这些记录
continue # 在循环里,查询这一条记录是否已经存在(根据app_path),不存在则插入
source_cur.execute('SELECT id, uuid, app, app_path, app_info, source, create_at, create_by, update_at, update_by, is_delete FROM evm_store_build_logs')
string = "select app_name, app_version from evm_store_apps where id == {id}".format(id=line[2]) res = source_cur.fetchall()
source_cur.execute(string) sql = "insert into evm_package (id, uuid, app_name, app_path, app_version, app_info, source, create_at, create_by, update_at, update_by, is_delete) values ({a}, '{b}', '{c}', '{d}', '{e}', '{f}', {g}, '{h}', {i}, '{j}', {k}, {l});"
app = source_cur.fetchone() for line in res:
if app: sql_str = "select id, uuid, app_path from evm_store_app_logs where app_path = '{}'".format(line[3])
s = 1 if line[5] and line[5].find("evueapps") > -1 else 0 source_cur.execute(sql_str)
sql.format(a=line[0], b=uuid.uuid1().hex, c=app[0], d=line[3], e=app[1], f=line[4], g=s, h=line[6], i=line[7], j=line[8], k=line[9], l=line[10]) print("%%%%%%%%%%%%%%", sql_str)
target_cur.execute(string) tmp = source_cur.fetchone()
target_conn.commit() if tmp:
continue
target_conn.commit()
target_conn.close() print("===========>", line)
sql_str = string = "select app_name, app_version from evm_store_apps where id == {id}".format(id=line[2])
source_conn.commit() source_cur.execute(sql_str)
source_conn.close() app = source_cur.fetchone()
print("app:", app)
if app:
s = 1 if line[5] and line[5].find("evueapps") > -1 else 0
sql_str = sql.format(a=line[0], b=uuid.uuid1().hex, c=app[0], d=line[3], e=app[1], f=line[4], g=s, h=line[6], i=line[7], j=line[8], k=line[9], l=line[10])
# target_cur.execute(sql_str)
fd.write(sql_str + "\n")
target_conn.commit()
print("next >>>>>>>>>>>")
print("finished!!!")
target_conn.commit()
target_conn.close()
source_conn.commit()
source_conn.close()
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment