Best Python code snippet using avocado_python
distro.py
Source:distro.py  
...98        '''99        if self.check_name_for_file():100            if os.path.exists(self.CHECK_FILE):101                return self.CHECK_FILE_DISTRO_NAME102    def check_name_for_file_contains(self):103        '''104        Checks if this class will look for text on a file and return a distro105        The conditions that must be true include the file that identifies the106        distro file being set (:attr:`CHECK_FILE`), the text to look for107        inside the distro file (:attr:`CHECK_FILE_CONTAINS`) and the name108        of the distro to be returned (:attr:`CHECK_FILE_DISTRO_NAME`)109        '''110        if self.CHECK_FILE is None:111            return False112        if self.CHECK_FILE_CONTAINS is None:113            return False114        if self.CHECK_FILE_DISTRO_NAME is None:115            return False116        return True117    def name_for_file_contains(self):118        '''119        Get the distro if the :attr:`CHECK_FILE` is set and has content120        '''121        if self.check_name_for_file_contains():122            if os.path.exists(self.CHECK_FILE):123                for line in open(self.CHECK_FILE).readlines():124                    if self.CHECK_FILE_CONTAINS in line:125                        return self.CHECK_FILE_DISTRO_NAME126    def check_version(self):127        '''128        Checks if this class will look for a regex in file and return a distro129        '''130        if self.CHECK_FILE is None:131            return False132        if self.CHECK_VERSION_REGEX is None:133            return False134        return True135    def _get_version_match(self):136        '''137        Returns the match result for the version regex on the file content138        '''139        if self.check_version():140            if os.path.exists(self.CHECK_FILE):141                version_file_content = open(self.CHECK_FILE).read()142            else:143                return None144            return self.CHECK_VERSION_REGEX.match(version_file_content)145    def version(self):146        '''147        Returns the version of the distro148        '''149        version = UNKNOWN_DISTRO_VERSION150        match = self._get_version_match()151        if match is not None:152            if match.groups() > 0:153                version = match.groups()[0]154        return version155    def check_release(self):156        '''157        Checks if this has the conditions met to look for the release number158        '''159        return (self.check_version() and160                self.CHECK_VERSION_REGEX.groups > 1)161    def release(self):162        '''163        Returns the release of the distro164        '''165        release = UNKNOWN_DISTRO_RELEASE166        match = self._get_version_match()167        if match is not None:168            if match.groups() > 1:169                release = match.groups()[1]170        return release171    def get_distro(self):172        '''173        Returns the :class:`LinuxDistro` this probe detected174        '''175        name = None176        version = UNKNOWN_DISTRO_VERSION177        release = UNKNOWN_DISTRO_RELEASE178        arch = UNKNOWN_DISTRO_ARCH179        distro = None180        if self.check_name_for_file():181            name = self.name_for_file()182            self.score += 1183        if self.check_name_for_file_contains():184            name = self.name_for_file_contains()185            self.score += 1186        if self.check_version():187            version = self.version()188            self.score += 1189        if self.check_release():190            release = self.release()191            self.score += 1192        # can't think of a better way to do this193        arch = os.uname()[4]194        # name is the first thing that should be identified. If we don't know195        # the distro name, we don't bother checking for versions196        if name is not None:197            distro = LinuxDistro(name, version, release, arch)198        else:...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!!
