def cmd_dump_project(args): if len(mainlist.projects) == 0: putter.error('No projects available.') return apply_define_args(args) if args.project is None: with putter.group('Projects'): for name in mainlist.projects: path = resolve_project_path(name, do_not_crash=True) if path is None: putter.warning( f'No path allowed by conditions for {cf.bold(name)}.') continue try: data = read_project(path) dump_project(data) except (ValueError, AssertionError): putter.error('Could not parse file.') except FileNotFoundError: putter.error(f'File not found: {cf.underlined(path)}.') return try: data = read_project(resolve_project_path(args.project)) dump_project(data) except (ValueError, AssertionError): putter.error('Could not parse file.') raise except FileNotFoundError: putter.error(f'File not found: {cf.underlined(path)}.') raise
def cmd_build(args): if args.group is None: putter.error('Specify a group to build.') print() with putter.group('Available groups'): print(putter.render_list(mainlist.groups.keys())) return apply_define_args(args) build_project('client')
def print_inst(inst): if inst.type == 'macro': print( f'{cf.bold("$"+inst.name)} = {cf.bold(inst.value)}{cond_suffix(inst)}' ) elif inst.type == 'include': print(f'include {cf.italic(inst.path)}{cond_suffix(inst)}') elif inst.type == 'configuration': with putter.group('configuration'): if 'compiler' in inst: with putter.group('compiler'): for k, v in inst.compiler.items(): print(f'{cf.bold(k)} = {cf.bold(v)}') elif inst.type == 'project': with putter.group('project'): for k, v in inst.folders.items(): print_folder(k, v) else: print(inst)
def cmd_dump_group(args): if len(mainlist.groups) == 0: putter.error('No groups available.') return if args.group is None: with putter.group('Groups'): for name in mainlist.groups: dump_group(name) return dump_group(args.group)
def print_folder(name, folder_data): with putter.group(f'{name}/'): for k, v in folder_data.folders.items(): print_folder(k, v) for f in folder_data.files: print(f'{cf.bold(f.path)}{cond_suffix(f)}') with putter.indent(): for inst in f.instructions: print_inst(inst) # TODO(maximsmol): only print this when there was a lot of output? print(cf.gray(f'--- {name} ---'))
def cmd_dump_project_manifest(args): if len(mainlist.projects) == 0: putter.error('No projects available.') return apply_define_args(args) if args.project is None: with putter.group('Projects'): for name in mainlist.projects: dump_project_manifest(name) return dump_project_manifest(args.project)
def print_generic_dict(x_name): x_key = vpc.configuration_commands[x_name].pythonized if x_key not in inst: return # TODO(maximsmol): print the merging process merged = Namespace() for x in inst[x_key]: if 'cond' not in x or eval_cond(x.cond): merge_command_data(merged, x) with putter.group(x_name): for k, v in merged.items(): print(f'{cf.bold(k)} = {cf.bold(v)}')
def dump_group(name): data = mainlist.groups[name] with putter.group(f'{name}'): for project in data.projects: print(f'{project}')
def dump_project_manifest(name): data = mainlist.projects[name] with putter.group(f'{name}'): for path in data.paths: print(f'{cf.italic(path.path)}{cond_suffix(path)}')
def build_data(path): data = read_project(path) for inst in data.instructions: if inst.type == 'conditional': val = expand_macros_in_string(inst.value) if 'cond' not in inst or eval_cond(inst.cond): if val == '1': val = True if val == '0': val = False if val in no_strings or val in yes_strings: putter.warning( f'Found yes/no string but refusing to convert it: {render_macro_value(val)}' ) print( f'{cf.magenta("Set conditional")} {cf.bold("$"+inst.name)} = {render_macro_value(val)}{cond_suffix(inst)}' ) if inst.name in macro_state and val != macro_state[ inst.name]: with putter.indent(): putter.warning( f'Overriding old value of {render_macro_value(macro_state[inst.name])}' ) macro_state[inst.name] = val else: print( f'Not setting conditional {cf.bold("$"+inst.name)} = {render_macro_value(val)}{cond_suffix(inst)} due to the false condition' ) elif inst.type == 'macro': val = expand_macros_in_string(inst.value) if 'cond' not in inst or eval_cond(inst.cond): if val == '1': val = True if val == '0': val = False if val in no_strings or val in yes_strings: putter.warning( f'Found yes/no stringbut refusing to convert it: {render_macro_value(val)}' ) print( f'{cf.magenta("Set")} {cf.bold("$"+inst.name)} = {render_macro_value(val)}{cond_suffix(inst)}' ) if inst.name in macro_state and val != macro_state[ inst.name]: with putter.indent(): putter.warning( f'Overriding old value of {render_macro_value(macro_state[inst.name])}' ) macro_state[inst.name] = val else: print( f'Not setting {cf.bold("$"+inst.name)} = {render_macro_value(val)}{cond_suffix(inst)} due to the false condition' ) elif inst.type == 'include': if 'cond' not in inst or eval_cond(inst.cond): print( f'{cf.magenta("Including")} {cf.italic(inst.path)}{cond_suffix(inst)}' ) with putter.indent(): include_path = expand_macros_in_string(inst.path) resolved_path = Path( ntpath.normpath( str(root_path.parent / include_path))) print( f'{cf.magenta("Resolved to")} {cf.italic(resolved_path)}' ) build_data(resolved_path) else: print( f'Not including {cf.italic(Path(inst.path).name)}{cond_suffix(inst)} due to the false condition' ) elif inst.type == 'configuration': def print_generic_dict(x_name): x_key = vpc.configuration_commands[x_name].pythonized if x_key not in inst: return # TODO(maximsmol): print the merging process merged = Namespace() for x in inst[x_key]: if 'cond' not in x or eval_cond(x.cond): merge_command_data(merged, x) with putter.group(x_name): for k, v in merged.items(): print(f'{cf.bold(k)} = {cf.bold(v)}') suffix = '' if 'name' in inst: suffix = f' "{inst.name}"' with putter.group(f'Configuration{suffix}'): for generic_group in vpc.configuration_commands: print_generic_dict(generic_group) elif inst.type == 'macro_required': invalid_value = macro_state.get( inst.name) == '' and not inst.allow_empty if inst.name not in macro_state or invalid_value: if 'default' not in inst: if inst.name not in macro_state: die(f'Macro {cf.bold("$"+inst.name)} is required, but not defined.' ) if not inst.allow_empty: die(f'Macro {cf.bold("$"+inst.name)} is required, but is set to an empty string.' ) with putter.indent(): print( f'{cf.magenta("Defaulted")} {cf.bold("$"+inst.name)} = {render_macro_value(inst.default)}' ) macro_state[inst.name] = inst.default else: print( f'{cf.magenta("Found required")} {cf.bold("$"+inst.name)}' ) else: putter.warning(f'Skipped instruction {cf.bold(inst.type)}.')