Esempio n. 1
0
 def create_organism(self, organism_type, schema, identifier=None):
     model = get_any_model(organism_type)
     org = model(community=self, schema=schema)
     if identifier and hasattr(org, "identifier"):
         org.identifier = identifier
     org.save()
     return org
Esempio n. 2
0
 def create_organism(self, organism_type, schema, identifier=None):
     model = get_any_model(organism_type)
     org = model(community=self, schema=schema)
     if identifier and hasattr(org, "identifier"):
         org.identifier = identifier
     org.save()
     return org
Esempio n. 3
0
def manifest(config, *args, **kwargs):
    success = []
    errors = []
    community_model = get_any_model(config.community)
    signature = community_model.get_signature_from_input(*args, **kwargs)
    community_instance = community_model.objects.get_latest_by_signature(
        signature, **kwargs)
    community_path = CommunityView.get_full_path(community_model,
                                                 "/".join(args), kwargs)
    try:
        manifestation = Manifestation.objects.get(uri=community_path)
    except Manifestation.DoesNotExist:
        manifestation = Manifestation(
            uri=community_path,
            community=community_instance,
            config=community_model.get_configuration_from_input(
                *args, **kwargs))
        manifestation.save()
    try:
        manifestation.get_data()
        success.append(manifestation.id)
    except Exception as exc:
        log.error(exc)
        errors.append(manifestation.id)
    return [success, errors]
Esempio n. 4
0
 def get_session(cls, config):  # TODO: test to unlock
     auth_config = config.auth
     login_resource = get_any_model(auth_config["resource"])
     login_credentials = auth_config["credentials"]
     login = login_resource()
     login.post(**login_credentials)
     return login.session
Esempio n. 5
0
    def handle(self, *args, **options):
        Community = get_any_model(options.pop("community"))
        self.model = Community
        self.config = options["config"]
        self.signature = getattr(self, "signature", Community.get_signature_from_input(*args, **self.config))

        community = self.get_community()
        log.info("Signature: {}".format(self.signature))
        log.info("Community: {}".format(community))
        log.info("Start: {}".format(datetime.now()))
        self.handle_community(community, *args, **options)
        log.info("End: {}".format(datetime.now()))
Esempio n. 6
0
    def handle(self, *args, **options):
        Community = get_any_model(options.pop("community"))
        self.model = Community
        self.config = options["config"]
        self.signature = getattr(self, "signature", Community.get_signature_from_input(*args, **self.config))

        community = self.get_community()
        log.info("Signature: {}".format(self.signature))
        log.info("Community: {}".format(community))
        log.info("Start: {}".format(datetime.now()))
        self.handle_community(community, *args, **options)
        log.info("End: {}".format(datetime.now()))
Esempio n. 7
0
def get_resource_link(config, session=None):
    assert isinstance(config, ConfigurationType), \
        "get_resource_link expects a fully prepared ConfigurationType for config"
    Resource = get_any_model(config.resource)
    link = Resource(config=config.to_dict(protected=True))

    if session is not None:
        link.session = session
    assert link.session, "Http resources require a session object to get a link object."
    token = getattr(link.session, "token", None)
    if token:
        link.token = session.token
    # FEATURE: update session to use proxy when configured
    return link
Esempio n. 8
0
def get_resource_link(config, session=None):
    assert isinstance(config, ConfigurationType), \
        "get_resource_link expects a fully prepared ConfigurationType for config"
    Resource = get_any_model(config.resource)
    link = Resource(config=config.to_dict(protected=True))

    if session is not None:
        link.session = session
    assert link.session, "Http resources require a session object to get a link object."
    token = getattr(link.session, "token", None)
    if token:
        link.token = session.token
    # FEATURE: update session to use proxy when configured
    return link
Esempio n. 9
0
def run(config, *args, **kwargs):
    # Set vars
    success = []
    errors = []
    Resource = get_any_model(config.resource)
    cmd = Resource(config=config.to_dict(protected=True))
    # Run the command
    try:
        cmd = cmd.run(*args, **kwargs)
        cmd.clean()
        cmd.save()
        success.append(cmd.id)
    except DSResourceException as exc:
        log.debug(exc)
        cmd = exc.resource
        cmd.clean()
        cmd.save()
        errors.append(cmd.id)

    # Output results in simple type for json serialization
    return [success, errors]
Esempio n. 10
0
def run(config, *args, **kwargs):
    # Set vars
    success = []
    errors = []
    Resource = get_any_model(config.resource)
    cmd = Resource(config=config.to_dict(protected=True))
    # Run the command
    try:
        cmd = cmd.run(*args, **kwargs)
        cmd.clean()
        cmd.save()
        success.append(cmd.id)
    except DSResourceException as exc:
        log.debug(exc)
        cmd = exc.resource
        cmd.clean()
        cmd.save()
        errors.append(cmd.id)

    # Output results in simple type for json serialization
    return [success, errors]
Esempio n. 11
0
def manifest(config, *args, **kwargs):
    success = []
    errors = []
    community_model = get_any_model(config.community)
    signature = community_model.get_signature_from_input(*args, **kwargs)
    try:
        community_instance = community_model.objects.get_latest_by_signature(signature, **kwargs)
    except community_model.DoesNotExist:
        # We can't manifest without a community, so no results effectively
        # But something should not have been calling this task probably
        log.warning("Community of class {} does not have instance with signature {}".format(
            community_model.__class__.__name__,
            signature
        ))
        return [success, errors]
    growth_configuration = community_model.filter_growth_configuration(**kwargs)
    scope_configuration = community_model.filter_scope_configuration(**kwargs)
    configuration = dict(**growth_configuration)
    configuration.update(**scope_configuration)
    uri = CommunityView.get_uri(community_model, "/".join(args), configuration)
    try:
        manifestation = Manifestation.objects.get(uri=uri)
    except Manifestation.DoesNotExist:
        manifestation = Manifestation(
            uri=uri,
            community=community_instance,
            config=community_model.filter_scope_configuration(*args, **kwargs)
        )
        manifestation.save()
    try:
        manifestation.get_data()
        success.append(manifestation.id)
    except Exception as exc:
        log.error("{}".format(exc))
        errors.append(manifestation.id)
    return [success, errors]
Esempio n. 12
0
 def resources(self):
     Resource = get_any_model(self.config.resource)
     Type = ContentType.objects.get_for_model(self)
     return Resource.objects.filter(retainer_type__pk=Type.id,
                                    retainer_id=self.id)
Esempio n. 13
0
 def resources(self):
     Resource = get_any_model(self.config.resource)
     Type = ContentType.objects.get_for_model(self)
     return Resource.objects.filter(retainer_type__pk=Type.id, retainer_id=self.id)
Esempio n. 14
0
 def resource(self):
     if not self._resource:
         self._resource = get_any_model(self.config.resource)
     return self._resource
Esempio n. 15
0
 def resource(self):
     if not self._resource:
         self._resource = get_any_model(self.config.resource)
     return self._resource