本文整理汇总了Python中World.initialize_world方法的典型用法代码示例。如果您正苦于以下问题:Python World.initialize_world方法的具体用法?Python World.initialize_world怎么用?Python World.initialize_world使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类World
的用法示例。
在下文中一共展示了World.initialize_world方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: main
# 需要导入模块: import World [as 别名]
# 或者: from World import initialize_world [as 别名]
def main(argv=[]):
"""
This is the first function called when the program starts. Do all initialization here.
@param argv Optionally pass the command-line arguments.
@return Exit code. 0 for success, non-zero for unnatural exit.
"""
# Write pid to file.
if not os.path.exists("./logs"):
os.mkdir("logs");
run_unit_tests = False;
config_file = os.path.abspath("config.cfg");
debug_mode = False;
# The first argument isn't important to us -- it's the program's name.
del argv[0];
for arg in argv:
if arg == "--test" or arg == "-t":
# Testing mode enabled. The server will not run; it will perform unit tests.
run_unit_tests = True;
elif arg.startswith("-p") or arg.startswith("--port"):
# Let user know how to set a port.
print "Port cannot be set through command line, look in the config file.";
return 1;
elif arg == "-d" or arg == "--debug":
# Enable debugging.
debug_reporter("Debug mode enabled.");
debug_mode = True;
elif arg == "--generate-config" or arg == "-g":
# Generate a configuration file.
temp_config = Config.VTank_Config();
result = temp_config.generate_config(os.path.abspath(".") + os.sep + "config.cfg");
debug_reporter("Result: %s" % result);
return int(result);
elif arg == "--load-slice" or arg == "-s":
# Load slice dynamically without generating files.
load_slice_files();
elif arg.startswith("--config-file="):
# User is specifying the config file's name.
config_file = arg[len("--config-file="):];
if not config_file:
print "--config-file usage:";
print "--config-file=[FILENAME]";
return 1;
if not os.path.exists(os.path.abspath(config_file)):
print "Config file does not exist:", config_file;
return 1;
debug_reporter("Using config file " + config_file + ".");
else:
# Unknown.
print "Unknown option:", arg, " -- ignoring it.";
# Run unit testing here.
if run_unit_tests:
import Unit_Test;
return Unit_Test.run_all_tests();
import Log;
import World;
import Config;
import Map_Manager;
if debug_mode:
reporter_func = debug_reporter;
else:
reporter_func = Log.log_reporter;
# Start handling the world.
try:
World.initialize_world(config_file, reporter_func);
world = World.get_world();
Map_Manager.initialize(world.get_config(), world.get_database(), reporter_func);
# Write the process ID of this server to file.
file = open('echelon.pid', 'w');
with file:
file.write(str(os.getpid()));
stackless.tasklet(VersionChecker.get_mysql_version)();
stackless.run();
# Unless some design changes, it will likely never reach this point.
# Instead, it will be running through the stackless scheduler.
reporter_func("Waiting for Ice shutdown.");
World.get_world().get_communicator().waitForShutdown();
except Force_Exit_Exception, e:
Log.log_print("CRITICAL_ERROR.log", "", "Startup failure: " + str(e));
reporter_func("Critical error occurred: " + str(e));
from sys import exit;
return e.exit_code;