Exemple #1
0
    def __init__(self, init_session=True, **kwargs):
        if kwargs:
            # If kwargs have been supplied, use these in same way argsparse
            # would.
            # Mainly used for testing, but could be used to run commands from
            # within python scripts.

            # We can't add attributes to instances of Object, so we need create
            # a new class.
            class Args(object):
                pass

            self.args = Args()
            for key, value in kwargs.items():
                setattr(self.args, key, value)
        else:
            # If the command is created from the command line, we'll have
            # arguments to parse.
            parser = argparse.ArgumentParser(
                description="Taming the bull: Change management for Agresso systems")
            self._add_arguments(parser)
            self.args, unknown = parser.parse_known_args()

        self._logger = logging.getLogger(__name__)
        if init_session:
            Session.initialise()
        self._execute()
 def _execute(self):
     Session.set_environment(self.args.environment)
     if self.args.commit == 'none':
         commit = None
     else:
         commit = self.args.commit
     execute_ticket(self.args.ticket, self.action, commit, False)
Exemple #3
0
 def _execute(self):
     Session.set_environment(self.args.environment)
     if self.args.commit == 'none':
         commit = Session.project_repo.head().decode(encoding='ascii')
     else:
         commit = self.args.commit
     execute_ticket(self.args.ticket, self.action, commit, False)
Exemple #4
0
 def _execute(self):
     Session.set_environment(self.args.environment)
     kwargs = {
         **Session.environment['database'],
         **Session.credentials,
         **self.args.__dict__}
     run_sql_script(self._logger, **kwargs)
 def _execute(self):
     Session.set_environment(self.args.environment)
     if self.args.commit == 'none':
         commit = None
     else:
         commit = self.args.commit
     self._checkout_package(self.args.package, commit)
    def _execute(self):
        Session.set_environment(self.args.environment)

        file_path = os.path.join(self.args.directory, self.args.file)

        run_sql_script(
            self._logger,
            file_path)
def test_initialise(project_repo):
    Session.initialise()
    assert Session.project_folder == Path(project_repo.path)
    assert Session.project == project
    assert Session.matador_project_folder == Path(
        Path.home(), '.matador', project)
    assert Session.matador_repository_folder == Path(
        Path.home(), '.matador', project, 'repository')
    assert Session.environments == environments
    def _checkout_package(package, commit):
        repo_folder = Session.matador_repository_folder
        package_folder = Path(
            Session.matador_packages_folder, package)

        shutil.rmtree(str(package_folder), ignore_errors=True)

        Session.update_repository()

        git.checkout(Session.matador_repo, commit)

        src = Path(repo_folder, 'deploy', 'packages', package)
        shutil.copytree(str(src), str(package_folder))
Exemple #9
0
def execute_ticket(ticket, action, commit, packaged=False):
    ticket_folder = Path(Session.matador_tickets_folder, ticket)
    Session.deployment_folder = ticket_folder

    shutil.rmtree(str(ticket_folder), ignore_errors=True)

    if not packaged:
        Session.update_repository()

    _checkout_ticket(ticket, Session.matador_repo, ticket_folder, commit)

    actionFile = Path(action + '.py')
    sourceFile = Path(ticket_folder, actionFile)
    SourceFileLoader(action, str(sourceFile)).load_module()
Exemple #10
0
def test_set_environment(project_repo):
    env = 'test'
    Session.set_environment(env)
    config = Repo(str(Session.matador_repository_folder)).get_config()
    assert config.get(b'core', b'sparsecheckout') == b'true'
    assert Session.matador_project_folder.is_dir()
    assert Session.matador_repository_folder.is_dir()
    assert Session.environment == environments[env]
    assert Session.credentials == credentials[env]
    assert Session.matador_environment_folder == Path(
        Path.home(), '.matador', project, env)
    assert Session.matador_tickets_folder == Path(
        Path.home(), '.matador', project, env, 'tickets')
    assert Session.matador_packages_folder == Path(
        Path.home(), '.matador', project, env, 'packages')
    assert Session.matador_environment_folder.is_dir()
    assert Session.matador_tickets_folder.is_dir()
    assert Session.matador_packages_folder.is_dir()
Exemple #11
0
 def finalise():
     Session.clear()
Exemple #12
0
def test_update_repository(project_repo):
    Session.update_repository()
    refs = LocalGitClient().get_refs(str(Session.matador_repository_folder))
    assert b'refs/remotes/origin/master' in refs