Exemplo n.º 1
0
def write_result(result, ctx):

    alias = ctx.parent.params['alias']

    file_path = ctx.parent.parent.repo.path(alias)
    fmt = ctx.parent.parent.repo.fmt(alias)

    writer.dump(obj=result, file_path=file_path, fmt=fmt)
Exemplo n.º 2
0
def write_result(result, ctx):

    alias = ctx.parent.params['alias']

    file_path = ctx.parent.parent.repo.path(alias)
    fmt = ctx.parent.parent.repo.fmt(alias)

    writer.dump(obj=result, file_path=file_path, fmt=fmt)
Exemplo n.º 3
0
def write_file(dictionary, configure):

    if configure.fmt == constants.INI:
        # ini format must have its sections as the
        # first level keys of the dictionary
        dictionary = {'section1': copy.deepcopy(dictionary)}

    writer.dump(obj=dictionary,
                file_path=configure.repo.path(configure.alias),
                fmt=configure.fmt)
    configure.repo.commit(alias=configure.alias)
Exemplo n.º 4
0
    def __init__(self, config_dir, logger=None):

        self._repo_dir = os.path.join(config_dir, 'repo')
        self._state_file = os.path.join(self._repo_dir, 'repo.json')
        self._logger = logger or log.Logger('{0}.api.repository.Repository'
                                            .format(constants.PROGRAM_NAME))

        utils.smkdir(self._repo_dir)

        if not os.path.exists(self._state_file):
            writer.dump(obj=self.BLANK_STATE, file_path=self._state_file, fmt=constants.JSON)
Exemplo n.º 5
0
    def __init__(self, config_dir):

        self._repo_dir = os.path.join(config_dir, 'repo')
        self._state_file = os.path.join(self._repo_dir, 'repo.json')
        self._logger = logger.get_logger(
            '{0}.api.repository.Repository'.format(constants.PROGRAM_NAME))

        utils.smkdir(self._repo_dir)

        if not os.path.exists(self._state_file):
            writer.dump(obj=self.BLANK_STATE,
                        file_path=self._state_file,
                        fmt=constants.JSON)
Exemplo n.º 6
0
def _repo(temp_file, temp_dir, request):

    alias = request.node.name
    fmt = request.param

    writer.dump(obj=get_test_dict(fmt), file_path=temp_file, fmt=fmt)

    repo = Repository(config_dir=temp_dir)
    repo.add(alias=alias, file_path=temp_file, fmt=fmt)

    # attach the format to the repo instance so that
    # test functions will have it.
    repo.test_fmt = fmt
    repo.tracked_file = temp_file

    yield repo
Exemplo n.º 7
0
def _repo(temp_file, temp_dir, request):

    alias = request.node.name
    fmt = request.param

    writer.dump(obj=get_test_dict(fmt),
                file_path=temp_file,
                fmt=fmt)

    repo = Repository(config_dir=temp_dir)
    repo.add(alias=alias, file_path=temp_file, fmt=fmt)

    # attach the format to the repo instance so that
    # test functions will have it.
    repo.test_fmt = fmt
    repo.tracked_file = temp_file

    yield repo
Exemplo n.º 8
0
def repo(request, home_dir, runner):

    class Repository(CommandLineFixture):

        def run(self, command, catch_exceptions=False, escape=False):

            command = 'repository {}'.format(command)

            return runner.run(command, catch_exceptions=catch_exceptions, escape=escape)

    repository = Repository(request, home_dir)

    # create the file we intent to alias
    file_path = os.path.join(home_dir, repository.alias)

    writer.dump(obj=get_test_dict(repository), file_path=file_path, fmt=repository.fmt)
    repository.run('add --alias {0} --file-path {1} --fmt {2}'
                   .format(repository.alias, file_path, repository.fmt))

    yield repository
Exemplo n.º 9
0
def conf(request, home_dir, runner):

    class Configure(CommandLineFixture):

        def run(self, command, catch_exceptions=False, escape=False):

            command = 'configure {} {}'.format(self.alias, command)

            return runner.run(command, catch_exceptions=catch_exceptions, escape=escape)

    configure = Configure(request, home_dir)

    # create the file we intent to operate on
    file_path = os.path.join(home_dir, configure.alias)
    writer.dump(obj={},
                file_path=file_path,
                fmt=configure.fmt)

    # add the file to the repository
    runner.run('repository add --alias {} --file-path {} --fmt {}'
               .format(configure.alias, file_path, configure.fmt),
               catch_exceptions=False)

    yield configure
Exemplo n.º 10
0
def test_dump_unsupported_format():

    with pytest.raises(exceptions.UnsupportedFormatException):
        writer.dump(obj={}, fmt='unsupported', file_path='dummy')
Exemplo n.º 11
0
 def _save_state(self, state):
     writer.dump(obj=state, file_path=self._state_file, fmt=constants.JSON)
Exemplo n.º 12
0
 def _save_state(self, state):
     writer.dump(obj=state, file_path=self._state_file, fmt=constants.JSON)