Пример #1
0
def cli(json):
    base_dir = find_project_basedir('.')
    load_all_from(base_dir)

    actors = [actor for actor in get_actors() if is_local(base_dir, actor)]
    models = [model for model in get_models() if is_local(base_dir, model)]
    channels = [
        channel for channel in get_channels() if is_local(base_dir, channel)
    ]
    if not json:
        print_group('Models', models)
        print_group('Channels', channels)
        print_group('Actors', actors)
    else:
        output = {
            'project': get_project_name(base_dir),
            'base_dir': base_dir,
            'channels': {
                channel.__name__: get_channel_details(channel)
                for channel in channels
            },
            'models':
            {model.__name__: get_model_details(model)
             for model in models},
            'actors':
            {actor.__name__: get_actor_details(actor)
             for actor in actors}
        }
        json_mod.dump(output, sys.stdout, indent=2)
Пример #2
0
 def _do_run(stdin, logger, messaging, definition, args, kwargs):
     sys.stdin = os.fdopen(stdin)
     definition.load()
     with definition.injected_context():
         target_actor = [
             actor for actor in get_actors()
             if actor.name == definition.name
         ][0]
         target_actor(logger=logger,
                      messaging=messaging).run(*args, **kwargs)
Пример #3
0
def _with_loaded_actor(repository, actor_name, messaging=None):
    definition = repository.lookup_actor(actor_name)
    with py.path.local(definition.full_path).as_cwd():
        # Ensure environmental cleanup after the test
        with definition.injected_context():
            # Load the actor class
            definition.load()
            # Lookup the actor class
            actor = [a for a in get_actors() if a.name == definition.name][0]
            yield (definition, actor(messaging=messaging, logger=logging.getLogger('root')))
Пример #4
0
 def _do_run(stdin, logger, messaging, definition, config_model, skip_dialogs, args, kwargs):
     if stdin is not None:
         try:
             sys.stdin = os.fdopen(stdin)
         except OSError:
             pass
     definition.load()
     with definition.injected_context():
         target_actor = [actor for actor in get_actors() if actor.name == definition.name][0]
         target_actor(logger=logger, messaging=messaging, config_model=config_model,
                      skip_dialogs=skip_dialogs).run(*args, **kwargs)
Пример #5
0
def cli(actor_name, discard_output, print_output):
    basedir = find_project_basedir('.')
    load_all_from(basedir)
    channels = RunChannels()
    channels.load()
    [actor for actor in get_actors()
     if actor.name == actor_name][0](channels=channels).process()
    if not discard_output:
        channels.store()
    if print_output:
        json.dump(channels.get_new(), sys.stdout, indent=2)
Пример #6
0
def inspect_actor(definition, result_queue):
    """
    Retrieves the actor information in a child process and returns the results back through `result_queue`.

    :param definition: the actor definition to load
    :type definition: :py:class:`ActorDefinition`
    :param result_queue: queue to pass results back to the calling process
    :type result_queue: :py:class:`multiprocessing.Queue`
    """
    definition.load()
    result = [get_actor_metadata(actor) for actor in get_actors()]
    result = [entry for entry in result if entry['path'] in definition.full_path]
    result_queue.put(result)
Пример #7
0
 def _do_run(stdin, logger, messaging, definition, config_model,
             skip_dialogs, args, kwargs):
     if stdin is not None:
         try:
             sys.stdin = os.fdopen(stdin)
         except OSError:
             pass
     with warnings.catch_warnings(record=True) as recording:
         warnings.simplefilter(action="always",
                               category=_LeappDeprecationWarning)
         definition.load()
         with definition.injected_context():
             target_actor = [
                 actor for actor in get_actors()
                 if actor.name == definition.name
             ][0]
             actor_instance = target_actor(logger=logger,
                                           messaging=messaging,
                                           config_model=config_model,
                                           skip_dialogs=skip_dialogs)
             actor_instance.run(*args, **kwargs)
         try:
             # By this time this is no longer set, so we have to get it back
             os.environ['LEAPP_CURRENT_ACTOR'] = actor_instance.name
             for rec in recording:
                 if issubclass(rec.category, _LeappDeprecationWarning):
                     entry = {
                         'message':
                         str(rec.message),
                         'filename':
                         rec.filename,
                         'line':
                         linecache.getline(rec.filename, rec.lineno)
                         if rec.line is None else rec.line,
                         'lineno':
                         rec.lineno,
                         'since':
                         rec.category.since,
                         'reason':
                         rec.category.msg
                     }
                     create_audit_entry('deprecation', entry)
         finally:
             # Remove it again
             os.environ.pop('LEAPP_CURRENT_ACTOR')
Пример #8
0
def setup_module(module):
    for actor in get_actors():
        for tag in actor.tags:
            tag.actors = tag.actors + (actor, )
Пример #9
0
 def _do_run(logger, messaging, definition, args, kwargs):
     definition.load()
     get_actors()[0](logger=logger,
                     messaging=messaging).run(*args, **kwargs)
Пример #10
0
def inspect_actor(definition, result_queue):
    definition.load()
    result_queue.put([get_actor_metadata(actor) for actor in get_actors()])