def __init__(self, url=URL): super(Cwp, self).__init__(url) self._url = url # create cmd process self._cmdHdrs = CmdProcessing() self._cmdHdrs.register_cmd_handler(self.get_cmd_handlers()) d.dbg('Cwp init done!')
def help(self, cmds): for cmd in cmds: if cmd == 'help': d.info('repo:[init][,sync|fsync]') d.info(' init : repo init source code') d.info(' sync : repo sync source code') d.info(' fsync: repo sync source code with -f') elif cmd == 'cfg': d.info('url: {}'.format(self._url))
def fdel_handler(self, cmds): d.dbg('fdel_handler: {}'.format(cmds)) try: n = len(cmds) if n == 1: self.find_delete('./', cmds[0]) elif n >= 2: self.find_delete(cmds[0], cmds[1]) except KeyError as e: d.err('Error: %s' % e)
def url_handler(self, cmds): d.dbg('url_handler: %s' % cmds) for cmd in cmds: if cmd == 'init': self.repo_init() elif cmd == 'sync': self.repo_sync() elif cmd == 'fsync': self.repo_sync(True)
def repo_sync(self, force=False): hw = HwInfo() cpus = hw.get_cups() if int(cpus) > 5: cpus = 5 if force: cmd = r'repo sync -c -j{n} -f'.format(n=cpus) else: cmd = r'repo sync -c -j{n}'.format(n=cpus) d.info(cmd) subprocess.call(cmd, shell=True)
def help(self, cmds): super(Fpc, self).help(cmds) for cmd in cmds: if cmd == 'help': d.info('ftest:[make][,push][,xxx]') d.info(' make: build fingerprint test binary') d.info(' push: push ftest to /data/') d.info(' xxx : run ftest xxx test')
def avb_make_image(self, image, broxton): # copy image to flashfiles folder cmd = r'cp {out}/{src}.img {flashfiles}/{tar}.img'.format( out=broxton._out, src=image, flashfiles=broxton._flashfiles, tar=image) subprocess.call(cmd, shell=True) d.dbg('avb make image now.') cmd = r'''out/host/linux-x86/bin/avbtool make_vbmeta_image \ --output {}/vbmeta.img \ --include_descriptors_from_image {}/boot.img \ --include_descriptors_from_image {}/system.img \ --include_descriptors_from_image {}/vendor.img \ --include_descriptors_from_image {}/tos.img \ --key external/avb/test/data/testkey_rsa4096.pem \ --algorithm SHA256_RSA4096'''.format( broxton._flashfiles, broxton._flashfiles, broxton._flashfiles, broxton._flashfiles, broxton._flashfiles) subprocess.call(cmd, shell=True)
def make_image(self, images): d.dbg('Broxton.make_image: {}'.format(images)) make_sh = MakeSH(pdt=self._pdt, opt=self._opt, user=self._user) sh = None pre_delete = False for image in images: # pre delete. if image in ['clear', 'clr', 'delete', 'del']: pre_delete = True continue elif image in ['noclear', 'noclr', 'nodelete', 'nodel']: pre_delete = False continue # create and excute make shell d.dbg('create makesh for {}'.format(image)) if type(image) is dict: if 'mmm' in image: sh = MakeSH(pdt=self._pdt, opt=self._opt, user=self._user).create_mmm_sh(image['mmm']) else: d.err('Not support: %s' % str(image)) exit() else: sh = make_sh.create_make_sh(image, pre_delete) # run makesh to build images. make_sh.execute_make_sh(sh)
def parser_cmd_args2(self, cmds): re_dict = re.compile(r'^([\w]+):([\w,\.\/\*\|#-]+)$') re_args = re.compile(r'[\w\.\/\*\|#-]+') re_argv = re.compile('^([\w]+)#([\w,\.\/\*\|-]+)$') output = dict() if len(cmds) == 0: cmds = ['help:help'] for cmd in cmds: dict_cmds = re_dict.match(cmd) if dict_cmds: # dict type k, v = dict_cmds.groups() d.dbg((k, v)) if k in output: for x in re_args.findall(v): output[k].append(x) else: output[k] = re_args.findall(v) else: k = None if k in output: for x in re_args.findall(cmd): output[k].append(x) else: output[k] = re_args.findall(cmd) # parse # argv list_argv = output[k] for index in range(len(list_argv)): find_argv = re_argv.match(list_argv[index]) if find_argv: dict_argv = dict() argv = find_argv.groups() dict_argv[argv[0]] = list(argv[1:]) list_argv[index] = dict_argv d.dbg('parser_cmd_args(): %s' % output) return output
def flash_images(self, images): fimgs = list() avb = None for image in images: if image == 'fw': self.flash_firmware('{path}/{fw}'.format(path=self._flashfiles, fw=self._fw)) elif image == 'ioc': self.flash_ioc('{path}/{fw}'.format(path=self._flashfiles, fw=self._ioc)) else: # avb make images. d.info('update %s image' % image) if not avb: avb = AvbImage() avb.avb_make_image(image, self) fimgs.append(image) # flash images. if len(fimgs) != 0: fimgs.append('vbmeta') # setup flash env ad = Android() # ad.adb_wait() # enter bootloader mode. ad.run_cmd_handler(['rebootloader']) # unlock ad.run_cmd_handler(['deviceunlock']) # flash image now for image in fimgs: fimage = r'{}/{}.img'.format(self._flashfiles, image) d.info('fastboot flash {} {}'.format(image, fimage)) ad.flash_image(image, fimage) # lock device. ad.run_cmd_handler(['devicelock']) # reboot ad.run_cmd_handler(['fastreboot'])
def run(self, cmds): d.dbg('PyCmdProcess.run(): %s' % cmds) for key in cmds: # check help. if key == 'help': for sub_cmd in cmds[key]: if sub_cmd != 'cfg': # no show while cfg. d.info('help:[help][,cfg]') d.info(' help: show help') d.info(' cfg : show config info') if key in self._cmd_dict: d.dbg(self._cmd_dict[key]) if type(self._cmd_dict[key]) == dict: sub_cmds = self._cmd_dict[key] for sub_key in sub_cmds.iterkeys(): f = sub_cmds[sub_key] d.dbg(f(cmds[key])) else: t = type(self._cmd_dict[key]) if t == list: for f in self._cmd_dict[key]: d.dbg(f(cmds[key])) else: f = self._cmd_dict[key] d.dbg(f(cmds[key])) else: d.err('No handler for: %s' % key)
def help(self, cmds): for cmd in cmds: if cmd == 'help': d.info('make:[option][,option]') d.info(' [option]:') d.info(' all/flashfiles: make all of images') d.info(' boot : make bootimage') d.info(' system: make systemimage') d.info(' tos : make tosimage') d.info(' vendor: make vendorimage') d.info(' mmm#xxx: make xxx dir') d.info('flash:[option][,option]') d.info(' [option]:') d.info(' boot : flash bootimage') d.info(' system: flash systemimage') d.info(' tos : flash tosimage') d.info(' vendor: flash vendorimage') d.info(' fw : flash firmware') d.info(' ioc : flash ioc') elif cmd == 'cfg': d.info('pdt: {}'.format(self._pdt)) d.info('opt: {}'.format(self._opt)) d.info('user: {}'.format(self._user)) d.info('out: {}'.format(self._out)) d.info('flashfiles: {}'.format(self._flashfiles)) d.info('fw: {}'.format(self._fw)) d.info('ioc: {}'.format(self._ioc))
def help(self, cmds): for cmd in cmds: if cmd == 'help': d.info('hwinfo:[ncpu][,ip]') d.info(' ncpu: get number of CPU') d.info(' ip: get host IP address')
def flash_ioc(self, ioc): tool = '/opt/intel/platformflashtool/bin/ioc_flash_server_app' cmd = r'sudo {} -s /dev/ttyUSB2 -grfabc -t {}'.format(tool, ioc) d.info(cmd) subprocess.call(cmd, shell=True)
def get_cups(self, cmds=None): cmd = r'cat /proc/cpuinfo | grep "processor"| wc -l' d.dbg(cmd) return int(subprocess.check_output(cmd, shell=True))
def __init__(self): d.dbg('HwInfo init done!')
def flash_firmware(self, fw): tool = '/opt/intel/platformflashtool/bin/ias-spi-programmer' cmd = r'sudo {} --write {}'.format(tool, fw) d.info(cmd) subprocess.call(cmd, shell=True)
def delete(self, f): cmd = r'rm -rf %s' % f d.dbg(cmd) return subprocess.call(cmd, shell=True)
def make_image(self, images): d.dbg('_make_image: get input {}'.format(images)) for image in images.values(): d.dbg('_make_image: make {}'.format(image)) cmd = r'make {}'.format(image) subprocess.call(cmd, shell=True)
def repo_init(self): cmd = r'repo init -u %s' % self._url d.info(cmd) subprocess.call(cmd, shell=True)
def find(self, path, name): cmd = r'find %s -name %s' % (path, name) d.dbg(cmd) return subprocess.call(cmd, shell=True)
def __init__(self, url): self._url = url d.dbg('RepoHelper init set url={}'.format(url))
def help(self, cmds): for cmd in cmds: if cmd == 'help': d.info('ps:kw[,list/kill]') d.info(' kw: the keyword will be search.') d.info(' list/kill: list/kill the ps.')
def hwif_handler(self, cmds): for cmd in cmds: if cmd == 'ncpu': d.info(self.get_cups()) elif cmd == 'ip': d.info(self.get_host_ip())
def help(self, cmds): super(Cwp, self).help(cmds) for cmd in cmds: if cmd == 'help': d.info('make:[option][,option]') d.info(' [option]:') d.info(' all: make all of images') d.info(' sos: make sos image') d.info(' sos_dm: make sos_dm image') d.info(' sos_kernel: make sos_kernel image') d.info(' uos: make uos image') d.info(' uos_kernel: make uos_kernel image') d.info(' flash: flash all of image') d.info(' flash_sos: flash sos image') d.info(' flash_uos: flash uos image') d.info(' flash_data: flash data image') elif cmd == 'cfg': d.info('url: {}'.format(self._url))
def help(self, cmds): for cmd in cmds: if cmd == 'help': d.info('del:[xxx][,xxx]') d.info(' xxx: xxx file will be delete.') d.info('fdel:[path,]file') d.info(' path: path to be find, not set to ./') d.info(' file: file to be delete.') d.info('find:[path,]file') d.info(' path: path to find, not set to ./') d.info(' file: file to be find.')
def __init__(self): d.dbg('Parser init done.')
def find_delete(self, path, name): cmd = r'find %s -name %s | xargs rm -rf {}' % (path, name) d.dbg(cmd) return subprocess.call(cmd, shell=True)
def __init__(self): d.dbg('Input init done.') pass
def __init__(self): d.dbg('FileOps init done!')