How to use extract_tarball method in autotest

Best Python code snippet using autotest_python Github


Full Screen

...10import tarfile11import zipfile12__all__ = ['extract_tarball', 'extract_zip', 'extract', 'rmtree']13### utilities for extracting archives14def extract_tarball(src, dest):15 """extract a .tar file"""16 bundle = namelist = bundle.getnames()18 for name in namelist:19 bundle.extract(name, path=dest)20 bundle.close()21 return namelist22def extract_zip(src, dest):23 """extract a zip file"""24 bundle = zipfile.ZipFile(src)25 namelist = bundle.namelist()26 for name in namelist:27 filename = os.path.realpath(os.path.join(dest, name))28 if name.endswith('/'):29 os.makedirs(filename)30 else:31 path = os.path.dirname(filename)32 if not os.path.isdir(path):33 os.makedirs(path)34 _dest = open(filename, 'wb')35 _dest.write( _dest.close()37 bundle.close()38 return namelist39def extract(src, dest=None):40 """41 Takes in a tar or zip file and extracts it to dest42 If dest is not specified, extracts to os.path.dirname(src)43 Returns the list of top level files that were extracted44 """45 assert os.path.exists(src), "'%s' does not exist" % src46 assert not os.path.isfile(dest), "dest cannot be a file"47 if dest is None:48 dest = os.path.dirname(src)49 elif not os.path.isdir(dest):50 os.makedirs(dest)51 if zipfile.is_zipfile(src):52 namelist = extract_zip(src, dest)53 elif tarfile.is_tarfile(src):54 namelist = extract_tarball(src, dest)55 else:56 raise Exception("mozfile.extract: no archive format found for '%s'" %57 src)58 # namelist returns paths with forward slashes even in windows59 top_level_files = [os.path.join(dest, name) for name in namelist60 if len(name.rstrip('/').split('/')) == 1]61 # namelist doesn't include folders, append these to the list62 for name in namelist:63 root = os.path.join(dest, name[:name.find('/')])64 if root not in top_level_files:65 top_level_files.append(root)66 return top_level_files67def rmtree(dir):68 """This is a replacement for shutil.rmtree that works better under...

Full Screen

Full Screen Github


Full Screen

...12 sys.stdout.write('Downloading %s... ' % url)13 sys.stdout.flush()14 urlretrieve(url, filename)15 sys.stdout.write('DONE\n')16def extract_tarball(tarball_filename):17 tarball =, 'r:gz')18 sys.stdout.write('Extracting %s... ' % tarball_filename)19 sys.stdout.flush()20 tarball.extractall('.')21 sys.stdout.write('DONE\n')22def sha256_file(filename):23 return hashlib.sha256(open(filename, 'rb').read()).hexdigest()24def download_and_extract_tarball(tarball_url,25 tarball_filename=None,26 expected_sha256=None):27 if tarball_filename is None:28 tarball_filename = os.path.basename(urlparse(tarball_url).path)29 if not os.path.exists(tarball_filename):30 download_file(tarball_url, tarball_filename)31 if expected_sha256 is not None:32 sys.stdout.write('Checking that SHA256 of %s is %s... ' %33 (tarball_filename, expected_sha256))34 actual_sha256 = sha256_file(tarball_filename)35 sys.stdout.write('SHA256 is %s. ' % actual_sha256)36 if actual_sha256 == expected_sha256:37 sys.stdout.write('OK\n')38 else:39 sys.stdout.write('Incorrect SHA256!\n')40 sys.exit(1)...

Full Screen

Full Screen

Automation Testing Tutorials

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.

LambdaTest Learning Hubs:


You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run autotest automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?