26
26
27
27
log = LogManager .get_logger (__name__ )
28
28
29
+
29
30
def from_entity (entity_type , entity_id ):
30
31
"""
31
32
Factory method that constructs a pipeline configuration given a Shotgun Entity.
@@ -87,19 +88,20 @@ def _from_entity(entity_type, entity_id, force_reread_shotgun_cache):
87
88
# figure out if we are running a tank command / api from a local
88
89
# pipeline config or from a studio level install
89
90
config_context_path = _get_configuration_context ()
91
+ config_context_id = _get_configuration_id ()
90
92
91
- if config_context_path :
93
+ if config_context_id and config_context_path :
92
94
# we are running the tank command or python core API directly from a configuration
93
95
#
94
96
# make sure that the tank command we are launching from belong to a shotgun project
95
97
# that the input entity type/id is associated with.
96
- if config_context_path not in [x ["path " ] for x in all_pc_data ]:
98
+ if config_context_id not in [x ["id " ] for x in all_pc_data ]:
97
99
# the tank command / api proxy that this session was launched for is *not*
98
100
# associated with the given entity type and entity id!
99
- raise TankError ("The pipeline configuration in '%s' is is associated with a different "
101
+ raise TankError ("The pipeline configuration in '%s' with id %s is is associated with a different "
100
102
"project from %s %s. To see which pipeline configurations are available "
101
103
"for a project, open the pipeline configurations page "
102
- "in Shotgun." % (config_context_path , entity_type , entity_id ))
104
+ "in Shotgun." % (config_context_path , config_context_id , entity_type , entity_id ))
103
105
104
106
# ok we got a pipeline config matching the tank command from which we launched.
105
107
# because we found the pipeline config in the list of PCs for this project,
@@ -124,8 +126,8 @@ def _from_entity(entity_type, entity_id, force_reread_shotgun_cache):
124
126
# incorrectly re-using the same paths.
125
127
126
128
pcs_msg = ", " .join ([
127
- "'%s' (Pipeline config id %s, Project id %s)" % (x ["path" ], x ["id" ], x ["project_id" ])
128
- for x in primary_pc_data ])
129
+ "'%s' (Pipeline config id %s, Project id %s)" % (x ["path" ], x ["id" ], x ["project_id" ])
130
+ for x in primary_pc_data ])
129
131
130
132
raise TankError ("More than one primary pipeline configuration is associated "
131
133
"with the entity %s %s. This happens if more than one pipeline configuration "
@@ -137,7 +139,6 @@ def _from_entity(entity_type, entity_id, force_reread_shotgun_cache):
137
139
return PipelineConfiguration (primary_pc_data [0 ]["path" ])
138
140
139
141
140
-
141
142
def from_path (path ):
142
143
"""
143
144
Factory method that constructs a pipeline configuration given a path on disk.
@@ -221,21 +222,21 @@ def _from_path(path, force_reread_shotgun_cache):
221
222
# figure out if we are running a tank command / api from a
222
223
# local pipeline config or from a studio level install
223
224
config_context_path = _get_configuration_context ()
225
+ config_context_id = _get_configuration_id ()
224
226
225
- if config_context_path :
227
+ if config_context_id and config_context_path :
226
228
227
229
# we are running the tank command or python core API directly from a configuration
228
230
#
229
- # now if this tank command is associated with the path , the registered path should be in
231
+ # now if this tank command is associated with the id , the registered id should be in
230
232
# in the pipeline configuration data coming from
231
- if config_context_path not in [x ["path" ] for x in all_pc_data ]:
232
-
233
+ if config_context_id not in [x ["id" ] for x in all_pc_data ]:
233
234
pcs_msg = ", " .join ([
234
- "'%s' (Pipeline config id %s, Project id %s)" % (x ["path" ], x ["id" ], x ["project_id" ])
235
- for x in all_pc_data ])
235
+ "'%s' (Pipeline config id %s, Project id %s)" % (x ["path" ], x ["id" ], x ["project_id" ])
236
+ for x in all_pc_data ])
236
237
237
238
raise TankError ("You are trying to start Toolkit using the pipeline configuration "
238
- "located in '%s'. The path '%s' you are trying to load is not "
239
+ "located in '%s' with id '%s' . The path '%s' you are trying to load is not "
239
240
"associated with that configuration. Instead, it is "
240
241
"associated with the following pipeline configurations: %s. "
241
242
"Please use the tank command or Toolkit API in any of those "
@@ -244,7 +245,7 @@ def _from_path(path, force_reread_shotgun_cache):
244
245
"the 'tank move_configuration command'. It can also occur if you "
245
246
"are trying to use a tank command associated with one Project "
246
247
"to try to operate on a Shot or Asset that belongs to another "
247
- "project." % (config_context_path , path , pcs_msg ))
248
+ "project." % (config_context_path , config_context_id , path , pcs_msg ))
248
249
249
250
# okay so this pipeline config is valid!
250
251
return PipelineConfiguration (config_context_path )
@@ -253,20 +254,18 @@ def _from_path(path, force_reread_shotgun_cache):
253
254
# we are running a studio level tank command.
254
255
# find the primary pipeline configuration in the list of matching configurations.
255
256
if len (primary_pc_data ) == 0 :
256
-
257
257
pcs_msg = ", " .join ([
258
- "'%s' (Pipeline config id %s, Project id %s)" % (x ["path" ], x ["id" ], x ["project_id" ])
259
- for x in all_pc_data ])
258
+ "'%s' (Pipeline config id %s, Project id %s)" % (x ["path" ], x ["id" ], x ["project_id" ])
259
+ for x in all_pc_data ])
260
260
261
261
raise TankError ("Cannot find a primary pipeline configuration for path '%s'. "
262
262
"The following pipeline configurations are associated with the "
263
263
"path, but none of them is marked as Primary: %s" % (path , pcs_msg ))
264
264
265
265
if len (primary_pc_data ) > 1 :
266
-
267
266
pcs_msg = ", " .join ([
268
- "'%s' (Pipeline config id %s, Project id %s)" % (x ["path" ], x ["id" ], x ["project_id" ])
269
- for x in primary_pc_data ])
267
+ "'%s' (Pipeline config id %s, Project id %s)" % (x ["path" ], x ["id" ], x ["project_id" ])
268
+ for x in primary_pc_data ])
270
269
271
270
raise TankError ("The path '%s' is associated with more than one Primary pipeline "
272
271
"configuration. This can happen if there is ambiguity in your project setup, where "
@@ -315,6 +314,30 @@ def _get_configuration_context():
315
314
return val
316
315
317
316
317
+ def _get_configuration_id ():
318
+ """
319
+ Returns a id if the API was invoked via a configuration context, otherwise None.
320
+
321
+ If this session was involved (tank command or python API) from a studio level API,
322
+ e.g. with no connection to any config, None is returned.
323
+
324
+ In the case the session was started via a python proxy API or tank command
325
+ connected to a configuration, the id to that configuration root is returned.
326
+ The id returned should reflect the exact value stored in the pipeline configuration
327
+ entry in shotgun.
328
+
329
+ :returns: id or None
330
+ """
331
+ # default for studio level tank command/API
332
+ val = None
333
+ if "TANK_CURRENT_PC" in os .environ :
334
+ config_path = os .environ ["TANK_CURRENT_PC" ]
335
+ pc = PipelineConfiguration (config_path )
336
+ data = pc ._get_metadata ()
337
+ val = data ["pc_id" ]
338
+ return val
339
+
340
+
318
341
def _get_pipeline_configuration_data (sg_pipeline_configs ):
319
342
"""
320
343
Helper method. Given a list of Shotgun Pipeline configuration entity data, return a
@@ -462,7 +485,7 @@ def _get_pipeline_configs_for_path(path, data):
462
485
# in the pipeline config before associating it here.
463
486
if pc not in project_paths [project_path ]:
464
487
project_paths [project_path ].append (pc )
465
-
488
+
466
489
# step 3 - look at the path we passed in - see if any of the computed
467
490
# project folders are determined to be a parent path
468
491
all_matching_pcs = []
@@ -520,7 +543,6 @@ def _get_pipeline_configs_for_project(project_id, data):
520
543
return matching_pipeline_configs
521
544
522
545
523
-
524
546
#################################################################################################################
525
547
# methods relating to maintaining a small cache to speed up initialization
526
548
@@ -629,6 +651,7 @@ def _get_pipeline_configs(force=False):
629
651
630
652
return data
631
653
654
+
632
655
def _load_lookup_cache ():
633
656
"""
634
657
Load lookup cache file from disk.
@@ -652,6 +675,7 @@ def _load_lookup_cache():
652
675
653
676
return cache_data
654
677
678
+
655
679
@filesystem .with_cleared_umask
656
680
def _add_to_lookup_cache (key , data ):
657
681
"""
@@ -688,7 +712,6 @@ def _add_to_lookup_cache(key, data):
688
712
)
689
713
690
714
691
-
692
715
def _get_cache_location ():
693
716
"""
694
717
Get the location of the initializtion lookup cache.
0 commit comments