示例#1
0
 def stop(self):
     try:
         self.stopCallback()
         self.plugin.ytStop()
         self.stoppedCallback()
     except Exception, e:
         yl.error(e.message)
示例#2
0
 def updateItemCount(self, item):
     if isinstance(item, pkgItem):
         if item.getType() == pkgItemType.SPACEROOT:
             self.fileTreeWidget.topLevelItem(0).setText(
                 1, str(item.getCount()))
         elif item.getType() == pkgItemType.SPACE:
             self.fileTreeWidget.topLevelItem(0).child(
                 item.getPos()).setText(1, str(item.getCount()))
         elif item.getType() == pkgItemType.NODECLASS:
             self.fileTreeWidget.topLevelItem(0).child(
                 item.getParent().getPos()).child(item.getPos()).setText(
                     1, str(item.getCount()))
         elif item.getType() == pkgItemType.NODE:
             self.fileTreeWidget.topLevelItem(0).child(
                 item.getParent().getParent().getPos()).child(
                     item.getParent().getPos()).child(
                         item.getPos()).setText(1, str(item.getCount()))
         elif item.getType() in (pkgItemType.DIR, pkgItemType.FILE):
             self.fileTreeWidget.topLevelItem(0).child(
                 item.getParent().getParent().getParent().getPos()).child(
                     item.getParent().getParent().getPos()).child(
                         item.getParent().getPos()).child(
                             item.getPos()).setText(1, str(item.getCount()))
     else:
         yl.error('TypeError: item need pkgItem, but recevie a %s.' %
                  type(item))
示例#3
0
 def __new__(cls, name='', node=None, parent=None):
     if parent is not None and not isinstance(parent, ytNode):
         yl.error('TypeError: parameter parent need ytNode')
     elif not isinstance(name, str):
         yl.error('TypeError: parameter name need string')
     else:
         return object.__new__(cls, name=name, node=node, parent=parent)
示例#4
0
 def updateTreeView(self, item):
     if isinstance(item, pkgItem):
         qitem = QtGuiWidgets.QTreeWidgetItem()
         qitem.setText(0, item.getValue())
         qitem.setText(1, str(item.getCount()))
         if item.getType() == pkgItemType.SPACEROOT:
             self.fileTreeWidget.addTopLevelItem(qitem)
         elif item.getType() == pkgItemType.SPACE:
             self.fileTreeWidget.topLevelItem(0).insertChild(
                 item.getPos(), qitem)
         elif item.getType() == pkgItemType.NODECLASS:
             self.fileTreeWidget.topLevelItem(0).child(
                 item.getParent().getPos()).insertChild(
                     item.getPos(), qitem)
         elif item.getType() == pkgItemType.NODE:
             self.fileTreeWidget.topLevelItem(0).child(
                 item.getParent().getParent().getPos()).child(
                     item.getParent().getPos()).insertChild(
                         item.getPos(), qitem)
         elif item.getType() in (pkgItemType.DIR, pkgItemType.FILE):
             self.fileTreeWidget.topLevelItem(0).child(item.getParent(
             ).getParent().getParent().getParent().getPos()).child(
                 item.getParent().getParent().getPos()).child(
                     item.getParent().getPos()).insertChild(
                         item.getPos(), qitem)
     else:
         yl.error('TypeError: item need pkgItem, but recevie a %s.' %
                  type(item))
示例#5
0
 def getPkgNodeByPath(self, nodePkgPath=''):
     '''
     used by root ytNode
     nodePath is node fullName in nuke, getted by node.fullName()
     '''
     yl.debug('get ytNode by path: %s' % nodePkgPath)
     if not isinstance(nodePkgPath, str):
         yl.error(
             'TypeError: parameter need string, getted by node.fullName() in nuke'
         )
         return None
     if nodePkgPath == '':
         return self.rootNode
     pathNames = nodePkgPath.split('.')
     nodePkg = self.rootNode
     if pathNames != []:
         for p in pathNames:
             cn = nodePkg.getChildrenName()
             if p in cn:
                 nodePkg = nodePkg[cn.index(p)]
             else:
                 yl.error('can not find node: %s' % nodePkgPath)
                 return None
         return nodePkg
     return None
示例#6
0
 def appendItem(self, item):
     callBackType = 2
     if isinstance(item, pkgItem):
         self.__list.append(item)
         self.__count += 1
         self.callback(self, callBackType)
     else:
         yl.error('item need pkgItem class.')
示例#7
0
 def go(self):
     if not self.plugin.isRunning():
         try:
             self.startCallback()
             self.plugin.ytStart()
             self.startedCallback()
         except Exception, e:
             yl.error(e.message)
示例#8
0
 def stoppedCallback(self):
     if len(self.stoppedCallbackList) > 0:
         yl.debug('stoppedCallback of plugin: %s ' % self.plugin.name)
         try:
             for c in self.stoppedCallbackList:
                 c[0](self, *c[1])
         except Exception as e:
             yl.error(e.message)
示例#9
0
 def appendChild(self, child, caller=ytVariables.ytCaller.yt_caller_gui):
     if not isinstance(child, ytNode):
         yl.error('TypeError: parameter child need ytNode')
     if child not in self._children:
         self._children.append(child)
         self.callback(child, 4, caller)
         child.setParent(self)
     else:
         yl.error('%s has exist in %s, pass' % (child.getName(), self._name))
示例#10
0
 def popItem(self, index=-1):
     callBackType = 2
     try:
         self.__list.pop(index)
     except Exception as e:
         yl.error(e.message)
         return
     self.__count -= 1
     self.callback(self, callBackType)
示例#11
0
 def getNukeMainWindow(self):
     yl.debug('get main window instance of nuke')
     self.app = QtWidgets.QApplication.instance()
     for w in self.app.topLevelWidgets():
         if w.inherits('QMainWindow') and w.metaObject().className(
         ) == 'Foundry::UI::DockMainWindow':
             return w
     else:
         yl.error('RuntimeError: Could not find DockMainWindow instance')
示例#12
0
 def setIcon(self, icon, status):
     if status in ytVariables.ytIcon.__dict__.values():
         i = self.findIcon(icon)
         if i:
             self.icon[status] = i
         else:
             yl.error('can not find icon: %s, use default icon' % icon)
     else:
         yl.error('TypeError: status need ytVariables.ytIcon.status')
示例#13
0
 def callback(self, n):
     '''
     n value:
         0: valueChanged
     '''
     if n == 0 and yCallbacks.valueChangedCallback:
         try:
             for c in yCallbacks.valueChangedCallback:
                 c[0](*c[1])
         except Exception as e:
             yl.error(e.message)
示例#14
0
 def setStatus(self, s):
     callbackType = 1
     if s in [
             i[1] for i in inspect.getmembers(
                 pkgStatus, lambda a: not (inspect.isroutine(a)))
             if not (i[0].startswith('__') and i[0].endswith('__'))
     ]:
         self.__status = s
         self.callback(s, callbackType)
     else:
         yl.error('pkgStatus 没有 %s 属性' % s)
示例#15
0
def unitePath(path):
    try:
        path = str(path)
    except Exception as e:
        yl.error(e.message)
    if os.path.isfile(path):
        return path.replace('\\', '/')
    elif os.path.isdir(path):
        if not path.endswith('/') or not path.endswith('\\'):
            path += '/'
        return path.replace('\\', '/')
示例#16
0
 def __setitem__(self, key, item):
     if isinstance(item, pkgItem):
         if isinstance(key, int):
             self.__list[key] = item
         elif isinstance(key, str):
             for index, it in enumerate(self.__list):
                 if it.getValue() == key:
                     self.__list[index] = item
                 else:
                     yl.error('没有关键字: %s ' % key)
     else:
         yl.error('值必须是 pkgItem 类型')
示例#17
0
 def run(self):
     runningTasks = []
     yl.debug('start pkgItemThreadQueue')
     while not self.__stop:
         taskIndex = 0
         while self.__activeTaskCount >= self.__wantTaskCount:
             yl.debug(
                 'acitveTaskCount is equal or greater than wantTaskCount, so loop until one thread complete'
             )
             if taskIndex >= self.__wantTaskCount:
                 yl.debug('taskIndex turn to 0')
                 taskIndex = 0
             if runningTasks[taskIndex].isRunning():
                 yl.debug('task is running, next')
                 taskIndex += 1
             else:
                 yl.debug('task is complete, pop it form running tasks')
                 runningTasks.pop(taskIndex)
                 self.__activeTaskCount -= 1
             threading.Event().wait(0.1)
         yl.debug('prepare to get item')
         try:
             result = self.__queue.get()
         except Exception as e:
             threading.Event().wait(0.1)
             continue
         # stop if get pkgItemThreadQueueSignal.STOP_SIGNAL
         if isinstance(
                 result,
                 str) and result == pkgItemThreadQueueSignal.STOP_SIGNAL:
             break
         elif isinstance(result, pkgItemThread):
             yl.debug('get pkgItem: %s' % result.getPkgItem().getValue())
             runningTasks.append(result)
             self.__activeTaskCount += 1
             try:
                 result.start()
             except Exception as e:
                 yl.error(e.message)
         else:
             yl.warning(
                 'pkgItemThreadQueue need pkgItemThread,but receive %s' %
                 str(type(result)))
         yl.debug('next pkgItemThread')
         if self.__queue.empty():
             yl.debug('pkgItemThreadQueue is empty')
             self.callback(0)
         else:
             yl.debug('pkgItemThreadQueue is not empty')
             self.callback(1)
         threading.Event().wait(0.1)
     yl.debug('stop pkgItemThreadQueue')
示例#18
0
 def callback(self, item, n):
     '''
     n value:
         0: valueChanged
         1: statusChanged
         2: countChanged
         3: create
     '''
     if n == 0 and yCallbacks.valueChangedCallback:
         try:
             for c in yCallbacks.valueChangedCallback:
                 c[0](item, *c[1])
         except Exception as e:
             yl.error(e.message)
     elif n == 1 and yCallbacks.statusChangedCallback:
         try:
             for c in yCallbacks.statusChangedCallback:
                 c[0](item, *c[1])
         except Exception as e:
             yl.error(e.message)
     elif n == 2 and yCallbacks.countChangedCallback:
         try:
             for c in yCallbacks.countChangedCallback:
                 c[0](item, *c[1])
         except Exception as e:
             yl.error(e.message)
     elif n == 3 and yCallbacks.createCallback:
         try:
             for c in yCallbacks.createCallback:
                 c[0](item, *c[1])
         except Exception as e:
             yl.error(e.message)
示例#19
0
 def pkgItems(self, path):
     if not self.__isPackaging:
         self.__isPackaging = True
         if os.path.isdir(path):
             self.__pkgedFilePath = {}
             for items in self.walkItems():
                 for index, item in enumerate(items):
                     yl.debug('add pkg item:%s to thread queue' %
                              item.getValue())
                     self.__queue.put(
                         pkgItemThread(item, path, self.__pkgedFilePath))
         else:
             yl.error('path: %s is not exists' % path)
     else:
         yl.warning('packaging, wait a moment')
示例#20
0
 def copy(self, newName=None, newDirname=None, replace=False):
     '''
     copy file
     if newName is None, keep name as source
     if newDirname is None, copy to source path, so newName must be different with source name.
     if replace is True, if destination path is exists, remove it, than move.
     '''
     # newName analize
     if not os.path.isdir(newDirname):
         os.mkdirs(newDirname)
     dirname = os.path.dirname(self.__path)
     if newDirname is None:
         newDirname = dirname
     if newName is None:
         newName = os.path.basename(self.__path)
     analizePathPattern = re.compile(self.__regex)
     newNameResult = analizePathPattern.match(newName)
     if newNameResult:
         result = analizePathPattern.match(os.path.basename(self.__path))
         for num in self.__frames:
             fileName = ''.join(
                 (result.group(1), str(seq2num(num, result.group(2))),
                  result.group(5)))
             newName = ''.join((newNameResult.group(1),
                                str(seq2num(num, newNameResult.group(2))),
                                newNameResult.group(5)))
             if newName != fileName or newDirname != dirname:
                 if os.path.exists(os.path.join(newDirname, newName)):
                     if replace:
                         try:
                             os.remove(os.path.join(newDirname, newName))
                             yl.warning('destination is exists ,remove it')
                         except Exception, e:
                             yl.error(e.message)
                     else:
                         yl.warning(
                             'copy failed, destination is exists, pass')
                         continue
                 try:
                     shutil.copyfile(os.path.join(dirname, fileName),
                                     os.path.join(newDirname, newName))
                 except Exception, e:
                     yl.error(e.message)
                 yl.debug('copy file: {} => {}'.format(fileName, newName))
             else:
                 yl.warning(
                     'copy failed, destination name is the same as source name'
                 )
示例#21
0
 def callback(self, n):
     '''
     n value:
         0: close event
         1: show event
     '''
     if n == 0 and yCallbacks.pkgGuiCloseCallback:
         try:
             for c in yCallbacks.pkgGuiCloseCallback:
                 c[0](*c[1])
         except Exception as e:
             yl.error(e.message)
     if n == 1 and yCallbacks.pkgGuiShowCallback:
         try:
             for c in yCallbacks.pkgGuiShowCallback:
                 c[0](*c[1])
         except Exception as e:
             yl.error(e.message)
示例#22
0
 def __new__(cls,
             parent=None,
             value='',
             status=None,
             itemtype=None,
             count=0,
             pos=0):
     if not (parent is None or isinstance(parent, pkgItem)):
         yl.error('参数 parent 类型错误,需要 pkgItem')
     elif not isinstance(value, str):
         yl.error('参数 value 类型错误, 需要 string')
     elif status not in pkgStatus.__dict__.values():
         yl.error('参数 status 值错误, 需要 pkgStatus')
     elif itemtype not in pkgItemType.__dict__.values():
         yl.error('参数 itemtype 值错误, 需要 pkgItemType')
     elif not isinstance(count, int):
         yl.error('参数 count 类型错误, 需要 int')
     else:
         return object.__new__(cls, value, status, itemtype, count)
示例#23
0
 def callback(self, n):
     '''
     n value:
         0: yCallbacks.pkgItemThreadQueueEmptyCallback
         1: yCallbacks.pkgItemThreadQueueNotEmptyCallback
     '''
     if n == 0 and yCallbacks.pkgItemThreadQueueEmptyCallback:
         yl.debug('call yCallbacks.pkgItemThreadQueueEmptyCallback')
         try:
             for c in yCallbacks.pkgItemThreadQueueEmptyCallback:
                 c[0](*c[1])
         except Exception as e:
             yl.error(e.message)
     elif n == 1 and yCallbacks.pkgItemThreadQueueNotEmptyCallback:
         yl.debug('call yCallbacks.pkgItemThreadQueueNotEmptyCallback')
         try:
             for c in yCallbacks.pkgItemThreadQueueNotEmptyCallback:
                 c[0](*c[1])
         except Exception as e:
             yl.error(e.message)
示例#24
0
 def optimizeList(self):
     if len(self.__frames) > 0:
         frameLen = len(self.__frames)
         if frameLen < 2:
             return [self.__frames]
         splittedFrame = []
         splittedList = [self.__frames[0]]
         i = 1
         while i < frameLen:
             if abs(self.__frames[i] - self.__frames[i - 1]) == 1:
                 splittedList.append(self.__frames[i])
             else:
                 splittedFrame.append(splittedList)
                 splittedList = [self.__frames[i]]
             i += 1
         splittedFrame.append(splittedList)
         return splittedFrame
     else:
         yl.error(
             'there is noting in frames, please ensure there are files in this path ,then call scan method to get frames'
         )
示例#25
0
 def setPos(self, pos):
     if isinstance(pos, int):
         self.__pos = pos
     else:
         yl.error('TypeError: pos need int, but receive a %s.' % type(pos))
示例#26
0
                        else:
                            yl.warning(
                                'move failed, destination is exists, pass')
                            continue
                    try:
                        os.rename(os.path.join(dirname, fileName),
                                  os.path.join(newDirname, newName))
                    except Exception, e:
                        yl.error(e.message)
                    yl.debug('move file: {} => {}'.format(fileName, newName))
                else:
                    yl.warning(
                        'move failed, destination name is the same as source name'
                    )
        else:
            yl.error(
                'newName format error, for example: abc.###.dpx, abc.%05d.dpx')

    def copy(self, newName=None, newDirname=None, replace=False):
        '''
        copy file
        if newName is None, keep name as source
        if newDirname is None, copy to source path, so newName must be different with source name.
        if replace is True, if destination path is exists, remove it, than move.
        '''
        # newName analize
        if not os.path.isdir(newDirname):
            os.mkdirs(newDirname)
        dirname = os.path.dirname(self.__path)
        if newDirname is None:
            newDirname = dirname
        if newName is None:
示例#27
0
 def __new__(cls, plugin):
     if isinstance(plugin, ytPlugin):
         return object.__new__(cls, plugin)
     else:
         yl.error('TypeError: plugin need ytPlugin, but: %s' %
                  str(type(plugin)))
示例#28
0
 def run(self):
     global searchNodes
     # 如果 item 类型为 文件 或者 文件夹,将 文件 或 文件夹 拷贝到目标路径下。
     self.__running = True
     yl.debug(
         'start running pkgItemThread, package item: %s, type is: %s, status is: %s'
         % (self.__item.getValue(), self.__item.getType(),
            self.__item.getStatus()))
     if self.__item.getType() in (pkgItemType.FILE, pkgItemType.DIR):
         yl.debug('%s is a file or directory' % self.__item.getValue())
         if self.__item.getParent().getStatus() != pkgStatus.PKGED:
             pkgPath = os.path.join(
                 self.__path,
                 '/'.join(self.__item.getParent().getNodePath().split('.')),
                 os.path.basename(self.__item.getDirPath()))
             yl.debug(pkgPath)
             if not os.path.exists(pkgPath):
                 try:
                     os.makedirs(pkgPath)
                 except Exception as e:
                     yl.error(e.message)
             # 拷贝文件
             dst = os.path.join(pkgPath, self.__item.getValue())
             if os.path.exists(dst):
                 yl.debug('%s is exist, try to remove it' %
                          self.__item.getValue())
                 try:
                     shutil.rmtree(dst)
                 except Exception as e:
                     yl.error(e.message)
             yl.debug('copy %s to %s' % (os.path.join(
                 self.__item.getDirPath(), self.__item.getValue()), dst))
             try:
                 shutil.copy(
                     os.path.join(self.__item.getDirPath(),
                                  self.__item.getValue()), dst)
                 self.__item.setStatus(pkgStatus.PKGED)
                 self.__item.callback(self, 1)
             except Exception as e:
                 yl.error(e.message)
     # 如果 item 类型为 节点,替换节点的文件路径。
     elif self.__item.getType() == pkgItemType.NODE:
         yl.debug('%s is a node' % self.__item.getValue())
         pkgPath = os.path.join(
             self.__path, '/'.join(self.__item.getNodePath().split('.')))
         filePath = os.path.join(
             pkgPath,
             os.path.basename(os.path.dirname(self.__item.getDirPath())),
             os.path.basename(self.__item.getDirPath())).replace('\\', '/')
         if self.__item.getDirPath() not in self.__pkgedFilePathList:
             self.__pkgedFilePathList[self.__item.getDirPath()] = filePath
         else:
             filePath = self.__pkgedFilePathList[self.__item.getDirPath()]
             self.__item.setStatus(pkgStatus.PKGED)
         n = nuke.toNode(self.__item.getNodePath())
         for nodeClass, knob, conditionKnob, conditionKnobValue in searchNodes:
             if n.Class() == nodeClass:
                 n[knob].setValue(filePath)
     # 如果 item 类型为 spaceroot,则在目录下创建同名的文件夹。
     elif self.__item.getType() == pkgItemType.SPACEROOT:
         yl.debug('%s is a root namespace' % self.__item.getValue())
         pkgPath = self.__path
         if not os.path.exists(pkgPath):
             try:
                 os.makedirs(pkgPath)
             except Exception as e:
                 yl.error(e.message)
         try:
             # 保存 Nuke 脚本到该目录下
             nuke.scriptSaveAs(
                 os.path.join(self.__path, self.__item.getValue()), 1)
             self.__item.setStatus(pkgStatus.PKGED)
             self.__item.callback(self, 1)
         except Exception as e:
             yl.error(e.message)
     else:
         yl.debug('%s is not a file or directory, pass' %
                  self.__item.getValue())
     self.__running = False
     yl.debug('%s thread is completed' % self.__item.getValue())
示例#29
0
 def __setItemThreadQueueEmpty(self, empty):
     if empty in (1, 0, True, False):
         yl.debug('set __itemThreadQueueEmpty %s' % empty)
         self.__itemThreadQueueEmpty = empty
     else:
         yl.error('need boolean')
示例#30
0
 def callback(self, item, n):
     '''
     n value:
         0: spaceRoot
         1: space
         2: nodeclass
         3: nodefilepath
         4: filepath
         5: package file
         6: start get files
         7: get files complete
     '''
     if n == 0 and yCallbacks.spaceRootCallback:
         try:
             for c in yCallbacks.spaceRootCallback:
                 c[0](item, *c[1])
         except Exception as e:
             yl.error(e.message)
     elif n == 1 and yCallbacks.perSpaceCallback:
         try:
             for c in yCallbacks.perSpaceCallback:
                 c[0](item, *c[1])
         except Exception as e:
             yl.error(e.message)
     elif n == 2 and yCallbacks.perNodeClassCallback:
         try:
             for c in yCallbacks.perNodeClassCallback:
                 c[0](item, *c[1])
         except Exception as e:
             yl.error(e.message)
     elif n == 3 and yCallbacks.perNodeFilePathCallback:
         try:
             for c in yCallbacks.perNodeFilePathCallback:
                 c[0](item, *c[1])
         except Exception as e:
             yl.error(e.message)
     elif n == 4 and yCallbacks.perFileCallback:
         try:
             for c in yCallbacks.perFileCallback:
                 c[0](item, *c[1])
         except Exception as e:
             yl.error(e.message)
     elif n == 5 and yCallbacks.perPkgFileCallback:
         try:
             for c in yCallbacks.perPkgFileCallback:
                 c[0](item, *c[1])
         except Exception as e:
             yl.error(e.message)
     elif n == 6 and yCallbacks.startGetFilesCallback:
         try:
             for c in yCallbacks.startGetFilesCallback:
                 c[0](item, *c[1])
         except Exception as e:
             yl.error(e.message)
     elif n == 7 and yCallbacks.getFilesCompleteCallback:
         try:
             for c in yCallbacks.getFilesCompleteCallback:
                 c[0](item, *c[1])
         except Exception as e:
             yl.error(e.message)