

def react(actions, reactions, paths_changed, new_files, base_dir, resources):
    '\n    Performs actions based on reaction criteria. Each action is only performed\n    once, and reactions are handled in order.\n\n    Keyword arguments:\n        actions -- map of action names to action descriptions\n        reactions -- list of reactions to check for\n        paths_changes -- list of files that were updated\n        new_files -- list of files that are new this run\n    '
    done_actions = set()
    for reaction in reactions:
        run_action = False
        when = reaction['when']
        if (('always' in when) and when['always']):
            run_action = True
        elif (('command' in when) and _runcommand(when['command'], when['exitcode_not'])):
            run_action = True
        elif (('files' in when) and _checkfiles(when['files'], (paths_changed + new_files))):
            run_action = True
        elif (('files_modified' in when) and _checkfiles(when['files_modified'], paths_changed)):
            run_action = True
        elif (('files_created' in when) and _checkfiles(when['files_created'], new_files)):
            run_action = True
        elif (('not_exist' in when) and _checknotexists(when['not_exist'])):
            run_action = True
        if (not run_action):
            log.debug('Not running reaction {}'.format(reaction))
            continue
        for action in reaction['execute']:
            log.info('Running action {} in reaction {}'.format(action, reaction))
            if (action in actions):
                if (action not in done_actions):
                    not_after = set()
                    action_item = actions[action]
                    if ('not_after' in action_item):
                        not_after = set(action_item['not_after'])
                    if (len(done_actions.intersection(not_after)) == 0):
                        service_name = os.path.splitext(action)[0]
                        if ('chdir' in action_item):
                            chdir = action_item['chdir']
                            if (not os.path.isabs(chdir)):
                                chdir = os.path.join(base_dir, service_name, chdir)
                        else:
                            chdir = os.path.join(base_dir, service_name)
                        with dirio.SafeChdir(chdir):
                            for command in action_item['commands']:
                                try:
                                    _execute(command, resources)
                                except subprocess.CalledProcessError as e:
                                    log.error('Command {} errored with code {}'.format(command, e.returncode))
                                    raise e
                        done_actions.add(action)
            else:
                raise ValueError('Action {} from reaction {} not in action list'.format(action, reaction))

dataset/ETHPy150Open gosquadron/squadron/squadron/service.py react/original