def initFromString()

in automation/tinc/main/ext/qautils/gppylib/gparray.py [0:0]


    def initFromString(s):
        """
        Factory method, initializes a GpDB object from string representation.
          - Used when importing from file format.
          - TODO: Should be compatable with repr() formatting.
        """
        tup = s.strip().split('|')
        
        # Old format: 8 fields
        #    Todo: remove the need for this, or rework it to be cleaner
        if len(tup) == 8:
            # This describes the gp_configuration catalog (pre 3.4)
            content         = int(tup[0])
            definedprimary  = tup[1]
            dbid            = int(tup[2])
            isprimary       = tup[3]
            valid           = tup[4]
            address         = tup[5]
            port            = int(tup[6])
            datadir         = tup[7]

            # Calculate new fields from old ones
            #
            # Note: this should be kept in sync with the code in
            # GpArray.InitFromCatalog() code for initializing old catalog
            # formats.
            preferred_role  = ROLE_PRIMARY if definedprimary else ROLE_MIRROR
            role            = ROLE_PRIMARY if isprimary else ROLE_MIRROR
            hostname        = None
            mode            = MODE_SYNCHRONIZED       # ???
            status          = STATUS_UP if valid else STATUS_DOWN
            replicationPort = None
            filespaces      = ""
            catdirs         = ""

        # Catalog 3.4 format: 12 fields
        elif len(tup) == 12:
            # This describes the gp_segment_configuration catalog (3.4)
            dbid            = int(tup[0])
            content         = int(tup[1])
            role            = tup[2]
            preferred_role  = tup[3]
            mode            = tup[4]
            status          = tup[5]
            hostname        = tup[6]
            address         = tup[7]
            port            = int(tup[8])
            replicationPort = tup[9]
            datadir         = tup[10]  # from the pg_filespace_entry table
            filespaces      = tup[11]
            catdirs         = ""

        # Catalog 4.0+: 13 fields
        elif len(tup) == 13:
            # This describes the gp_segment_configuration catalog (3.4+)
            dbid            = int(tup[0])
            content         = int(tup[1])
            role            = tup[2]
            preferred_role  = tup[3]
            mode            = tup[4]
            status          = tup[5]
            hostname        = tup[6]
            address         = tup[7]
            port            = int(tup[8])
            replicationPort = tup[9]
            datadir         = tup[10]  # from the pg_filespace_entry table
            filespaces      = tup[11]
            catdirs         = tup[12]
        else:
            raise Exception("GpDB unknown input format: %s" % s)

        # Initialize segment without filespace information
        gpdb = GpDB(content         = content, 
                    preferred_role  = preferred_role, 
                    dbid            = dbid, 
                    role            = role, 
                    mode            = mode, 
                    status          = status,
                    hostname        = hostname, 
                    address         = address,
                    port            = port, 
                    datadir         = datadir, 
                    replicationPort = replicationPort)

        # Add in filespace information, if present
        for fs in filespaces.split(","):
            if fs == "":
                continue
            (fsoid, fselocation) = fs.split(":")
            gpdb.addSegmentFilespace(fsoid, fselocation)
            
        # Add Catalog Dir, if present
        gpdb.catdirs = []
        for d in catdirs.split(","):
            if d == "":
                continue
            gpdb.catdirs.append(d)

        # Return the completed segment
        return gpdb