def test_replace_notreplaceable_reference(mock_suggestions, mock_replaceable, djprj, reftrackroot, refobjinter): mock_suggestions.return_value = [] mock_replaceable.return_value = False ref0 = Reference(True) robj0 = Refobj('Asset', None, ref0, djprj.assettaskfiles[-4], None) robj1 = Refobj('Asset', robj0, None, djprj.assettaskfiles[0], ref0) robj2 = Refobj('Asset', robj1, None, djprj.assettaskfiles[0], ref0) print robj0, robj1, robj2 ref0.content.append(robj1) ref0.content.append(robj2) t0, t1, t2 = Reftrack.wrap(reftrackroot, refobjinter, [robj0, robj1, robj2]) assert not t0.uptodate() assert t0.get_refobjinter().is_replaceable(t0.get_refobj()) is False assert t0.alien() t0.replace(TaskFileInfo.create_from_taskfile(djprj.assettaskfiles[2])) assert t0 in reftrackroot._reftracks assert t0.status() == Reftrack.LOADED assert len(t0._children) == 1 assert t0.get_refobj().taskfile == djprj.assettaskfiles[2] tfi = t0.get_taskfileinfo() reftfi = TaskFileInfo.create_from_taskfile(djprj.assettaskfiles[2]) assert tfi.version == reftfi.version assert tfi.task == reftfi.task assert tfi.releasetype == reftfi.releasetype assert tfi.descriptor == reftfi.descriptor t4 = t0._children[0] assert t4.get_refobj().parent is t0.get_refobj()
def test_import_without_dag(taskfile_without_dagnodes, djprj, assettypinter, mrefobjinter): cmds.file(new=True, force=True) cmds.namespace(add="foo") cmds.namespace(set="foo") assert cmds.namespaceInfo(absoluteName=True) == ":foo" tf = djprj.assettaskfiles[0] tfi = TaskFileInfo.create_from_taskfile(tf) refobj = mrefobjinter.create(typ="Asset", identifier=0) assettypinter.import_taskfile(refobj, tfi) # assert namespace is still the same assert cmds.namespaceInfo(absoluteName=True) == ":foo" ns = cmds.getAttr("%s.namespace" % refobj) assert ns == "smurf_1" assert not cmds.ls(type="jb_asset") assert cmds.getAttr("%s.taskfile_id" % refobj) == tf.pk # reference2 refobj2 = mrefobjinter.create(typ="Asset", identifier=1) assettypinter.import_taskfile(refobj2, tfi) # assert namespace is still the same assert cmds.namespaceInfo(absoluteName=True) == ":foo" ns2 = cmds.getAttr("%s.namespace" % refobj2) assert ns2 == "smurf_2" assert ns2 != ns assert not cmds.ls(type="jb_asset") assert cmds.getAttr("%s.taskfile_id" % refobj2) == tf.pk content = cmds.namespaceInfo(ns, listNamespace=True) content2 = cmds.namespaceInfo(ns2, listNamespace=True) for n in content + content2: assert cmds.referenceQuery(n, isNodeReferenced=True) is False
def test_replace(taskfile_with_dagnodes, taskfile_with_dagnodes2, djprj, assettypinter, mrefobjinter): cmds.file(new=True, force=True) tf = djprj.assettaskfiles[0] tfi = TaskFileInfo.create_from_taskfile(tf) refobj = mrefobjinter.create(typ="Asset", identifier=0) assettypinter.reference(refobj, tfi) refnode = cmds.referenceQuery(taskfile_with_dagnodes, referenceNode=True) ns = cmds.referenceQuery(refnode, namespace=True) ns = cmds.namespaceInfo(ns, fullName=True) assert "%s:testdagnode" % ns in cmds.ls(type="transform") assert "%s:othertestnode" % ns not in cmds.ls(type="transform") tf2 = djprj.assettaskfiles[1] tfi2 = TaskFileInfo(task=tf2.task, version=tf2.version, releasetype=tf2.releasetype, descriptor=tf2.descriptor, typ=tf2.typ) assettypinter.replace(refobj, refnode, tfi2) assert "%s:othertestnode" % ns in cmds.ls(type="transform") assert "%s:testdagnode" % ns not in cmds.ls(type="transform") assert cmds.getAttr("%s.taskfile_id" % refobj) == tf2.pk assert '%s:jb_sceneNode_test' % ns in cmds.listConnections('%s.scenenode' % refobj) assert cmds.listConnections('%s.taskfile_id' % refobj) == ['%s:jb_sceneNode_test' % ns] assettypinter.replace(refobj, refnode, tfi2) # this will reference the same file again. it will get a copy number # the file command does not return the name with copy number. seems like a bug # because the doc sais it will. You have to use the reference node for referenceQuery instead # to get the namespace, not the filename that is returned by the file command. assettypinter.replace(refobj, refnode, tfi)
def release_callback(self, *args, **kwargs): """Create a new release :returns: None :rtype: None :raises: None """ tf = self.browser.get_current_selection() if not tf: self.statusbar.showMessage("Select a file to release, please!") return tfi = TaskFileInfo.create_from_taskfile(tf) checks = self.get_checks() cleanups = self.get_cleanups() comment = self.get_comment() r = Release(tfi, checks, cleanups, comment) self.statusbar.showMessage("Release in progress...") try: success = r.release() except OSError: self.statusbar.showMessage("Could not copy workfile!") return except Exception as e: self.statusbar.showMessage("%s" % e) return if success: self.statusbar.showMessage("Success!") else: self.statusbar.showMessage("Release failed!")
def test_unload(taskfile_with_dagnodes, djprj, assettypinter, mrefobjinter): cmds.file(new=True, force=True) tf = djprj.assettaskfiles[0] tfi = TaskFileInfo.create_from_taskfile(tf) refobj = mrefobjinter.create(typ="Asset", identifier=0) assettypinter.reference(refobj, tfi) refnode = cmds.referenceQuery(taskfile_with_dagnodes, referenceNode=True) assert cmds.referenceQuery(refnode, isLoaded=True) is True assettypinter.unload(refobj, refnode) assert cmds.referenceQuery(refnode, isLoaded=True) is False
def test_reference(mock_suggestions, djprj, reftrackroot, refobjinter): mock_suggestions.return_value = [] t0 = Reftrack(reftrackroot, refobjinter, typ='Asset', element=djprj.assets[0], parent=None) assert reftrackroot._reftracks == set([t0]) t0.reference(TaskFileInfo.create_from_taskfile(djprj.assettaskfiles[0])) assert t0 in reftrackroot._reftracks assert len(t0._children) == 1 t1 = t0._children[0] assert t1.get_parent() is t0 robj0 = t0.get_refobj() robj1 = t1.get_refobj() assert robj0.taskfile == djprj.assettaskfiles[0] assert robj1.parent is robj0 assert robj0.parent is None assert robj0.typ == 'Asset' assert robj0.get_status() == Reftrack.LOADED assert t0.status() == Reftrack.LOADED tfi = t0.get_taskfileinfo() reftfi = TaskFileInfo.create_from_taskfile(djprj.assettaskfiles[0]) assert tfi.version == reftfi.version assert tfi.task == reftfi.task assert tfi.releasetype == reftfi.releasetype assert tfi.descriptor == reftfi.descriptor t2 = Reftrack(reftrackroot, refobjinter, typ='Asset', element=djprj.assets[0], parent=t0) t2.reference(TaskFileInfo.create_from_taskfile(djprj.assettaskfiles[0])) t3 = t2._children[0] assert len(t2._children) == 1 assert t2.get_parent() is t0 robj2 = t2.get_refobj() robj3 = t3.get_refobj() assert robj2.taskfile == djprj.assettaskfiles[0] assert robj2.parent is robj0 assert robj3.parent is robj2 assert robj2.typ == 'Asset' assert robj2.get_status() == Reftrack.LOADED assert t2.status() == Reftrack.LOADED tfi = t2.get_taskfileinfo() reftfi = TaskFileInfo.create_from_taskfile(djprj.assettaskfiles[0]) assert tfi.version == reftfi.version assert tfi.task == reftfi.task assert tfi.releasetype == reftfi.releasetype assert tfi.descriptor == reftfi.descriptor
def test_import_taskfile(mock_suggestions, djprj, reftrackroot, refobjinter): mock_suggestions.return_value = [] t0 = Reftrack(reftrackroot, refobjinter, typ='Asset', element=djprj.assets[0]) assert t0._children == [] assert t0.get_refobj() is None t0.import_file(TaskFileInfo.create_from_taskfile(djprj.assettaskfiles[0])) assert len(t0._children) == 1 t1 = t0._children[0] robj0 = t0.get_refobj() robj1 = t1.get_refobj() assert robj0.typ == 'Asset' assert robj0.parent is None assert robj0.children == [robj1] assert robj0.taskfile == djprj.assettaskfiles[0] assert robj1.parent is robj0 assert t0.status() == Reftrack.IMPORTED tfi = t0.get_taskfileinfo() reftfi = TaskFileInfo.create_from_taskfile(djprj.assettaskfiles[0]) assert tfi.version == reftfi.version assert tfi.task == reftfi.task assert tfi.releasetype == reftfi.releasetype assert tfi.descriptor == reftfi.descriptor
def test_delete(taskfile_with_dagnodes, djprj, assettypinter, mrefobjinter): cmds.file(new=True, force=True) tf = djprj.assettaskfiles[0] tfi = TaskFileInfo.create_from_taskfile(tf) refobj = mrefobjinter.create(typ="Asset", identifier=0) assettypinter.import_taskfile(refobj, tfi) ns = cmds.getAttr("%s.namespace" % refobj) assert cmds.objExists("%s:testdagnode" % ns) assert cmds.objExists(refobj) assettypinter.delete(refobj) assert cmds.namespace(exists=ns) is False assert cmds.objExists(refobj)
def taskfile_without_dagnodes(request, djprj, mrefobjinter): """Create a scene with a scenenode for djprj.assettaskfiles[0]. """ cmds.file(new=True, force=True) tf = djprj.assettaskfiles[0] scenenode = cmds.createNode("jb_sceneNode") cmds.setAttr("%s.taskfile_id" % scenenode, tf.pk) tfi = TaskFileInfo.create_from_taskfile(tf) jb = JB_File(tfi) jb.create_directory() f = cmds.file(rename=jb.get_fullpath()) cmds.file(save=True, type='mayaBinary') def fin(): os.remove(f) request.addfinalizer(fin) return f
def fetch_option_taskfileinfos(self, element): """Fetch the options for possible files to load, replace etc for the given element. Options from which to choose a file to load or replace. :param element: The element for which the options should be fetched. :type element: :class:`jukeboxcore.djadapter.models.Asset` | :class:`jukeboxcore.djadapter.models.Shot` :returns: The options :rtype: list of :class:`TaskFileInfo` :raises: None """ tfs = [] for task in element.tasks.all(): taskfiles = list(task.taskfile_set.filter(releasetype=djadapter.RELEASETYPES['release'], typ=djadapter.FILETYPES['mayamainscene'])) tfs.extend(taskfiles) tfis = [TaskFileInfo.create_from_taskfile(tf) for tf in tfs] return tfis
def test_reference_with_dag(taskfile_with_dagnodes, djprj, assettypinter, mrefobjinter): cmds.file(new=True, force=True) cmds.namespace(add="foo") cmds.namespace(set="foo") assert cmds.namespaceInfo(absoluteName=True) == ":foo" tf = djprj.assettaskfiles[0] tfi = TaskFileInfo.create_from_taskfile(tf) refobj = mrefobjinter.create(typ="Asset", identifier=0) assettypinter.reference(refobj, tfi) # assert namespace is still the same assert cmds.namespaceInfo(absoluteName=True) == ":foo" refnode = cmds.referenceQuery(taskfile_with_dagnodes, referenceNode=True) ns = cmds.referenceQuery(refnode, namespace=True) ns = cmds.namespaceInfo(ns, fullName=True) assert "%s:testdagnode" % ns in cmds.namespaceInfo( ns, listOnlyDependencyNodes=True) assert cmds.listRelatives("%s:testdagnode" % ns, parent=True, type="jb_asset") assert cmds.getAttr("%s.taskfile_id" % refobj) == tf.pk # reference2 refobj2 = mrefobjinter.create(typ="Asset", identifier=1) assettypinter.reference(refobj2, tfi) # assert namespace is still the same assert cmds.namespaceInfo(absoluteName=True) == ":foo" refnode2 = cmds.referenceQuery(taskfile_with_dagnodes + "{1}", referenceNode=True) ns2 = cmds.referenceQuery(refnode2, namespace=True) ns2 = cmds.namespaceInfo(ns2, fullName=True) assert refnode2 != refnode assert ns2 != ns assert "%s:testdagnode" % ns2 in cmds.namespaceInfo( ns2, listOnlyDependencyNodes=True) assert cmds.listRelatives("%s:testdagnode" % ns2, parent=True, type="jb_asset") assert cmds.getAttr("%s.taskfile_id" % refobj2) == tf.pk
def test_import_with_dag(taskfile_with_dagnodes, djprj, assettypinter, mrefobjinter): cmds.file(new=True, force=True) cmds.namespace(add="foo") cmds.namespace(set="foo") assert cmds.namespaceInfo(absoluteName=True) == ":foo" tf = djprj.assettaskfiles[0] tfi = TaskFileInfo.create_from_taskfile(tf) refobj = mrefobjinter.create(typ="Asset", identifier=0) assettypinter.import_taskfile(refobj, tfi) # assert namespace is still the same assert cmds.namespaceInfo(absoluteName=True) == ":foo" ns = cmds.getAttr("%s.namespace" % refobj) assert ns == "smurf_1" assert "%s:testdagnode" % ns in cmds.namespaceInfo( ns, listOnlyDependencyNodes=True) assert cmds.listRelatives("%s:testdagnode" % ns, parent=True, type="jb_asset") assert cmds.getAttr("%s.taskfile_id" % refobj) == tf.pk # reference2 refobj2 = mrefobjinter.create(typ="Asset", identifier=1) assettypinter.import_taskfile(refobj2, tfi) # assert namespace is still the same assert cmds.namespaceInfo(absoluteName=True) == ":foo" ns2 = cmds.getAttr("%s.namespace" % refobj2) assert ns2 == "smurf_2" assert ns2 != ns assert "%s:testdagnode" % ns2 in cmds.namespaceInfo( ns2, listOnlyDependencyNodes=True) assert cmds.listRelatives("%s:testdagnode" % ns2, parent=True, type="jb_asset") assert cmds.getAttr("%s.taskfile_id" % refobj2) == tf.pk assert cmds.referenceQuery("smurf_1:testdagnode", isNodeReferenced=True) is False assert cmds.referenceQuery("smurf_2:testdagnode", isNodeReferenced=True) is False
def taskfile_with_dagnodes2(request, djprj, mrefobjinter): cmds.file(new=True, force=True) """Create a scene with a scenenode for djprj.assettaskfiles[1] and a dag transform node "othertestnode". """ cmds.createNode("transform", name="othertestnode") tf = djprj.assettaskfiles[1] scenenode = cmds.createNode("jb_sceneNode", name='jb_sceneNode_test') cmds.setAttr("%s.taskfile_id" % scenenode, tf.pk) tfi = TaskFileInfo.create_from_taskfile(tf) jb = JB_File(tfi) jb.create_directory() f = cmds.file(rename=jb.get_fullpath()) cmds.file(save=True, type='mayaBinary') def fin(): os.remove(f) request.addfinalizer(fin) return f
def fetch_option_taskfileinfos(self, element): """Fetch the options for possible files to load, replace etc for the given element. Options from which to choose a file to load or replace. :param element: The element for which the options should be fetched. :type element: :class:`jukeboxcore.djadapter.models.Asset` | :class:`jukeboxcore.djadapter.models.Shot` :returns: The options :rtype: list of :class:`TaskFileInfo` :raises: None """ tfs = [] for task in element.tasks.all(): taskfiles = list( task.taskfile_set.filter( releasetype=djadapter.RELEASETYPES['release'], typ=djadapter.FILETYPES['mayamainscene'])) tfs.extend(taskfiles) tfis = [TaskFileInfo.create_from_taskfile(tf) for tf in tfs] return tfis