summaryrefslogtreecommitdiff
path: root/test-cli/test/tasks/flashmemory.py
blob: ad9d92a2998c5690757b9e80322612b4d4e9ee85 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import sh
import os

class NAND_Flasher:
    __Name = None
    __varlist = None
    __xmlObj = None
    __igepflashPath = None
    __lastError = ''

    def __init__(self, varlist):
        self.__varlist = varlist
        self.__xmlObj = varlist['xml']
        self.__Name = varlist.get('name_flashnand', self.__xmlObj.getKeyVal('NAND_Flasher', 'name', 'NAND_Flasher'))
        self.__igepflashPath = self.__xmlObj.getKeyVal('NAND_Flasher', 'igep_flash', '/usr/bin/igep-flash')
        self.__ImagePath = varlist.get('flashimagepath', '')
        self.__SkipNandtest = varlist.get('skipnandtest', self.__xmlObj.getKeyVal('NAND_Flasher', 'skipnandtest', '1'))

    def getTaskName(self):
        return self.__Name

    def getError(self):
        return self.__lastError

    def Execute(self):
        try:
            self.__lastError = ''
            if not os.path.isfile(self.__ImagePath):
                self.__lastError('Not Image Found: {}'.format(self.__ImagePath))
                return False, None
            if self.__SkipNandtest == '1':
                p = sh.bash('{}'.format(self.__igepflashPath), "--skip-nandtest", "--image", self.__ImagePath)
            else:
                p = sh.bash('{}'.format(self.__igepflashPath), "--image", self.__ImagePath)
            if p.exit_code != 0:
                return False, None
        except OSError as e:
            self.__lastError('Exception: {}'.format(e.strerror))
            return False, None
        except Exception as Error:
            self.__lastError('Exception: {}'.format(Error))
            return False, None
        return True, None