def gen_jsonifier(self, pkg, target_dir): import io_utils entities = get_package_entities(pkg) if len(entities) > 0: norm_pkg = norm_package(pkg) pkg_file = norm_pkg + "_jsonifiers.dart" target_file = target_dir + '/' + pkg_file package_name = to_camel_case(norm_pkg, True) lines = [] # import 'package:sagas_meta/src/models/product_subscription.dart'; lines.append("import 'package:sagas_meta/src/models/%s.dart';" % norm_pkg) lines.append(imports) lines.append('class %sJsonifier{' % package_name) for entity_name in entities: print('.. generate', entity_name) gen_bloc_jsonifier(lines, entity_name) gen_map_overrides(lines, entity_name) lines.append('}') cnt = ("\n".join(lines)) io_utils.write_to_file(target_file, cnt) print('done.') else: print("package %s doesn't has entities.")
def normal(self, file): """ $ python -m sagas.tool.creators normal ./out/xxx.xx :param file: :return: """ if not io_utils.exists(file): io_utils.write_to_file(file, normal_cnt) print(f"file {file} doesn't exists, create it")
def scribes(dot): import io_utils import subprocess from subprocess import STDOUT io_utils.write_to_file('./out/sents.dot', dot.source, True) # $ graph-easy ./out/sents.dot --from=dot --as_ascii out_format = '--as_boxart' # '--as_ascii' cmd_args = ['graph-easy', './out/sents.dot', '--from=dot', out_format] # r = subprocess.call(cmd_args) # print('done -', r) r = subprocess.check_output(cmd_args, stderr=STDOUT) result_text = r.decode('utf-8') # print(result_text) return result_text
def save_data(model_class): jsonified = object_list_to_json(model_class.data) print(jsonified) result = write_to_file(jsonified, model_class.entity_verbose_name) # I could have passed the whole class return result
def gen_services(group_name, srvs, target_file): deps = set() for srv in srvs: proc_service_refs(srv, deps) lines = [] for dep in deps: lines.append("import 'package:sagas_meta/src/models/%s.dart';" % dep) lines.append(package_header.format(package_name=to_camel_case(group_name, True))) for service in srvs: gen_service_stub(lines, service) lines.append('') lines.append(package_footer) cnt = "\n".join(lines) io_utils.write_to_file(target_file, cnt)
def gen_sample_dss_data(): import io_utils import os import sagas.ofbiz root_dir = os.path.dirname(sagas.ofbiz.__file__).replace("sagas/ofbiz", "") entity_name = "DssOrdinalSales" id_col = "dssOrdinalSalesId" index_col = 'year' val_col = 'sales' ps = gen_ordinal_sales() cnt = gen_xml_data(ps, entity_name, id_col, index_col, val_col) target = root_dir + 'data/dss/' + entity_name + "GenData.xml" io_utils.write_to_file(target, cnt) print('write to', target, "ok.")
def gen_package(self, pkg, target_dir): import io_utils entities = get_package_entities(pkg) if len(entities) > 0: pkg_file = norm_package(pkg) + ".dart" target_file = target_dir + '/' + pkg_file lines = [] lines.append(package_header) for entity_name in entities: print('.. generate', entity_name) # entity_name='TestFieldType' gen_bloc_model(lines, entity_name) cnt = ("\n".join(lines)) io_utils.write_to_file(target_file, cnt) print('done.') else: print("package %s doesn't has entities.")
def write_json_to_file(filename:Text, obj:Any, **kwargs): """Write an object as a json string to a file.""" write_to_file(filename, json_to_string(obj, **kwargs))