Best Python code snippet using autotest_python
packager.py
Source:packager.py  
...170                shutil.rmtree(temp_dir)171        elif action == ACTION_REMOVE:172            pkgmgr.remove_pkg(pkg_name, remove_checksum=True)173        print "Done."174def tar_packages(pkgmgr, pkg_type, pkg_names, src_dir, temp_dir):175    """Tar all packages up and return a list of each tar created"""176    tarballs = []177    exclude_string = ' .'178    names = [p.strip() for p in pkg_names.split(',')]179    for name in names:180        print "tar_packages: Processing %s ... " % name181        if pkg_type == 'client':182            pkg_dir = src_dir183            exclude_string = get_exclude_string(pkg_dir)184        elif pkg_type == 'test':185            # if the package is a test then look whether it is in client/tests186            # or client/site_tests187            pkg_dir = os.path.join(get_test_dir(name, src_dir), name)188        else:189            # for the profilers and deps190            pkg_dir = os.path.join(src_dir, name)191        pkg_name = pkgmgr.get_tarball_name(name, pkg_type)192        # We don't want any pre-existing tarballs and checksums to193        # be repackaged, so we should purge these.194        exclude_string_tar = ((195            ' --exclude="**%s" --exclude="**%s.checksum" ' %196            (pkg_name, pkg_name)) + exclude_string)197        # Check if tarball already exists. If it does, don't duplicate198        # the effort.199        tarball_path = os.path.join(pkg_dir, pkg_name);200        if os.path.exists(tarball_path):201          print("tar_packages: Tarball %s already exists" % tarball_path);202        else:203            tarball_path = pkgmgr.tar_package(pkg_name, pkg_dir,204                                              temp_dir, exclude_string_tar)205        tarballs.append(tarball_path)206    return tarballs207def process_all_packages(pkgmgr, client_dir, action):208    """Process a full upload of packages as a directory upload."""209    dep_dir = os.path.join(client_dir, "deps")210    prof_dir = os.path.join(client_dir, "profilers")211    # Directory where all are kept212    temp_dir = tempfile.mkdtemp()213    try:214        packages.check_diskspace(temp_dir)215    except error.RepoDiskFullError, e:216        print ("Temp destination for packages is full %s, aborting upload: %s"217               % (temp_dir, e))218        os.rmdir(temp_dir)219        sys.exit(1)220    # process tests221    tests_list = get_subdir_list('tests', client_dir)222    tests = ','.join(tests_list)223    # process site_tests224    site_tests_list = get_subdir_list('site_tests', client_dir)225    site_tests = ','.join(site_tests_list)226    # process deps227    deps_list = get_subdir_list('deps', client_dir)228    deps = ','.join(deps_list)229    # process profilers230    profilers_list = get_subdir_list('profilers', client_dir)231    profilers = ','.join(profilers_list)232    # Update md5sum233    if action == ACTION_UPLOAD:234        all_packages = []235        all_packages.extend(tar_packages(pkgmgr, 'profiler', profilers,236                                         prof_dir, temp_dir))237        all_packages.extend(tar_packages(pkgmgr, 'dep', deps, dep_dir,238                                         temp_dir))239        all_packages.extend(tar_packages(pkgmgr, 'test', site_tests,240                                         client_dir, temp_dir))241        all_packages.extend(tar_packages(pkgmgr, 'test', tests, client_dir,242                                         temp_dir))243        all_packages.extend(tar_packages(pkgmgr, 'client', 'autotest',244                                         client_dir, temp_dir))245        for package in all_packages:246            pkgmgr.upload_pkg(package, update_checksum=True)247        client_utils.run('rm -rf ' + temp_dir)248    elif action == ACTION_REMOVE:249        process_packages(pkgmgr, 'test', tests, client_dir, action=action)250        process_packages(pkgmgr, 'test', site_tests, client_dir, action=action)251        process_packages(pkgmgr, 'client', 'autotest', client_dir,252                         action=action)253        process_packages(pkgmgr, 'dep', deps, dep_dir, action=action)254        process_packages(pkgmgr, 'profiler', profilers, prof_dir,255                         action=action)256# Get the list of sub directories present in a directory257def get_subdir_list(name, client_dir):...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!!
