def getControlShapeFiles(): dir = CONTROL_DIRECTORY if isinstance(dir, basestring): dir = Path(dir) if not isinstance(dir, Path) or not dir.exists(): dir = Path(__file__).up() shapes = [] if dir.exists(): shapes = [f for f in dir.files() if f.hasExtension('shape')] if not shapes: searchPaths = map(Path, sys.path) searchPaths += map(Path, os.environ.get('MAYA_SCRIPT_PATH', '').split(';')) searchPaths = removeDupes(searchPaths) for d in searchPaths: try: shapes += [f for f in d.files() if f.hasExtension('shape')] except WindowsError: continue return shapes
def build_popup(self, parent, *a): cmd.setParent(parent, m=True) cmd.menu(parent, e=True, dai=True) thisFile = Path(cmd.file(q=True, sn=True)) #if the file doesn't exist, then use teh cwd if not thisFile.exists(): thisFile = thisFile.getcwd() / "tmp.ma" dir = thisFile.up() curFile = Path(cmd.textField(self.UI_file, q=True, tx=True)) for f in dir.files(): if f.hasExtension(skinWeights.EXTENSION): cmd.menuItem(l=f.name(), cb=f == curFile, c=api.Callback(cmd.textField, self.UI_file, e=True, tx=f)) cmd.menuItem(d=True) cmd.menuItem(l="browse", c=self.on_browseWeightFile) cmd.menuItem(d=True) cmd.menuItem(l="clear", c=lambda *a: cmd.textField(self.UI_file, e=True, tx='')) if curFile.exists(): cmd.menuItem(d=True) api.addExploreToMenuItems(curFile)
def packageScripts(scriptFilesToPackage, destPackageFilepath, dependencyTree): ''' will package all given files and import dependencies into a single zip file ''' destPackageFilepath = Path(destPackageFilepath).setExtension('zip') if destPackageFilepath.exists(): destPackageFilepath.delete() filesToPackage = map(Path, scriptFilesToPackage) for f in scriptFilesToPackage: filesToPackage += dependencyTree.findDependencies(f, None, False) if not filesToPackage: return None #remove any duplicate files... filesToPackage = removeDupes(filesToPackage) #this is a little hacky - but we don't want to re-distribute wingdbstub so lets check to see if its in the list of files for f in filesToPackage: if f.name() == 'wingdbstub': filesToPackage.remove(f) break #now build the zip file import zipfile with zipfile.ZipFile(str(destPackageFilepath), 'w') as thePackage: for f in filesToPackage: thePackage.write(str(f), str(makeScriptPathRelative(f))) return destPackageFilepath
def packageScripts( scriptFilesToPackage, destPackageFilepath, dependencyTree ): ''' will package all given files and import dependencies into a single zip file ''' destPackageFilepath = Path( destPackageFilepath ).setExtension( 'zip' ) if destPackageFilepath.exists(): destPackageFilepath.delete() filesToPackage = map( Path, scriptFilesToPackage ) for f in scriptFilesToPackage: filesToPackage += dependencyTree.findDependencies( f, None, False ) if not filesToPackage: return None #remove any duplicate files... filesToPackage = removeDupes( filesToPackage ) #this is a little hacky - but we don't want to re-distribute wingdbstub so lets check to see if its in the list of files for f in filesToPackage: if f.name() == 'wingdbstub': filesToPackage.remove( f ) break #now build the zip file import zipfile with zipfile.ZipFile( str( destPackageFilepath ), 'w' ) as thePackage: for f in filesToPackage: thePackage.write( str( f ), str( makeScriptPathRelative( f ) ) ) return destPackageFilepath
def __new__(cls, dirsToWalk=(), dirsToExclude=(), extraSearchPaths=(), rebuildCache=False, skipLib=True): ''' constructs a new dependencyTree dictionary or loads an existing one from a disk cache, and strips out files that no longer exist ''' if not dirsToWalk: dirsToWalk = sys.path[:] dirsToWalk = map(Path, dirsToWalk) dirsToExclude = map(Path, dirsToExclude) if skipLib: dirsToExclude += _LIB_PATHS cache = Path(cls._CACHE_PATH) self = None if cache.exists() and not rebuildCache: try: with file(cache, 'r') as f: version, self = pickle.load(f) except: pass else: if version == cls._VERSION: cls.FromSimpleDict( self ) #keys are converted to strings before pickling - so convert them back to Path instances cls.FromSimpleDict(self._crcs) cls.FromSimpleDict(self._stats) #remove any files from the cache that don't exist for f in self.keys(): if not f.exists(): self.pop(f) else: self = None logWarning('VERSION UPDATE: forcing rebuild') if self is None: self = dict.__new__(cls) self._crcs = {} self._stats = {} self._dirs = dirsToWalk self._dirsExclude = dirsToExclude self._extraPaths = extraSearchPaths self.freshenDependencies() return self
def getControlShapeFiles(): dir = CONTROL_DIRECTORY if isinstance( dir, basestring ): dir = Path( dir ) if not isinstance( dir, Path ) or not dir.exists(): dir = Path( __file__ ).up() shapes = [] if dir.exists(): shapes = [ f for f in dir.files() if f.hasExtension( 'shape' ) ] if not shapes: searchPaths = map( Path, sys.path ) searchPaths += map( Path, os.environ.get( 'MAYA_SCRIPT_PATH', '' ).split( ';' ) ) searchPaths = removeDupes( searchPaths ) for d in searchPaths: try: shapes += [ f for f in d.files() if f.hasExtension( 'shape' ) ] except WindowsError: continue return shapes
def on_browse( self, *a ): curValue = self.getValue() ext = curValue.getExtension() or 'txt' if curValue.isFile(): curValue = curValue.up() elif not curValue.isDir(): curValue = Path( cmd.file( q=True, sn=True ) ).up( 2 ) if not curValue.exists(): curValue = Path( '' ) filepath = cmd.fileDialog( directoryMask=curValue / ("/*.%s" % ext) ) if filepath: self.setValue( filepath, True )
def build_popup( self, parent, *a ): cmd.setParent( parent, m=True ) cmd.menu( parent, e=True, dai=True ) thisFile = Path( cmd.file( q=True, sn=True ) ) #if the file doesn't exist, then use teh cwd if not thisFile.exists(): thisFile = thisFile.getcwd() / "tmp.ma" dir = thisFile.up() curFile = Path( cmd.textField( self.UI_file, q=True, tx=True ) ) for f in dir.files(): if f.hasExtension( skinWeights.EXTENSION ): cmd.menuItem( l=f.name(), cb=f==curFile, c=api.Callback( cmd.textField, self.UI_file, e=True, tx=f ) ) cmd.menuItem( d=True ) cmd.menuItem( l="browse", c=self.on_browseWeightFile ) cmd.menuItem( d=True ) cmd.menuItem( l="clear", c=lambda *a: cmd.textField( self.UI_file, e=True, tx='' ) ) if curFile.exists(): cmd.menuItem( d=True ) api.addExploreToMenuItems( curFile )
def __new__( cls, dirsToWalk=(), dirsToExclude=(), extraSearchPaths=(), rebuildCache=False, skipLib=True ): ''' constructs a new dependencyTree dictionary or loads an existing one from a disk cache, and strips out files that no longer exist ''' if not dirsToWalk: dirsToWalk = sys.path[:] dirsToWalk = map( Path, dirsToWalk ) dirsToExclude = map( Path, dirsToExclude ) if skipLib: dirsToExclude += _LIB_PATHS cache = Path( cls._CACHE_PATH ) self = None if cache.exists() and not rebuildCache: try: with file( cache, 'r' ) as f: version, self = pickle.load( f ) except: pass else: if version == cls._VERSION: cls.FromSimpleDict( self ) #keys are converted to strings before pickling - so convert them back to Path instances cls.FromSimpleDict( self._crcs ) cls.FromSimpleDict( self._stats ) #remove any files from the cache that don't exist for f in self.keys(): if not f.exists(): self.pop( f ) else: self = None logWarning( 'VERSION UPDATE: forcing rebuild' ) if self is None: self = dict.__new__( cls ) self._crcs = {} self._stats = {} self._dirs = dirsToWalk self._dirsExclude = dirsToExclude self._extraPaths = extraSearchPaths self.freshenDependencies() return self