@@ -83,6 +83,30 @@ def expandPath(path, parentPath=None, sdf_format_args=None):
83
83
return os .path .expandvars (os .path .expanduser (os .path .normpath (path )))
84
84
85
85
86
+ def expandUrl (path , parentPath = None ):
87
+ """ Expand and normalize a URL that may have variables in it and a query string after it.
88
+
89
+ :Parameters:
90
+ path : `str`
91
+ File path
92
+ parentPath : `str` | None
93
+ Parent file path this file is defined in relation to.
94
+ Helps with asset resolution.
95
+ :Returns:
96
+ Normalized path with variables expanded.
97
+ :Rtype:
98
+ `str`
99
+ """
100
+ sdf_format_args = {}
101
+ if "?" in path :
102
+ sdf_format_args .update (sdfQuery (QtCore .QUrl (path )))
103
+ path , query = path .split ("?" , 1 )
104
+ query = "?" + query
105
+ else :
106
+ query = ""
107
+ return QtCore .QUrl (os .path .abspath (expandPath (path , parentPath , sdf_format_args )) + query )
108
+
109
+
86
110
def findModules (subdir ):
87
111
""" Find and import all modules in a subdirectory of this project.
88
112
Ignores any files starting with an underscore or tilde.
@@ -107,20 +131,22 @@ def findModules(subdir):
107
131
return modules
108
132
109
133
110
- def generateTemporaryUsdFile (usdFileName ):
134
+ def generateTemporaryUsdFile (usdFileName , tmpDir = None ):
111
135
""" Generate a temporary ASCII USD file that the user can edit.
112
136
113
137
:Parameters:
114
138
usdFileName : `str`
115
139
Binary USD file path
140
+ tmpDir : `str` | None
141
+ Temp directory to create the new unzipped directory within
116
142
:Returns:
117
143
Temporary file name
118
144
:Rtype:
119
145
`str`
120
146
:Raises OSError:
121
147
If usdcat fails
122
148
"""
123
- fd , tmpFileName = tempfile .mkstemp (suffix = ".usd" )
149
+ fd , tmpFileName = tempfile .mkstemp (suffix = ".usd" , dir = tmpDir )
124
150
try :
125
151
usdcat (usdFileName , tmpFileName , format = "usda" )
126
152
finally :
@@ -180,7 +206,7 @@ def usdzip(inputs, dest):
180
206
181
207
182
208
# TODO: Support nested references (e.g. @set.usdz[areas/shire.usdz[architecture/BilboHouse/Table.usd]]@)
183
- def unzip (path , layer = None ):
209
+ def unzip (path , layer = None , tmpDir = None ):
184
210
""" Unzip a usdz format file to a temporary directory.
185
211
186
212
:Parameters:
@@ -189,6 +215,8 @@ def unzip(path, layer=None):
189
215
layer : `str` | None
190
216
Default layer within file (e.g. the portion within the square brackets here:
191
217
@foo.usdz[path/to/file/within/package.usd]@)
218
+ tmpDir : `str` | None
219
+ Temp directory to create the new unzipped directory within
192
220
:Returns:
193
221
Destination file
194
222
:Rtype:
@@ -198,8 +226,7 @@ def unzip(path, layer=None):
198
226
:Raises ValueError:
199
227
If default layer not found
200
228
"""
201
- # TODO: Clean up this temp dir when exiting the app?
202
- destDir = tempfile .mkdtemp (prefix = "usdmanager_usdz_" )
229
+ destDir = tempfile .mkdtemp (prefix = "usdmanager_usdz_" , dir = tmpDir )
203
230
cmd = "unzip {} -d {}" .format (path , destDir )
204
231
logger .debug (cmd )
205
232
try :
0 commit comments