Best Python code snippet using avocado_python
apt.py
Source:apt.py
...75 Add an apt repository.76 :param repo: Repository string. Example:77 'deb http://archive.ubuntu.com/ubuntu/ maverick universe'78 """79 def _add_repo_file():80 add_cmd = "bash -c \"echo '%s' > %s\"" % (repo, self.repo_file_path)81 process.system(add_cmd, shell=True, sudo=True)82 def _get_repo_file_contents():83 with open(self.repo_file_path, 'r', encoding='utf-8') as repo_file:84 return repo_file.read()85 if not os.path.isfile(self.repo_file_path):86 _add_repo_file()87 return True88 repo_file_contents = _get_repo_file_contents()89 if repo not in repo_file_contents:90 try:91 _add_repo_file()92 return True93 except process.CmdError:94 return False95 def remove_repo(self, repo):96 """97 Remove an apt repository.98 :param repo: Repository string. Example:99 'deb http://archive.ubuntu.com/ubuntu/ maverick universe'100 """101 try:102 new_file_contents = []103 with open(self.repo_file_path, 'r', encoding='utf-8') as repo_file:104 for line in repo_file.readlines():105 if line != repo:...
folder_index.py
Source:folder_index.py
...78 entry.description = ""79 entry.size = 080 entry.modified = datetime.datetime.fromtimestamp(stat.st_mtime)81 if entry_name == "repodata":82 self._add_repo_file()83 self._dirs.append(entry)84 def _add_file(self, entry_name):85 entry_path = f"{self._folder_path}/{entry_name}"86 stat = os.stat(entry_path)87 entry = FolderEntry()88 if entry_name.startswith("RPM-GPG-KEY-"):89 entry.name = self._make_key_name(entry_name)90 else:91 entry.name = entry_name92 if entry_name.endswith(".rpm") and self._repo_data:93 package_info = self._repo_data.package_info(entry_path)94 if package_info:95 entry.description = package_info.description.replace("\n", "<br>")96 entry.summary = package_info.summary97 entry.size = stat.st_size98 entry.modified = datetime.datetime.fromtimestamp(stat.st_mtime)99 self._files.append(entry)100 def _make_key_name(self, entry_name):101 app = flask.current_app102 return re.sub(103 r"^RPM-GPG-KEY-",104 f"RPM-GPG-KEY-{app.repo_name_encoded}-",105 entry_name106 )107 def repo_file_name(self):108 app = flask.current_app109 return f"{app.repo_name_encoded.lower()}.repo"110 def _add_repo_file(self):111 app = flask.current_app112 stat = os.stat(self._folder_path)113 entry = FolderEntry()114 entry.name = "repository.repo"115 entry.description = ""116 entry.size = len(self.repo_file_content())117 entry.modified = datetime.datetime.fromtimestamp(stat.st_mtime)118 self._files.append(entry)119 entry = FolderEntry()120 entry.name = self.repo_file_name()121 entry.description = ""122 entry.size = len(self.repo_file_content())123 entry.modified = datetime.datetime.fromtimestamp(stat.st_mtime)124 self._files.append(entry)...
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!!