Commit 5e559b46 authored by wanliofficial's avatar wanliofficial

update

parent 4451a647
......@@ -76,6 +76,7 @@ class AppsManager(object):
result = Apps.get(uuid=uuid)
if result:
result.app_icon.delete()
result.delete()
return result, "delete app {}.".format("success" if result else "fail")
......
......@@ -91,87 +91,28 @@ class DownloadManager(object):
# 此次下载将生成一次下载记录
# 当前还没有校验前端传来的IMEI是否是合法的
epk_path = None
epk_path = ""
app = None
with db_session:
# 判断应用UUID是否等于evue_launcher
if data.get("id") == "evue_launcher123":
# 按照格式创建文件夹
dir_format = datetime.now().strftime("%Y%m%d%H%M%S")
build_path = os.sep.join([os.getcwd(), config.get("UPLOAD_DIR"), conf.get('application', 'launcher_dir'), data.get("imei"), dir_format])
if not os.path.exists(build_path):
os.makedirs(build_path)
build_source_path = os.sep.join([build_path, "src"])
if not os.path.exists(build_source_path):
os.mkdir(build_source_path)
# 判断下name为evue_launcher的文件是否存在
# 存在则移动到目标文件夹中
launcher = Apps.get(app_name="evue_launcher")
if launcher:
# 查找所有关联文件,复制到目标文件夹中
for f in launcher.app_annex:
tf = convert_url_to_local_path(f.path)
if not os.path.exists(tf):
continue
filename = os.path.basename(tf)
name, suffix = os.path.splitext(filename)
name = re.sub(r"_\d{14}$", "", name)
shutil.copy(tf, os.sep.join([build_source_path, name + suffix]))
# 根据应用UUID查找相关应用
app = Apps.get(app_name=data.get("id"), is_delete=False)
temp = []
# 读取当前系统所有应用及其资源文件
apps = Apps.select().where(is_delete=False).order_by(Apps.sort)
result_json = []
for val in apps:
tmp = val.to_dict(with_collections=True, related_objects=True)
if val.app_build_log:
temp.append({
'icon': val.app_icon.title,
'name': val.app_name,
'url': val.app_url,
'version': val.app_version,
'epk': tmp.get("app_build_log")[0].app_path,
'category': val.category,
'id': str(val.uuid),
})
if len(temp) % 4 == 0 and temp:
result_json.append(copy.deepcopy(temp))
temp = []
if temp:
result_json.append(copy.deepcopy(temp))
json_str = json.dumps(result_json, sort_keys=False, ensure_ascii=False)
with open(os.sep.join([build_source_path, 'evue_dock_apps.json']), 'w') as json_file:
json_file.write(json_str)
# 打包成EPK文件
epk = EpkApp(appName="evue_launcher", appDir=build_source_path, appVersion="1.0", output=build_path)
epk.pack()
epk_path = os.sep.join([build_path, 'evue_launcher.epk'])
else:
# 根据应用UUID查找相关应用
app = Apps.get(app_name=data.get("id"), is_delete=False)
if not app:
return False, "app not found"
if not app.app_build_log:
return False, "app build file not found"
tmp = app.to_dict(with_collections=True, related_objects=True)
epk_path = convert_url_to_local_path(tmp.get("app_build_log")[0].app_path)
if not os.path.exists(epk_path):
return False, "epk file not found"
# 创建一条下载记录
if app:
AppDownload(app=app, imei=data.get("imei"))
commit()
return epk_path, "get dictionary {}.".format("success" if epk_path else "no data")
if not app:
return False, "app not found"
tmp = app.to_dict(with_collections=True, related_objects=True)
if tmp.get("app_build_log"):
epk_path = convert_url_to_local_path(tmp.get("app_build_log")[0].app_path)
if not os.path.exists(epk_path):
return False, "epk file not found"
if app:
AppDownload(app=app, imei=data.get("imei"))
commit()
return epk_path, "get dictionary {}.".format("success" if epk_path else "no data")
def getList(self, data):
if not data or len(data) <= 0:
......
......@@ -14,7 +14,7 @@ class Annex(db.Entity):
id = PrimaryKey(int, auto=True)
uuid = Required(uuid.UUID, unique=True, default=uuid.uuid1, index=True)
app = Optional("Apps", reverse="app_annex")
app_icon = Optional("Apps", reverse="app_icon")
app_icon = Optional("Apps", reverse="app_icon", cascade_delete=True)
title = Required(str, max_len=200) # 文件名
path = Required(LongStr) # 文件路径
type = Required(int, default=0) # 文件类型 PNG/JPG/GIF/MP3/MP4/DOCX/XLSX/PPT/PDF...
......
#!/usr/bin/env python
# -*- coding: utf_8 -*-
import uuid
from datetime import datetime
from pony.orm import PrimaryKey, Required, Optional, Set, LongStr, Json
from app import config
from . import fullStackDB
# ********************************
from .app_users import AppUser
# ********************************
db = fullStackDB.db
class Apps(db.Entity):
_table_ = "{}".format(config['TABLE_PREFIX']) + "apps"
id = PrimaryKey(int, auto=True)
uuid = Required(uuid.UUID, unique=True, default=uuid.uuid1, index=True)
app_name = Required(str, max_len=200)
app_version = Optional(str, default="")
app_url = Optional(str, default="")
category = Optional(str, default="")
app_icon = Required("Annex", reverse="app_icon")
app_desc = Optional(str, default="")
app_annex = Set("Annex", reverse="app")
app_user = Optional("AppUser", reverse="app")
app_build_log = Set("BuildLogs", reverse="app")
app_download = Set("AppDownload", reverse="app")
create_at = Required(datetime, default=datetime.now)
create_by = Required("User", reverse='apps_creator') # BuildLogs与User一对一关系
update_at = Required(datetime, default=datetime.now)
update_by = Required("User", reverse='apps_updater') # BuildLogs与User一对一关系
delete_at = Optional(datetime)
delete_by = Optional("User", reverse='apps_deleter') # BuildLogs与User一对一关系
is_delete = Required(bool, default=False)
#!/usr/bin/env python
# -*- coding: utf_8 -*-
import uuid
from datetime import datetime
from pony.orm import PrimaryKey, Required, Optional, Set, LongStr, Json
from app import config
from . import fullStackDB
# ********************************
from .app_users import AppUser
# ********************************
db = fullStackDB.db
class Apps(db.Entity):
_table_ = "{}".format(config['TABLE_PREFIX']) + "apps"
id = PrimaryKey(int, auto=True)
uuid = Required(uuid.UUID, unique=True, default=uuid.uuid1, index=True)
app_name = Required(str, max_len=200)
app_version = Optional(str, default="")
app_url = Optional(str, default="")
category = Optional(str, default="")
app_icon = Optional("Annex", reverse="app_icon", cascade_delete=True)
app_desc = Optional(str, default="")
app_annex = Set("Annex", reverse="app", cascade_delete=True)
app_user = Optional("AppUser", reverse="app", cascade_delete=True)
app_build_log = Set("BuildLogs", reverse="app", cascade_delete=True)
app_download = Set("AppDownload", reverse="app", cascade_delete=True)
create_at = Required(datetime, default=datetime.now)
create_by = Required("User", reverse='apps_creator') # BuildLogs与User一对一关系
update_at = Required(datetime, default=datetime.now)
update_by = Required("User", reverse='apps_updater') # BuildLogs与User一对一关系
delete_at = Optional(datetime)
delete_by = Optional("User", reverse='apps_deleter') # BuildLogs与User一对一关系
is_delete = Required(bool, default=False)
sort = Optional(int, size=32, default=0)
\ No newline at end of file
......@@ -59,7 +59,8 @@ def get():
if os.path.exists(result):
with open(result, "rb") as f:
ret = f.read()
return ret
return ret
return response_result(ResponseCode.SERVER_ERROR, msg="file not found: %s" % "")
except Exception as e:
traceback.print_exc()
logger.error(str(e))
......
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