コード例 #1
0
def main(argv=sys.argv):
    # Options.
    backup = True
    logging_level = logging.WARNING
    
    option_parser = OptionParser(usage=usage_message, args=argv[1:])
    for option in option_parser:
        if (option == '-h' or option == '--help'):
            print(option_parser.usage)
            sys.exit(0)
        elif (option == '-n' or option == '--no-backup'):
            backup = False
        elif (option == '-v' or option == '--verbose'):
            logging_level -= 10
        elif (option == '-q' or option == '--quiet'):
            logging_level += 10
        else:
            # invalid option
            message = '"{0}" is not a valid argument or option'.format(option)
            option_parser.error(message)
    logging.basicConfig(format='%(message)s', level=logging_level,
                        stream=sys.stdout)
    
    path = option_parser.get_next_prog_arg()
    if (os.path.isdir(path)):
        for filepath in os.listdir(path):
            qualified_filepath = os.path.join(path, filepath)
            if (not os.path.isfile(qualified_filepath)):
                continue
            convert_dialogue_file(qualified_filepath, backup=backup)
    else:
        convert_dialogue_file(path, backup=backup)
コード例 #2
0
def main(argv=sys.argv):
    option_parser = OptionParser(
        usage=USAGE_MESSAGE,
        args=argv[1:]
    )
    logging_level = logging.WARNING
    for option in option_parser:
        if option == '-h' or option =='--help':
            print(option_parser.usage)
            sys.exit(0)
        elif option == '-v':
            logging_level -= 10
        elif option == '-q':
            logging_level += 10
        else:
            print('Error: unknown option {0!r}\n'.format(option),
                  file=sys.stderr)
            print(option_parser.usage, file=sys.stderr)
            sys.exit(1)
    try:
        xml_script_path = os.path.abspath(option_parser.get_next_prog_arg())
    except OptionError as exception:
        print('Error: {0}\n'.format(exception), file=sys.stderr)
        print(option_parser.usage, file=sys.stderr)
        sys.exit(1)
    application = GuichanDesignerApplication()
    application.setupLogging(logging_level)
    parpg_root = os.path.abspath(os.path.join('..', '..', 'game'))
    os.chdir(parpg_root)
    application.xml_script_path = xml_script_path
    with file(xml_script_path) as xml_file:
        application.loadXml(xml_file)
    application.run()
コード例 #3
0
def main(argv=sys.argv):
    option_parser = OptionParser(usage=USAGE_MESSAGE)
    for option in option_parser:
        if (option in ['-h', '--help']):
            print(option_parser.usage)
            sys.exit(0)
        else:
            option_parser.error('unrecognized option "{0}"'.format(option))
    try:
        dialogue_file_path = option_parser.get_next_prog_arg()
    except OptionError:
        dialogue_file_path = selectDialogueFile()
    game_state = {
        'quest': QuestEngine('quests'),
        'pc': MockPlayerCharacter(),
        'box': MockBox(),
        'beer': MockBeer()
    }
    dialogue_parser = YamlDialogueParser()
    with file(dialogue_file_path, 'r') as dialogue_file:
        dialogue = dialogue_parser.load(dialogue_file)
    processDialogue(dialogue, game_state)