def mainTemplate( guitoolkit, *args): import sys if len(sys.argv) not in [2,3]: if args: appfilename=args[0] else: print usage(sys.argv[0]) sys.exit(1) appClassName = None elif len(sys.argv)==2: appfilename = sys.argv[1] appClassName = None elif len(sys.argv)==3: appfilename = sys.argv[1] appClassName = sys.argv[2] import journal journal.error("pyre.inventory").deactivate() try: run( appfilename, appClassName, guitoolkit ) except: raise print "%s failed" % ' '.join( sys.argv ) print " - This might be due to an incorrect guess of the pyre application class." print " - Please specifiy the class name in the command line." print usage(sys.argv[0]) 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
def daemon(self, pid): import os # change the working directory to my home directory if not os.path.exists(self.home): import journal journal.error(self.name).log("directory %r does not exist" % self.home) self.home = '/tmp' os.chdir(self.home) # redirect the journal output since we are about to close all the # standard file descriptors # currently disabled since a better strategy is to have the application author # build a journal configuration file # self.configureJournal() # close all ties with the parent process os.close(2) os.close(1) os.close(0) # launch the application self.main(*self.args, **self.kwds) return
def _both(self): import os # the process id of the main script pid = os.getpid() child = os.fork() if child > 0: # in the parent process self._info.log("server(%r): spawned client(%r)" % (pid, child)) self._info.log("server(%r): proceeding in server mode" % pid) self.onServer() self._info.log("server(%r): finished" % pid) elif child == 0: pid = os.getpid() self._info.log("client(%r): sleeping for %r seconds" % (pid, self._delay)) import select select.select([], [], [], self._delay) self._info.log("client(%r): proceeding in client mode" % pid) self.onClient() self._info.log("client(%r): finished" % pid) else: import journal journal.error(self.name).log("fork: error %d" % child) return
def launch(self, application): Solver.launch(self, application) # verify the machine layout layout = application.layout rank = layout.rank communicator = layout.communicator if not communicator: import journal journal.error(self.name).log("null communicator") return if communicator.size > 1: import journal journal.error(self.name).log("this is a single processor solver") return # save the communicator info self._fluidServer = rank self._solidServer = (rank + 1) % 2 self.coupler = application.coupler # initial boundary synchronization with the fluid if self.inventory.syncOnInit: self.applyBoundaryConditions() else: raise "pulse requires options.syncBoundaryInitialization=true" from pyre.units.SI import second t, step = 0.0 * second, 0 return (t, step)
def launch(self, application): Solver.launch(self, application) # verify the machine layout layout = application.layout rank = layout.rank communicator = layout.communicator if not communicator: import journal journal.error(self.name).log("null communicator") return if communicator.size > 1: import journal journal.error(self.name).log("this is a single processor solver") return # save the communicator info self._fluidServer = rank self._solidServer = (rank + 1) % 2 self.coupler = application.coupler # initial boundary synchronization with the fluid if self.inventory.syncOnInit: self.applyBoundaryConditions() else: raise "pulse requires options.syncBoundaryInitialization=true" from pyre.units.SI import second t, step = 0.0*second, 0 return (t, step)
def test(): """ Verify that channels lower in the hierarchy inherit their parent default state """ # get the journal import journal # make a channel parent = journal.error(name="test.index.parent") # verify that the state is off 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 # make it non fatal parent.fatal = False # set the device to a trash can parent.device = journal.trash() # lookup a name that is lower in the hierarchy child = journal.error(name="test.index.parent.blah.blah.child") # 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
def retrieveLayout(self, encoding=None): layout = self.layout print " ++ layout description in '%s'" % layout import os base, extension = os.path.splitext(layout) if encoding is None: if extension: encoding = extension[1:] else: import journal journal.error("blade").log("unknown layout type in '%s'" % layout) return print " ++ encoding:", encoding try: codec = self.codecs[encoding] except KeyError: import journal journal.error("blade").log("unknown encoding '%s'" % encoding) return print codec.open(base) document = None return document
def mainTemplate(guitoolkit, *args): import sys if len(sys.argv) not in [2, 3]: if args: appfilename = args[0] else: print usage(sys.argv[0]) sys.exit(1) appClassName = None elif len(sys.argv) == 2: appfilename = sys.argv[1] appClassName = None elif len(sys.argv) == 3: appfilename = sys.argv[1] appClassName = sys.argv[2] import journal journal.error("pyre.inventory").deactivate() try: run(appfilename, appClassName, guitoolkit) except: raise print "%s failed" % ' '.join(sys.argv) print " - This might be due to an incorrect guess of the pyre application class." print " - Please specifiy the class name in the command line." print usage(sys.argv[0]) return
def main(): import sys from optparse import OptionParser parser = OptionParser( "usage: %prog [options] -a PYREAPP [pyreapp-options] ") parser.add_option( '-v', '--verbosity', dest='verbosity', type='int', default='1', help='When verbosity is increased, more advanced options will show up') parser.add_option('-a', '', dest='pyreapp', help='pyre application') argv = sys.argv helpargv, appargv = _splitArgv(argv) opts, args = parser.parse_args(helpargv) appname = opts.pyreapp classname = None sys.argv = appargv import journal journal.error('pyre.inventory').deactivate() verbosity = opts.verbosity help(appname, classname, verbosity) return
def daemon(self, pid): import os # change the working directory to my home directory if not os.path.exists(self.home): import journal journal.error(self.name).log("directory %r does not exist" % self.home) self.home = '/tmp' os.chdir(self.home) # redirect the journal output since we are about to close all the # standard file descriptors # currently disabled since a better strategy is to have the application author # build a journal configuration file # self.configureJournal() # close all ties with the parent process, unless in debug mode if pid: os.close(2) os.close(1) os.close(0) # launch the application self.main(*self.args, **self.kwds) return
def mechanism(mix, proxy, type="pyre"): factory = registrar().retrieve(type) if not factory: import journal journal.error("fuego").log("unknown chemistry solver mode '%s'" % type) factory = registrar().retrieve("pyre") return factory.mechanism(mix, proxy)
def mixture(speciesSet, type="pyre"): factory = registrar().retrieve(type) if not factory: import journal journal.error("fuego").log("unknown chemistry solver mode '%s'" % type) factory = registrar().retrieve("pyre") return factory.mixture(speciesSet)
def connect(database, wrapper=None): if wrapper is None or wrapper == "psycopg": from Psycopg import Psycopg return Psycopg(database) import journal journal.error("pyre.db").log("%r: unknown db wrapper type" % wrapper) return None
def daemon(self, pid): import os # change the working directory to my home directory if not os.path.exists(self.home): import journal journal.error(self.name).log("directory %r does not exist" % self.home) self.home = '/tmp' os.chdir(self.home) # redirect the journal output since we are about to close all the # standard file descriptors # currently disabled since a better strategy is to have the application author # build a journal configuration file # self.configureJournal() # close all ties with the parent process, unless in debug mode if pid: import sys sys.stdout.flush() sys.stderr.flush() stdin = self.kwds.get('stdin') stdout = self.kwds.get('stdout') stderr = self.kwds.get('stderr') # close or redirect standard file descriptors if stdin is None: os.close(0) else: if not isinstance(stdin, file): stdin = file(stdin, 'r') os.dup2(stdin.fileno(), sys.stdin.fileno()) if stdout is None: os.close(1) else: if not isinstance(stdout, file): stdout = file(stdout, 'a+') os.dup2(stdout.fileno(), sys.stdout.fileno()) if stderr is None: os.close(2) else: if not isinstance(stderr, file): stderr = file(stderr, 'a+', 0) os.dup2(stderr.fileno(), sys.stderr.fileno()) # launch the application self.main(*self.args, **self.kwds) return
def _createNeutronComponent(self, component_specifier): '''create a pyre neutron component from the given name the name could be * <componenttype> eg. MonochromaticSource * <componentcategory>/<componenttype> eg. sources/MonochromaticSource * <supplier>://<componenttype> eg. mcni://MonochromaticSource * <supplier>://<componentcategory>/<componenttype> eg. mcni://sources/MonochromaticSource * <supplier>://<componentcategory>/<componenttypefactory>(*args) eg. mcni://sources/NDMonitor(x, y) ''' component_specifier = str(component_specifier) supplier, category, type, args = _decode(component_specifier) # component factory from mcni.pyre_support import findcomponentfactory try: factory = findcomponentfactory(type, category, supplier) except: import journal, traceback tb = traceback.format_exc() journal.error('pyre.inventory').log('failed to find component factory %r. \n%s' % ( component_specifier, tb)) return None, None # error handling if not factory: import journal journal.error("mcvine.component").log( "could not bind facility '%s': component factory '%s' not found." % ( self.name, component_specifier) ) return None, None # component type factory ? if args: factory = factory(*args) # instantiate the component component = factory(self.name) # uri uri = _encode(factory.supplier, factory.category, factory.type, args) component.uri = uri # locator locator = '<mcvine.componentfactory>' # return component, locator
def project(self, name, type): """load a project manager of type <type>""" project = self.retrieveComponent( name=type, factory='project', args=[name], vault=['projects']) if project: self._info.log("loaded project manager '%s' from %s" % (type, project.getLocator())) else: import journal journal.error("merlin").log("could not find project definition file for %r" % type) return project
def monitor(mode): if mode == 'tcp': from TCPMonitor import TCPMonitor return TCPMonitor() if mode == 'udp': from UDPMonitor import UDPMonitor return UDPMonitor() import journal journal.error('pyre.ipc').log("unknown monitor mode '%s'" % mode) return None
def connection(mode): if mode == 'tcp': from TCPSocket import TCPSocket return TCPSocket() if mode == 'udp': from UDPSocket import UDPSocket return UDPSocket() import journal journal.error('pyre.ipc').log("unknown connection mode '%s'" % mode) return None
def _retrieveLanguage(self, language): weaver = self.retrieveComponent( factory=self.name, name=language, vault=['mills']) if weaver: return weaver import journal journal.error('pyre.weaver').log("could not locate weaver for '%s'" % language) self.getCurator().dump() return None
def _retrieveLanguage(self, language): weaver = self.retrieveComponent(factory=self.name, name=language, vault=['mills']) if weaver: return weaver import journal journal.error('pyre.weaver').log("could not locate weaver for '%s'" % language) self.getCurator().dump() return None
def complain(msg): """ Print error messages """ # if there is journal try: # use it import journal journal.error('mm').log(msg) # otherwise except ImportError: # print the error message print('mm:', msg, file=sys.stderr) # return return
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
def test(): """ Verify the channel initial state """ # access import journal # make a channel channel = journal.error(name="tests.journal.error") # verify the channel name assert channel.name == "tests.journal.error" # the detail should be at the default level assert channel.detail == 1 # the channel should be active assert channel.active == True # and fatal assert channel.fatal == True # 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 pyre_selectColumns(cls, headers): """ Prepare a tuple of the column numbers needed to populate my instances, given a map (column name) -> (column index). This enables the managers of the various persistent stores to build record instances from a subset of the information they have access to. It is also designed to perform column name translations from whatever meta data is available in the store to the canonical record field names """ # iterate over my measures for measure in cls.pyre_measures: # and over its aliases for alias in measure.aliases: # if this alias appears in the headers try: # compute the column index and return it yield headers[alias] # get the next field break except KeyError: continue # error: unable to find a source for this field else: # if it is not an optional field if not measure.optional: # complain msg = "unable to find a source for field {!r}".format(measure.name) import journal raise journal.error("pyre.records").log(msg) # all done return
def test(): """ Verify access to the channel metadata """ # access import journal # make a channel channel = journal.error("test.channel") # get its metadata notes = channel.notes # adjust the application name notes["application"] = "error_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"] == "error_notes" assert notes["author"] == "michael" assert notes["channel"] == "test.channel" assert notes["severity"] == "error" # 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 prep_frequency_and_polarizations(self): ''' check frequency and polarizations and fix as needed ''' error_channel = journal.error( 'RunConfig.prep_frequency_and_polarizations') input_path = self.cfg['input_file_group']['input_file_path'] freq_pols = self.cfg['processing']['input_subset'][ 'list_of_frequencies'] slc = SLC(hdf5file=input_path) for freq in freq_pols.keys(): if freq not in slc.frequencies: err_str = f"Frequency {freq} invalid; not found in source frequencies." error_channel.log(err_str) raise ValueError(err_str) # first check polarizations from source hdf5 rslc_pols = slc.polarizations[freq] # use all RSLC polarizations if None provided if freq_pols[freq] is None: freq_pols[freq] = rslc_pols continue # use polarizations provided by user # check if user provided polarizations match RSLC ones for usr_pol in freq_pols[freq]: if usr_pol not in rslc_pols: err_str = f"{usr_pol} invalid; not found in source polarizations." error_channel.log(err_str) raise ValueError(err_str)
def test(): """ Exercise the usual test case """ # get the journal import journal # make a channel channel = journal.error(name="test.journal.error") # send the output to the trash channel.device = journal.trash() # add some metadata channel.notes["time"] = "now" # carefully try: # inject channel.line("error:") channel.log(" a nasty bug was detected") # shouldn't get here assert False, "unreachable" # if the correct exception was raised except channel.ApplicationError as error: # check the description assert str(error) == "test.journal.error: application error" # all done return
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, hdf5file=None, **kwds): ''' Constructor. ''' # Set error channel self.error_channel = journal.error('Base') # Check hdf5file if hdf5file is None: err_str = f"Please provide an input HDF5 file" self.error_channel.log(err_str) # Filename self.filename = hdf5file # Identification information self.identification = None # Polarization dictionary self.polarizations = {} self.populateIdentification() self.identification.productType = self._ProductType if self._ProductType is None: return self.parsePolarizations()
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 check_write_dir(dst_path: str): ''' Raise error if given path does not exist or not writeable. ''' if not dst_path: dst_path = '.' error_channel = journal.error('helpers.check_write_dir') # check if scratch path exists dst_path_ok = os.path.isdir(dst_path) if not dst_path_ok: try: os.makedirs(dst_path, exist_ok=True) except OSError: err_str = f"Unable to create {dst_path}" error_channel.log(err_str) raise OSError(err_str) # check if path writeable write_ok = os.access(dst_path, os.W_OK) if not write_ok: err_str = f"{dst_path} scratch directory lacks write permission." error_channel.log(err_str) raise PermissionError(err_str)
def spell(self): """retrieve the project definition file""" # NYI: embed the locator in the retrieved asset print " ** NYI" spell = self.retrieveComponent( name='', factory='project', args=[self], encoding='merlin') if spell: self._info.log("loaded project definition file from %s" % spell.getLocator()) else: import journal journal.error("merlin").log("could not find project definition file") return spell
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=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 test(): """ Verify that the channel buffers are cleared after flushing a message; this is a non-trivial test because it guarantees that the implementation handles the transaction correctly """ # get the journal import journal # make a channel channel = journal.error(name="test.journal.error") # 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.ApplicationError as error: # no problem pass # verify that the buffer is empty after the flush assert len(channel.page) == 0 # all done return
def cli_arg_load(self): ''' Load user-provided command line args into minimal cfg dictionary ''' error_channel = journal.error('ResampleSlcRunConfig.cli_arg_load') self.cfg = defaultdict(helpers.autovivified_dict) # Valid input h5? if os.path.isfile(self.args.input_h5): self.cfg['InputFileGroup'][ 'SecondaryFilePath'] = self.args.input_h5 else: err_str = f"{self.args.input_h5} not a valid path" error_channel.log(err_str) raise FileNotFoundError(err_str) # Valid lines_per_tile? if isinstance(self.args.lines_per_tile, int): self.cfg['processing']['resample'][ 'lines_per_tile'] = self.args.lines_per_tile else: err_str = f"{self.args.lines_per_tile} not a valid number" error_channel.log(err_str) raise ValueError(err_str) # Valid input for frequencies and polarizations? for k, vals in self.args.freq_pols.items(): # Check if frequency is valid if k not in ['A', 'B']: err_str = f"frequency {k} not valid" error_channel.log(err_str) raise ValueError(err_str) # Check if polarizations values are valid for v in vals: if v not in ['HH', 'VV', 'HV', 'VH']: err_str = f"polarization {v} not valid" error_channel.log(err_str) raise ValueError(err_str) self.cfg['processing']['input_subset'][ 'list_of_frequencies'] = self.args.freq_pols # Check scratch directory helpers.check_write_dir(self.args.scratch) self.cfg['ProductPathGroup']['ScratchPath'] = self.args.scratch # Check if the offset directory is provided if self.args.off_dir is None: off_dir = self.args.off_dir else: # Full InSAR workflow expect geometric offsets in scratch off_dir = self.args.scratch # Check offsets directory structure frequencies = self.args.freq_pols.keys() helpers.check_mode_directory_tree(off_dir, 'geo2rdr', frequencies) self.cfg['processing']['resample']['offset_dir'] = off_dir
def test(): """ Exercise the usual test case with an non-fatal channel """ # get the journal import journal # make an error channel channel = journal.error(name="tests.journal.error") # 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("error channel:") channel.log(" hello world!") # if the correct exception was raised except channel.ApplicationError as error: # shouldn't get here assert False, "unreachable" # all done return
def connect(database, wrapper=None, **kwds): name2mod = { None: 'Psycopg', 'psycopg': 'Psycopg', 'psycopg2': 'Psycopg2', 'sqlite': 'SQLite', } mod = name2mod.get(wrapper) if not mod: import journal journal.error("pyre.db").log("%r: unknown db wrapper type" % wrapper) return None package = 'pyre.db' module = __import__(package+'.'+mod, {}, {}, ['']) factory = getattr(module, mod) return factory(database, **kwds)
def error(message): """ Generate an error message """ # get the logging mechanism import journal # build an error message object in my namespace error = journal.error('merlin') # log and return return error.log(message)
def _import(self, name): try: module = __import__(name, {}, {}) except ImportError: import journal journal.error("pyre.inventory").log( "could not bind facility '%s': component '%s' not found" % (self.name, name) ) return try: factory = module.__dict__[self.family] except KeyError: import journal journal.error("pyre.inventory").log( "no factory for facility '%s' in '%s'" % (self.name, module.__file__)) return try: item = factory(*self.args) except TypeError: import journal journal.error("pyre.inventory").log( "no factory for facility '%s' in '%s'" % (self.name, module.__file__)) return return item
def daemon(self, pid, spawn=True): import os import journal # change the working directory to my home directory if not os.path.exists(self.home): journal.error(self.name).log("directory %r does not exist" % self.home) self.home = '/tmp' os.chdir(self.home) # redirect the journal output since we are about to close all the # standard file descriptors # currently disabled since a better strategy is to have the application author # build a journal configuration file # self.configureJournal() if spawn: # close all ties with the parent process os.close(2) os.close(1) os.close(0) # launch the application try: self.main(*self.args, **self.kwds) except KeyboardInterrupt: journal.error(self.name).log("interrupt") except Exception, e: import traceback journal.error(self.name).log("exception:\n%s" % traceback.format_exc())
def main(): import journal journal.error('pyre.inventory').deactivate() from drchops.applications.WebApplication import WebApplication class MainApp(WebApplication): def __init__(self): WebApplication.__init__(self, name='main')#, asCGI=True) return def run(self): WebApplication.run(self) return app = MainApp() return app.run()
def test(): # access the package import journal # build a error channel error = journal.error("journal.test1") # verify that it is on by default assert error.active == True # disable it error.active = False # access the same channel through another object clone = journal.error("journal.test1") # verify that it is now off assert clone.active == False # build a error channel with a different name another = journal.error("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
def test(): # access the package import journal # build a error channel error = journal.error("activation") # verify that it is off by default, deactivated from a configuration source assert error.active == False # enable it error.active = True # access the same channel through another object clone = journal.error("activation") # verify that it is on assert clone.active == True # disable it clone.active = False # check that the other channel has been deactivated as well assert error.active == False # all done return
def main(): import sys from optparse import OptionParser parser = OptionParser( "usage: %prog [options] -a PYREAPP [pyreapp-options] ") parser.add_option( '-v', '--verbosity', dest = 'verbosity', type = 'int', default = '1', help = 'When verbosity is increased, more advanced options will show up' ) parser.add_option( '-a', '', dest = 'pyreapp', help = 'pyre application' ) argv = sys.argv helpargv, appargv = _splitArgv(argv) opts, args = parser.parse_args(helpargv) appname = opts.pyreapp classname = None sys.argv = appargv import journal journal.error( 'pyre.inventory' ).deactivate() verbosity = opts.verbosity help( appname, classname, verbosity) return
def endElement(self, name): line, column = self._locator.getLineNumber(), self._locator.getColumnNumber() self._info.log("endElement: '%s', at (%d, %d)" % (name, line, column)) node = self._currentNode self._currentNode = self._nodeStack.pop() try: node.notify(self._currentNode) except ValueError, text: l = self._document.locator import journal error = journal.error("pyre.xml.parsing") error.log("%s: line %s, column %s: %s" % (l.filename, l.line, l.column, text))
def _import(self, name): # convert 'a/b/c' to 'a.b.c' so we can directly import the module # 'a/b/c' is better than 'a.b.c' because command line configuration in pyre 0.8 # won't work for components with names including dots. name = name.replace('/', '.') try: module = __import__(name, {}, {}, ['']) except ImportError: import traceback tb = traceback.format_exc() import journal journal.error("pyre.inventory").log( "could not bind facility '%s': component '%s' not found:\n%s" % ( self.name, name, tb) ) return except ValueError: import traceback tb = traceback.format_exc() import journal journal.error("pyre.inventory").log( "could not bind facility '%s': component '%s' not found:\n%s" % ( self.name, name, tb) ) return try: factory = module.__dict__[self.family] except KeyError: import journal journal.error("pyre.inventory").log( "no factory for facility '%s' in '%s'" % (self.name, module.__file__)) return try: item = factory(*self.args) except TypeError: import journal journal.error("pyre.inventory").log( "no factory for facility '%s' in '%s'" % (self.name, module.__file__)) return return item, module.__file__
def __init__(self, dim, order): self.dim = dim self.order = order try: import pyre._pyre except ImportError: import journal error = journal.error('pyre') error.line("unable to import the C++ pyre extensions") error.log("mesh objects are not supported") self._mesh = None return self._mesh = pyre._pyre.createMesh(dim, order) return
def test(): # access the package import journal # build a channel of each kind using the same name debug = journal.debug("journal.test") firewall = journal.firewall("journal.test") info = journal.info("journal.test") warning = journal.warning("journal.test") error = journal.error("journal.test") # check their expected default state assert debug.active == False assert firewall.active == True assert info.active == True assert warning.active == True assert error.active == True # all done return
def test(): import journal from jtest import jtest print " ** testing C++ informationals" info = journal.info("jtest") info.activate() jtest.info("jtest") print " ** testing C++ warnings" warning = journal.warning("jtest") #warning.deactivate() warning = jtest.warning("jtest") print " ** testing C++ errors" error = journal.error("jtest") #error.deactivate() jtest.error("jtest") return