def getFiles(self): if not nuke.root()['name'].value(): yl.warning('save script first') return yl.info('start getting file list') # get files callback self.callback(self, 6) # 初始化根 spaceRoot yl.debug('create script namespace') self.__spaceRoot = pkgItem(value=os.path.basename( nuke.root()['name'].value()), status=pkgStatus.NORMAL, itemtype=pkgItemType.SPACEROOT) self.__spaceRoot.setDirPath( os.path.dirname(nuke.root()['name'].value())) # spaceRootCallback self.callback(self.__spaceRoot, 0) yl.debug('get root and group node, named space') for spaces in self.getSpaces(): for space in spaces: sp = pkgItem(parent=self.__spaceRoot, value=space, status=pkgStatus.NORMAL, itemtype=pkgItemType.SPACE) sp.setNodePath(space) yl.debug('create space: %s' % sp.getValue()) # perSpaceCallback self.callback(sp, 2) self.__spaceRoot.appendItem(sp) self.getFilesInSpace(sp) yl.info('getting files list complete') return
def deRegeditPlugin(pluginName): global plugins if pluginName in getPluginsName(): yl.debug('deRegedited plugin: %s' % pluginName) p = getPluginByName(pluginName) plugins.pop(getPluginsName().index(pluginName)) else: yl.warning('plugin: %s do not existed, ignore' % p.getName())
def getFiles(self): if not self.__isGettingFiles: self.__isGettingFiles = True yl.debug('create getting file thread') getFilesThread = pkgGetFilesThread() yl.debug('start get file list thread') getFilesThread.start() else: yl.warning('getting file list, please wait a moment...')
def registerPlugin(plugin): global plugins if isinstance(plugin, ytPlugin.ytPlugin): if plugin.name not in getPluginsName(): p = ytPlugin.ytRegeditPlugin(plugin) plugins.append(p) yl.debug('registered plugin: %s' % p.getName()) return True else: yl.warning('plugin: %s has existed, ignore' % p.getName()) return False
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')
def printRootTree(self): if self.__spaceRoot: print self.__spaceRoot for idr, r in enumerate(self.__spaceRoot.children()): print '├─' + r.getValue() for idi, i in enumerate(r.children()): print '│ ├─' + i.getValue() for idj, j in enumerate(i.children()): print '│ │ ├─' + j.getValue() for idn, n in enumerate(j.children()): print '│ │ │ ├─' + n.getValue() else: yl.warning('spaceRoot 不存在,请先保存工程')
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')
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' )