Exemplo n.º 1
0
    def __init__(self, synctrex, name, **params):
        # Note: Synctrex initialize value using the yaml's generated
        # data. That means that they are unsafe, untyped, and that there
        # are not yet cross-references between objects.
        super().__init__()
        self.synctrex = synctrex

        self.name = name
        self.method = params.get('method')
        self.shell = params.get('shell') or 'bash'
        self.source = Address(params.get('source') or '')
        self.dest = Address(params.get('dest') or '')
        self.source_dir = Address(params.get('source_dir') or '')
        self.dest_dir = Address(params.get('dest_dir') or '')

        self.options = params.get('options') or []
        self.options = as_list(self.options)

        self.group = params.get('group') or []
        self.groups = params.get('groups') or []
        self.groups = as_list(self.groups)

        #self.require = params.get('require') or []
        #self.require = as_list_of(str, self.require)

        self.files = params.get('files') or []
        self.files = as_list_of(Address, self.files)

        self.exclude = params.get('exclude') or []
        self.exclude = as_list_of(str, self.exclude)

        self.mode = params.get('mode') or 'normal'

        handlers = params.get('events') or {}
        for type, cmds in handlers.items():
            commands = as_list_of(str, cmds)
            for command in commands:
                if command[0] == '`' == command[-1]:
                    command = events.Shell(command[1:-1], self.shell)
                else:
                    command = events.Script(command)
                self.add_handler(type, command)
Exemplo n.º 2
0
    def __init__(self, **params):
        self.clear()
        self.force = {}
        self.already_loaded = []
        self.already_run = []

        self.exclude = utils.as_list_of(str, params.get('exclude') or [])
        self.force = params.get('force')
        if params.get('all'):
            self.select = True
        else:
            self.select = params.get('sync')
        self.allow_rerun = params.get('allow-rerun')
        super().__init__()
Exemplo n.º 3
0
    def load(self, path):
        """
        Parse a configuration file and generate all needed object.
        Raise a ValueError if there are at least one error raised when
        reading the configuration file.
        """
        def prepare_value(value):
            value.update(self.force)
            return value

        if path in self.already_loaded:
            logger.warning('file %s has already been loaded, skip -- '
                           'you might want to check for cycles', path)
            return
        self.already_loaded.append(path)

        logger.debug('open configuration %s', path)
        errors = []
        with open(path, 'r') as file:
            data = yaml.load(file)

            # imports
            imports = data.get('imports')
            if imports:
                base_dir = os.path.dirname(path)
                for i_path in utils.as_list_of(str, imports):
                    i_path = utils.expand_path(base_dir, i_path,
                                               expand_vars=True)
                    self.load(i_path)

            # syncs
            syncs = data.get('syncs')
            if syncs:
                syncs = [ (name, Sync(self, name, **prepare_value(value)))
                          for name, value in syncs.items() ]
                self.syncs.update(syncs)

        if errors:
            raise ValueError('configuration contains {} errors: abort'
                             .format(len(errors)))