Beispiel #1
0
    def __init__(self, parent, obj_type='file', **kwargs):
        """Constructor.

        **kwargs: 
            - 'path': 'relative\path\to\file.ext'   
            - 'command': 'command string'  
            - 'comment': 'comment at the end of the command'
        
        Args:
            hash(str): unique code for this object.
            parent(str): unique hash code for this object.
        
        Raises:
            keyError: if kwargs 'root', 'command', 'path' are not given.
        """
        root = kwargs['root']  # raises keyerror
        self.command = kwargs['command']
        path = kwargs['path']
        self.comment = kwargs.get('comment', '')
        TuflowPart.__init__(self, parent, obj_type, **kwargs)
        PathHolder.__init__(self, path, root)
        self.TOP_CLASS = 'file'
        self.all_types = None
        self.has_own_root = False
Beispiel #2
0
    def __init__(self,
                 global_order,
                 path,
                 hex_hash,
                 type,
                 command,
                 root=None,
                 parent_relative_root='',
                 category=None,
                 parent_hash=None,
                 child_hash=None):
        """Constructor.
        

        Most tuflow files are referenced relative to the file that they are
        called from. This method eakes a 'root' as an optional argument.
        The root will allow for an absolute path to be created from the 
        relative path. 
        
        This means that the file stored in this object will be
        able to store it's absolute path as well the path relative to the
        callng file.
        
        E.g.  
            ..\bc_dbase\bc.csv  
            c:\actual\path\runs\..\bc_dbase\bc.csv

        Args:
            global_order(int): order that the file object was read in.
            path (str): the path to the file that this object holds the meta 
                data for.
            hex_hash(str): hexidecimal code for this object.
            type(int): the TuflowTypes value for this object.
            command (str): the command that was used to call this path in the 
                model file.
            root=None (str): the path to the directory that is the root of 
                this file.
            parent_relative_root=''(str): the path section relative to the main
                file read in (the tcf or ecf).
            category=None(str): Any category specification for the file.
            parent=None(str): the hash code of any parent that this file may
                have. This will be non-None if the file is read in after a 
                pipe command (e.g. with: file_1.mif | file_2.mif | file_3.mif 
                if this file is file_3 then the parent will be the hash code for 
                file_2.
            child=None(str): the hash code of any child that this file may
                have. This will be non-None if the file is read in after a 
                pipe command (e.g. with: file_1.mif | file_2.mif | file_3.mif 
                if this file is file_1 then the child will be the hash code for 
                file_2.
                
        See Also:
            :class:'TuflowTypes'  
            :class:'TuflowFilePart'
        """
        if not isinstance(path, basestring):
            raise TypeError

        TuflowFilePart.__init__(self, global_order, hex_hash, type)

        self.command = command
        self.category = category
        self.comment = None
        self.all_types = None
        self.parent_hash = parent_hash
        self.child_hash = child_hash

        # If it's an absolute path then we will set the root to be that rather
        # than the normal root used for absolute paths so this will be True.
        self.has_own_root = False
        self.file_name_is_prefix = False

        # Tuflow commands are allowed comments after them denoted by '!' so we
        # split on this to make sure it's removed from the path name.
        if '!' in path:
            path, self.comment = path.split('!', 1)
            self.comment = self.comment.strip()
        elif '#' in path:
            path, self.comment = path.split('#', 1)
            self.comment = self.comment.strip()

        # Call superclass constructor
        PathHolder.__init__(self, path, root)
        self.parent_relative_root = parent_relative_root