• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# encoding=utf-8
2
3# from aw.Exception.upgrade_exception import UpgradeException
4from aw.Param import UpgradeParam
5from util.log_info import logger
6
7from aw.Common.Constant import CONSTANT
8
9import platform
10import traceback
11import sys
12import os
13
14from util.time_info import get_now_time_str_info
15
16class BaseApp(object):
17    param_List = None
18    flash_type = None
19
20    def __init__(self, param=None):
21        self.logFilePath = None
22
23        self.TAG = self.__class__.__name__
24
25        self.logFilePath = CONSTANT.OSType.default_log_dir
26
27        if isinstance(param, dict):
28            self.logFilePath = param.get('logFilePath')
29            self.params_dict = param
30        elif isinstance(param, str):
31            param_file_path, param_file_name = os.path.split(param)
32            self.logFilePath = os.path.join(param_file_path, ''.join([param_file_name.split('.')[0], '.log']))
33            self.params_dict = upgrade_param.getAllParam(param)
34        else:
35            # raise UpgradeException(200)
36            pass
37        logger.switchFilePath(self.logFilePath)
38
39
40    def _excuteApp(self, flash_type):
41        # exit_code = 0
42
43        try:
44            ret = self._excute()
45            logger.info(ret)
46            nowtime = get_now_time_str_info()
47            #sn = self.params_dict.get("sn")
48            #os.system("hdc_std -t %s shell reboot loader" % sn)
49            if ret == 98:
50                flash_two(nowtime, flash_type)
51                return 98
52            if ret == 99:
53                flash_two(nowtime, flash_type)
54                return 99
55            if not ret:
56                flash_two(nowtime, flash_type)
57                return -1
58            else:
59                logger.printLog("========================%s %s flash success========================" % (nowtime, flash_type))
60                logger.info("============================= end autotest facoty device flash==================================")
61                return 0
62            # else:
63            #     logger.printLog("========================%s %s flash fail========================" % (nowtime, flash_type))
64            #     exit_code = -1
65                # raise UpgradeException(ERROR_OTHER_ERROR)
66        # except UpgradeException as e:
67        #     nowtime = get_now_time_str_info()
68        #     errormessage = e.getUpgradeMessage(e.code)
69        #     logger.printLog("%s ========================== %s ===============================" % (nowtime, errormessage))
70        #     exit_code = e.code
71        except Exception as e:
72            traceback.print_exc()
73            return 200
74        # finally:
75        #     logger.info("============================= end autotest facoty device flash==================================")
76        # return exit_code
77
78
79    def _excute(self):
80        ret = self.excute()
81        return ret
82
83    def parsePropertiesFile(self, all_params):
84        logger.debug('select all params')
85        return all_params
86
87
88    #在用户级实现,如果用户级没实现,就直接报错
89    def excute(self):
90        logger.error('No custom executor ,check your APP pls')
91        pass
92
93def dec_stepmsg(excutmsg):
94    '''
95    #===================================================================================
96    #   @Method:        dec_stepmsg(excutmsg)
97    #   @Precondition:  none
98    #   @Func:          装饰器函数,将app执行步骤的开始时间、结束时间以及相关步骤信息打印到控制
99    #                   台,excutmsg为执行步骤标识需自己传入
100    #   @PostStatus:    excutmsg:执行步骤标识
101    #   @Param:         local_upgrade_hotaLocation: hota大包在本地的路径
102    #   @eg:            dec_stepmsg("download")
103    #   @return:        被装饰函数
104    #===================================================================================
105    '''
106    def do_dec(fn):
107        def do(self, *args, **kargs):
108            nowtime = get_now_time_str_info()
109            logger.printLog("========================%s start %s ========================" % (nowtime, excutmsg))
110            ret = fn(self, *args, **kargs)
111            nowtime = get_now_time_str_info()
112            logger.printLog("========================%s end %s ========================" % (nowtime, excutmsg))
113            return ret
114        return do
115    return do_dec
116
117
118def flash_two(nowtime, flash_type):
119    logger.printLog("========================%s %s flash fail========================" % (nowtime, flash_type))
120    logger.info("============================= end autotest facoty device flash==================================")
121