Changeset 131


Ignore:
Timestamp:
07/22/2009 06:19:02 PM (13 years ago)
Author:
marcus
Message:
  • fix: ctypes structure
  • simple event manager
  • two simple unittest's
Location:
SHX/trunk/src/SeismicHandler
Files:
9 added
9 edited

Legend:

Unmodified
Added
Removed
  • SHX/trunk/src/SeismicHandler/config/__init__.py

    r127 r131  
    2525import os 
    2626import textwrap 
     27from SeismicHandler.core.log import logging 
    2728 
    2829# change prompt style 
  • SHX/trunk/src/SeismicHandler/config/options.py

    r127 r131  
    55# This file is part of Seismic Handler eXtended (SHX) 
    66# Full details can be found at project website http://www.seismic-handler.org/ 
    7 #  
     7# 
    88# SHX is free software; you can redistribute it and/or modify 
    99# it under the terms of the GNU LESSER GENERAL PUBLIC LICENSE as published by 
     
    4040    args = None 
    4141 
    42     def __new__(type, *args, **kwargs): 
     42    def __new__(cls, *args, **kwargs): 
    4343        """ensure single instance""" 
    4444 
    45         if not '_the_instance' in type.__dict__: 
    46             type._the_instance = object.__new__(type) 
     45        if not '_the_instance' in cls.__dict__: 
     46            cls._the_instance = object.__new__(cls) 
    4747 
    48         return type._the_instance 
     48        return cls._the_instance 
    4949 
    5050    def __init__(self): 
     
    6969                  help="Root of Seismic Handler installation.") 
    7070 
    71             (opt, args) = parser.parse_args(os.environ["SHXPARAMETERS"].split()) 
     71            try: 
     72                p = os.environ["SHXPARAMETERS"].split() 
     73            except KeyError: 
     74                p = [] 
     75 
     76            (opt, args) = parser.parse_args(p) 
    7277 
    7378            self.options = opt 
     
    8792class Environment(object): 
    8893    """check local os environment for necessary elements: 
    89      
     94 
    9095    SH_ROOT 
    9196    SH_INPUTS 
    9297    SH_SCRATCH 
    93      
     98 
    9499    a fallback is included (In fact this will be the standard case, since this 
    95100    will be conveniently configurable.""" 
     
    97102    env = None 
    98103 
    99     def __new__(type, *args, **kwargs): 
     104    def __new__(cls, *args, **kwargs): 
    100105        """ ensure single instance """ 
    101106 
    102         if not '_the_instance' in type.__dict__: 
    103             type._the_instance = object.__new__(type) 
     107        if not '_the_instance' in cls.__dict__: 
     108            cls._the_instance = object.__new__(cls) 
    104109 
    105         return type._the_instance 
     110        return cls._the_instance 
    106111 
    107112    def __init__(self): 
  • SHX/trunk/src/SeismicHandler/core/codes.py

    r127 r131  
    2323 
    2424LICENCE = """ 
    25 Seismic Handler version %s, Copyright by Klaus Stammler, Marcus Walther, others  
    26 and Federal Institute for Geosciences and Natural Resources (BGR). 
     25Seismic Handler eXtended version %s, Copyright by Klaus Stammler, Marcus  
     26Walther, others and Federal Institute for Geosciences and Natural Resources  
     27(http://www.bgr.bund.de/). 
    2728  
    2829Seismic Handler comes with ABSOLUTELY NO WARRANTY. This is free software 
  • SHX/trunk/src/SeismicHandler/core/error.py

    r127 r131  
    55# This file is part of Seismic Handler eXtended (SHX) 
    66# Full details can be found at project website http://www.seismic-handler.org/ 
    7 #  
     7# 
    88# SHX is free software; you can redistribute it and/or modify 
    99# it under the terms of the GNU LESSER GENERAL PUBLIC LICENSE as published by 
     
    4747        return "commands must be passed as readable stream (file-like object)" 
    4848 
    49 class GotoTargetNotFound(Error): 
     49class GotoTargetNotFoundError(Error): 
    5050    def __init__(self, target): 
    5151        Error.__init__(self) 
     
    5555        return """Scripting: GOTO target "%s" not found!""" % self.target 
    5656 
    57 class CommandRemoved(Error): 
     57class CommandRemovedError(Error): 
    5858    def __init__(self, cmd): 
    5959        Error.__init__(self) 
  • SHX/trunk/src/SeismicHandler/core/modules/Command.py

    r127 r131  
    55# This file is part of Seismic Handler eXtended (SHX) 
    66# Full details can be found at project website http://www.seismic-handler.org/ 
    7 #  
     7# 
    88# SHX is free software; you can redistribute it and/or modify 
    99# it under the terms of the GNU LESSER GENERAL PUBLIC LICENSE as published by 
     
    2626      old command line interface 
    2727    - if a cmdstr attribute is found, the cmdstr will automatically promoted 
    28       to shlib interface  
     28      to shlib interface 
    2929""" 
    3030 
    31 from SeismicHandler.core import history, codes 
     31from SeismicHandler.core import history 
     32from SeismicHandler.core.log import logging 
    3233from SeismicHandler.core.shlib import shlib 
    33 from SeismicHandler.core.log import logging 
     34from  SeismicHandler.core.modules.Events import EventManager 
    3435 
    3536class Command(object): 
     
    7475            self.promote() 
    7576 
     77        EventManager.trigger(EventManager.COMMANDRUN) 
     78 
    7679    def Cancel(self): 
    7780        """stop command execution""" 
     
    8184    def promote(self): 
    8285        """run command on seismic handler c routine 
    83             
     86 
    8487           - command line also processed by c lib""" 
    8588 
  • SHX/trunk/src/SeismicHandler/core/modules/__init__.py

    r127 r131  
    3030    modules = {} 
    3131     
    32     def __new__(type, *args, **kwargs): 
     32    def __new__(cls, *args, **kwargs): 
    3333        """ensure single instance""" 
    3434         
    35         if not '_the_instance' in type.__dict__: 
    36             type._the_instance = object.__new__(type) 
     35        if not '_the_instance' in cls.__dict__: 
     36            cls._the_instance = object.__new__(cls) 
    3737             
    38         return type._the_instance 
     38        return cls._the_instance 
    3939 
    4040    def __init__(self): 
  • SHX/trunk/src/SeismicHandler/core/shheaders.py

    r127 r131  
    6868     
    6969    _fields_ = [ 
    70         ("hi", C.c_long), 
    71         ("lo", C.c_int), 
     70        ("hi", C.c_ulong), 
     71        ("lo", C.c_uint), 
    7272    ] 
    7373 
     
    100100 
    101101    _fields_ = [ 
    102         ("lm", C.c_int * 30), 
     102        ("lm", C.c_long * 30), 
    103103        ("im", C.c_int * 30), 
    104         ("bm", C.c_int * 20), 
     104        ("bm", C.c_byte * 20), 
    105105        ("rm", C.c_float * 60), 
    106106        ("tm", TIME * 15), 
  • SHX/trunk/src/SeismicHandler/core/shlib.py

    r127 r131  
    55# This file is part of Seismic Handler eXtended (SHX) 
    66# Full details can be found at project website http://www.seismic-handler.org/ 
    7 #  
     7# 
    88# SHX is free software; you can redistribute it and/or modify 
    99# it under the terms of the GNU LESSER GENERAL PUBLIC LICENSE as published by 
     
    2222"""wrapper for seismic handler c library 
    2323 
    24    - implemented as multiton (which does not work at the moment, because c  
    25      library is accessed as shared library, which can only loaded once into  
     24   - implemented as multiton (which does not work at the moment, because c 
     25     library is accessed as shared library, which can only loaded once into 
    2626     one process 
    2727   - maybe this will be changed later using parallel processing methods""" 
     
    3434 
    3535from SeismicHandler.core.log import logging 
    36 from SeismicHandler.core.error import MultipleLibError, CommandStreamError, GotoTargetNotFound 
     36from SeismicHandler.core.error import MultipleLibError, CommandStreamError, GotoTargetNotFoundError 
    3737from SeismicHandler.config.options import environment 
    38 from SeismicHandler.core.shheaders import LINELENGTH, NOERROR, PARAM, CAPCNV 
     38from SeismicHandler.core.shheaders import LINELENGTH, NOERROR, PARAM, CAPCNV, MEMBLC 
    3939 
    4040logger = logging.getLogger("core.shlib") 
     
    4646    def __new__(cls, id="_standard", *args, **kwargs): 
    4747        """ensure single instance with identifier "xyz" 
    48             
     48 
    4949           - requested instance will be set as active""" 
    5050 
     
    7171                sys.exit(1) 
    7272 
     73            # import must be done here! 
     74            from SeismicHandler.core.modules.Events import EventManager 
     75            self.EventManager = EventManager 
     76 
    7377            self._init() 
    7478 
     
    102106    def call(self, stream): 
    103107        """call original c lib function to execute SH command in cmd 
    104             
     108 
    105109           GOTO command is replaced by own implementation 
    106110 
     
    178182                    C.byref(iscmdproc), C.byref(rdlevel), prompt, C.byref(status)) 
    179183 
     184                if redraw.value: 
     185                    self.EventManager.trigger(self.EventManager.REDRAW) 
     186 
    180187#                print quit.value, redraw.value, iscmdproc.value, rdlevel.value, status.value 
    181188 
     
    290297            self.pointer = self.targets[target.upper()] 
    291298        except KeyError: 
    292             raise GotoTargetNotFound(target.upper()) 
     299            raise GotoTargetNotFoundError(target.upper()) 
    293300 
    294301    def IfGoto(self, cmd): 
  • SHX/trunk/src/SeismicHandler/startup.py

    r128 r131  
    3838 
    3939# check for parameters (e.g. for scripts to run) 
    40 if len(os.environ["SHXPARAMETERS"]): 
    41     logging.info("start-up parameter found") 
    42     from SeismicHandler.config.options import options 
    43     try: 
    44         Run(options.args[0]) 
    45     except IndexError: 
    46         pass 
    47  
    48     if not options["keepcmdline"]: 
    49         Quit() 
    50  
    51     del options 
     40try: 
     41    if len(os.environ["SHXPARAMETERS"]): 
     42        logging.info("start-up parameter found") 
     43        from SeismicHandler.config.options import options 
     44         
     45        try: 
     46            Run(options.args[0]) 
     47        except IndexError: 
     48            pass 
     49     
     50        if not options["keepcmdline"]: 
     51            Quit() 
     52     
     53        del options 
     54except KeyError: 
     55    pass 
    5256 
    5357del os 
    54  
Note: See TracChangeset for help on using the changeset viewer.