Commit 949eedb6 authored by Cristiano Urban's avatar Cristiano Urban
Browse files

Modified 'getOSPath()' and 'setAsyncTrans()' methods + minor changes.

parent ea5ba2c4
Loading
Loading
Loading
Loading
+26 −19
Original line number Diff line number Diff line
@@ -47,22 +47,29 @@ class DbConnector(object):
                return False

    def getOSPath(self, vospacePath):
        """Returns the os relative path according to the VOSpace path."""
        """Returns a list containing full path, storage type and username for a VOSpace path."""
        if self.conn:
            self.cursor.execute("""
                SELECT os_path, tstamp_wrapper_dir 
                FROM node_path np 
                JOIN node n ON np.node_id = n.node_id 
                WHERE vos_path = %s;
                SELECT storage_type, base_path, user_name, tstamp_wrapper_dir, os_path
                FROM node_path p
                JOIN node n ON p.node_id = n.node_id
                JOIN location l ON n.location_id = l.location_id
                JOIN storage s ON s.storage_id = l.storage_src_id
                JOIN users u ON u.rap_id = n.owner_id
                WHERE p.vos_path = %s;
                """,
                (vospacePath,))
            result = self.cursor.fetchall()
            nodeOSPath = result[0]["os_path"]
            storageType = result[0]["storage_type"]
            basePath = result[0]["base_path"]
            userName = result[0]["user_name"]
            tstampWrappedDir = result[0]["tstamp_wrapper_dir"]
            pathElementList = nodeOSPath.split('/')
            pathElementList.insert(2, tstampWrappedDir)
            osPath = '/' + '/'.join(filter(None, pathElementList))
            return osPath
            osPath = result[0]["os_path"]
            if tstampWrappedDir is None:
                fullPath = basePath + "/" + userName + osPath
            else:
                fullPath = basePath + "/" + userName + "/" + tstampWrappedDir + osPath
            return [ fullPath, storageType, userName ]

    def getVOSpacePathList(self, vospacePath):
        """Returns the list of VOSpace paths carried by a VOSpace node, according to the node VOSpace path."""
@@ -188,11 +195,9 @@ class DbConnector(object):
                out.write(f"queryResult: {i}\n")
            #parentLtreePath = self.cursor.fetchone()[0]
            parentLtreePath = result[0]["path"]
            parentLtreeRelativePath = None
            parentLtreeRelativePath = ""
            if "." in parentLtreePath:
                parentLtreeRelativePath = ".".join(parentLtreePath.strip(".").split('.')[1:])
            if parentLtreeRelativePath is None:
                parentLtreeRelativePath = '' # first relative node
            out.write(f"parentLtreeRelativePath: {parentLtreeRelativePath}\n")
            out.write(f"parentLtreePath: {parentLtreePath}\n")
            out.write(f"parentPath: {node.parentPath}\n\n")
@@ -213,14 +218,16 @@ class DbConnector(object):
                 node.contentMD5,))
            self.conn.commit()

    def setAsyncTrans(self, nodeOSPath, value):
    def setAsyncTrans(self, nodeVOSPath, value):
        """Sets the 'asyncTrans' flag for a VOSpace node."""
        if self.conn:
            self.cursor.execute("""
                UPDATE node SET async_trans = %s                                                                                        
                WHERE node_id =
                (SELECT node_id FROM node_os_path
                WHERE os_path = %s);
                WHERE path <@
                (SELECT path
                 FROM node_path p
                 JOIN node n ON p.node_id = n.node_id
                 WHERE p.vos_path = %s);
                """,
                (value, nodeOSPath,))
                (value, nodeVOSPath,))
            self.conn.commit()