Commit 754d65ff authored by wanli's avatar wanli

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

parent 8c4fd68a
'''
Author: your name
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
Description: In User Settings Edit
FilePath: \evm-store\backend\controller\monitor.py
......@@ -15,7 +15,11 @@ class SystemResource(object):
return result
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)
return session.commit()
......@@ -32,7 +36,11 @@ class LvglResource(object):
return result
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)
return session.commit()
......@@ -49,7 +57,11 @@ class EvmResource(object):
return result
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)
return session.commit()
......@@ -66,7 +78,11 @@ class ImageResource(object):
return result
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)
return session.commit()
......@@ -74,7 +90,11 @@ class ImageResource(object):
t = []
for a in array:
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)
return session.commit()
......
......@@ -58,6 +58,8 @@ class System(Base):
id = Column(Integer, primary_key=True, autoincrement=True)
watch = Column(Integer) # 手表ID
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())
def to_dict(self):
......
......@@ -3,135 +3,157 @@
'''
Author: your name
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
Description: In User Settings Edit
FilePath: \evm-store\tools\database_migration.py
'''
import os
import sqlite3
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()
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()
# 更新user表
opts = [
[2, 39],
[3, 40],
[4, 41]
]
sqls = [
"update evm_store_annex set create_by = {a} where create_by = {b};",
"update evm_store_annex set update_by = {a} where update_by = {b};",
"update evm_store_app_logs set create_by = {a} where create_by = {b};",
"update evm_store_build_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_device 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:
string = s.format(a=o[0], b=o[1])
source_cur.execute(string)
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')
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);"
res = source_cur.fetchall()
i = 0
for line in res:
i += 1
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_cur.execute(string)
target_conn.commit()
# login logs
source_cur.execute('SELECT id, username, ip, address, create_at, create_by, remarks FROM evm_store_login_logs')
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);"
for line in res:
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])
target_cur.execute(string)
target_conn.commit()
# 更新app_url字段
sql = "select app, app_path from evm_store_build_logs"
source_cur.execute(sql)
res = source_cur.fetchall()
for line in res:
string = "update evm_store_apps set app_url = '{u}' where id = {a}".format(u=line[1], a=line[0])
target_cur.execute(string)
target_conn.commit()
# annex
source_cur.execute('SELECT id, uuid, app, title, path, size, create_by, create_at, update_by, update_at, is_delete FROM evm_store_annex')
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);"
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])
target_cur.execute(string)
target_conn.commit()
# app
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()
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);"
for line in res:
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)
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')
res = source_cur.fetchall()
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});"
for line in res:
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_cur.execute(string)
target_conn.commit()
# app log & build log
# 先插入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')
res = source_cur.fetchall()
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});"
for line in res:
s = 1 if line[3].find("evueapps") > -1 else 0
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)
target_conn.commit()
# 然后查询出所有build log记录,遍历这些记录
# 在循环里,查询这一条记录是否已经存在(根据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')
res = source_cur.fetchall()
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});"
for line in res:
string = "select id, uuid, app_path from evm_store_app_logs where app_path = '{}'".format(line[3])
source_cur.execute(string)
tmp = source_cur.fetchone()
if tmp:
continue
string = "select app_name, app_version from evm_store_apps where id == {id}".format(id=line[2])
source_cur.execute(string)
app = source_cur.fetchone()
if app:
s = 1 if line[5] and line[5].find("evueapps") > -1 else 0
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(string)
target_conn.commit()
target_conn.commit()
target_conn.close()
source_conn.commit()
source_conn.close()
with open("database_migration.sql", "w+") as fd:
# 更新user表
opts = [
[2, 39],
[3, 40],
[4, 41]
]
sqls = [
"update evm_store_annex set create_by = {a} where create_by = {b};",
"update evm_store_annex set update_by = {a} where update_by = {b};",
"update evm_store_app_logs set create_by = {a} where create_by = {b};",
"update evm_store_build_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_device 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:
sql_str = s.format(a=o[0], b=o[1])
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')
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);"
res = source_cur.fetchall()
i = 0
for line in res:
i += 1
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])
print("sql:", sql_str)
# target_cur.execute(sql_str)
fd.write(sql_str + "\n")
target_conn.commit()
# login logs
source_cur.execute('SELECT id, username, ip, address, create_at, create_by, remarks FROM evm_store_login_logs')
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);"
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])
# target_cur.execute(sql_str)
fd.write(sql_str + "\n")
target_conn.commit()
# 更新app_url字段
sql = "select app, app_path from evm_store_build_logs"
source_cur.execute(sql)
res = source_cur.fetchall()
for line in res:
sql_str = string = "update evm_store_apps set app_url = '{u}' where id = {a}".format(u=line[1], a=line[0])
# target_cur.execute(sql_str)
fd.write(sql_str + "\n")
target_conn.commit()
# annex
source_cur.execute('SELECT id, uuid, app, title, path, size, create_by, create_at, update_by, update_at, is_delete FROM evm_store_annex')
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);"
for line in res:
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])
# target_cur.execute(sql_str)
fd.write(sql_str + "\n")
target_conn.commit()
# app
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()
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);"
for line in res:
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])
# target_cur.execute(sql_str)
fd.write(sql_str + "\n")
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')
res = source_cur.fetchall()
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});"
for line in res:
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])
# target_cur.execute(sql_str)
fd.write(sql_str + "\n")
target_conn.commit()
# app log & build log
# 先插入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')
res = source_cur.fetchall()
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});"
for line in res:
s = 1 if line[3].find("evueapps") > -1 else 0
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)
# target_cur.execute(sql_str)
fd.write(sql_str + "\n")
target_conn.commit()
# 然后查询出所有build log记录,遍历这些记录
# 在循环里,查询这一条记录是否已经存在(根据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')
res = source_cur.fetchall()
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});"
for line in res:
sql_str = "select id, uuid, app_path from evm_store_app_logs where app_path = '{}'".format(line[3])
source_cur.execute(sql_str)
print("%%%%%%%%%%%%%%", sql_str)
tmp = source_cur.fetchone()
if tmp:
continue
print("===========>", line)
sql_str = string = "select app_name, app_version from evm_store_apps where id == {id}".format(id=line[2])
source_cur.execute(sql_str)
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