Пример #1
0
    def loc_max_users(self, value):
        """
        Creates a uniform probability distribution for the given value. If the
        value is an integer, then it will return that value constantly. If it
        is a range, it will return the uniform distribution.

        If the value is None, it will look the value up in the configuration.
        """
        value = value or settings.simulation.max_users_location

        if value is None: return None

        if isinstance(value, int):
            return Uniform(value, value)

        if isinstance(value, (tuple, list)):
            if len(value) != 2:
                raise ImproperlyConfigured(
                    "Specify the max users per location as a range: (min, max)"
                )
            return Uniform(*value)

        else:
            raise ImproperlyConfigured(
                "Specify the maximum number of users per location as a "
                "constant or uniform random range (or None).")
Пример #2
0
    def __init__(self, **kwargs):
        self.logger = ServerLogger()
        self.htdocs = kwargs.get('htdocs', settings.site.htdocs)

        if not os.path.exists(self.htdocs):
            raise ImproperlyConfigured(
                "Root web directory, {!r} does not exist!".format(self.htdocs))

        if not os.path.isdir(self.htdocs):
            raise ImproperlyConfigured(
                "Web docs root, {!r} is not a directory!".format(self.htdocs))

        self.addr = kwargs.get('addr', settings.server.address)
        self.port = kwargs.get('port', settings.server.port)

        HTTPServer.__init__(self, (self.addr, self.port), CloudScopeHandler)
Пример #3
0
def replica_factory(simulation, **kwargs):
    """
    Factory to create a replica with the correct type, based on consistency.
    """
    # Determine the consistency level of the simulation
    consistency = Consistency.get(
        kwargs.get('consistency', settings.simulation.default_consistency))

    # Determine the integration level of the simulation
    integration = settings.simulation.integration
    if integration not in ReplicaTypes:
        raise ImproperlyConfigured(
            'Integration "{}" not recognized, use one of {}'.format(
                integration, ", ".join(ReplicaTypes.keys())))

    # Check that the desired consistenty matches the integration level
    # If not fall back to the default replica type with a warning
    if consistency not in ReplicaTypes[integration]:
        simulation.logger.warn(
            'Consistency level "{}" not implemented in {}'.format(
                consistency, integration))
        integration = 'default'

    # Return a replica with the given consistency level for the integration.
    return ReplicaTypes[integration][consistency](simulation, **kwargs)
Пример #4
0
 def get_template(self):
     """
     Uses Jinja2 to fetch the template from the environment
     """
     if self.template_name is None:
         raise ImproperlyConfigured(
             "Pages requires either a definition of template_name "
             "or an implementation of get_template on the subclass.")
     return self.environment.get_template(self.template_name)
Пример #5
0
    def n_objects(self, value):
        """
        Creates a uniform probability distribution for the given value. If the
        value is an integer, then it will return that value constantly. If it
        is a range, it will return the uniform distribution.

        If the value is None, it will look the value up in the configuration.
        """
        value = value or settings.simulation.max_objects_accessed

        if isinstance(value, int):
            return Uniform(value, value)

        if isinstance(value, (tuple, list)):
            if len(value) != 2:
                raise ImproperlyConfigured(
                    "Specify the number of objects as a range: (min, max)")
            return Uniform(*value)

        else:
            raise ImproperlyConfigured(
                "Specify the number of objects as a constant "
                "or uniform random range.")
Пример #6
0
    def get_version_class(self):
        """
        Returns the class type for the version.
        """
        klass = {
            'default': Version,
            'lamport': LamportVersion,
            'federated': FederatedVersion,
        }.get(settings.simulation.versioning, None)

        if klass is None:
            raise ImproperlyConfigured(
                "'{}' is not a valid versioning method.".format(
                    settings.simulation.versioning))

        return klass
Пример #7
0
    def get_url_path(self):
        """
        Returns the file path to render the page to based on the static
        location and the page_url_path property set on the class.
        """
        if self.page_url_path is None:
            raise ImproperlyConfigured(
                "Pages requires either a definition of page_url_path "
                "or an implementation of get_url_path on the subclass.")

        path = self.page_url_path

        # Create index.html files for pretty urls
        if path.endswith('/'):
            path += "index.html"

        return os.path.join(settings.site.htdocs, path)