def onSink(self): import journal journal.debug("elc.exchange").activate() self.coupler.exchangeBoundary() return
def load(filename, format=None, mechanism=None): import journal journal.debug("fuego").log("loading file '%s', format='%s')" % (filename, format)) if not mechanism: from mechanisms.Mechanism import Mechanism mechanism = Mechanism(filename) # patrickh else: mechanism._name = filename if not format: format = guessMechanismType(filename) factory = registrar().find(format) if not factory: journal.error("fuego").log("unknown mechanism file format '%s'" % format) return None parser = factory.parser() file = locate(filename) parser.parse(mechanism, file) return mechanism
class Mesh(object): def read(self, simplices, file): count = 0 self._info.log("scanning for simplices") while count < simplices: self._dump.log("processing simplex %d" % count) simplex = [ (int(node) - 1) for node in file.readline().split() ] self.simplices.append(simplex) count += 1 self._info.log("read %d simplices" % count) return def __init__(self): self.simplices = [] return import journal _info = journal.debug("tecplot") _dump = journal.debug("tecplot.scanning")
def findRetriever(Computation, depositories): candidates = [] for depository in depositories: package = ['vnf', 'components'] if depository: package.append(depository) package += ['computation_result_retrievers'] package = '.'.join(package) module = Computation.__name__ code = 'from %s.%s import Retriever' % (package, module) try: print code exec code in locals() except: import journal import traceback journal.debug('main').log(traceback.format_exc()) continue candidates.append(Retriever) continue l = filter(lambda Retriever: Retriever.Computation == Computation, candidates) if len(l) != 1: if not len(l): raise RuntimeError, 'No result retriever found for computation %s' % Computation if len(l) > 1: raise RuntimeError, 'More than one result retrievers for computation %s exist' % Computation return l[0]
def main(): from opal.applications.CGI import CGI class CmdlineApp(CGI): def main(self): import os import sys print '<pre>' print sys.argv print '</pre>' print '<pre>' for key, value in os.environ.iteritems(): print ' %s = {%s}' % (key, value) print '</pre>' print '<pre>' print self.registry.render() print '</pre>' return def __init__(self): CGI.__init__(self, 'cmdline') return import journal journal.info('opal.cmdline').activate() journal.debug('opal.commandline').activate() app = CmdlineApp() return app.run()
def findRetriever(Computation, depositories): candidates = [] for depository in depositories: package = ['vnf', 'components'] if depository: package.append(depository) package += ['computation_result_retrievers'] package = '.'.join(package) module = Computation.__name__ code = 'from %s.%s import Retriever' % (package, module) try: print code exec code in locals() except: import journal import traceback journal.debug('main').log(traceback.format_exc()) continue candidates.append(Retriever) continue l = filter(lambda Retriever: Retriever.Computation==Computation, candidates) if len(l) != 1: if not len(l): raise RuntimeError, 'No result retriever found for computation %s' % Computation if len(l) > 1: raise RuntimeError, 'More than one result retrievers for computation %s exist' % Computation return l[0]
class Nodal(object): def read(self, points, fields, input): for zone in fields: self.fields[zone] = [] count = 0 self._info.log("scanning for %d points" % points) while 1: line = input.readline() self._dump.log("processing point %d" % count) tokens = line.split() for zone, value in map(None, fields, tokens): self.fields[zone].append(float(value)) count += 1 if count == points: break self._info.log("read %d nodes" % count) return def __init__(self): self.fields = {} return import journal _info = journal.debug("tecplot") _dump = journal.debug("tecplot.scanning")
def test(): """ Verify that channels lower in the hierarchy inherit their parent default state """ # get the journal import journal # make a channel parent = journal.debug(name="test.index.parent") # verify that the state is off assert parent.active is False # and that is not fatal assert parent.fatal is False # and the device is at the default value assert parent.device is parent.chronicler.device # activate it parent.active = True # and make it fatal parent.fatal = True # and set the device to a trash can parent.device = journal.trash() # lookup a name that is lower in the hierarchy child = journal.debug(name="test.index.parent.blah.blah.child") # that it's active 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
def main(): #debug.activate() journal.debug('periodicdispersion_3d').activate() pytests = pysuite() alltests = unittest.TestSuite( (pytests, ) ) res = unittest.TextTestRunner(verbosity=2).run(alltests) import sys; sys.exit(not res.wasSuccessful())
def onServer(self): name = 'journal' # turn on my channels so we can watch what happens import journal journal.info(name).activate() journal.debug(name).activate() # build the registry settings registry = self.createRegistry() registry.name = 'root' node = registry.getNode(name) node.setProperty('port', self.port, self.inventory.getTraitDescriptor('port').locator) marshaller = node.getNode('marshaller') marshaller.setProperty('key', self.key, None) # instantiate the services service = journal.service(name) # configure it self.configureComponent(service, registry) # initialize it service.init() # enter the indefinite loop waiting for requests service.serve() return
def main(): from opal.applications.CGI import CGI class HelloApp(CGI): class Inventory(CGI.Inventory): import pyre.inventory name = pyre.inventory.str("name", default="world") name.meta['tip'] = "the target of the greeting" def main(self): import os pid = os.getpid() euid = os.geteuid() uid = os.getuid() print '<pre>' print 'content: {%s}' % self.content print "(%d, %s): Hello %s!" % (pid, uid, self.inventory.name) print '</pre>' return def __init__(self): CGI.__init__(self, 'hello') return import journal journal.info('opal.cmdline').activate() journal.debug('opal.commandline').activate() app = HelloApp() return app.run()
def _import(): try: import BoostPythonBinding except: import warnings, journal, traceback warnings.warn('binding not imported') journal.debug('BoostPythonBinding').log(traceback.format_exc()) return
def main(): import journal journal.debug("instrument.visitors.Instrument2VisualElements") from instrument.applications.InstrumentEditor.MainWinApp import MainWinApp mainWin = MainWinApp() mainWin.MainLoop() return
def main(): #debug.activate() import journal journal.debug("Event2QE").activate() pytests = pysuite() alltests = unittest.TestSuite( (pytests, ) ) res = unittest.TextTestRunner(verbosity=2).run(alltests) import sys; sys.exit(not res.wasSuccessful())
def main(): #debug.activate() journal.debug('phonon_incoherent_inelastic_kernel').activate() #journal.debug('random').activate() pytests = pysuite() alltests = unittest.TestSuite( (pytests, ) ) res = unittest.TextTestRunner(verbosity=2).run(alltests) import sys; sys.exit(not res.wasSuccessful())
def main(): #debug.activate() journal.debug('phonon_incoherent_inelastic_kernel').activate() #journal.debug('random').activate() pytests = pysuite() alltests = unittest.TestSuite((pytests, )) res = unittest.TextTestRunner(verbosity=2).run(alltests) import sys sys.exit(not res.wasSuccessful())
def main(): #debug.activate() import journal journal.debug("Event2QE").activate() pytests = pysuite() alltests = unittest.TestSuite((pytests, )) res = unittest.TextTestRunner(verbosity=2).run(alltests) import sys sys.exit(not res.wasSuccessful())
def main(): import journal journal.info('ssher').activate() journal.debug('dds').activate() pytests = pysuite() alltests = unittest.TestSuite((pytests, )) unittest.TextTestRunner(verbosity=2).run(alltests) return
def main(): # debug.activate() journal.debug("periodicdispersion_3d").activate() pytests = pysuite() alltests = unittest.TestSuite((pytests,)) res = unittest.TextTestRunner(verbosity=2).run(alltests) import sys sys.exit(not res.wasSuccessful())
def main(self, *args, **kwds): debugOn = journal.debug("debug_on") debugOn.activate() debugOn.log("This journal should be on.") debugOn.deactivate() debugOn.log("This journal should be off.") debugOff = journal.debug("debug_off") debugOff.log("This journal should be off.")
def test(): import journal journal.debug("pyre.geometry").activate() import pyre.geometry mesh = pyre.geometry.mesh(dim=3, order=3) return
def main(): import os curdir = os.path.abspath( '.' ) import sys sys.path = [curdir] + sys.path import journal journal.debug( 'gml-wx-renderer' ).activate() run( 'wx', ['main.gml', 'hello.gml' ] ) return
def onChild(pid, fromparent, toparent): try: response = self._server._marshaled_dispatch(data) self._sendResponse(response) line = fromparent.readline() toparent.write('done\n') toparent.flush() except: journal.debug('pathos').log(print_exc_info()) os._exit(0)
def main(): #debug.activate() #journal.debug("CompositeNeutronScatterer_Impl").activate() journal.warning('mcstas2.parsers.ComponentInfo').deactivate() # comment out this line to hide the error msg in searching for component journal.debug("mcstas2.pyre_support").activate() import mcstas2.mcstas2bp pytests = pysuite() alltests = unittest.TestSuite( (pytests, ) ) res = unittest.TextTestRunner(verbosity=2).run(alltests) import sys; sys.exit(not res.wasSuccessful())
def main(): name = 'harness' import journal journal.info(name).activate() journal.debug(name).activate() from pyre.applications.ServiceHarness import ServiceHarness app = ServiceHarness(name) return app.run()
def main(): #debug.activate() #journal.debug("CompositeNeutronScatterer_Impl").activate() journal.warning('mcstas2.parsers.ComponentInfo').deactivate() # comment out this line to hide the error msg in searching for component journal.debug("mcstas2.pyre_support").activate() import mcstas2.mcstas2bp pytests = pysuite() alltests = unittest.TestSuite((pytests, )) res = unittest.TextTestRunner(verbosity=2).run(alltests) import sys sys.exit(not res.wasSuccessful())
def main(): from opal.applications.CGI import CGI class LoginApp(CGI): class Inventory(CGI.Inventory): import pyre.inventory username = pyre.inventory.str("username") password = pyre.inventory.str("password") def main(self): import os import sys print '<pre>' print sys.argv print '</pre>' print '<pre>' for key, value in os.environ.iteritems(): print ' %s = {%s}' % (key, value) print '</pre>' print '<pre>' print self.registry.render() print "username:"******"password:"******"This is an info message") self._debug.log("This is a debug message") return def __init__(self): CGI.__init__(self, 'login') return import journal journal.debug('opal.commandline').activate() app = LoginApp() return app.run()
class Scanner(object): def match(self, text, column): match = self._scanner.match(text, column) if not match: return None return self._decode(match) def __init__(self): self._tokens = self._tokenClasses() self._scanner = self._constructTokenRecognizer() return def _tokenClasses(self): raise NotImplementedError("class '%s' must override '_tokenClasses'" % self.__class__.__name__) def _constructTokenRecognizer(self): import re patterns = [ "(?P<%s>%s)" % (token.__name__, token.pattern) for token in self._tokens ] scanner = '|'.join(patterns) self._debugPattern.log("pattern: {%s}" % scanner) return re.compile(scanner) 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 _pattern(self): return self._scanner.pattern import journal _info = journal.debug("pyre.parsing.scanner") _debugPattern = journal.debug("pyre.parsing.scanner.pattern") from TokenizationException import TokenizationException
def journald(name=None): if name is None: name = "journald" import journal journal.info("journal").activate() journal.debug("journal").activate() journal.info("journald").activate() journal.debug("journald").activate() app = journal.daemon(name) app.run()
def save(mechanism, format="chemkin"): import journal journal.debug("fuego").log("pickling mechanism, format='%s')" % format) factory = registrar().retrieve(format) if not factory: journal.error("fuego").log("unknown mechanism file format '%s'" % format) return [] pickler = factory.pickler() pickler.initialize() return pickler.pickle(mechanism)
def save(weaver, mechanism, stream, format="chemkin"): # mga 20070913: FIXME: impossible to use with an driver: # who can configure a weaver manually? import journal journal.debug("fuego").log("pickling mechanism, format='%s')" % format) mill = pickler(format) if not pickler: journal.error("fuego").log("unknown mechanism file format '%s'" % format) return [] weaver.renderer = mill return weaver.weave(mechanism, stream)
def test(): """ Verify the channel initial state """ # access import journal # make a channel channel = journal.debug(name="tests.journal.debug") # verify the channel name assert channel.name == "tests.journal.debug" # the verbosity should be at the default level assert channel.verbosity == 1 # the channel should be inactive assert channel.active == False # and non fatal assert channel.fatal == False # the page should be empty assert tuple(channel.page) == () # verify the metadata assert channel.notes["application"] == "journal" assert channel.notes["channel"] == channel.name assert channel.notes["severity"] == channel.severity # all done return
def _configure(self): """ Set members based using inventory. """ PetscComponent._configure(self) self.matrixType = self.inventory.matrixType self.timeStep = self.inventory.timeStep self.solver = self.inventory.solver self.output = self.inventory.output self.viewJacobian = self.inventory.viewJacobian self.jacobianViewer = self.inventory.jacobianViewer self.perfLogger = self.inventory.perfLogger import journal self._debug = journal.debug(self.name) if self.inventory.useCustomConstraintPC and \ not self.inventory.useSplitFields: print "WARNING: Request to use custom preconditioner for Lagrange " \ "constraints without splitting fields. " \ "Setting split fields flag to 'True'." self.inventory.useSplitFields = True ModuleFormulation.splitFields(self, self.inventory.useSplitFields) ModuleFormulation.useCustomConstraintPC(self, self.inventory.useCustomConstraintPC) return
def __init__(self, name=None): Traceable.__init__(self) if name is None: name = self.name # class attribute else: self.name = name self.inventory = self.createInventory() # provide simple, convenient access to descriptors self.metainventory = self.createMetaInventory() # other names by which I am known for configuration purposes self.aliases = [ name ] import journal self._debug = journal.debug(name) self._info = journal.info(name) self._error = journal.error(name) self._warning = journal.warning(name) # modify the inventory defaults that were hardwired at compile time # gives derived components an opportunity to modify their default behavior # from what was inherited from their parent's inventory self._defaults() return
def createContinuousAxis(name, unit, centers=None, boundaries=None, centersCreationArgs=None, attributes=None): """create a continuous axis a continuos axis represents a continuous physics quantity like energy, time of flight, etc. datatype is set to 'double' because of the continuity a mapper is created and attached to the axis. """ if (centers is not None or centersCreationArgs is not None) and boundaries is not None: raise ValueError("both centers and boundaries are specified") if centers is not None and centersCreationArgs is not None: raise ValueError( "both centers and center creation arguments are specified") if centers is not None: boundaries = boundariesFromCenters(centers) pass # end if centers if centersCreationArgs is not None: min, delta, nBins = centersCreationArgs boundaries = calcBinBoundaries(min, delta, nBins) pass # end if centersCreationArgs unit = unitFromString(unit) from .EvenlyContinuousAxisMapper import \ EvenlyContinuousAxisMapper as AxisMapper, NotEvenlySpaced try: axisMapper = AxisMapper(binBoundaries=boundaries) except NotEvenlySpaced: import traceback import journal debug = journal.debug('histogram.createContinuousAxis') #debug.log( traceback.format_exc() ) debug.log( 'createContinuousAxis(name = %r, unit = %r, centers= %r, boundaries = %r' % (name, unit, centers, boundaries)) from .ContinuousAxisMapper import ContinuousAxisMapper as AxisMapper axisMapper = AxisMapper(boundaries) nBins = len(boundaries) - 1 storage = ndArray("double", boundaries) from .Axis import Axis return Axis(name, unit, length=nBins, storage=storage, mapper=axisMapper, centers=centers, attributes=attributes)
def debug(): d = journal.debug("foo") d.active = True d.log("unknown error") # also from C++ journal.extension.debugTest("foo") return
def test(): import journal # journal.debug("postgres.init").active = True # journal.debug("postgres.execute").active = True # journal.debug("postgres.connection").active = True journal.debug("postgres.transactions").active = True # this is the SQL statement that looks for a table by a given name sql = "SELECT tablename FROM pg_tables WHERE tablename='{}'".format(Weather.pyre_name) # build a database component and connect to the database specified in the local # configuration file db = pyre.db.postgres(name="test").attach() # in a transaction block with db: # create the table db.createTable(Weather) # verify it is there assert db.execute(sql) == (('tablename',), ('weather',)) # drop the table db.dropTable(Weather) # verify it is not there assert db.execute(sql) == (('tablename',),) # and return the connection and the table return db, Weather
def findPendingTask(self, db, iworker=None): import journal debug = journal.debug('itask-findPendingTask') from ITask import ITask tasks = self.getReferences(db, ITask, 'beneficiary') if not tasks: return found = None for task in tasks: # if not the right task, skip if task.worker != iworker: continue if task.state == 'finished': raise RuntimeError, "Task %s for %s finished but apparently it is not giving the right results or the results of this task has been mistakenly removed." % (task.id, self.id) if task.state == 'failed': debug.log("Task %s for %s found. Which has failed before." % (task.id, self.id)) return task if task.state == 'cancelled': debug.log("Task %s for %s found. Which was cancelled." % (task.id, self.id)) # reopen the task task.state = 'created' db.updateRecord(task) found = task break found = task break return found
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
def __init__(self, name=None, timer=None, **kwds): # chain up super().__init__(name=name, **kwds) # i am not have a name, but i need one in what follows name = name or self.pyre_family() or "pyre.nexus.peers" # if i were handed a timer to use if timer is not None: # save it self.timer = timer # otherwise else: # make a new one and start it self.timer = self.pyre_executive.newTimer(name=name).start() # journal channels import journal self.info = journal.info(name=name) self.debug = journal.debug(name=name) self.warning = journal.warning(name=name) self.error = journal.error(name=name) # all done return
def __init__(self): self.port = None import journal self._debug = journal.debug("pyre.ipc.monitor") return
def test(): """ Verify access to the channel metadata """ # access import journal # make a channel channel = journal.debug("test.channel") # get its metadata notes = channel.notes # adjust the application name notes["application"] = "debug_notes" # add something notes["author"] = "michael" # make sure the adjustments stick by asking for the notes once again; this step is # non-trivial: if support is provided by the C++ library, it ensures that the notes are # mutable notes = channel.notes # and comparing against expectations assert notes["application"] == "debug_notes" assert notes["author"] == "michael" assert notes["channel"] == "test.channel" assert notes["severity"] == "debug" # all done return
def __init__(self, name=None, timer=None, **kwds): # chain up super().__init__(name=name, **kwds) # i may not have a name, but i need one in what follows name = name or self.pyre_family() or "pyre.nexus.peers" # if i didn't get handed a timer to use if timer is None: # make a new one timer = self.pyre_executive.newTimer(name=name) # start it timer.start() # save it self.timer = timer # journal channels import journal self.info = journal.info(name=name) self.debug = journal.debug(name=name) self.warning = journal.warning(name=name) self.error = journal.error(name=name) # all done return
def __init__(self, name): self._name = name self._options = None import journal self._debug = journal.debug(name) return
def test2(self): "bpext: double array" import journal journal.debug('wrap_native_ptr').activate() journal.debug('extract_native_ptr').activate() import bpext._bpext as binding arr = binding.newdblarr(10) print arr wrapped_ptr_bpobj = binding.wrap_native_ptr( arr ) print wrapped_ptr_bpobj extracted = binding.extract_native_ptr( wrapped_ptr_bpobj ) print extracted return
def __init__(self, name="CitcomS"): """Constructor. Inventory object is not initialized yet. """ Application.__init__(self, name) # channel for debugging output self._info = journal.debug("application") return
def __init__( self, name = "snaccitcom" ): SnacApplication.__init__( self, name ) self.solverCommunicator = None self.myPlus = [] self.remotePlus = [] self._info = journal.debug( "application" ) return
def _configure(self): """ Set members based using inventory. """ Formulation._configure(self) import journal self._debug = journal.debug(self.name) return
def __init__(self, name, facility=None): if facility is None: facility = "solver" Component.__init__(self, name, facility) self._elc = None import journal self._loopInfo = journal.debug("%s.timeloop" % name) self._monitorInfo = journal.debug("%s.monitoring" % name) from pyre.units.time import second self.t = 0.0 * second self.step = 0 return
def __init__(self, name): self.codecs = {} tag = name + '.curator' import journal self._info = journal.info(tag) self._debug = journal.debug(tag) return
def test(): import journal journal.debug("pyre.ipc.selector").activate() import pyre.ipc selector = pyre.ipc.selector() selector.notifyWhenIdle(onTimeout) try: selector.watch() except: import sys type, value, tb = sys.exc_info() print "got %s: {%s}" % (type, value) raise type, value return
def onClient(self): # initialize the journal device import journal journal.remote(self.key, self.port, self.host) for idx in range(5): info = journal.debug("test-%02d" % idx).activate() info.log("test %02d: this a sample message" % idx) return