Best Python code snippet using autotest_python
boottool.py
Source:boottool.py
...1166 try:1167 shutil.move(path, backup_path)1168 except Exception:1169 self.log.warn('Failed to backup the current grubby binary')1170 def grubby_install_fetch_tarball(self, topdir):1171 '''1172 Fetches and verifies the grubby source tarball1173 '''1174 tarball_name = os.path.basename(GRUBBY_TARBALL_URI)1175 # first look in the current directory1176 try:1177 tarball = tarball_name1178 f = open(tarball)1179 except Exception:1180 try:1181 # then the autotest source directory1182 # pylint: disable=E06111183 from autotest.client.shared.settings import settings1184 top_path = settings.get_value('COMMON', 'autotest_top_path')1185 tarball = os.path.join(top_path, tarball_name)1186 f = open(tarball)1187 except Exception:1188 # then try to grab it from github1189 try:1190 tarball = os.path.join(topdir, tarball_name)1191 urllib.urlretrieve(GRUBBY_TARBALL_URI, tarball)1192 f = open(tarball)1193 except Exception:1194 return None1195 tarball_md5 = md5.md5(f.read()).hexdigest()1196 if tarball_md5 != GRUBBY_TARBALL_MD5:1197 return None1198 return tarball1199 def grubby_build(self, topdir, tarball):1200 '''1201 Attempts to build grubby from the source tarball1202 '''1203 def log_lines(lines):1204 for line in lines:1205 self.log.debug(line.strip())1206 try:1207 find_header('popt.h')1208 except ValueError:1209 self.log.debug('No popt.h header present, skipping build')1210 return False1211 tarball_name = os.path.basename(tarball)1212 srcdir = os.path.join(topdir, 'src')1213 srcdir = self._extract_tarball(tarball, srcdir)1214 os.chdir(srcdir)1215 self.grubby_install_patch_makefile()1216 result = subprocess.Popen(['make'],1217 stdout=subprocess.PIPE,1218 stderr=subprocess.PIPE)1219 if result.wait() != 0:1220 self.log.debug('Failed to build grubby during "make" step')1221 log_lines(result.stderr.read().splitlines())1222 return False1223 install_root = os.path.join(topdir, 'install_root')1224 os.environ['DESTDIR'] = install_root1225 result = subprocess.Popen(['make', 'install'],1226 stdout=subprocess.PIPE,1227 stderr=subprocess.PIPE)1228 if result.wait() != 0:1229 self.log.debug('Failed to build grubby during "make install" step')1230 log_lines(result.stderr.read().splitlines())1231 return False1232 return True1233 def grubby_install(self, path=None):1234 '''1235 Attempts to install a recent enough version of grubby1236 So far tested on:1237 * Fedora 16 x86_641238 * Debian 6 x86_641239 * SuSE 12.1 x86_641240 * RHEL 4 on ia64 (with updated python 2.4)1241 * RHEL 5 on ia641242 * RHEL 6 on ppc641243 '''1244 if path is None:1245 if os.geteuid() == 0:1246 path = GRUBBY_DEFAULT_SYSTEM_PATH1247 else:1248 path = GRUBBY_DEFAULT_USER_PATH1249 topdir = tempfile.mkdtemp()1250 deps_klass = DISTRO_DEPS_MAPPING.get(detect_distro_type(), None)1251 if deps_klass is not None:1252 deps = deps_klass()1253 if not deps.check():1254 self.log.warn('Installing distro build deps for grubby. This '1255 'may take a while, depending on bandwidth and '1256 'actual number of packages to install')1257 if not deps.install():1258 self.log.error('Failed to install distro build deps for '1259 'grubby')1260 tarball = self.grubby_install_fetch_tarball(topdir)1261 if tarball is None:1262 raise GrubbyInstallException('Failed to fetch grubby tarball')1263 srcdir = os.path.join(topdir, 'src')1264 install_root = os.path.join(topdir, 'install_root')1265 os.mkdir(install_root)1266 if not self.grubby_build(topdir, tarball):1267 raise GrubbyInstallException('Failed to build grubby')1268 self.grubby_install_backup(path)1269 grubby_bin = os.path.join(install_root, 'sbin', 'grubby')1270 inst_dir = os.path.dirname(path)1271 if not os.access(inst_dir, os.W_OK):1272 raise GrubbyInstallException('No permission to copy grubby '1273 'binary to directory "%s"' % inst_dir)1274 try:...
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!!