def run_debug(): a = Assemblage(); fac = Entry_Factory.get_factory(); print("Testing Assemblage Node"); print( str(a)); water_res = fac.get_entry_by_key("res", "water"); melt_proc = fac.get_proc("smelt_iron"); #melt_proc = fac.get_proc_by_key("melt_water_ice"); print(" proc: \n"+str(melt_proc)); if melt_proc == None: return None; a.add_process( melt_proc); a.add_process( melt_proc); #a.set_process( melt_proc, 0.4 ); print( str(a)); a.update_time(); print( str(a)); return;
def proc_command_line(): fac = Entry_Factory.get_factory(); parser = generate_parser(); # parse command line options options = parser.parse_args(); # interpret all those command line options: options = fac.configure(options); options.action = coerce_action_name( options.action); # dump all important command line parameters (raw) if options.debug: print("---"); for var in dir(options): if not var.startswith('_'): if isinstance( getattr(options, var), Entry): print(" options.{0: <20} {1}".format(var+" :", (getattr(options, var).get_type_name().title()))); else: print(" options.{0: <20} {1}".format(var+":", str(getattr(options, var)))); print("---\n"); # Initialize Data if options.load_database: fac.read_list_from_database( options.type); if 1 < options.verbosity: print( ">> Read list from database: "+str(fac.get_list_sizes())); if options.load_backups: fac.read_list_from_backup( options.type); if 1 < options.verbosity: print( ">> Read list from backups: "+str(fac.get_list_sizes())); if 1 < options.verbosity: print(">>> ACTION: "+options.action+" >>> TABLE: "+options.table); if ACTION_ADD[0] == options.action: add_type = options.type; add_filename = options.infile; add_format = Text_Format().as_filename(add_filename); if 1 < options.verbosity: print(" importing type: <"+options.type.get_type_name() +"> from file: <"+options.infile +"> as <" +add_format.name.lower()+">\n"); if None == add_format: if options.infile == DEFAULT_IN_FILENAME: print(" !! please specify file to load from."); return None; else: print(" !! Unrecognized file_extension: "+str(add_ext)+"\n"); return None; if options.table == Entry_Factory.TABLE_ALL[0]: fac.read_mixed_file( add_filename); else: pre = fac.get_list_sizes(); #DEBUG fac.get_list_by_type(add_type).clear(); fac.add_from_file( options.type, add_filename, add_format); post = fac.get_list_sizes(); # DEBUG delta = []; for i in range(len(pre)): # DEBUG delta.append( post[i] - pre[i] ); # DEBUG print("{0: <36}".format("Read <"+add_type.get_type_name()+">. Deltas: ")+str(delta)); # DEBUG #fac.get_list_by_type(options.type).write_to_file( options.type, "test.out.js", Text_Format().as_json()); # DEBUG return None; # DEBUG elif ACTION_SEARCH[0] == options.action: if "" == options.column: print(" No search column specified. Assuming: "+str(options.column)); return None; results = fac.search( options.type, options.column, options.pattern, allow_subtypes=False); print(results); pass; elif ACTION_WRITE[0] == options.action: if 1 < options.verbosity: print(">>> Write data out. \n"); if options.outfile: fac.get_list_by_type(options.type).write_to_file( options.type, options.outfile, options.format); else: print("Error: requested to write file, but provided no filename."); elif ACTION_DIAG[0] == options.action: print("Diagnostics:\n " + fac.get_stat_str( options.type)); print("\n"); elif ACTION_DEV[0] == options.action: Assemblage.run_debug(); else: print("Unrecognized Action: "+options.action); return; if not options.dry_run: if options.write_backups: if 1 < options.verbosity: print(" >> Writing Data to Text File Backup \n"); fac.write_all_to_backups(); if options.write_database: if 1 < options.verbosity: print(" >> Writing Data to Database Backup \n"); fac.write_all_to_database(); pass # DEBUG #fac.get_list_by_type(add_type).write_to_file( add_type, "test.res.js", Entry_Format().as_json()); #fac.get_list_by_type(add_type).write_to_file( add_type, "test.tech.gv", Entry_Format().as_dot()); #os.system("dot -Tpng -O test.tech.gv"); # works :) #subprocess.call("dot -Tpng -O -v test.tech.dot"); # still doesn't work. return;