How to use enumerate_projects method in autotest

Best Python code snippet using autotest_python

compile_gwt_clients.py

Source:compile_gwt_clients.py Github

copy

Full Screen

...20 def configure_logging(self, results_dir=None, verbose=False):21 super(CompileClientsLoggingConfig, self).configure_logging(22 use_console=True,23 verbose=verbose)24def enumerate_projects():25 """List projects in _DEFAULT_APP_DIR."""26 src_path = os.path.join(_DEFAULT_APP_DIR, 'src')27 projects = {}28 for project in os.listdir(src_path):29 projects[project] = []30 project_path = os.path.join(src_path, project)31 for file in os.listdir(project_path):32 if file.endswith('.gwt.xml'):33 projects[project].append(file[:-8])34 return projects35def find_gwt_dir():36 """See if GWT is installed in site-packages or in the system,37 site-packages is favored over a system install or a /usr/local install.38 """39 site_gwt = os.path.join(_AUTOTEST_DIR, 'site-packages', 'gwt')40 gwt_dirs = [site_gwt] + _DEFAULT_GWT_DIRS41 for gwt_dir in gwt_dirs:42 if os.path.isdir(gwt_dir):43 return gwt_dir44 logging.error('Unable to find GWT. '45 'You can use utils/build_externals.py to install it.')46 sys.exit(1)47def install_completed_client(compiled_dir, project_client):48 """Remove old client directory if it exists, move installed client to the49 old directory and move newly compield client to the installed client50 dir.51 @param compiled_dir: Where the new client was compiled52 @param project_client: project.client pair e.g. autotest.AfeClient53 @returns True if installation was successful or False if it failed54 """55 tmp_client_dir = os.path.join(_TMP_COMPILE_DIR, project_client)56 install_dir = os.path.join(_DEFAULT_INSTALL_DIR, project_client)57 old_install_dir = os.path.join(_DEFAULT_INSTALL_DIR,58 project_client + '.old')59 if not os.path.exists(_DEFAULT_INSTALL_DIR):60 os.mkdir(_DEFAULT_INSTALL_DIR)61 if os.path.isdir(tmp_client_dir):62 if os.path.isdir(old_install_dir):63 shutil.rmtree(old_install_dir)64 if os.path.isdir(install_dir):65 os.rename(install_dir, old_install_dir)66 try:67 os.rename(tmp_client_dir, install_dir)68 return True69 except Exception, err:70 # If we can't rename the client raise an exception71 # and put the old client back72 shutil.rmtree(install_dir)73 shutil.copytree(old_install_dir, install_dir)74 logging.error('Copying old client: %s', err)75 else:76 logging.error('Compiled directory is gone, something went wrong')77 return False78def compile_and_install_client(project_client, extra_args='',79 install_client=True):80 """Compile the client into a temporary directory, if successful81 call install_completed_client to install the new client.82 @param project_client: project.client pair e.g. autotest.AfeClient83 @param install_client: Boolean, if True install the clients84 @return True if install and compile was successful False if it failed85 """86 java_args = {}87 java_args['compile_dir'] = _TMP_COMPILE_DIR88 java_args['app_dir'] = _DEFAULT_APP_DIR89 java_args['gwt_dir'] = find_gwt_dir()90 java_args['extra_args'] = extra_args91 java_args['project_client'] = project_client92 cmd = _COMPILE_LINE % java_args93 logging.info('Compiling client %s', project_client)94 try:95 utils.run(cmd, verbose=True)96 if install_client:97 return install_completed_client(java_args['compile_dir'],98 project_client)99 return True100 except error.CmdError:101 logging.error('Error compiling %s, leaving old client', project_client)102 return False103def compile_all_projects(extra_args=''):104 """Compile all projects available as defined by enumerate_projects.105 @returns list of failed client installations106 """107 failed_clients = []108 for project,clients in enumerate_projects().iteritems():109 for client in clients:110 project_client = '%s.%s' % (project, client)111 if not compile_and_install_client(project_client, extra_args):112 failed_clients.append(project_client)113 return failed_clients114def print_projects():115 logging.info('Projects that can be compiled:')116 for project,clients in enumerate_projects().iteritems():117 for client in clients:118 logging.info('%s.%s', project, client)119def main():120 logging_manager.configure_logging(CompileClientsLoggingConfig(),121 verbose=True)122 parser = optparse.OptionParser()123 parser.add_option('-l', '--list-projects',124 action='store_true', dest='list_projects',125 default=False,126 help='List all projects and clients that can be compiled')127 parser.add_option('-a', '--compile-all',128 action='store_true', dest='compile_all',129 default=False,130 help='Compile all available projects and clients')...

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