def main(): if not AdbHelper.has_adb(): print("No adb installed; terminated") sys.exit(1) options = ArgParse(sys.argv[1:]) try: archive = {} prog = ConsoleApp() if option.full_flash: archives[PathParser._IMAGES] = option.full_flash else: if option.gecko: archives[PathParser._GECKO] = option.gecko if option.gaia: archives[PathParser._GAIA] = option.gaia if not archive: print("Nothing to flash; terminated") return sys.exit(1) ret_obj = prog.dialog.yes_no('Bulk Flasher Prompt', 'Warning: this program will flash all devices! Please make sure devices are the same. continue? (y/N)', ConsoleDialog._NO_CMD_INDEX) devices = AdbHelper.adb_devices().keys() for serial in devices: prog.do_flash(self.flash_params, archives, serial, keep_profile=self.target_keep_profile) except KeyboardInterrupt: print '' print '### Quit' sys.exit(0)
def run(self): # get the device's serial number devices = AdbHelper.adb_devices() if len(devices) == 0: self.logger.warning("No device.") exit(1) else: if self.args.serial is not None and self.args.serial in devices: self.logger.debug("Setup serial to [{0}] by --serial".format(self.args.serial)) device_serial = self.args.serial elif "ANDROID_SERIAL" in os.environ and os.environ["ANDROID_SERIAL"] in devices: self.logger.debug("Setup serial to [{0}] by ANDROID_SERIAL".format(os.environ["ANDROID_SERIAL"])) device_serial = os.environ["ANDROID_SERIAL"] else: if self.args.serial is None and not "ANDROID_SERIAL" in os.environ: if len(devices) == 1: self.logger.debug("No serial, and only one device") device_serial = None else: self.logger.debug("No serial, but there are more than one device") self.logger.warning("Please specify the device by --serial option.") exit(1) # Backup if self.args.backup: try: self.logger.info("Target device [{0}]".format(device_serial)) # Create temp folder tmp_dir = tempfile.mkdtemp(prefix="backup_restore_") # Stop B2G self.stop_b2g(serial=device_serial) # Backup User Profile self.backup_profile(local_dir=tmp_dir, serial=device_serial) # Backup SDCard if self.args.sdcard: self.backup_sdcard(local_dir=tmp_dir, serial=device_serial) # Copy backup files from temp folder to target folder if os.path.isdir(self.args.profile_dir): self.logger.warning("Removing [{0}] folder...".format(self.args.profile_dir)) shutil.rmtree(self.args.profile_dir) self.logger.info("Copy profile from [{0}] to [{1}].".format(tmp_dir, self.args.profile_dir)) shutil.copytree(tmp_dir, self.args.profile_dir) # Start B2G if not self.args.no_reboot: self.start_b2g(serial=device_serial) finally: self.logger.debug("Removing [{0}] folder...".format(tmp_dir)) shutil.rmtree(tmp_dir) # Restore elif self.args.restore: self.logger.info("Target device [{0}]".format(device_serial)) # Stop B2G self.stop_b2g(serial=device_serial) # Restore User Profile self.restore_profile(local_dir=self.args.profile_dir, serial=device_serial) # Restore SDCard if self.args.sdcard: self.restore_sdcard(local_dir=self.args.profile_dir, serial=device_serial) # Start B2G if not self.args.no_reboot: self.start_b2g(serial=device_serial)
def run(self): devices = AdbHelper.adb_devices() is_no_color = self.args.no_color if 'NO_COLOR' in os.environ: try: is_no_color = bool(util.strtobool(os.environ['NO_COLOR'].lower())) except: print 'Invalid NO_COLOR value [{0}].'.format(os.environ['NO_COLOR']) if len(devices) == 0: print 'No device.' exit(1) elif len(devices) >= 1: # has --serial, then skip ANDROID_SERIAL, then list one device by --serial if (self.args.serial is not None): if self.args.serial in devices: serial = self.args.serial print 'Serial: {0} (State: {1})'.format(serial, devices[serial]) device_info = self.get_device_info(serial=serial) self.print_device_info(device_info, no_color=is_no_color) self.output_log([device_info]) else: print 'Can not found {0}.\nDevices:'.format(self.args.serial) for device, state in devices.items(): print 'Serial: {0} (State: {1})'.format(device, state) exit(1) # no --serial, but has ANDROID_SERIAL, then list one device by ANDROID_SERIAL elif (self.args.serial is None) and ('ANDROID_SERIAL' in os.environ): if os.environ['ANDROID_SERIAL'] in devices: serial = os.environ['ANDROID_SERIAL'] print 'Serial: {0} (State: {1})'.format(serial, devices[serial]) device_info = self.get_device_info(serial=serial) self.print_device_info(device_info, no_color=is_no_color) self.output_log([device_info]) else: print 'Can not found {0}.\nDevices:'.format(os.environ['ANDROID_SERIAL']) for device, state in devices.items(): print 'Serial: {0} (State: {1})'.format(device, state) exit(1) # no --serial, no ANDROID_SERIAL, then list all devices if (self.args.serial is None) and (not 'ANDROID_SERIAL' in os.environ): if len(devices) > 1: print 'More than one device.' print 'You can specify ANDROID_SERIAL by "--serial" option.\n' device_info_list = [] for device, state in devices.items(): print 'Serial: {0} (State: {1})'.format(device, state) if state == 'device': device_info = self.get_device_info(serial=device) self.print_device_info(device_info, no_color=is_no_color) device_info_list.append(device_info) else: print 'Skipped.\n' device_info_list.append({'Serial': device, 'Skip': True}) self.output_log(device_info_list)
def run(self): devices = AdbHelper.adb_devices() is_no_color = self.args.no_color if 'NO_COLOR' in os.environ: try: is_no_color = bool( util.strtobool(os.environ['NO_COLOR'].lower())) except: print 'Invalid NO_COLOR value [{0}].'.format( os.environ['NO_COLOR']) if len(devices) == 0: print 'No device.' exit(1) elif len(devices) >= 1: # has --serial, then skip ANDROID_SERIAL, then list one device by --serial if (self.args.serial is not None): if self.args.serial in devices: serial = self.args.serial print 'Serial: {0} (State: {1})'.format( serial, devices[serial]) device_info = self.get_device_info(serial=serial) self.print_device_info(device_info, no_color=is_no_color) self.output_log([device_info]) else: print 'Can not found {0}.\nDevices:'.format( self.args.serial) for device, state in devices.items(): print 'Serial: {0} (State: {1})'.format(device, state) exit(1) # no --serial, but has ANDROID_SERIAL, then list one device by ANDROID_SERIAL elif (self.args.serial is None) and ('ANDROID_SERIAL' in os.environ): if os.environ['ANDROID_SERIAL'] in devices: serial = os.environ['ANDROID_SERIAL'] print 'Serial: {0} (State: {1})'.format( serial, devices[serial]) device_info = self.get_device_info(serial=serial) self.print_device_info(device_info, no_color=is_no_color) self.output_log([device_info]) else: print 'Can not found {0}.\nDevices:'.format( os.environ['ANDROID_SERIAL']) for device, state in devices.items(): print 'Serial: {0} (State: {1})'.format(device, state) exit(1) # no --serial, no ANDROID_SERIAL, then list all devices if (self.args.serial is None) and (not 'ANDROID_SERIAL' in os.environ): if len(devices) > 1: print 'More than one device.' print 'You can specify ANDROID_SERIAL by "--serial" option.\n' device_info_list = [] for device, state in devices.items(): print 'Serial: {0} (State: {1})'.format(device, state) if state == 'device': device_info = self.get_device_info(serial=device) self.print_device_info(device_info, no_color=is_no_color) device_info_list.append(device_info) else: print 'Skipped.\n' device_info_list.append({ 'Serial': device, 'Skip': True }) self.output_log(device_info_list)
# Create a TCP/IP socket sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) # Connect the socket to the port where the server is listening server_address = (control_server_ip, control_server_port) print 'Connecting to %s:%s' % server_address sock.connect(server_address) data = sock.recv(1024).strip() if data <> "<< Control Server Connected >>": print "Successfully connected to the control server.\n" sys.exit() try: # Send data adb_devices = AdbHelper.adb_devices() for device in adb_devices.items(): message = "" # Check for device type if device[1] == "device": device_type = re.sub(r'\r+|\n+', '', AdbHelper.adb_shell('getprop ro.product.device', serial=device[0])) else: device_type = "unknown" # Check for device build if device[1] == "device": device_build = re.sub(r'\r+|\n+', '', AdbHelper.adb_shell('getprop ro.build.version.incremental', serial=device[0])) else: device_build = "unknown"
def run(self): # get the device's serial number devices = AdbHelper.adb_devices() if len(devices) == 0: self.logger.warning('No device.') exit(1) else: if self.args.serial is not None and self.args.serial in devices: self.logger.debug('Setup serial to [{0}] by --serial'.format( self.args.serial)) device_serial = self.args.serial elif 'ANDROID_SERIAL' in os.environ and os.environ[ 'ANDROID_SERIAL'] in devices: self.logger.debug( 'Setup serial to [{0}] by ANDROID_SERIAL'.format( os.environ['ANDROID_SERIAL'])) device_serial = os.environ['ANDROID_SERIAL'] else: if self.args.serial is None and not 'ANDROID_SERIAL' in os.environ: if len(devices) == 1: self.logger.debug('No serial, and only one device') device_serial = None else: self.logger.debug( 'No serial, but there are more than one device') self.logger.warning( 'Please specify the device by --serial option.') exit(1) # Backup if self.args.backup: try: self.logger.info('Target device [{0}]'.format(device_serial)) # Create temp folder tmp_dir = tempfile.mkdtemp(prefix='backup_restore_') # Stop B2G self.stop_b2g(serial=device_serial) # Backup User Profile self.backup_profile(local_dir=tmp_dir, serial=device_serial) # Backup SDCard if self.args.sdcard: self.backup_sdcard(local_dir=tmp_dir, serial=device_serial) # Copy backup files from temp folder to target folder if os.path.isdir(self.args.profile_dir): self.logger.warning('Removing [{0}] folder...'.format( self.args.profile_dir)) shutil.rmtree(self.args.profile_dir) self.logger.info('Copy profile from [{0}] to [{1}].'.format( tmp_dir, self.args.profile_dir)) shutil.copytree(tmp_dir, self.args.profile_dir) # Start B2G if not self.args.no_reboot: self.start_b2g(serial=device_serial) finally: self.logger.debug('Removing [{0}] folder...'.format(tmp_dir)) shutil.rmtree(tmp_dir) # Restore elif self.args.restore: self.logger.info('Target device [{0}]'.format(device_serial)) # Stop B2G self.stop_b2g(serial=device_serial) # Restore User Profile self.restore_profile(local_dir=self.args.profile_dir, serial=device_serial) # Restore SDCard if self.args.sdcard: self.restore_sdcard(local_dir=self.args.profile_dir, serial=device_serial) # Start B2G if not self.args.no_reboot: self.start_b2g(serial=device_serial)
def run(self): # get the device's serial number devices = AdbHelper.adb_devices() if len(devices) == 0: self.logger.warning('No device.') exit(1) else: if self.args.serial is not None and self.args.serial in devices: self.logger.debug('Setup serial to [{0}] by --serial'.format(self.args.serial)) device_serial = self.args.serial elif 'ANDROID_SERIAL' in os.environ and os.environ['ANDROID_SERIAL'] in devices: self.logger.debug('Setup serial to [{0}] by ANDROID_SERIAL'.format(os.environ['ANDROID_SERIAL'])) device_serial = os.environ['ANDROID_SERIAL'] else: if self.args.serial is None and not 'ANDROID_SERIAL' in os.environ: if len(devices) == 1: self.logger.debug('No serial, and only one device') device_serial = None else: self.logger.debug('No serial, but there are more than one device') self.logger.warning('Please specify the device by --serial option.') exit(1) # Backup if self.args.backup: try: self.logger.info('Target device [{0}]'.format(device_serial)) # Create temp folder tmp_dir = tempfile.mkdtemp(prefix='backup_restore_') # Stop B2G self.stop_b2g(serial=device_serial) # Backup User Profile self.backup_profile(local_dir=tmp_dir, serial=device_serial) # Backup SDCard if self.args.sdcard: self.backup_sdcard(local_dir=tmp_dir, serial=device_serial) # Copy backup files from temp folder to target folder if os.path.isdir(self.args.profile_dir): self.logger.warning('Removing [{0}] folder...'.format(self.args.profile_dir)) shutil.rmtree(self.args.profile_dir) self.logger.info('Copy profile from [{0}] to [{1}].'.format(tmp_dir, self.args.profile_dir)) shutil.copytree(tmp_dir, self.args.profile_dir) # Start B2G if not self.args.no_reboot: self.start_b2g(serial=device_serial) finally: self.logger.debug('Removing [{0}] folder...'.format(tmp_dir)) shutil.rmtree(tmp_dir) # Restore elif self.args.restore: self.logger.info('Target device [{0}]'.format(device_serial)) # Checking the Version of Profile if self.check_profile_version(local_dir=self.args.profile_dir, serial=device_serial): # Stop B2G self.stop_b2g(serial=device_serial) # Restore User Profile self.restore_profile(local_dir=self.args.profile_dir, serial=device_serial) # Restore SDCard if self.args.sdcard: self.restore_sdcard(local_dir=self.args.profile_dir, serial=device_serial) # Start B2G if not self.args.no_reboot: self.start_b2g(serial=device_serial) else: self.logger.warn('The version on device is smaller than backup\'s version.')