How to use get_exclude_string method in autotest

Best Python code snippet using autotest_python

packager.py

Source:packager.py Github

copy

Full Screen

...9from autotest_lib.client.common_lib import base_packages, packages10from autotest_lib.server import utils as server_utils11c = global_config.global_config12logging.basicConfig(level=logging.DEBUG)13def get_exclude_string(client_dir):14 '''15 Get the exclude string for the tar command to exclude specific16 subdirectories inside client_dir.17 For profilers we need to exclude everything except the __init__.py18 file so that the profilers can be imported.19 '''20 exclude_string = ('--exclude=deps/* --exclude=tests/* '21 '--exclude=site_tests/* --exclude=**.pyc')22 # Get the profilers directory23 prof_dir = os.path.join(client_dir, 'profilers')24 # Include the __init__.py file for the profilers and exclude all its25 # subdirectories26 for f in os.listdir(prof_dir):27 if os.path.isdir(os.path.join(prof_dir, f)):28 exclude_string += ' --exclude=profilers/%s' % f29 # The '.' here is needed to zip the files in the current30 # directory. We use '-C' for tar to change to the required31 # directory i.e. src_dir and then zip up the files in that32 # directory(which is '.') excluding the ones in the exclude_dirs33 exclude_string += " ."34 # TODO(milleral): This is sad and ugly. http://crbug.com/25816135 # Surprisingly, |exclude_string| actually means argument list, and36 # we'd like to package up the current global_config.ini also, so let's37 # just tack it on here.38 # Also note that this only works because tar prevents us from un-tarring39 # files into parent directories.40 exclude_string += " ../global_config.ini"41 return exclude_string42def parse_args():43 parser = optparse.OptionParser()44 parser.add_option("-d", "--dependency", help="package the dependency"45 " from client/deps directory and upload to the repo",46 dest="dep")47 parser.add_option("-p", "--profiler", help="package the profiler "48 "from client/profilers directory and upload to the repo",49 dest="prof")50 parser.add_option("-t", "--test", help="package the test from client/tests"51 " or client/site_tests and upload to the repo.",52 dest="test")53 parser.add_option("-c", "--client", help="package the client "54 "directory alone without the tests, deps and profilers",55 dest="client", action="store_true", default=False)56 parser.add_option("-f", "--file", help="simply uploads the specified"57 "file on to the repo", dest="file")58 parser.add_option("-r", "--repository", help="the URL of the packages"59 "repository location to upload the packages to.",60 dest="repo", default=None)61 parser.add_option("--all", help="Upload all the files locally "62 "to all the repos specified in global_config.ini. "63 "(includes the client, tests, deps and profilers)",64 dest="all", action="store_true", default=False)65 options, args = parser.parse_args()66 return options, args67# Method to upload or remove package depending on the flag passed to it.68def process_packages(pkgmgr, pkg_type, pkg_names, src_dir,69 remove=False):70 exclude_string = ' .'71 names = [p.strip() for p in pkg_names.split(',')]72 for name in names:73 print "Processing %s ... " % name74 if pkg_type == 'client':75 pkg_dir = src_dir76 exclude_string = get_exclude_string(pkg_dir)77 elif pkg_type == 'test':78 # if the package is a test then look whether it is in client/tests79 # or client/site_tests80 pkg_dir = os.path.join(get_test_dir(name, src_dir), name)81 else:82 # for the profilers and deps83 pkg_dir = os.path.join(src_dir, name)84 pkg_name = pkgmgr.get_tarball_name(name, pkg_type)85 if not remove:86 # Tar the source and upload87 temp_dir = tempfile.mkdtemp()88 try:89 try:90 base_packages.check_diskspace(temp_dir)91 except error.RepoDiskFullError, e:92 msg = ("Temporary directory for packages %s does not have "93 "enough space available: %s" % (temp_dir, e))94 raise error.RepoDiskFullError(msg)95 tarball_path = pkgmgr.tar_package(pkg_name, pkg_dir,96 temp_dir, exclude_string)97 pkgmgr.upload_pkg(tarball_path, update_checksum=True)98 finally:99 # remove the temporary directory100 shutil.rmtree(temp_dir)101 else:102 pkgmgr.remove_pkg(pkg_name, remove_checksum=True)103 print "Done."104def tar_packages(pkgmgr, pkg_type, pkg_names, src_dir, temp_dir):105 """Tar all packages up and return a list of each tar created"""106 tarballs = []107 exclude_string = ' .'108 names = [p.strip() for p in pkg_names.split(',')]109 for name in names:110 print "Processing %s ... " % name111 if pkg_type == 'client':112 pkg_dir = src_dir113 exclude_string = get_exclude_string(pkg_dir)114 elif pkg_type == 'test':115 # if the package is a test then look whether it is in client/tests116 # or client/site_tests117 pkg_dir = os.path.join(get_test_dir(name, src_dir), name)118 else:119 # for the profilers and deps120 pkg_dir = os.path.join(src_dir, name)121 pkg_name = pkgmgr.get_tarball_name(name, pkg_type)122 tarball_path = pkgmgr.tar_package(pkg_name, pkg_dir,123 temp_dir, exclude_string)124 tarballs.append(tarball_path)125 return tarballs126def process_all_packages(pkgmgr, client_dir, remove=False):127 """Process a full upload of packages as a directory upload."""...

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:

YouTube

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?

Helpful

NotHelpful