def test_warning_suppress(): """Log a warning message with logging at 1""" log.LOG_LEVEL_STDOUT = 1 log.LOG_LEVEL_FILE = 1 log.w(TAG, "This is a warning!")
def del_prop(section, prop): """Delete a property""" config = ConfigParser.ConfigParser() config.read(CONFIG_FILE_NAME) rtn = None # Remove the parameter try: rtn = config.remove_option(section, prop) except ConfigParser.NoSectionError: log.w(TAG, "Property not removed (the section did not exist).") return -1 if not rtn: log.w(TAG, "Property not removed (did not exist).") return -2 # Let's make sure we don't have an empty section now. if len(config.items(section)) == 0: config.remove_section(section) prop_f = open(CONFIG_FILE_NAME, 'w') config.write(prop_f) prop_f.close() return 0
def install_single_package(item, force=False): """Install a single package""" rtn = 0 try: # First check if we know about this package if is_binary_installed(item.name): # Prompt for install. if not force: print( "[WARNING] An item with this name is already installed." " See details below.") installed_item = __load_item(item) if __prompt_install(item, installed_item): log.d(TAG, "User would like to install") rtn = __do_single_package_install(item) else: log.i(TAG, "Package installation skipped.") # Force else: log.d(TAG, "Forcing component installation.") rtn = __do_single_package_install(item) else: log.d(TAG, "This is a new package, installing.") rtn = __do_single_package_install(item) except KeyError: log.w(TAG, "Error checking if the package was installed. Skipping") rtn = -4 return rtn
def run(self, args): """ Internal entry point for starting a module. It basically executes the 'execute' method if it exists. """ # Save module name self.__self__ = type(self).__name__ # Determine if we have an execute() method. if hasattr(self, 'execute'): # Do python logging override try: log.LOG_LEVEL_STDOUT = int(os.environ['GLOG_LEVEL']) except KeyError: pass except ValueError: log.w(TAG, "Invalid GLOG_LEVEL value (0-5 is allowed)") result = getattr(self, 'execute')(args) else: log.e(TAG, "Module '%s' does not define a entry point!" % self.__self__) result = None return result
def del_prop(section, prop): """Delete a property""" config = __load_config() section = section.capitalize() rtn = None # Remove the parameter try: rtn = config.remove_option(section, prop) except configparser.NoSectionError: log.w(TAG, "Property not removed (the section did not exist).") return -1 if not rtn: log.w(TAG, "Property not removed (did not exist).") return -2 # Let's make sure we don't have an empty section now. if len(config.items(section)) == 0: config.remove_section(section) __update_config(config) return 0
def item_to_xml_binaries(cls, etree_root, export_items): """Export all binaries""" # Add binaries bin_items = [ item for item in export_items if item.type == dtf.core.item.TYPE_BINARY ] for item in bin_items: item_xml = etree.SubElement(etree_root, 'Item') item_xml.attrib['type'] = dtf.core.item.TYPE_BINARY item_xml.attrib['name'] = item.name if item.version is None: log.w(TAG, "Skipping version for %s" % item.name) else: item_xml.attrib['version'] = item.version if item.author is None: log.w(TAG, "Skipping author for %s" % item.name) else: item_xml.attrib['author'] = item.author item_xml.attrib['localName'] = "binaries/%s" % item.install_name return
def item_to_xml_packages(cls, etree_root, export_items): """Export all packages""" pkg_items = [ item for item in export_items if item.type == dtf.core.item.TYPE_PACKAGE ] for item in pkg_items: item_xml = etree.SubElement(etree_root, 'Item') item_xml.attrib['type'] = dtf.core.item.TYPE_PACKAGE item_xml.attrib['name'] = item.name if item.version is None: log.w(TAG, "Skipping version for %s" % item.name) else: item_xml.attrib['version'] = item.version if item.author is None: log.w(TAG, "Skipping author for %s" % item.name) else: item_xml.attrib['author'] = item.author item_xml.attrib['localName'] = "packages/%s" % item.install_name return
def test_warning(): """Log a warning message""" log.LOG_LEVEL_STDOUT = 5 log.LOG_LEVEL_FILE = 5 log.w(TAG, "This is a warning!")
def install_single_package(item, force=False): """Install a single package""" rtn = 0 try: # First check if we know about this package if is_binary_installed(item.name): # Prompt for install. if not force: print ("[WARNING] An item with this name is already installed." " See details below.") installed_item = __load_item(item) if __prompt_install(item, installed_item): log.d(TAG, "User would like to install") rtn = __do_single_package_install(item) else: log.i(TAG, "Package installation skipped.") # Force else: log.d(TAG, "Forcing component installation.") rtn = __do_single_package_install(item) else: log.d(TAG, "This is a new package, installing.") rtn = __do_single_package_install(item) except KeyError: log.w(TAG, "Error checking if the package was installed. Skipping") rtn = -4 return rtn
def do_shutdown(cls, signum, frame): """Handle a Ctrl+C""" log.w(TAG, "Exiting dtf initialization!") rmfile(utils.CONFIG_FILE_NAME) rmfile(log.LOG_FILE_NAME) exit(-4)
def delete_tree(directory_path): """Delete a directory recursively""" try: rmtree(directory_path) return 0 except OSError: log.w(TAG, "OSError when removing the tree at '%s'" % directory_path) return 0
def __launch_python_module(path, cmd, args, chdir=True, skip_checks=False): """Launch a python module by path""" mod_class = None mod_inst = None # We should always be in TOP (unless we are `pm`). # However, we should save off the current directory. launch_dir = os.getcwd() if chdir and prop.TOP is not None: os.chdir(prop.TOP) # Next, get the path setup. if __update_path() != 0: log.e(TAG, "Unable to update library path!") return -7 # If we got here, we try to load as a python module. try: module = imp.load_source(cmd, path) # pylint:disable=bare-except except: # NOQA msg = sys.exc_info()[0] log.e(TAG, "An Exception occured while calling load_source()") log.e(TAG, "Exception: %s" % msg) return -9 if module is None: log.e(TAG, "Error launching module '%s'." % cmd) return -5 try: mod_class = getattr(module, cmd) mod_inst = mod_class() mod_inst.launch_dir = launch_dir except AttributeError: log.e(TAG, "Unable to find class '%s' in module!" % cmd) return -6 if not skip_checks and __do_python_prelaunch_checks(mod_inst) != 0: log.e(TAG, "Module prelaunch checks failed.") return -8 # Save module name mod_inst.__self__ = type(mod_inst).__name__ # Do python logging override try: log.LOG_LEVEL_STDOUT = int(os.environ['GLOG_LEVEL']) except KeyError: pass except ValueError: log.w(TAG, "Invalid GLOG_LEVEL value (0-5 is allowed)") return __do_launch_python_module(mod_inst, args)
def delete_file(file_path): """Delete a file""" try: remove(file_path) return 0 except OSError: log.w(TAG, "There was an OSError when removing the file '%s'" % file_path) return 0
def parse_single_item(self, args): # pylint: disable=too-many-branches """Parse args, return Item""" item = dtf.core.item.Item() if args.single_name is None: log.e(TAG, "No '--name' specified in single item mode. Exiting.") return None item.name = args.single_name if args.single_type not in dtf.core.item.VALID_TYPES: log.e(TAG, "Invalid type passed to single. Exiting.") return None item.type = args.single_type version = args.single_version if version is not None: if dtf.core.item.is_valid_version(version): item.version = version else: log.e(TAG, "Version string is not valid. Exiting.") return None else: log.w(TAG, "No version provided, using v1.0.0") item.version = "1.0.0" try: item.author = " ".join(args.single_author) except TypeError: item.author = None try: item.about = " ".join(args.single_about) except TypeError: item.about = None install_name = args.single_install_name local_name = args.single_local_name if install_name is None: log.d(TAG, "install_name is null, using name...") install_name = os.path.basename(args.single_name) if local_name is None: log.d(TAG, "local_name is null, using name...") local_name = args.single_name item.install_name = install_name item.local_name = local_name if self.check_local_exists(item): return item else: return None
def is_python_module(module_path, name): """Try to load as a Python module""" try: imp.load_source(name, module_path) except (NameError, SyntaxError): return False except ImportError: log.w(TAG, "This is a python module, but has non-existent imports!") return False return True
def do_version_checks(item, strict): """Run version checks""" if item.version is None: log.w(TAG, "[WARN] Version is none, this should be set!") if strict: return -1 elif not dtf.core.item.is_valid_version(item.version): log.e(TAG, "[FAIL] invalid version (must be semvar)") return -1 else: log.i(TAG, "[PASS] Valid version.") return 0
def parse_bash_module(module_path, name): """Parse as a bash module""" attributes = dict() # Parse file for "#@", strings, store in dictionary. for line in open(module_path).read().split("\n"): match = re.match("#@[a-zA-Z ]+:.*", line) if match is None: continue try: attribute, value = match.group(0).replace("#@", "").split(":") value = value.lstrip(" ") except ValueError: log.w(TAG, "Unable to parse the module version, not including.") continue attributes[attribute] = value item = Item() item.type = TYPE_MODULE item.name = name item.local_name = module_path item.install_name = name item.author = get_dict_attrib(attributes, "Author") item.about = get_dict_attrib(attributes, "About") health = get_dict_attrib(attributes, "Health") if health not in VALID_HEALTH_VALUES: log.e(TAG, "Invalid health specified. Exiting.") return None item.health = health version = get_dict_attrib(attributes, "Version") if version is not None: try: (item.major_version, item.minor_version) = version.split('.') except ValueError: log.e(TAG, "Version string is not valid. Exiting.") return None else: item.major_version = None item.minor_version = None #Return our item. return item
def execute(self, args): """Main module executor""" print('Are you sure you want to delete the dtf project in this ' 'directory? This cannot be reversed! [y/N]'), inp = raw_input() if inp.lower() == 'y': os.remove(utils.CONFIG_FILE_NAME) log.i(TAG, "Reset complete!") return 0 else: log.w(TAG, "Reset aborted.") return -1
def __item_from_xml(item, relative_root="./"): """create Item object from XML""" item_type = __get_xml_attrib(item, "type") if item_type is None: log.e(TAG, "Found tag with no 'type' attribute, skipping!") return None if item_type not in dtf.core.item.VALID_TYPES: log.e(TAG, "Illegal 'type' attribute found, skipping!") return None name = __get_xml_attrib(item, "name") if name is None: log.e(TAG, "Found NULL named moduled, skipping!") return None # Ok, lets start. We can generically parse. local_item = dtf.core.item.Item() local_item.type = item_type local_item.version = __get_xml_attrib(item, "version") local_item.author = __get_xml_attrib(item, "author") local_item.about = __get_xml_attrib(item, "about") if local_item.version is None: log.w(TAG, "No version for '%s', using 1.0.0" % name) local_item.version = "1.0.0" install_name = __get_xml_attrib(item, "installName") local_name = __get_xml_attrib(item, "localName") if install_name is None: log.d(TAG, "install_name is null, using name...") install_name = name if local_name is None: log.d(TAG, "local_name is null, using name...") local_name = name else: local_name = os.path.normpath("%s/%s" % (relative_root, local_name)) local_item.name = name local_item.install_name = install_name local_item.local_name = local_name return local_item
def main(): """Main loop""" parser = ArgumentParser(prog='dtf_checker', description='Check module for syntax & style.') parser.add_argument('module_name', metavar="module_name", type=str, nargs='+', default=None, help='The module to check.') parser.add_argument('-a', '--all', dest='all_checks', action='store_const', const=True, default=False, help="Run more vigorous checks.") parser.add_argument('-s', '--strict', dest='strict', action='store_const', const=True, default=False, help="Treat warnins as errors.") parsed_args = parser.parse_args() all_checks = parsed_args.all_checks strict_checks = parsed_args.strict module_name = parsed_args.module_name[0] # First, lets make sure have stuff if not check_required(): return -1 # Do python logging override try: log.LOG_LEVEL_STDOUT = int(os.environ['GLOG_LEVEL']) except KeyError: pass except ValueError: log.w(TAG, "Invalid GLOG_LEVEL value (0-5 is allowed)") # Do checks return do_checks(module_name, all_checks, strict_checks)
def execute(self, args): # pylint: disable=unused-argument,no-self-use """Main module executor""" print( 'Are you sure you want to delete the dtf project in this ' 'directory? This cannot be reversed! [y/N]', end=" ") inp = compat.raw_input() if inp.lower() == 'y': os.remove(utils.CONFIG_FILE_NAME) log.i(TAG, "Reset complete!") return 0 else: log.w(TAG, "Reset aborted.") return -1
def determine_seandroid_state(self): """Determine if SEAndroid is used""" self.adb.shell_command("getenforce") response = self.adb.get_output()[0].lower() if response.find("not found") != -1: return SEANDROID_OFF elif response == "permissive": return SEANDROID_PERMISSIVE elif response == "enforcing": return SEANDROID_ENFORCING elif response == "disabled": return SEANDROID_DISABLED else: log.w(TAG, "Unable to determine SEAndroid state!") return SEANDROID_UNKNOWN
def do_other_checks(item, strict): """Run rest of the auto checkks""" if item.about is None: log.w(TAG, "[WARN] About string is none, this should be set!") if strict: return -1 else: log.i(TAG, "[PASS] Valid about.") # Check Author if item.author is None: log.w(TAG, "[WARN] Author is none, this should be set!") if strict: return -1 else: log.i(TAG, "[PASS] Valid author.") return 0
def __install_zip_binary(zip_file, item, force_mode): """Install a binary from a ZIP""" rtn = 0 # Does the resource even exist? if not file_in_zip(zip_file, item.local_name): log.w( TAG, "'%s' defined, but local file '%s' does not exist!" % (item.name, item.local_name)) return -1 try: # First check if we know about this binary if is_binary_installed(item.name): # Prompt for install. if not force_mode: print( "[WARNING] An item with this name is already installed." " See details below.") installed_item = __load_item(item) if __prompt_install(item, installed_item): log.d(TAG, "User would like to install") rtn = __do_zip_binary_install(zip_file, item) else: log.i(TAG, "Binary installation skipped.") # Force else: log.d(TAG, "Forcing component installation.") rtn = __do_zip_binary_install(zip_file, item) else: log.d(TAG, "This is a new binary, installing.") rtn = __do_zip_binary_install(zip_file, item) except KeyError: log.w(TAG, "Error checking if the binary was installed. Skipping") rtn = -4 return rtn
def __install_zip_binary(zip_file, item, force_mode): """Install a binary from a ZIP""" rtn = 0 # Does the resource even exist? if not file_in_zip(zip_file, item.local_name): log.w(TAG, "'%s' defined, but local file '%s' does not exist!" % (item.name, item.local_name)) return -1 try: # First check if we know about this binary if is_binary_installed(item.name): # Prompt for install. if not force_mode: print ("[WARNING] An item with this name is already installed." " See details below.") installed_item = __load_item(item) if __prompt_install(item, installed_item): log.d(TAG, "User would like to install") rtn = __do_zip_binary_install(zip_file, item) else: log.i(TAG, "Binary installation skipped.") # Force else: log.d(TAG, "Forcing component installation.") rtn = __do_zip_binary_install(zip_file, item) else: log.d(TAG, "This is a new binary, installing.") rtn = __do_zip_binary_install(zip_file, item) except KeyError: log.w(TAG, "Error checking if the binary was installed. Skipping") rtn = -4 return rtn
def install_zip(zip_file_name, force=False, new_only=False): """Install a ZIP file""" rtn = 0 export_zip = mp.ExportZip(zip_file_name) for item in export_zip.iter_items(): if not export_zip.assert_item(item): log.w( TAG, "'%s' defined, but local file '%s' does not exist!" % (item.name, item.local_name)) continue item_type = item.type if item_type == dtf.core.item.TYPE_BINARY: rtn |= __generic_install(item, force, new_only, is_binary_installed, __do_zip_binary_install, (export_zip, item)) elif item_type == dtf.core.item.TYPE_LIBRARY: rtn |= __generic_install(item, force, new_only, is_library_installed, __do_zip_library_install, (export_zip, item)) elif item_type == dtf.core.item.TYPE_MODULE: rtn |= __generic_install(item, force, new_only, is_module_installed, __do_zip_module_install, (export_zip, item)) elif item_type == dtf.core.item.TYPE_PACKAGE: rtn |= __generic_install(item, force, new_only, is_package_installed, __do_zip_package_install, (export_zip, item)) return rtn
def item_to_xml_modules(cls, etree_root, export_items): """Export all modules""" mod_items = [ item for item in export_items if item.type == dtf.core.item.TYPE_MODULE ] for item in mod_items: item_xml = etree.SubElement(etree_root, 'Item') item_xml.attrib['type'] = dtf.core.item.TYPE_MODULE item_xml.attrib['name'] = item.name if item.version is None: log.w(TAG, "Skipping version for %s" % item.name) else: item_xml.attrib['version'] = item.version if item.about is None: log.w(TAG, "Skipping about for %s" % item.name) else: item_xml.attrib['about'] = item.about if item.author is None: log.w(TAG, "Skipping author for %s" % item.name) else: item_xml.attrib['author'] = item.author item_xml.attrib['localName'] = "modules/%s" % item.install_name return
def parse_bash_module(module_path, name): """Parse as a bash module""" attributes = dict() # Parse file for "#@", strings, store in dictionary. for line in open(module_path).read().split("\n"): match = re.match("#@[a-zA-Z ]+:.*", line) if match is None: continue try: attribute, value = match.group(0).replace("#@", "").split(":") value = value.lstrip(" ") except ValueError: log.w(TAG, "Unable to parse the module version, not including.") continue attributes[attribute] = value item = dtf.core.item.Item() item.type = dtf.core.item.TYPE_MODULE item.name = name item.local_name = module_path item.install_name = name item.author = get_dict_attrib(attributes, "Author") item.about = get_dict_attrib(attributes, "About") version = get_dict_attrib(attributes, "Version") if version is not None: if dtf.core.item.is_valid_version(version): item.version = version else: log.e(TAG, "Invalid version specified. Exiting.") return None else: item.version = None # Return our item. return item
def __generic_install(item, force_mode, new_only, check_function, install_function, install_args): """Generic check and caller""" try: # First check if we know about this item if check_function(item.name): log.d(TAG, "Item exists, need to check") # If forced, don't even check. if force_mode: log.i( TAG, "Forcing component installation: %s (%s)" % (item.name, item.type)) return install_function(*install_args) installed_item = __load_item(item) # Ok, next, we check the versions. if dtf.core.item.item_is_newer(installed_item, item): log.i( TAG, "Upgrading %s from v%s to v%s" % (item.name, installed_item.version, item.version)) return install_function(*install_args) elif new_only: log.w(TAG, "Skipping due to older version: %s" % item.name) return 0 # Otherwise we need to prompt else: print("[WARNING] An item with this name is already installed." " See details below.") if __prompt_install(item, installed_item): log.d(TAG, "User would like to install") return install_function(*install_args) else: log.w(TAG, "Installation skipped.") return 0 else: log.i(TAG, "Installing new item: %s (%s)" % (item.name, item.type)) return install_function(*install_args) except KeyError: log.w(TAG, "Error checking if the item was installed. Skipping") return -4
def initialize_device(self, init_device): """Perform the actual initialization""" device_serial = init_device['serial'] log.d(TAG, "Preparing device: %s" % device_serial) utils.touch(utils.CONFIG_FILE_NAME) set_prop('Info', 'serial', device_serial) # Set the client section. set_prop('Client', 'mode', adb.MODE_USB) # Since we have a serial now, lets create a new DtfAdb instance self.adb = adb.DtfAdb() # Kernel self.adb.shell_command('cat /proc/version') kernel = self.adb.get_output()[0] log.d(TAG, "Kernel version: %s" % kernel) set_prop('Info', 'kernel', kernel) # SDK sdk = self.getprop('ro.build.version.sdk') log.d(TAG, "Using SDK API %s" % sdk) set_prop('Info', 'SDK', sdk) if int(sdk) > const.API_MAX: log.w( TAG, "API %s isn't supported by dtf (yet), results may vary!" % sdk) self.adb.shell_command('set') set_output = self.adb.get_output() # $PATH path = get_set_value(set_output, 'PATH') if path is None: log.e(TAG, "Unable to get $PATH variable!") self.do_shutdown(None, None) log.d(TAG, "PATH : %s" % path) set_prop('Info', 'path', path) # $BOOTCLASSPTH bootclasspath = get_set_value(set_output, 'BOOTCLASSPATH') if bootclasspath is None: log.e(TAG, "Unable to get $BOOTCLASSPATH variable!") self.do_shutdown(None, None) log.d(TAG, "BOOTCLASSPATH : %s" % bootclasspath) set_prop('Info', 'bootclasspath-jars', bootclasspath) # Version string version_string = self.generate_version_string() log.d(TAG, "Using version string: %s" % version_string) set_prop('Info', 'version-string', version_string) # Determine architecture and CPU bitness arch, cpu_bits = self.determine_cpu_arch() if cpu_bits is None: self.do_shutdown(None, None) log.d(TAG, "CPU Architecture: %s" % arch) set_prop("Info", "cpu-arch", arch) log.d(TAG, "Using %s-bit CPU" % cpu_bits) set_prop('Info', 'cpu-bits', cpu_bits) # Set the VM type (Dalvik|Art) vm_type = self.determine_vm_type(sdk, cpu_bits) if vm_type is None: self.do_shutdown(None, None) log.d(TAG, "Determined runtime: %s" % vm_type) set_prop('Info', 'vmtype', vm_type) # Determine SEAndroid se_state = self.determine_seandroid_state() log.d(TAG, "Determine SEAndroid state: %s" % se_state) set_prop('Info', 'seandroid-state', se_state) # Setup the directory structure self.make_project_directories() # Set directory related properties set_prop('Local', 'reports-dir', utils.REPORTS_DIRECTORY) set_prop('Local', 'db-dir', utils.DBS_DIRECTORY) # Invoke client installation rtn = pkg.launch_builtin_module('client', ['install']) if rtn != 0: log.w(TAG, "Unable to install dtf client. Try manually.") return 0
def initialize_device(self, device_serial): """Perform the actual initialization""" log.d(TAG, "Preparing device: %s" % device_serial) touch(utils.CONFIG_FILE_NAME) set_prop('Info', 'serial', device_serial) # Since we have a serial now, lets create a new DtfAdb instance self.adb = DtfAdb.DtfAdb() # Kernel self.adb.shell_command('cat /proc/version') kernel = self.adb.get_output()[0] log.d(TAG, "Kernel version: %s" % kernel) set_prop('Info', 'kernel', kernel) # SDK sdk = self.getprop('ro.build.version.sdk') log.d(TAG, "Using SDK API %s" % sdk) set_prop('Info', 'SDK', sdk) self.adb.shell_command('set') set_output = self.adb.get_output() # $PATH path = get_set_value(set_output, 'PATH') if path is None: log.e(TAG, "Unable to get $PATH variable!") self.do_shutdown(None, None) log.d(TAG, "PATH : %s" % path) set_prop('Info', 'path', path) # $BOOTCLASSPTH bootclasspath = get_set_value(set_output, 'BOOTCLASSPATH') if bootclasspath is None: log.e(TAG, "Unable to get $BOOTCLASSPATH variable!") self.do_shutdown(None, None) log.d(TAG, "BOOTCLASSPATH : %s" % bootclasspath) set_prop('Info', 'bootclasspath-jars', bootclasspath) # Version string version_string = self.generate_version_string() log.d(TAG, "Using version string: %s" % version_string) set_prop('Info', 'version-string', version_string) # Determine CPU bitness cpu_bits = self.determine_cpu_bits() if cpu_bits is None: self.do_shutdown(None, None) log.d(TAG, "Using %s-bit CPU" % cpu_bits) set_prop('Info', 'cpu-bits', cpu_bits) # Set the VM type (Dalvik|Art) vm_type = self.determine_vm_type(sdk, cpu_bits) if vm_type is None: self.do_shutdown(None, None) log.d(TAG, "Determined runtime: %s" % vm_type) set_prop('Info', 'vmtype', vm_type) # Make project directories mkdir(REPORTS_DIRECTORY) mkdir(DBS_DIRECTORY) mkdir(LOCAL_MODULES_DIRECTORY) set_prop('Local', 'reports-dir', REPORTS_DIRECTORY) set_prop('Local', 'db-dir', DBS_DIRECTORY) # Invoke client installation rtn = pkg.launch_builtin_module('client', ['install']) if rtn != 0: log.w(TAG, "Unable to install dtf client. Try manually.") return 0
def do_upgrade(self, args): """Do content upgrade""" parser = ArgumentParser(prog='pm upgrade', description='Upgrade managed content.') parser.add_argument('-v', '--dont-verify-ssl', dest='verify', action='store_const', const=False, default=True, help="Allow SSL certificate issues.") parser.add_argument('-a', '--allow-http', dest='allow_http', action='store_const', const=True, default=False, help="Allow HTTP downloads.") parser.add_argument('-f', '--force', dest='force', action='store_const', const=True, default=False, help="Force install of component(s).") parser.add_argument('-p', '--prompt-all', dest='new_only', action='store_const', const=False, default=True, help="Prompt install regardless of version.") parsed_args = parser.parse_args(args) verify = parsed_args.verify allow_http = parsed_args.allow_http force = parsed_args.force new_only = parsed_args.new_only for repo_name, url in packagemanager.get_repos(): log.i(TAG, "Requesting content from '%s' (%s).." % (repo_name, url)) if utils.is_http_url(url) and not allow_http: log.w( TAG, "Skipping '%s' due to HTTP (use --allow-http)" % repo_name) continue file_f = self.download_temp_file(url, verify=verify) if file_f is None: continue if not zipfile.is_zipfile(file_f.name): log.w(TAG, "Pulled content is not a valid ZIP file, skipping!") continue log.i(TAG, "Starting install...") packagemanager.install_zip(file_f.name, force=force, new_only=new_only) file_f.close() log.i(TAG, "Upgrade complete.") return 0