Commit 5e559b46 authored by wanliofficial's avatar wanliofficial

update

parent 4451a647
...@@ -76,6 +76,7 @@ class AppsManager(object): ...@@ -76,6 +76,7 @@ class AppsManager(object):
result = Apps.get(uuid=uuid) result = Apps.get(uuid=uuid)
if result: if result:
result.app_icon.delete()
result.delete() result.delete()
return result, "delete app {}.".format("success" if result else "fail") return result, "delete app {}.".format("success" if result else "fail")
......
...@@ -91,82 +91,23 @@ class DownloadManager(object): ...@@ -91,82 +91,23 @@ class DownloadManager(object):
# 此次下载将生成一次下载记录 # 此次下载将生成一次下载记录
# 当前还没有校验前端传来的IMEI是否是合法的 # 当前还没有校验前端传来的IMEI是否是合法的
epk_path = None epk_path = ""
app = None
with db_session: 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]))
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查找相关应用 # 根据应用UUID查找相关应用
app = Apps.get(app_name=data.get("id"), is_delete=False) app = Apps.get(app_name=data.get("id"), is_delete=False)
if not app: if not app:
return False, "app not found" 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) 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) epk_path = convert_url_to_local_path(tmp.get("app_build_log")[0].app_path)
if not os.path.exists(epk_path): if not os.path.exists(epk_path):
return False, "epk file not found" return False, "epk file not found"
# 创建一条下载记录
if app: if app:
AppDownload(app=app, imei=data.get("imei")) AppDownload(app=app, imei=data.get("imei"))
commit() commit()
......
...@@ -14,7 +14,7 @@ class Annex(db.Entity): ...@@ -14,7 +14,7 @@ class Annex(db.Entity):
id = PrimaryKey(int, auto=True) id = PrimaryKey(int, auto=True)
uuid = Required(uuid.UUID, unique=True, default=uuid.uuid1, index=True) uuid = Required(uuid.UUID, unique=True, default=uuid.uuid1, index=True)
app = Optional("Apps", reverse="app_annex") 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) # 文件名 title = Required(str, max_len=200) # 文件名
path = Required(LongStr) # 文件路径 path = Required(LongStr) # 文件路径
type = Required(int, default=0) # 文件类型 PNG/JPG/GIF/MP3/MP4/DOCX/XLSX/PPT/PDF... type = Required(int, default=0) # 文件类型 PNG/JPG/GIF/MP3/MP4/DOCX/XLSX/PPT/PDF...
......
...@@ -21,12 +21,12 @@ class Apps(db.Entity): ...@@ -21,12 +21,12 @@ class Apps(db.Entity):
app_version = Optional(str, default="") app_version = Optional(str, default="")
app_url = Optional(str, default="") app_url = Optional(str, default="")
category = Optional(str, default="") category = Optional(str, default="")
app_icon = Required("Annex", reverse="app_icon") app_icon = Optional("Annex", reverse="app_icon", cascade_delete=True)
app_desc = Optional(str, default="") app_desc = Optional(str, default="")
app_annex = Set("Annex", reverse="app") app_annex = Set("Annex", reverse="app", cascade_delete=True)
app_user = Optional("AppUser", reverse="app") app_user = Optional("AppUser", reverse="app", cascade_delete=True)
app_build_log = Set("BuildLogs", reverse="app") app_build_log = Set("BuildLogs", reverse="app", cascade_delete=True)
app_download = Set("AppDownload", reverse="app") app_download = Set("AppDownload", reverse="app", cascade_delete=True)
create_at = Required(datetime, default=datetime.now) create_at = Required(datetime, default=datetime.now)
create_by = Required("User", reverse='apps_creator') # BuildLogs与User一对一关系 create_by = Required("User", reverse='apps_creator') # BuildLogs与User一对一关系
update_at = Required(datetime, default=datetime.now) update_at = Required(datetime, default=datetime.now)
......
...@@ -60,6 +60,7 @@ def get(): ...@@ -60,6 +60,7 @@ def get():
with open(result, "rb") as f: with open(result, "rb") as f:
ret = f.read() ret = f.read()
return ret return ret
return response_result(ResponseCode.SERVER_ERROR, msg="file not found: %s" % "")
except Exception as e: except Exception as e:
traceback.print_exc() traceback.print_exc()
logger.error(str(e)) 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