def check_document_map(): heading('Verify Document Map') cli_repo = get_cli_repo_path() map_path = os.path.join(cli_repo, DOC_SOURCE_MAP_PATH) help_files_in_map = _get_help_files_in_map(map_path) help_files_not_found = _map_help_files_not_found(cli_repo, help_files_in_map) help_files_to_add_to_map = _help_files_not_in_map(cli_repo, help_files_in_map) subheading('Results') if help_files_not_found or help_files_to_add_to_map: error_lines = [] error_lines.append('Errors whilst verifying {}!'.format(DOC_MAP_NAME)) if help_files_not_found: error_lines.append( 'The following files are in {} but do not exist:'.format( DOC_MAP_NAME)) error_lines += help_files_not_found if help_files_to_add_to_map: error_lines.append( 'The following files should be added to {}:'.format( DOC_MAP_NAME)) error_lines += help_files_to_add_to_map error_msg = '\n'.join(error_lines) raise CLIError(error_msg) display('Verified {} OK.'.format(DOC_MAP_NAME))
def check_license_headers(): heading('Verify License Headers') cli_path = get_cli_repo_path() env_path = os.path.join(cli_path, 'env') files_without_header = [] for current_dir, _, files in os.walk(cli_path): if current_dir.startswith(env_path): continue file_itr = (os.path.join(current_dir, p) for p in files if p.endswith('.py') and p != 'azure_bdist_wheel.py') for python_file in file_itr: with open(python_file, 'r') as f: file_text = f.read() if file_text and LICENSE_HEADER not in file_text: files_without_header.append( os.path.join(current_dir, python_file)) subheading('Results') if files_without_header: raise CLIError( "{}\nError: {} files don't have the required license headers.". format('\n'.join(files_without_header), len(files_without_header))) display('License headers verified OK.')
def create_module(mod_name='test', display_name=None, display_name_plural=None, required_sdk=None, client_name=None, operation_name=None, sdk_property=None, not_preview=False, github_alias=None, local_sdk=None): repo_path = os.path.join(get_cli_repo_path(), _MODULE_ROOT_PATH) _create_package('', repo_path, False, mod_name, display_name, display_name_plural, required_sdk, client_name, operation_name, sdk_property, not_preview, local_sdk) _add_to_codeowners(get_cli_repo_path(), '', mod_name, github_alias) _add_to_doc_map(get_cli_repo_path(), mod_name) _display_success_message(COMMAND_MODULE_PREFIX + mod_name, mod_name)
def check_license_headers(): heading('Verify License Headers') cli_path = get_cli_repo_path() all_paths = [cli_path] try: ext_repo = get_ext_repo_paths() for path in ext_repo: all_paths.append(path) except CLIError: display("No CLI ext path, running check only on modules") files_without_header = [] for path in all_paths: py_files = pathlib.Path(path).glob('**' + os.path.sep + '*.py') for py_file in py_files: py_file = str(py_file) if py_file.endswith('azure_bdist_wheel.py'): continue for ignore_token in _IGNORE_SUBDIRS: if ignore_token in py_file: break else: with open(str(py_file), 'r', encoding='utf-8') as f: file_text = f.read() if not file_text: continue test_results = [ LICENSE_HEADER in file_text, WRAPPED_LICENSE_HEADER in file_text, CODEGEN_LICENSE_HEADER in file_text ] if not any(test_results): files_without_header.append(py_file) subheading('Results') if files_without_header: raise CLIError( "{}\nError: {} files don't have the required license headers.". format('\n'.join(files_without_header), len(files_without_header))) display('License headers verified OK.')
def _load_doc_source_map(self): map_path = os.path.join(get_cli_repo_path(), DOC_SOURCE_MAP_PATH) with open(map_path) as open_file: return json.load(open_file)