Пример #1
0
    def run(self):

        print("")
        print(" Welcome, You're about to add a new max instance to {}.".format(self.options.instancesfile))
        print(" Please tell me:")
        print("")

        valid_new_section = False
        max_name = None
        while not valid_new_section:
            if max_name is not None:
                max_name = raw_input("  > Ooops!, there is already an instance with this name, try again:")
            else:
                max_name = raw_input("  > The name of the max instance (same as domain): ")
            new_section_name = max_name
            valid_new_section = not self.instances.has_section(new_section_name)

        precalculated_max_server = '{}/{}'.format(self.common.get('max', 'server'), max_name)
        max_server = raw_input("  > The base url of the max server [{}]: ".format(precalculated_max_server))
        if not max_server:
            max_server = precalculated_max_server

        precalculated_oauth_server = '{}/{}'.format(self.common.get('oauth', 'server'), max_name)
        max_oauth_server = raw_input("  > The base url of the oauth server [{}]: ".format(precalculated_oauth_server))
        if not max_oauth_server:
            max_oauth_server = precalculated_oauth_server

        max_hashtag = raw_input("  > The hashtag to track on twitter (without #): ")
        language = raw_input("  > The language used in push notification literals [ca]: ")
        if not language:
            language = 'ca'

        max_user = raw_input("  > The restricted user: "******"  > ")
        sys.stdout.flush()
        max_token = max_client.login(max_user)

        self.instances.add_section(new_section_name)
        self.instances.set(new_section_name, 'hashtag', max_hashtag)
        self.instances.set(new_section_name, 'server', max_server)
        self.instances.set(new_section_name, 'oauth_server', max_oauth_server)
        self.instances.set(new_section_name, 'restricted_user', max_user)
        self.instances.set(new_section_name, 'restricted_user_token', max_token)
        self.instances.set(new_section_name, 'language', language)

        self.instances.write(open(self.options.instancesfile, 'w'))

        print("")
        print(" Changes written to {}".format(self.options.instancesfile))
        print("")