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_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 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 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
def asset_save_callback(self, *args, **kwargs): """Callback for the shot open button :returns: None :rtype: None :raises: None """ tasksel = self.browser.assetbrws.selected_indexes(2) if not tasksel or not tasksel[0].isValid(): self.statusbar.showMessage('No task selected! Cannot save!') return taskitem = tasksel[0].internalPointer() task = taskitem.internal_data() rtype = djadapter.RELEASETYPES['work'] descriptor = self.asset_descriptor_le.text() if not self.check_selection_for_save(task, rtype, descriptor): return tfi = TaskFileInfo.get_next(task=task, releasetype=rtype, typ=self._filetype, descriptor=descriptor) self._save_tfi(tfi, asset=True)
def djprj(user): from jukeboxcore import djadapter as dj from jukeboxcore.filesys import TaskFileInfo c = DjangoProjectContainer() prjpath = os.path.join(tempfile.gettempdir(), "avatar3") prj = dj.projects.create(name="Avatar3", short='av3', _path=prjpath, semester='SS14', scale="cm") c.prjs.append(prj) seqparams = [{ 'name': 'Seq01', 'description': 'smurfs dancing' }, { 'name': 'Seq02', 'description': 'smurfs fighting cg crap' }] shotparams = [{ 'name': 'Shot01', 'description': 'smurfs face' }, { 'name': 'Shot02', 'description': 'more smurfing' }] atypeparams = [{ 'name': 'coolprop', 'description': 'cooler props' }, { 'name': 'coolchar', 'description': 'cooler characters' }] assetparams = [{ 'name': 'smurf', 'description': 'blue disney character' }, { 'name': 'gijoe', 'description': 'the stereotypes!' }] adepparams = [{ 'name': 'Texturing', 'short': 'tex' }, { 'name': 'Sculpting', 'short': 'scp' }] sdepparams = [{ 'name': 'Tracking', 'short': 'trck' }, { 'name': 'Cleaning', 'short': 'cl' }] stfparams = [{ 'version': 1, 'releasetype': 'release', 'typ': dj.FILETYPES['mayamainscene'], 'descriptor': None }, { 'version': 2, 'releasetype': 'release', 'typ': dj.FILETYPES['mayamainscene'], 'descriptor': None }, { 'version': 3, 'releasetype': 'release', 'typ': dj.FILETYPES['mayamainscene'], 'descriptor': None }, { 'version': 1, 'releasetype': 'work', 'typ': dj.FILETYPES['mayamainscene'], 'descriptor': 'desc1' }] atfparams = [{ 'version': 1, 'releasetype': 'release', 'typ': dj.FILETYPES['mayamainscene'], 'descriptor': None }, { 'version': 2, 'releasetype': 'release', 'typ': dj.FILETYPES['mayamainscene'], 'descriptor': None }, { 'version': 3, 'releasetype': 'release', 'typ': dj.FILETYPES['mayamainscene'], 'descriptor': None }, { 'version': 1, 'releasetype': 'work', 'typ': dj.FILETYPES['mayamainscene'], 'descriptor': 'desc1' }] for adepparam in adepparams: dep = dj.departments.create(assetflag=True, **adepparam) c.assetdepartments.append(dep) for sdepparam in sdepparams: dep = dj.departments.create(assetflag=False, **sdepparam) c.shotdepartments.append(dep) for seqparam in seqparams: seq = dj.sequences.create(project=prj, **seqparam) c.sequences.append(seq) for shotparam in shotparams: shot = dj.shots.create(project=prj, sequence=seq, **shotparam) c.shots.append(shot) for atypeparam in atypeparams: atype = dj.atypes.create(**atypeparam) atype.projects.add(prj) atype.save() c.atypes.append(atype) for assetparam in assetparams: asset = dj.assets.create(project=prj, atype=atype, **assetparam) c.assets.append(asset) for dep in c.shotdepartments: for s in c.shots: task = dj.tasks.create(department=dep, project=prj, status='New', element=s) c.shottasks.append(task) for stfparam in stfparams: tfile = dj.taskfiles.create( task=task, user=user, path="%s%s%s%s%s%s" % (prj.name, s.sequence.name, s.name, dep.short, stfparam['releasetype'], stfparam['version']), **stfparam) c.shottaskfiles.append(tfile) tfileinfo = TaskFileInfo(task=tfile.task, version=tfile.version, releasetype=tfile.releasetype, typ=tfile.typ, descriptor=tfile.descriptor) c.shottfis.append(tfileinfo) for dep in c.assetdepartments: for a in c.assets: task = dj.tasks.create(department=dep, project=prj, status='New', element=a) c.assettasks.append(task) for atfparam in atfparams: tfile = dj.taskfiles.create( task=task, user=user, path="%s%s%s%s%s%s" % (prj.name, a.atype.name, a.name, dep.short, atfparam['releasetype'], atfparam['version']), **atfparam) c.assettaskfiles.append(tfile) tfileinfo = TaskFileInfo(task=tfile.task, version=tfile.version, releasetype=tfile.releasetype, typ=tfile.typ, descriptor=tfile.descriptor) c.assettfis.append(tfileinfo) for shot in c.shots: for asset in c.assets[:-2]: shot.assets.add(asset) return c