コード例 #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)
    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)