Best Python code snippet using autotest_python
packager.py
Source:packager.py
...126 include_string=include_string,127 exclude_string=exclude_string)128 tarballs.append(tarball_path)129 return tarballs130def process_all_packages(pkgmgr, client_dir, remove=False):131 """Process a full upload of packages as a directory upload."""132 dep_dir = os.path.join(client_dir, "deps")133 prof_dir = os.path.join(client_dir, "profilers")134 # Directory where all are kept135 temp_dir = tempfile.mkdtemp()136 try:137 base_packages.check_diskspace(temp_dir)138 except error.RepoDiskFullError, e:139 print ("Temp destination for packages is full %s, aborting upload: %s"140 % (temp_dir, e))141 os.rmdir(temp_dir)142 sys.exit(1)143 # process tests144 tests_list = get_subdir_list('tests', client_dir)145 tests = ','.join(tests_list)146 # process site_tests147 site_tests_list = get_subdir_list('site_tests', client_dir)148 site_tests = ','.join(site_tests_list)149 # process deps150 deps_list = get_subdir_list('deps', client_dir)151 deps = ','.join(deps_list)152 # process profilers153 profilers_list = get_subdir_list('profilers', client_dir)154 profilers = ','.join(profilers_list)155 # Update md5sum156 if not remove:157 tar_packages(pkgmgr, 'profiler', profilers, prof_dir, temp_dir)158 tar_packages(pkgmgr, 'dep', deps, dep_dir, temp_dir)159 tar_packages(pkgmgr, 'test', site_tests, client_dir, temp_dir)160 tar_packages(pkgmgr, 'test', tests, client_dir, temp_dir)161 tar_packages(pkgmgr, 'client', 'autotest', client_dir, temp_dir)162 cwd = os.getcwd()163 os.chdir(temp_dir)164 client_utils.system('md5sum * > packages.checksum')165 os.chdir(cwd)166 pkgmgr.upload_pkg(temp_dir)167 client_utils.run('rm -rf ' + temp_dir)168 else:169 process_packages(pkgmgr, 'test', tests, client_dir, remove=remove)170 process_packages(pkgmgr, 'test', site_tests, client_dir, remove=remove)171 process_packages(pkgmgr, 'client', 'autotest', client_dir,172 remove=remove)173 process_packages(pkgmgr, 'dep', deps, dep_dir, remove=remove)174 process_packages(pkgmgr, 'profiler', profilers, prof_dir,175 remove=remove)176# Get the list of sub directories present in a directory177def get_subdir_list(name, client_dir):178 dir_name = os.path.join(client_dir, name)179 return [f for f in180 os.listdir(dir_name)181 if os.path.isdir(os.path.join(dir_name, f))]182# Look whether the test is present in client/tests and client/site_tests dirs183def get_test_dir(name, client_dir):184 names_test = os.listdir(os.path.join(client_dir, 'tests'))185 names_site_test = os.listdir(os.path.join(client_dir, 'site_tests'))186 if name in names_test:187 src_dir = os.path.join(client_dir, 'tests')188 elif name in names_site_test:189 src_dir = os.path.join(client_dir, 'site_tests')190 else:191 print "Test %s not found" % name192 sys.exit(0)193 return src_dir194def main():195 # get options and args196 options, args = parse_args()197 server_dir = server_utils.get_server_dir()198 autotest_dir = os.path.abspath(os.path.join(server_dir, '..'))199 # extract the pkg locations from global config200 repo_urls = settings.get_value('PACKAGES', 'fetch_location',201 type=list, default=[])202 upload_paths = settings.get_value('PACKAGES', 'upload_location',203 type=list, default=[])204 if options.repo:205 upload_paths.append(options.repo)206 # Having no upload paths basically means you're not using packaging.207 if not upload_paths:208 print("No upload locations found. Please set upload_location under"209 " PACKAGES in the global_config.ini or provide a location using"210 " the --repository option.")211 return212 client_dir = os.path.join(autotest_dir, "client")213 # Bail out if the client directory does not exist214 if not os.path.exists(client_dir):215 sys.exit(0)216 dep_dir = os.path.join(client_dir, "deps")217 prof_dir = os.path.join(client_dir, "profilers")218 if len(args) == 0 or args[0] not in ['upload', 'remove']:219 print("Either 'upload' or 'remove' needs to be specified "220 "for the package")221 sys.exit(0)222 if args[0] == 'upload':223 remove_flag = False224 elif args[0] == 'remove':225 remove_flag = True226 else:227 # we should not be getting here228 assert(False)229 pkgmgr = packages.PackageManager(autotest_dir, repo_urls=repo_urls,230 upload_paths=upload_paths,231 run_function_dargs={'timeout': 600})232 if options.all:233 process_all_packages(pkgmgr, client_dir, remove=remove_flag)234 if options.client:235 process_packages(pkgmgr, 'client', 'autotest', client_dir,236 remove=remove_flag)237 if options.dep:238 process_packages(pkgmgr, 'dep', options.dep, dep_dir,239 remove=remove_flag)240 if options.test:241 process_packages(pkgmgr, 'test', options.test, client_dir,242 remove=remove_flag)243 if options.prof:244 process_packages(pkgmgr, 'profiler', options.prof, prof_dir,245 remove=remove_flag)246 if options.file:247 if remove_flag:...
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!!