예제 #1
0
 def execute(self, command_args):
     if len(command_args) > 1:
         console_out(
             "\nError in executing command: {}  To many arguments".format(command_to_plain_string(command_args))
         )
     else:
         return console_out(get_supported_db())
예제 #2
0
    def execute(self, command_args):
        try:
            repo = Repository()
            repo.name = command_args[1]
            repo.host = command_args[2]
            repo.port = command_args[3]
            repo.username = command_args[4]
            repo.database_driver = command_args[5]
            repo.database_name = command_args[6]
            repo.scripts_path = command_args[7]

            validate_repository(repo)

            if has_errors(repo):
                return console_out(errors_parser(repo))

        except IndexError:
            console_error(
                "In executing command: {}  Not all arguments have been passed.".format(
                    command_to_plain_string(command_args)
                )
            )
        try:
            Repository.create(repo)
        except IntegrityError:
            console_error("Repository {} already exists.".format(repo.name))
            return
        console_info("Repository {} created successfully.".format(repo.name))
예제 #3
0
 def execute(self, command_args):
     if len(command_args) > 1:
         console_out(
             "\nError in executing command: {}  To many arguments".format(command_to_plain_string(command_args))
         )
     else:
         Repository.read_all()
         result = repository_formatter(Repository.read_all())
         console_out(result)
예제 #4
0
 def execute(self, command_args):
     if len(command_args) > 2:
         sys.stdout.write(
             "\nError in executing command: {}  To many arguments".format(command_to_plain_string(command_args))
         )
     else:
         try:
             repo_name = command_args[1]
             Repository.remove_by_name(repo_name)
             console_info("Deleted repository: {}".format(repo_name))
         except RepositoryException:
             console_out("Can't find repository: {}".format(repo_name))
예제 #5
0
    def execute(self, command_args):
        if len(command_args) != 3:
            sys.stdout.write(
                'Error in executing command: "{}", Init command requires 2 arguments: "REPOSITORY_NAME", '
                '"PASSWORD_TO_DATABASE"'.format(command_to_plain_string(command_args).strip())
            )
        else:
            repo_name = command_args[1]
            db_password = command_args[2]
            repository = Repository.read_by_name(repo_name)
            host = repository.host
            port = repository.port
            database_driver = repository.database_driver
            database_name = repository.database_name
            username = repository.username

            driver_resolver = DBResolver()
            driver_resolver.resolve_db_driver(database_driver)

            if host != "localhost":
                host = host + ":" + port

            try:
                connection = driver_resolver.connect_to_db(
                    dbname=database_name, user=username, host=host, password=db_password
                )
            except OperationalError:
                sys.stdout.write("Error: Can't connect to database: {} on host: {}".format(database_name, host))
                return

            cursor = connection.cursor()

            try:
                cursor.execute(driver_resolver.get_init_query())
                connection.commit()
            except ProgrammingError:
                console_out("Info: Migration table already exists")

            connection.close()
예제 #6
0
 def execute(self, command_args):
     if len(command_args) > 2:
         console_error("In executing command: {}  To many arguments.".format(command_to_plain_string(command_args)))
     else:
         return console_out(get_available_commands())