Beispiel #1
0
    def __get__(self, instance, cls=None):

        # attempt to get hold of the instance's attribute record
        try:
            return instance._getColumnValue(self.name)

        # instance is None when accessed as a class variable
        except AttributeError:
            # catch bad descriptors or changes in the python conventions
            if instance is not None:
                import journal
                firewall = journal.firewall("pyre.inventory")
                firewall.log("AttributeError on non-None instance. Bad descriptor?")

            # interpret this usage as a request for the trait object itself
            return self

        except KeyError:
            # column value is uinitialized
            return None

        # not reachable
        import journal
        journal.firewall('pyre.db').log("UNREACHABLE")
        return None
Beispiel #2
0
    def __get__(self, instance, cls=None):

        # attempt to get hold of the instance's attribute record
        try:
            return instance._getColumnValue(self.name)

        # instance is None when accessed as a class variable
        except AttributeError:
            # catch bad descriptors or changes in the python conventions
            if instance is not None:
                import journal
                firewall = journal.firewall("pyre.inventory")
                firewall.log(
                    "AttributeError on non-None instance. Bad descriptor?")

            # interpret this usage as a request for the trait object itself
            return self

        except KeyError:
            # column value is uinitialized
            return None

        # not reachable
        import journal
        journal.firewall('pyre.db').log("UNREACHABLE")
        return None
Beispiel #3
0
    def __get__(self, instance, cls=None):

        # attempt to get hold of the instance's attribute record
        try:
            return instance._getColumnValue(self.name)

        # instance is None when accessed as a class variable
        except AttributeError:
            # catch bad descriptors or changes in the python conventions
            if instance is not None:
                import journal
                firewall = journal.firewall("pyre.inventory")
                firewall.log("AttributeError on non-None instance. Bad descriptor?")

            # interpret this usage as a request for the trait object itself
            return self

        except KeyError:
            # look up the registered default value
            default = self.default

            # if we don't have a default, mark this column as uninitialized
            if default is None:
                return default

            # otherwise, store the default as the actual field value
            return instance._setColumnValue(self.name, default)


        # not reachable
        import journal
        journal.firewall('pyre.db').log("UNREACHABLE")
        return None
Beispiel #4
0
    def __init__(self, match, groups):
        Token.__init__(self, match, groups)

        # extract reaction participants
        self._thirdBody = None
        self._falloff = 0

        products = groups["products"].strip()
        self._products, self._externalProduct = self._extractParticipants(products)

        reactants = groups["reactants"].strip()
        self._reactants, self._externalReactant = self._extractParticipants(reactants)

        # extract the reaction type
        arrow = groups["reaction_arrow"]
        if arrow == "=>":
            self._reversibleReaction = 0
        elif arrow == "=" or arrow == "<=>":
            self._reversibleReaction = 1
        else:
            import journal
            journal.firewall("fuego").log("Reaction: Unknown arrow '%s'" % arrow)

        paramList = map(groups.get, self._paramNames)
        try:
            self.arrhenius = map(float, paramList)
        except ValueError:
            # this can't happen because the regexp requires three floats here
            import journal
            str = "Could not convert '%s' into a list of numbers" % paramList
            journal.firewall("fuego").log(str)
            return

        return
Beispiel #5
0
def test():
    """
    Verify that channels lower in the hierarchy inherit their parent default state
    """
    # get the journal
    import journal

    # make a channel
    parent = journal.firewall(name="test.index.parent")
    # verify that the state is on
    assert parent.active is True
    # that it is fatal
    assert parent.fatal is True
    # and the device is at the default value
    assert parent.device is parent.chronicler.device

    # deactivate it
    parent.active = False
    # and make it non fatal
    parent.fatal = False
    # and set the device to a trash can
    parent.device = journal.trash()

    # lookup a name that is lower in the hierarchy
    child = journal.firewall(name="test.index.parent.blah.blah.child")
    # check that its state is the same as the parent
    assert child.active == parent.active
    assert child.fatal == parent.fatal
    # and that it inherited the device correctly
    assert child.device is parent.device

    # all done
    return
Beispiel #6
0
 def processingInstruction(self, target, data):
     import journal
     journal.firewall("pyre.xml.parsing").log(
         "processingInstruction: target={%s}, data={%s}" % (target, data)
         )
     
     return
Beispiel #7
0
    def __get__(self, instance, cls=None):

        # attempt to get hold of the instance's attribute record
        try:
            return instance._getColumnValue(self.name)

        # instance is None when accessed as a class variable
        except AttributeError:
            # catch bad descriptors or changes in the python conventions
            if instance is not None:
                import journal
                firewall = journal.firewall("pyre.inventory")
                firewall.log(
                    "AttributeError on non-None instance. Bad descriptor?")

            # interpret this usage as a request for the trait object itself
            return self

        except KeyError:
            # look up the registered default value
            default = self.default

            # if we don't have a default, mark this column as uninitialized
            if default is None:
                return default

            # otherwise, store the default as the actual field value
            return instance._setColumnValue(self.name, default)

        # not reachable
        import journal
        journal.firewall('pyre.db').log("UNREACHABLE")
        return None
Beispiel #8
0
 def atomicNumber(self, n):
     if n < 1 or n > len(self._atomicNumberIndex):
         import journal
         journal.firewall("pyre.handbook").log(
             "element with atomic number %d not found" % atomicNumber)
         return None
     
     return self._atomicNumberIndex[n-1]
Beispiel #9
0
    def exit(self, pid):
        import sys
        sys.exit(0)

        # unreachable
        import journal
        journal.firewall("pyre.services").log("UNREACHABLE")
        return
Beispiel #10
0
    def exit(self, pid):
        import sys
        sys.exit(0)

        # unreachable
        import journal
        journal.firewall("pyre.services").log("UNREACHABLE")
        return
Beispiel #11
0
 def atomicNumber(self, n):
     if n < 1 or n > len(self._atomicNumberIndex):
         import journal
         journal.firewall("pyre.handbook").log(
             "element with atomic number %d not found" % atomicNumber)
         return None
     
     return self._atomicNumberIndex[n-1]
Beispiel #12
0
    def _set(self, instance, value, locator):
        try:
            return instance._setTraitValue(self.name, value, locator)
        except KeyError:
            return instance._initializeTraitValue(self.name, value, locator)

        # UNREACHABLE
        import journal
        journal.firewall("pyre.inventory").log("UNREACHABLE")
        return
Beispiel #13
0
    def getProperty(self, name, default=''):
        try:
            return self.properties[name].value
        except KeyError:
            return default

        # UNREACHABLE
        import journal
        journal.firewall("inventory").log("UNREACHABLE")
        return
Beispiel #14
0
    def _set(self, instance, value, locator):
        try:
            return instance._setTraitValue(self.name, value, locator)
        except KeyError:
            return instance._initializeTraitValue(self.name, value, locator)

        # UNREACHABLE
        import journal
        journal.firewall("pyre.inventory").log("UNREACHABLE")
        return
Beispiel #15
0
    def updateConfiguration(self, registry):
        # verify that we were handed the correct registry node
        if registry:
            name = registry.name
            if name not in self.aliases:
                import journal
                journal.firewall("inventory").log(
                    "bad registry node: %s != %s" % (name, self.name))

        return Configurable.updateConfiguration(self, registry)
Beispiel #16
0
    def updateConfiguration(self, registry):
        # verify that we were handed the correct registry node
        if registry:
            name = registry.name
            if name not in self.aliases:
                import journal
                journal.firewall("inventory").log(
                    "bad registry node: %s != %s" % (name, self.name))

        return Configurable.updateConfiguration(self, registry)
Beispiel #17
0
    def getProperty(self, name, default=''):
        try:
            return self.properties[name].value
        except KeyError:
            return default

        # UNREACHABLE
        import journal
        journal.firewall("inventory").log("UNREACHABLE")
        return
Beispiel #18
0
    def retrieveComponent(
        self, name, factory, args=(), kwds={}, encoding='odb', vault=[], extraDepositories=[]):
        """retrieve component <name> from the persistent store"""

        if extraDepositories:
            import journal
            journal.firewall("inventory").log("non-null extraDepositories")

        return self._priv_curator.retrieveComponent(
            name=name, facility=factory, args=args, kwds=kwds, encoding=encoding,
            vault=vault, extraDepositories=self._priv_depositories)
Beispiel #19
0
    def retrieveObject(
        self, name, symbol, encodings, vault=[], extraDepositories=[]):
        """retrieve object <name> from the persistent store"""

        if extraDepositories:
            import journal
            journal.firewall("inventory").log("non-null extraDepositories")

        return self._priv_curator.retrieveObject(
            name=name, symbol=symbol, encodings=encodings,
            vault=vault, extraDepositories=self._priv_depositories)
Beispiel #20
0
    def retrieveAllComponents(
        self, factory, args=(), encoding='odb', vault=[], extraDepositories=[]):
        """retrieve all possible components for <factory> from the persistent store"""

        if extraDepositories:
            import journal
            journal.firewall("inventory").log("non-null extraDepositories")

        return self._priv_curator.retrieveAllComponents(
            facility=factory, args=args, encoding=encoding,
            vault=vault, extraDepositories=self._priv_depositories)
Beispiel #21
0
    def endDocument(self):
        line, column = self._locator.getLineNumber(), self._locator.getColumnNumber()
        self._info.log("endDocument at (%d, %d)" % (line, column))

        if self._document != self._currentNode:
            import journal
            journal.firewall("pyre.xml.parsing").log("ooooops!")

        # break a circular reference introduced above
        self._document.locator = None

        return
Beispiel #22
0
    def thermalParametrization(self, type, lowT, highT, locator, parameters):
        if type == "NASA":
            from NASA import NASA
            model = NASA(lowT, highT, locator)
            model.parameters = parameters
        else:
            import journal
            journal.firewall("fuego").log(
                "unknown thermal parametrization type '%s'" % type)
            return

        self.thermo.append(model)
        return
Beispiel #23
0
    def run(self):

        mode = self.inventory.mode
        if mode == "read":
            self.read()
        elif mode == "write":
            registry = self.state()
            self.write(registry)
        else:
            import journal
            journal.firewall(self.name).log("unknown mode '%s'" % mode)

        return
Beispiel #24
0
    def endDocument(self):
        line, column = self._locator.getLineNumber(
        ), self._locator.getColumnNumber()
        self._info.log("endDocument at (%d, %d)" % (line, column))

        if self._document != self._currentNode:
            import journal
            journal.firewall("pyre.xml.parsing").log("ooooops!")

        # break a circular reference introduced above
        self._document.locator = None

        return
Beispiel #25
0
    def _decode(self, match):
        groups = match.groupdict()
        for token in self._tokens:
            if groups[token.__name__]:
                self._info.log("matched token class '%s'" % token.__name__)
                return token(match, groups)

        str = "The text '%s' matched the scanner pattern " % match.group()
        str += "but there is no corresponding token class"
        import journal
        journal.firewall("pyre.parsing").log(str)

        return
    def __init__(self, match, groups):
        Token.__init__(self, match, groups)
        text = map(groups.get, self._patternNames)
        try:
            self.range = tuple(map(float, text))
        except ValueError:
            # this can't happen because the regexp requires a float here
            import journal
            msg = "Can't convert '%s' into a list of numbers" % text
            journal.firewall("fuego").log(msg)
            return

        return
Beispiel #27
0
    def _decode(self, match):
        groups = match.groupdict()
        for token in self._tokens:
            if groups[token.__name__]:
                self._info.log("matched token class '%s'" % token.__name__)
                return token(match, groups)

        str = "The text '%s' matched the scanner pattern " % match.group()
        str += "but there is no corresponding token class"
        import journal
        journal.firewall("pyre.parsing").log(str)

        return
Beispiel #28
0
    def collectCGIInput(self, registry, argv):
        # get access to the environment variables
        import os

        # create a parser for query strings
        parser = self._createCGIParser()

        # figure out the request method
        try:
            method = os.environ['REQUEST_METHOD'].upper()
        except KeyError:
            method = 'GET'

        # extract the headers
        headers = {}
        headers['content-type'] = os.environ.get(
            'CONTENT_TYPE', 'application/x-www-form-urlencoded')
        try:
            headers['content-length'] = os.environ['CONTENT_LENGTH']
        except KeyError:
            pass

        # process arguments from query string
        if method == 'GET' or method == 'HEAD':
            try:
                query = os.environ['QUERY_STRING']
            except KeyError:
                pass
            else:
                parser.parse(registry, query, 'query string')
        elif method == 'POST':
            if headers['content-type'] == 'application/x-www-form-urlencoded':
                import sys
                for line in sys.stdin:
                    parser.parse(registry, line, 'form')
            else:
                import journal
                firewall = journal.firewall('opal')
                firewall.log("NYI: unsupported content-type '%s'" %
                             headers['content-type'])
        else:
            import journal
            journal.firewall('opal').log("unknown method '%s'" % method)

        # if we got commandline arguments, parse them as well
        for arg in argv:
            if arg and arg[0] == '?':
                arg = arg[1:]
            parser.parse(registry, arg, 'command line')

        return
Beispiel #29
0
    def collectCGIInput(self, registry, argv):
        # get access to the environment variables
        import os
        
        # create a parser for query strings
        parser = self._createCGIParser()

        # figure out the request method
        try:
            method = os.environ['REQUEST_METHOD'].upper()
        except KeyError:
            method = 'GET'

        # extract the headers
        headers = {}
        headers['content-type'] = os.environ.get(
            'CONTENT_TYPE', 'application/x-www-form-urlencoded')
        try:
            headers['content-length'] = os.environ['CONTENT_LENGTH']
        except KeyError:
            pass

        # process arguments from query string
        if method == 'GET' or method == 'HEAD':
            try:
                query = os.environ['QUERY_STRING']
            except KeyError:
                pass
            else:
                parser.parse(registry, query, 'query string')
        elif method == 'POST':
            if headers['content-type'] == 'application/x-www-form-urlencoded':
                import sys
                for line in sys.stdin:
                    parser.parse(registry, line, 'form')
            else:
                import journal
                firewall = journal.firewall('opal')
                firewall.log("NYI: unsupported content-type '%s'" % headers['content-type'])
        else:
            import journal
            journal.firewall('opal').log("unknown method '%s'" % method)

        # if we got commandline arguments, parse them as well
        for arg in argv:
            if arg and arg[0] == '?':
                arg = arg[1:]
            parser.parse(registry, arg, 'command line')
            
        return
Beispiel #30
0
    def verify(self, application):
        size = len(self.inventory.fine) + len(self.inventory.coarse)
        nodes = application.inventory.launcher.inventory.nodes

        if nodes != size:
            import journal
            firewall = journal.firewall("layout")
            firewall.log("processor count mismatch: %d != %d" % (nodes, size))

        if nodes < 2:
            import journal
            firewall = journal.firewall("layout")
            firewall.log("'%s' requires at least 2 processors"
                         % application.inventory.name)
        return
Beispiel #31
0
    def _extractCoefficient(self, coefficient):

        # Convert coefficient to an integer
        try:
            c = int(coefficient)
        except TypeError:  # attempt to int(None); set to 1
            c = 1
        except ValueError:
            # this can't happen since t he regexp requires a number
            import journal
            msg = "Could not convert '%s' into a number" % coefficient
            journal.firewall("fuego").log(str)
            return

        return c
Beispiel #32
0
    def __init__(self, name=None):
        if name is None:
            name = "ice"
            
        import journal
        journal.firewall("elc.ICE").log("NYI: this exchanger may not function properly")
        
        SynchronizedExchanger.__init__(self, name)

        self._root = None

        import elc
        self._xdmf = elc.xdmf()

        return
Beispiel #33
0
    def test_firewall(self):
        from journal.diagnostics.Diagnostic import Diagnostic

        firewall = journal.firewall("test")
        with self.assertRaises(Diagnostic.Fatal):
            self._check_journal("firewall.log", "firewall", firewall)
        os.remove("firewall.log")
Beispiel #34
0
    def __init__(self, name=None, **kwds):
        # chain up
        super().__init__(name=name, **kwds)

        # attach my renderer to the console
        import journal
        journal.console.renderer = self.pyre_renderer

        # make a name for my channels
        channel  = self.pyre_namespace or name
        # if I have a name
        if channel:
            # build my channels
            self.debug = journal.debug(channel)
            self.firewall = journal.firewall(channel)
            self.info = journal.info(channel).activate()
            self.warning = journal.warning(channel).activate()
            self.error = journal.error(channel).activate()
            # if i am in debugging mode
            if self.DEBUG:
                # activate the debug channel
                self.debug.active = True

        # sniff around for my environment
        self.pyre_home, self.pyre_prefix, self.pyre_defaults = self.pyre_explore()
        # instantiate my layout
        self.layout = self.pyre_loadLayout()
        # mount my folders
        self.pfs = self.pyre_mountPrivateFilespace()
        # go through my requirements and build my dependency map
        # self.dependencies = self.pyre_resolveDependencies()

        # all done
        return
Beispiel #35
0
    def __prepare__(cls, name, bases, **kwds):
        """
        Prepare a container for the attributes of a chart by looking through {kwds} for sheet
        aliases and making them available as class attributes during the chart
        declaration. This makes it possible to refer to sheets when setting up the chart
        dimensions
        """
        # make a pile of sheets
        sheets = dict(
            # mapping names to sheets
            (name, sheet) for name, sheet in kwds.items()
            # for every entry that is a sheet
            if isinstance(sheet, cls.pyre_tabulator))

        # my machinery is not smart enough to handle charts over multiple sheets. yet.
        if len(sheets) > 1:
            # get the journal
            import journal
            # complain
            raise journal.firewall('pyre.tabular').log('charts need precisely one sheet')

        # remove all the sheets from {kwds}
        for name in sheets: del kwds[name]

        # make the attribute container
        attributes = super().__prepare__(name, bases, **kwds)
        # add the sheets as individual variables
        attributes.update(sheets)
        # and as a name index, if present
        if sheets: attributes['pyre_sheets'] = sheets

        # return the attributes
        return attributes
Beispiel #36
0
    def __get__(self, instance, cls=None):

        # attempt to get hold of the instance's attribute record
        try:
            return instance._getTraitValue(self.name)

        # instance is None when accessed as a class variable
        except AttributeError:
            # catch bad descriptors or changes in the python conventions
            if instance is not None:
                import journal

                firewall = journal.firewall("pyre.inventory")
                firewall.log("AttributeError on non-None instance. Bad descriptor?")

            # interpret this usage as a request for the trait object itself
            return self

        except KeyError:
            # the value of this trait in this instance is uninitialized
            # initialize it and return the default value
            return self._initialize(instance)

        # not reachable
        return None
Beispiel #37
0
    def recognize(cls, entry, follow_symlinks=False):
        """
        The most basic file recognition: convert the name of a file into a {Node} descendant
        and decorate it with all the metadata available on the disk.
        """
        # attempt to
        try:
            # pull the information from the hard filesystem
            meta = entry.stat(follow_symlinks=follow_symlinks)
        # if something goes wrong
        except (FileNotFoundError, NotADirectoryError) as error:
            # there is nothing further to be done
            return None

        # grab my mode
        mode = meta.st_mode

        # lookup the file type
        try:
            # and build the meta-data
            info = cls.filetypes[stat.S_IFMT(mode)]
        # if not there
        except KeyError:
            # we have a bug
            import journal
            # build a message
            msg = "'{}': unknown file type: mode={}".format(entry, mode)
            # and complain
            return journal.firewall("pyre.filesystem").log(msg)

        # if successful, build an info node and return it
        return info(uri=entry, info=meta)
Beispiel #38
0
    def __get__(self, instance, cls=None):

        # attempt to get hold of the instance's attribute record
        try:
            return instance._getTraitValue(self.name)

        # instance is None when accessed as a class variable
        except AttributeError:
            # catch bad descriptors or changes in the python conventions
            if instance is not None:
                import journal
                firewall = journal.firewall("pyre.inventory")
                firewall.log(
                    "AttributeError on non-None instance. Bad descriptor?")

            # interpret this usage as a request for the trait object itself
            return self

        except KeyError:
            # the value of this trait in this instance is uninitialized
            # initialize it and return the default value
            return self._initialize(instance)

        # not reachable
        return None
Beispiel #39
0
    def __init__(self, name=None, **kwds):
        # chain up
        super().__init__(name=name, **kwds)

        # set up my nickname
        nickname = self.pyre_namespace or name

        # if i have one
        if nickname:
            # register it with the journal
            journal.application(name=nickname)

            # build my channels
            self.debug = journal.debug(nickname)
            self.firewall = journal.firewall(nickname)
            self.info = journal.info(nickname).activate()
            self.warning = journal.warning(nickname).activate()
            self.error = journal.error(nickname).activate()
            # if i am in debugging mode
            if self.DEBUG:
                # activate the debug channel
                self.debug.active = True

        # sniff around for my environment
        self.pyre_home, self.pyre_prefix, self.pyre_defaults = self.pyre_explore(
        )
        # instantiate my layout
        self.layout = self.pyre_loadLayout()
        # mount my folders
        self.pfs = self.pyre_mountPrivateFilespace()
        # go through my requirements and build my dependency map
        # self.dependencies = self.pyre_resolveDependencies()

        # all done
        return
Beispiel #40
0
def test():
    """
    Verify we can make firewalls non-fatal
    """
    # get the journal
    import journal

    # make a firewall channel
    channel = journal.firewall(name="tests.journal.firewall")
    # make it non-fatal
    channel.fatal = False
    # send the output to the trash
    channel.device = journal.trash()
    # add some metadata
    channel.notes["time"] = "now"

    # carefully
    try:
        # inject
        channel.line("firewall:")
        channel.log("    a nasty bug was detected")
    # if the correct exception was raised
    except channel.FirewallError as error:
        # shouldn't get here
        assert False, "unreachable"

    # all done
    return
Beispiel #41
0
    def recognize(cls, entry, follow_symlinks=False):
        """
        The most basic file recognition: convert the name of a file into a {Node} descendant
        and decorate it with all the metadata available on the disk.
        """
        # attempt to
        try:
            # pull the information from the hard filesystem
            meta = entry.stat(follow_symlinks=follow_symlinks)
        # if something goes wrong
        except (FileNotFoundError, NotADirectoryError) as error:
            # there is nothing further to be done
            return None

        # grab my mode
        mode = meta.st_mode

        # lookup the file type
        try:
            # and build the meta-data
            info = cls.filetypes[stat.S_IFMT(mode)]
        # if not there
        except KeyError:
            # we have a bug
            import journal
            # build a message
            msg = "'{}': unknown file type: mode={}".format(entry, mode)
            # and complain
            return journal.firewall("pyre.filesystem").log(msg)

        # if successful, build an info node and return it
        return info(uri=entry, info=meta)
Beispiel #42
0
    def fillNodeId(model, key=None, name=None, split=None):
        """
        Given one of the three representations of the key of a node in {model}, reconstruct all of
        them so clients can choose whichever representation fits their needs
        """
        # if I know the name but not the split version
        if name and not split:
            # set the split
            split = tuple(model.split(name))
        # otherwise, if I know the split but not the name
        elif split and not name:
            # get the name
            name = model.join(*split)

        # if I don't know the key but I know the split
        if split and not key:
            # look up the key
            key = model._hash.hash(items=split)

        # done my best: if i know the key
        if key:
            # return the info
            return name, split, key

        # otherwise, get the journal
        import journal
        # and complain; this is a bug
        raise journal.firewall('pyre.calc').log('insufficient nodal metadata')
Beispiel #43
0
def test():
    """
    Exercise the common use case
    """
    # get the journal
    import journal

    # make a channel
    channel = journal.firewall(name="test.journal.firewall")
    # send the output to the trash
    channel.device = journal.trash()
    # add some metadata
    channel.notes["time"] = "now"

    # carefully
    try:
        # inject
        channel.line("firewall:")
        channel.log("    a nasty bug was detected")
        # shouldn't get here
        assert False, "unreachable"
    # if the correct exception was raised
    except channel.FirewallError as error:
        # check the description
        assert str(error) == "test.journal.firewall: FIREWALL BREACHED!"

    # all done
    return
Beispiel #44
0
 def check_duplicated(self, group):
     s = set(group)
     if len(s) != len(group):
         import journal
         firewall = journal.firewall("layout")
         firewall.log('Duplicated element in group: %s' % group)
     return
Beispiel #45
0
    def _getDefaultValue(self, instance):
        component = self.default

        # build a default locator
        import pyre.parsing.locators
        here = pyre.parsing.locators.simple('default')

        if component is not None:
            # if we got a string, resolve
            if isinstance(component, basestring):
                component, locator = self._retrieveComponent(instance, component, args=())
                here = pyre.parsing.locators.chain(locator, here)
                
            return component, here

        if self.factory is not None:
            # instantiate the component
            component =  self.factory(*self.args)
            # adjust the configuration aliases to include my name
            aliases = component.aliases
            if self.name not in aliases:
                aliases.append(self.name)
            
            # build a default locator
            import pyre.parsing.locators
            locator = pyre.parsing.locators.simple('default')
            # return
            return component, locator

        # oops: expect exceptions galore!
        import journal
        firewall = journal.firewall('pyre.inventory')
        firewall.log(
            "facility %r was given neither a default value nor a factory method" % self.name)
        return None, None
Beispiel #46
0
def test():
    """
    Verify that flushing clears the message buffers
    """
    # get the journal
    import journal

    # make a channel
    channel = journal.firewall(name="test.journal.firewall")
    # send the output to the trash
    channel.device = journal.trash()

    # carefully
    try:
        # inject
        channel.log("hello world!")
        # shouldn't get here
        assert False, "unreachable"
    # if the correct exception was raised
    except channel.FirewallError as error:
        # no problem
        pass

    # verify that the buffer is empty after the flush
    assert len(channel.page) == 0

    # all done
    return
Beispiel #47
0
    def pyre_isCompatible(cls, spec, fast=True):
        """
        Check whether {this} protocol is compatible with the {other}
        """
        # print("PP: me={}, other={}".format(cls, spec))
        # first, the easy cases am i looking in the mirror?
        if cls == spec:
            # easy; no need to build a report since the rest of the code is not supposed to
            # touch the report unless it evaluates to {False}
            return True

        # i am never compatible with components...
        if spec.pyre_isComponent:
            # in fact, let's treat asking the question as a bug
            import journal
            # so complain
            raise journal.firewall('pyre.components').log(
                'PC compatibility checks are not supported')

        # do the assignment compatibility check
        report = super().pyre_isCompatible(spec=spec, fast=fast)
        # if we are in fast mode and got an error
        if fast and report:
            # all done
            return report

        # all done
        return report
Beispiel #48
0
    def __init__(self, name=None, **kwds):
        # chain up
        super().__init__(name=name, **kwds)

        # attach my renderer to the console
        import journal
        journal.console.renderer = self.pyre_renderer

        # make a name for my channels
        channel = self.pyre_namespace or name
        # if I have a name
        if channel:
            # build my channels
            self.debug = journal.debug(channel)
            self.firewall = journal.firewall(channel)
            self.info = journal.info(channel).activate()
            self.warning = journal.warning(channel).activate()
            self.error = journal.error(channel).activate()
            # if i am in debugging mode
            if self.DEBUG:
                # activate the debug channel
                self.debug.active = True

        # sniff around for my environment
        self.pyre_home, self.pyre_prefix, self.pyre_defaults = self.pyre_explore(
        )
        # instantiate my layout
        self.layout = self.pyre_loadLayout()
        # mount my folders
        self.pfs = self.pyre_mountPrivateFilespace()
        # go through my requirements and build my dependency map
        # self.dependencies = self.pyre_resolveDependencies()

        # all done
        return
Beispiel #49
0
 def check_duplicated(self, group):
     s = set(group)
     if len(s) != len(group):
         import journal
         firewall = journal.firewall("layout")
         firewall.log('Duplicated element in group: %s' % group)
     return
Beispiel #50
0
    def __prepare__(cls, name, bases, **kwds):
        """
        Prepare a container for the attributes of a chart by looking through {kwds} for sheet
        aliases and making them available as class attributes during the chart
        declaration. This makes it possible to refer to sheets when setting up the chart
        dimensions
        """
        # make a pile of sheets
        sheets = dict(
            # mapping names to sheets
            (name, sheet) for name, sheet in kwds.items()
            # for every entry that is a sheet
            if isinstance(sheet, cls.pyre_tabulator))

        # my machinery is not smart enough to handle charts over multiple sheets. yet.
        if len(sheets) > 1:
            # get the journal
            import journal
            # complain
            raise journal.firewall('pyre.tabular').log(
                'charts need precisely one sheet')

        # remove all the sheets from {kwds}
        for name in sheets:
            del kwds[name]

        # make the attribute container
        attributes = super().__prepare__(name, bases, **kwds)
        # add the sheets as individual variables
        attributes.update(sheets)
        # and as a name index, if present
        if sheets: attributes['pyre_sheets'] = sheets

        # return the attributes
        return attributes
Beispiel #51
0
    def __getattr__(self, name):
        """
        Trap attribute lookup errors and attempt to resolve the name in my inventory's name
        map. This makes it possible to get the value of a trait by using any of its aliases.
        """
        # attempt to
        try:
            # normalize the name
            normal = self.pyre_namemap[name]
        # if it's not one of my traits
        except KeyError:
            # get someone else to do the work
            raise AttributeError(f"{self} has no attribute '{name}'") from None

        # if the normalized name is the same as the original
        if normal == name:
            # nothing further to do but complain: this is almost certainly a framework bug;
            # build an error message
            error = self.TraitNotFoundError(configurable=self, name=name)
            # get the journal
            import journal
            # complain
            raise journal.firewall('pyre.components').log(str(error))

        # if we got this far, restart the attribute lookup using the canonical name
        # N.B.: don't be smart here; let {getattr} do its job, which involves invoking the
        # trait descriptors if necessary
        return getattr(self, normal)
Beispiel #52
0
    def pyre_isCompatible(cls, spec, fast=True):
        """
        Check whether {this} protocol is compatible with the {other}
        """
        # print("PP: me={}, other={}".format(cls, spec))
        # first, the easy cases am i looking in the mirror?
        if cls == spec:
            # easy; no need to build a report since the rest of the code is not supposed to
            # touch the report unless it evaluates to {False}
            return True

        # i am never compatible with components...
        if spec.pyre_isComponent:
            # in fact, let's treat asking the question as a bug
            import journal
            # so complain
            raise journal.firewall('pyre.components').log(
                'PC compatibility checks are not supported')

        # do the assignment compatibility check
        report = super().pyre_isCompatible(spec=spec, fast=fast)
        # if we are in fast mode and got an error
        if fast and report:
            # all done
            return report

        # all done
        return report
Beispiel #53
0
    def _getDefaultValue(self, instance):
        component = self.default

        # build a default locator
        import pyre.parsing.locators
        here = pyre.parsing.locators.simple('default')

        if component is not None:
            # if we got a string, resolve
            if isinstance(component, basestring):
                component, locator = self._retrieveComponent(instance, component)
                here = pyre.parsing.locators.chain(locator, here)
                
            return component, here

        if self.factory is not None:
            # instantiate the component
            component =  self.factory(*self.args)
            # adjust the configuration aliases to include my name
            aliases = component.aliases
            if self.name not in aliases:
                aliases.append(self.name)
            
            # build a default locator
            import pyre.parsing.locators
            locator = pyre.parsing.locators.simple('default')
            # return
            return component, locator

        # oops: expect exceptions galore!
        import journal
        firewall = journal.firewall('pyre.inventory')
        firewall.log(
            "facility %r was given neither a default value nor a factory method" % self.name)
        return None, None
Beispiel #54
0
    def read(self, input):
        self._info.log("reading from '%s' -- assuming ASCII Tecplot format" %
                       input.name)

        while 1:
            line = input.readline()
            if not line:
                break

            tokens = line.split()

            name = tokens[0].lower()
            if name == "title":
                value = line.split(" = ")[1]
                self.title = value.strip()
                self._info.log("title = {%s}" % self.title)
            elif name == "variables":
                value = line.split(" = ")[1]
                self.variables = value.split()
                self._info.log("variables = %r" % self.variables)
            elif name == "zone":
                self._zone(line, input)
            else:
                import journal
                firewall = journal.firewall("tecplot")
                firewall.log("unsupported tecplot tag '%s'" % name)
                return

        return
Beispiel #55
0
 def check_disjoint(self, group0, group1):
     s0 = set(group0)
     s1 = set(group1)
     if s0.intersection(s1):
         import journal
         firewall = journal.firewall("layout")
         firewall.log('Groups are not disjoint: %s and %s' % (group0, group1))
     return
Beispiel #56
0
 def __get__(self, chart, cls):
     # if i am being accessed through an instance
     if chart:
         # get the journal
         import journal
         # complain
         raise journal.firewall('pyre.tabular').log(
             "dimensions can't operate on chart instances")
     # otherwise
     return self
def test():
    # access the package
    import journal
    # build a firewall channel
    firewall = journal.firewall("journal.test1")
    # deactivate it
    firewall.active = False

    # and make it say something
    firewall.log("hello world!")

    # all done
    return
Beispiel #58
0
def test():
    # access the package
    import journal
    # build a firewall channel
    firewall = journal.firewall("journal.test1")
    # verify that it is on by default
    assert firewall.active == True
    # disable it
    firewall.active = False

    # access the same channel through another object
    clone = journal.firewall("journal.test1")
    # verify that it is now off
    assert clone.active == False

    # build a firewall channel with a different name
    another = journal.firewall("journal.test2")
    # verify that it is on by default, to make sure that there is no crosstalk between channels
    assert another.active == True

    # all done
    return
Beispiel #59
0
	def findLayout( self, layout ):
		if layout.coarse:
			self.inventory.solver = self.inventory.coarse
			self.inventory.controller = self.inventory.coarseController
			self.inventory.exchanger = self.inventory.cge
			self.solverCommunicator = layout.coarse #self._CommWorld
			self.myPlus = layout.coarsePlus
			self.remotePlus = layout.finePlus
		elif layout.fine:
			self.inventory.solver = self.inventory.fine
			self.inventory.controller = self.inventory.fineController
			self.inventory.exchanger = self.inventory.fge
			self.solverCommunicator = layout.fine #layout
			self.myPlus = layout.finePlus
			self.remotePlus = layout.coarsePlus
		else:
			import journal
			journal.firewall( self.name ).log( "node '%d' is an orphan" % layout.rank )

		self.solver = self.inventory.solver
		self.controller = self.inventory.controller
		self.exchanger = self.inventory.exchanger
		return
Beispiel #60
0
def createSymbolIndex(elements):
    index = {}

    # place all element in the index
    for element in elements:
        index[element.symbol] = element

    # detect collisions
    if len(elements) != len(index):
        import journal
        firewall = journal.firewall("handbook")
        firewall.log(
            "PeriodicTable: symbol index size mismatch: %d != %d" % (len(index), len(elements)))

    return index