def cli(ctx, service): """Generates configuration files for distinct CI services. This command needs to be executed on the root of your Git repository folder. """ if service not in ci_files: log.fail("Unrecognized service " + service) project_root = scm.get_git_root_folder() if project_root != os.getcwd(): log.fail('This command needs to be executed on the root of your ' 'Git project folder (where the .git/ folder is located).') for ci_file, ci_file_content in pu.get_items(ci_files[service]): ci_file_content = ci_file_content ci_file = os.path.join(project_root, ci_file) # create parent folder if not os.path.isdir(os.path.dirname(ci_file)): os.makedirs(os.path.dirname(ci_file)) # write content with open(ci_file, 'w') as f: f.write(ci_file_content) log.info('Wrote {} configuration successfully.'.format(service))
def cli(ctx, service, install): """Generates configuration files for distinct CI services. This command needs to be executed on the root of your Git repository folder. """ project_root = scm.get_git_root_folder() if project_root != os.getcwd(): log.fail( 'This command needs to be executed on the root of your ' 'Git project folder (where the .git/ folder is located).') for ci_file, ci_file_content in pu.get_items(ci_files[service]): # Prepare and write the CI config file. ci_file = os.path.join(project_root, ci_file) if not os.path.isdir(os.path.dirname(ci_file)): os.makedirs(os.path.dirname(ci_file)) install_script_cmd = '' if install: if service == 'jenkins' or service == 'gitlab': log.fail( 'Scaffolding of custom install scripts is not ' 'supported for Jenkins and Gitlab CI. Include it ' 'manually depending upon the CI\'s OS.') elif service == 'travis': install_script_cmd = ('before_install: scripts/' 'install_scripts.sh') elif service == 'circle': install_script_cmd = 'bash scripts/install_scripts.sh' elif service == 'brigade': install_script_cmd = '"bash scripts/install_scripts.sh",' with open(ci_file, 'w') as f: f.write(reformat(ci_file_content.safe_substitute( {'install_scripts': install_script_cmd}))) # Prepare and Write the install scripts. if install: install = set(install) install_script_file = os.path.join( project_root, 'scripts', 'install_scripts.sh') script_content = base_script_content for runtime in install: script_content += install_scripts_content[runtime] if not os.path.isdir(os.path.dirname(install_script_file)): os.makedirs(os.path.dirname(install_script_file)) with open(install_script_file, 'w') as f: f.write(script_content) st = os.stat(install_script_file) os.chmod(install_script_file, st.st_mode | stat.S_IEXEC) log.info('Wrote {} configuration successfully.'.format(service))
def cli(ctx, service, with_singularity): """Generates configuration files for distinct CI services. This command needs to be executed on the root of your Git repository folder. """ if service not in ci_files: log.fail("Unrecognized service " + service) project_root = scm.get_git_root_folder() if project_root != os.getcwd(): log.fail('This command needs to be executed on the root of your ' 'Git project folder (where the .git/ folder is located).') for ci_file, ci_file_content in pu.get_items(ci_files[service]): ci_file_content = ci_file_content ci_file = os.path.join(project_root, ci_file) # Create parent folder if not os.path.isdir(os.path.dirname(ci_file)): os.makedirs(os.path.dirname(ci_file)) # Customize content scripts = [] if with_singularity: if service in ['jenkins', 'gitlab']: log.fail('Scaffolding of Singularity install script is not ' 'supported for Jenkins and Gitlab CI. Include it ' 'manually depending upon the CI\'s OS.') scripts.append(install_scripts['singularity']) if scripts: scripts = ' && '.join(scripts) if service == 'travis': scripts = '- ' + scripts if service == 'brigade': scripts = '"' + scripts + '",' else: scripts = '' # Write content with open(ci_file, 'w') as f: f.write( reformat( ci_file_content.safe_substitute( {'install_scripts': scripts}))) log.info('Wrote {} configuration successfully.'.format(service))
def cli(ctx, service): """Generates configuration files for distinct CI services. """ project_root = pu.get_project_root() if service not in ci_files: pu.fail("Unrecognized service " + service) for ci_file, ci_file_content in pu.get_items(ci_files[service]): ci_file = os.path.join(project_root, ci_file) # create parent folder if not os.path.isdir(os.path.dirname(ci_file)): os.makedirs(os.path.dirname(ci_file)) # write content with open(ci_file, 'w') as f: f.write(ci_file_content)
def cli(ctx, service, skip, requirement_level): """Generates configuration files for distinct CI services. """ project_root = pu.get_project_root() if service not in ci_files: pu.fail("Unrecognized service " + service) runargs = '--skip={} '.format(skip) if skip else '' runargs += '--requirement-level {}'.format(requirement_level) for ci_file, ci_file_content in pu.get_items(ci_files[service]): ci_file_content = ci_file_content.format(runargs=runargs) ci_file = os.path.join(project_root, ci_file) # create parent folder if not os.path.isdir(os.path.dirname(ci_file)): os.makedirs(os.path.dirname(ci_file)) # write content with open(ci_file, 'w') as f: f.write(ci_file_content)
def test_get_items(self): sample_dict = {'1': 1, '2': 2} items = pu.get_items(sample_dict) for k, v in items: self.assertEqual(k, str(k))