def initialize(): from fortpy.msg import set_verbosity set_verbosity(args["verbose"]) comparer = FileComparer(template_folder=args["templates"]) result = comparer.compare(args["source"], args["target"], args["xmltemplate"], args["mode"]) if args["save"]: from os import path fullpath = path.abspath(path.expanduser(args["save"])) with open(fullpath, "w") as f: f.write(print_compare_result(result, args["verbose"])) else: print((print_compare_result(result, args["verbose"]))) return result
class OutputConverter(object): """Converts plain-text output files between versions.""" def __init__(self, template_dir): self.comparer = FileComparer(os.path.expanduser(template_dir)) def convert(self, path, version, target): """Converts the specified source file to a new version number.""" source = self.comparer.get_representation(path) lines = [ '# <fortpy version="{}"></fortpy>\n'.format(version) ] for line in self.comparer.template.contents[version].preamble: lines.append(line.write(source.preamble, source.version, source.stored) + "\n") for line in self.comparer.template.contents[version].body: for valueset in source.body: lines.append(line.write(valueset, source.version, source.stored) + "\n") with open(os.path.expanduser(target), 'w') as f: f.writelines(lines)
class OutputConverter(object): """Converts plain-text output files between versions.""" def __init__(self, template_dir): self.comparer = FileComparer(os.path.expanduser(template_dir)) def convert(self, path, version, target): """Converts the specified source file to a new version number.""" source = self.comparer.get_representation(path) lines = ['# <fortpy version="{}"></fortpy>\n'.format(version)] for line in self.comparer.template.contents[version].preamble: lines.append( line.write(source.preamble, source.version, source.stored) + "\n") for line in self.comparer.template.contents[version].body: for valueset in source.body: lines.append( line.write(valueset, source.version, source.stored) + "\n") with open(os.path.expanduser(target), 'w') as f: f.writelines(lines)
def __init__(self, template_dir): self.comparer = FileComparer(os.path.expanduser(template_dir))