Best Python code snippet using localstack_python
install.py
Source:install.py  
...362        if True, program is considered installed363        if False or None, program is not considered installed364        else, version information should be supplied as a string or tuple365      prompt_install(): same as start_install()366        calls get_install_version() by default367      announce_install(): opportunity to print any final message before install368      install(*args, **kwargs): called with arguments passed to run()369        if error occurs, cleanup(False) is called and False is returned370        else, cleanup(True) is called and True is returned371    """372    min_version = None373    install_prompt = "May I download and install %s?"374    url = None375    def start_install(self):376        return True377    def prompt_install_path(self, default):378        query = "Where should %s be installed?" % self.name379        path = prompt_user(query, default)380        return fix_path(path)381    def prompt_install(self):382        assert "%s" in self.install_prompt383        version = self.get_install_version()384        if version:385            info = "%s %s" % (self.name, version)386        else:387            info = self.name388        query = self.install_prompt % info389        return prompt_yes_no(query, default="Y")390    def parse_url(self):391        """Returns a dict of URL components"""392        components = {}393        if not self.url:394            return components395        dir, filename = os.path.split(self.url)396        # Remove extensions397        filebase = filename398        if filebase.endswith(".gz"):399            filebase = filebase[:-3]400        if filebase.endswith(".tar"):401            filebase = filebase[:-4]402        if filebase.endswith(".tgz"):403            filebase = filebase[:-4]404        filebase_tokens = filebase.split("-", 1)405        # Try to extract version from filename406        # Let version contain '-'s, but not progname407        #(Assumes form: <progname>-<version>.<ext>)408        if "-" in filebase:409            components["version"] = "-".join(filebase_tokens[1:])410            components["program"] = filebase_tokens[0]411        else:412            components["program"] = filebase413        components["dirname"] = dir414        components["file"] = filename415        components["filebase"] = filebase416        return components417    def get_install_version(self):418        """Returns the version being installed"""419        if self.url is None:420            return self.min_version421        else:422            url_info = self.parse_url()423            return url_info.get("version", None)424    def check_version(self):425        """Checks version and returns True if version is adequate"""426        print >>sys.stderr, ("\nSearching for an installation of %s..."427                             % self.name),428        version = self.get_version()429        if not version:430            print >>sys.stderr, "not found."431            return False432        else:433            print >>sys.stderr, "found."434            if version is True or self.min_version is None:435                # "True" testing necessary to distinguish from tuple or string436                return True437            elif str2version(self.min_version) > str2version(version):438                print >>sys.stderr, ("Found version: %s. Version %s or above"439                                     " required.") % (version,440                                                      self.min_version)441            else:442                return True443    def announce_install(self):444        print >>sys.stderr, "\n===== Installing %s =====" % self.name445    def cleanup(self, success):446        if success:447            print >>sys.stderr, "%s successfully installed." % self.name448        else:449            print >>sys.stderr, "%s not installed." % self.name450            query = ("\nWould you like to try to continue the installation"451                     " without this program?")452            permission = prompt_yes_no(query, default="n")453            if not permission:454                die("\n============== Installation aborted =================")455    def run(self, *args, **kwargs):456        """Program installation wrapper method.457        Checks if program is installed in a succificent version,458        if not, prompts user and installs program.459        Returns result of installation if installation attempted,460        else returns False461        """462        permission = self.start_install()463        if not permission:464            return False465        if self.check_version():466            return True467        permission = self.prompt_install()468        if not permission:469            return False470        self.announce_install()471        success = True472        try:473            self.install(*args, **kwargs)474        except Exception, e:475            success = False476            if str(e):  # print any error message477                print >>sys.stderr, "===== ERROR: %s =====" % e478        self.cleanup(success)479        return success480class EasyInstaller(Installer):481    """An installer that uses easy_install482    New attributes:483      version_requirment: None or a string that specifies version requirement484        for easy_install. These requirements will be appended to the default485        requirement of '>=min_version'. Thus, '!=1.2' would be a reasonable486        value.487      pkg_name: Name of package to easy_install. Defaults to self.name.lower().488      links: List of URLs to also search for package source. Uses489        easy_install's '-f' option.490    """491    install_prompt = "May I install %s (or later) and dependencies?"492    version_requirement = None493    pkg_name = None  # Replaced by self.name.lower() in __init__494    links = []495    def __init__(self):496        if self.pkg_name is None:497            self.pkg_name = self.name.lower()498    def install(self):499        """Easy-installs the program500        uses:501          self.name502          self.pkg_name503          self.get_install_version()504          self.version_requirement505          self.links506        if self.url is set, easy_install is run on that url instead of the507          program name and version requirement508        """509        # Make sure easy_install (setuptools) is installed510        try:511            import setuptools512        except ImportError:513            raise InstallationError("Setuptools necessary for easy_install")514        version = self.get_install_version()515        cmd = ["easy_install"]516        if self.links:517            for link in self.links:518                cmd.append("--find-links=%s" % link)519        if self.url is None:520            requirements = []521            if version:522                requirements.append(">=%s" % version)523            if self.version_requirement:524                requirements.append(self.version_requirement)525            cmd.append("%s%s" % (self.pkg_name, ",".join(requirements)))526        else:527            cmd.append(self.url)528        if os.path.isdir(self.pkg_name):...get.py
Source:get.py  
1# Python2import logging3log = logging.getLogger(__name__)4def get_install_version(device, install_type='IMG', install_state=None):5    """6    returns version of img/smu7    Args:8        device ('obj'): Device object9        install_type ('str, optional'): install type10        install_state ('str, optional'): install state11    Returns:12        Install version if match criteria is satisfied13        False if Install version if match criteria is not satisfied14    Raises:15        SubCommandFailure16    """17    output = device.parse("show install summary")18    location = list(output.get('location').keys())[0]...test_api_get_install_version.py
Source:test_api_get_install_version.py  
...23            learn_hostname=True,24            init_config_commands=[],25            init_exec_commands=[]26        )27    def test_get_install_version(self):28        result = get_install_version(device=self.device, install_type='IMG', install_state='C')29        expected_output = '17.10.01.0.161496'...Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!
