def bring_up(self, wagodict, **kwargs): ''' >>> com = Community() >>> tests = yaml.load(open('test/Community.bring_up.yaml').read()) >>> for t in tests: ... com.bring_up(t['wagodict']) ... assert t['wagodict'] == t['expected'] #... print (t['wagodict']) #... print (t['expected']) ''' filepath = wagopath2filepath(wagodict['wago']) code = yaml.load(open(filepath).read()) assert code assert isinstance(code, list), code codedict = code[0] wagodict2codedict(wagodict, codedict)
def new (filename): ''' あたらしくwagoファイルをつくる。 wagoファイルは、相対パス名。 フォルダの区切り文字は、OSの依存をなくすため、'.'(ピリオド)。 ''' text = '- code : |\n' text += ' /* write code here */\n' text += ' wagoキー : \n' text += '- wago : path.to.wagoファイル\n' text += ' wagoキー : 値\n' path = wagopath2filepath(filename) if os.path.exists(path) : print ('NOT CREATE') print (' ' + path + ' : already exists') else: open(path, 'w').write(text) print ('CREATE ') print (' ' + path)
def code(wagofile, **kwargs): ''' >>> tests = yaml.load(open('test/code.yaml').read()) >>> for t in tests: ... actual = code(t['wagofile']) ... # print (actual) ... # print (t['expected']) ... assert actual == t['expected'] ''' com = Community() filepath = wagopath2filepath(wagofile) baby = yaml.load(open(filepath).read()) walk(baby, com.bring_up) writer = CodeWriter() walk(baby, writer.write) if 'verbose' in kwargs and kwargs['verbose']: print (yaml.dump(baby)) print (writer.result) if 'output_file' in kwargs and kwargs['output_file']: with open(kwargs['output_file'], 'w') as fp: print (writer.result, file=fp) print ('WRITE: %s' % kwargs['output_file']) return baby