@@ -34,21 +34,20 @@ class FileInfo:
3434class FilesComponent (BaseComponent ):
3535 """Component for managing files and directories in DesignSafe."""
3636
37- def get_uri (self , path : str , system : Optional [ str ] = None ) -> str :
37+ def get_storage_info (self , path : str ) -> tuple [ str , str ] :
3838 """
39- Convert a path to a Tapis URI based on specific directory patterns.
39+ Determine storage system and processed path based on path patterns.
4040
4141 Args:
42- path (str): Path to convert to URI
43- system (str, optional): Storage system to use (ignored as system is determined by path)
42+ path (str): Input path
4443
4544 Returns:
46- str: Tapis URI for the given path
45+ tuple: (storage_id, processed_path)
4746
4847 Raises:
49- ValueError: If no matching directory pattern is found
48+ ValueError: If no matching pattern is found
5049 """
51- # Define directory patterns and their corresponding storage systems and username requirements
50+ # Define directory patterns and their corresponding storage systems
5251 directory_patterns = [
5352 ("jupyter/MyData" , "designsafe.storage.default" , True ),
5453 ("jupyter/mydata" , "designsafe.storage.default" , True ),
@@ -60,10 +59,10 @@ def get_uri(self, path: str, system: Optional[str] = None) -> str:
6059 # Check standard directory patterns
6160 for pattern , storage , use_username in directory_patterns :
6261 if pattern in path :
63- path = path .split (pattern , 1 )[1 ].lstrip ("/" )
64- input_dir = f" { self .tapis .username } / { path } " if use_username else path
65- input_uri = f"tapis:// { storage } /{ input_dir } "
66- return input_uri . replace ( " " , "%20" )
62+ processed_path = path .split (pattern , 1 )[1 ].lstrip ("/" )
63+ if use_username and not processed_path . startswith ( self .tapis .username ):
64+ processed_path = f"{ self . tapis . username } /{ processed_path } "
65+ return storage , processed_path
6766
6867 # Check project patterns
6968 project_patterns = [
@@ -75,21 +74,37 @@ def get_uri(self, path: str, system: Optional[str] = None) -> str:
7574 if pattern in path :
7675 path = path .split (pattern , 1 )[1 ].lstrip ("/" )
7776 project_id , * rest = path .split ("/" , 1 )
78- path = rest [0 ] if rest else ""
77+ remaining_path = rest [0 ] if rest else ""
7978
80- # Get project UUID using Tapis
79+ # Get project UUID
8180 try :
8281 resp = self .tapis .get (
8382 f"https://designsafe-ci.org/api/projects/v2/{ project_id } "
8483 )
8584 project_uuid = resp .json ()["baseProject" ]["uuid" ]
86- input_uri = f"tapis://{ prefix } { project_uuid } /{ path } "
87- return input_uri .replace (" " , "%20" )
85+ return f"{ prefix } { project_uuid } " , remaining_path
8886 except Exception as e :
8987 raise ValueError (f"Could not resolve project UUID: { str (e )} " )
9088
9189 raise ValueError (f"No matching directory pattern found for: { path } " )
9290
91+ def get_uri (self , path : str , system : Optional [str ] = None ) -> str :
92+ """
93+ Convert a path to a Tapis URI.
94+
95+ Args:
96+ path (str): Path to convert
97+ system (str, optional): Storage system to use (ignored as system is determined by path)
98+
99+ Returns:
100+ str: Tapis URI for the given path
101+
102+ Raises:
103+ ValueError: If path pattern is not recognized
104+ """
105+ storage_id , processed_path = self .get_storage_info (path )
106+ return f"tapis://{ storage_id } /{ processed_path } " .replace (" " , "%20" )
107+
93108 def list (
94109 self , path : str = None , recursive : bool = False , system : str = None
95110 ) -> List [FileInfo ]:
0 commit comments