71 lines
2.4 KiB
Python
71 lines
2.4 KiB
Python
##===============================how to use=================================##
|
|
## env require python-gitlab, do "pip install python-gitlab" first.
|
|
##
|
|
## cmd: python flash.py <app folder> <platform>
|
|
##
|
|
## example: python flash.py app/solution_Yolov5sLPD_OCR_HW sys520
|
|
##
|
|
## platform can be [520, 720, sys520, sys720, kdp520, kdp720]
|
|
##===============================how to use=================================##
|
|
import os, sys, re
|
|
import argparse
|
|
import json
|
|
import pathlib
|
|
import json, requests
|
|
|
|
def main(app_folder, platform):
|
|
## check lib
|
|
try:
|
|
import git
|
|
except:
|
|
error = 'there is no "git" library in your env, try "pip install gitpython"'
|
|
assert False, error
|
|
|
|
try:
|
|
import dvc
|
|
except:
|
|
error = 'there is no "dvc" library in your env, try "pip install dvc"'
|
|
assert False, error
|
|
|
|
try:
|
|
import paramiko
|
|
except:
|
|
error = 'there is no "paramiko" library in your env, try "pip install paramiko"'
|
|
assert False, error
|
|
|
|
##
|
|
app_name = app_folder.split('/')[-1].replace('solution_','')
|
|
print('==================================================================')
|
|
print('Start update app_name:',app_name)
|
|
print('Check out to:',platform)
|
|
|
|
## check tag
|
|
with git.Repo(path=app_folder) as repo:
|
|
tags = []
|
|
for tag in repo.tags:
|
|
tags.append(tag.name)
|
|
|
|
if platform.lower() not in ['master','dev','alg_dev','sys_app_dev']:
|
|
if platform not in tags:
|
|
error = f'can not find branch or tag named "{platform}", please check again'
|
|
assert False, error
|
|
|
|
## update solution
|
|
print('Checkout solution and update submodule')
|
|
os.system(f'cd {app_folder} && git checkout . && git checkout {platform} && git submodule init && git submodule update --init --recursive && cd models && for d in ./*/ ; do (cd "$d" && dvc remote modify --local storage password kneronshared && dvc pull); done')
|
|
|
|
print('Done')
|
|
print('==================================================================')
|
|
|
|
if __name__ == "__main__":
|
|
parser = argparse.ArgumentParser(description="init",
|
|
formatter_class=argparse.RawTextHelpFormatter)
|
|
parser.add_argument("app_folder", help="directory of your application")
|
|
parser.add_argument("platform", default="", help="platform to use for app")
|
|
args = parser.parse_args()
|
|
|
|
##
|
|
main(app_folder=args.app_folder, platform=args.platform)
|
|
|
|
|