def do_download(self, targets): if len(self.destFolder) == 0: self.destFolder = self.destRootFolder downloader = Downloader() archives = {} for target in targets: archives[target] = downloader.download(self.paths[target], self.destFolder, status_callback=self.printErr, progress_callback=self.progress_callback) return archives
def doFlash(self, targets): if len(self.destFolder) == 0: self.destFolder = self.destRootFolder download = Downloader() archives = {} cmd = './shallow_flash.sh -y' sp = '' if _platform == 'darwin': sp = ' ' for target in targets: archives[target] = download.download(self.paths[target], self.destFolder, status_callback=self.printErr) if PathParser._IMAGES in targets: try: self.temp_dir = tempfile.mkdtemp() self.logger.log('Create temporary folder:' + self.temp_dir, status_callback=self.printErr) Decompressor().unzip(archives[PathParser._IMAGES], self.temp_dir, status_callback=self.printErr) # set the permissions to rwxrwxr-x (509 in python's os.chmod) os.chmod( self.temp_dir + '/b2g-distro/flash.sh', stat.S_IRUSR | stat.S_IWUSR | stat.S_IXUSR | stat.S_IRGRP | stat.S_IWGRP | stat.S_IXGRP | stat.S_IROTH | stat.S_IXOTH) os.chmod( self.temp_dir + '/b2g-distro/load-config.sh', stat.S_IRUSR | stat.S_IWUSR | stat.S_IXUSR | stat.S_IRGRP | stat.S_IWGRP | stat.S_IXGRP | stat.S_IROTH | stat.S_IXOTH) os.system('cd ' + self.temp_dir + '/b2g-distro; ./flash.sh -f') return finally: try: shutil.rmtree(self.temp_dir) # delete directory except OSError: self.logger.log('Can not remove temporary folder:' + self.temp_dir, status_callback=self.printErr, level=Logger._LEVEL_WARNING) flash_img_cmd = 'CUR_DIR=`pwd`; TEMP_DIR=`mktemp -d`; unzip -d $TEMP_DIR ' + archives[PathParser._IMAGES] + '; \\\n' + \ 'cd $TEMP_DIR/b2g-distro/; ./flash.sh -f; \\\ncd $CUR_DIR; rm -rf $TEMP_DIR' self.logger.log( '!!NOTE!! Following commands can help you to flash packages into other device WITHOUT download again.\n%s\n' % (flash_img_cmd, )) else: if PathParser._GAIA in targets: cmd = cmd + ' -g' + sp + archives[PathParser._GAIA] if PathParser._GECKO in targets: cmd = cmd + ' -G' + sp + archives[PathParser._GECKO] print('run command: ' + cmd) os.system(cmd) self.logger.log( '!!NOTE!! Following commands can help you to flash packages into other device WITHOUT download again.\n%s\n' % (cmd, )) self.logger.log('Flash Done.', status_callback=self.printErr) self.after_flash_action() self.quit()
def downloadExec(url, fileName): var = Downloader() var.downloadFile(url, fileName)