def addScene(self, name=None, sceneFile=None): if (name == None): suffix = len(self.scenes) defaultname = "default_" name = defaultname + str(suffix) sceneFile = Filename(name + ".scene") f = Filename(sceneFile) f.setDirname(self.dir.getFullpath()) while (os.path.exists(f.toOsSpecific()) or self.filenameIndexes.has_key( sceneFile.getBasenameWoExtension())): suffix += 1 name = defaultname + str(suffix) sceneFile = Filename(name + ".scene") f = Filename(sceneFile) f.setDirname(self.dir.getFullpath()) #if there is a name but no sceneFile given for that name #create a file with that name #TO DO: make it more error prone, for example this is not checking #if the file with the name already exist in the folder. This part may not be #be used at all but should be thought about. if (sceneFile == None): sceneFile = Filename(name + ".scene") self.scenes[name] = sceneFile self.filenameIndexes[sceneFile.getBasenameWoExtension()] = sceneFile if (len(self.scenes) == 1): #self.sceneFilename = sceneFile self.sceneName = name #f = Filename(sceneFile) #f.setDirname(self.dir.getFullpath()) self.scenesOrder = sorted(self.scenes) return (name, sceneFile)
def addScene(self,name=None, sceneFile=None): if(name == None): suffix = len(self.scenes) defaultname = "default_" name = defaultname+str(suffix) sceneFile = Filename(name+".scene") f = Filename(sceneFile) f.setDirname(self.dir.getFullpath()) while(os.path.exists(f.toOsSpecific())or self.filenameIndexes.has_key(sceneFile.getBasenameWoExtension())): suffix += 1 name = defaultname+str(suffix) sceneFile = Filename(name+".scene") f = Filename(sceneFile) f.setDirname(self.dir.getFullpath()) #if there is a name but no sceneFile given for that name #create a file with that name #TO DO: make it more error prone, for example this is not checking #if the file with the name already exist in the folder. This part may not be #be used at all but should be thought about. if(sceneFile == None): sceneFile = Filename(name+".scene") self.scenes[name] = sceneFile self.filenameIndexes[sceneFile.getBasenameWoExtension()] = sceneFile if(len(self.scenes) == 1 ): #self.sceneFilename = sceneFile self.sceneName = name #f = Filename(sceneFile) #f.setDirname(self.dir.getFullpath()) self.scenesOrder = sorted(self.scenes) return (name,sceneFile)
def saveAs(self, newDir, newName, keepOld=False): if keepOld: shutil.copytree(self.dir.toOsSpecific(), newDir.toOsSpecific()) else: if not os.path.exists(newDir.toOsSpecific()): os.makedirs(newDir.toOsSpecific()) for x in os.listdir(self.dir.toOsSpecific()): shutil.move((self.dir + '/' + x).toOsSpecific(), (newDir + '/' + x).toOsSpecific()) #make sure everything in the new directory is not marked read only for root, dirs, files in os.walk(newDir.toOsSpecific()): for name in files: os.chmod(os.path.join(root, name), stat.S_IWRITE) newFilename = newDir + '/' + newName + '.proj' newSceneFilename = Filename(newName + '.scene') newJournalFilename = Filename(newName + '.journal') newInventoryMapFilename = Filename(newName + '.inventory') f = Filename(self.filename) f.setDirname(newDir.getFullpath()) f2 = Filename(self.scenes[self.sceneName]) #self.sceneFilename) f2.setDirname(newDir.getFullpath()) f3 = Filename(self.journalFilename) f3.setDirname(newDir.getFullpath()) f4 = Filename(self.inventoryMapFilename) f4.setDirname(newDir.getFullpath()) #make sure we don't end up with a project or scene file with the old name #in the new directory if os.path.exists(f.toOsSpecific()): os.remove(f.toOsSpecific()) if os.path.exists(f2.toOsSpecific()): os.remove(f2.toOsSpecific()) if os.path.exists(f3.toOsSpecific()): os.remove(f3.toOsSpecific()) if os.path.exists(f4.toOsSpecific()): os.remove(f4.toOsSpecific()) self.name = newName self.dir = newDir self.filename = newFilename #self.scenes["default"] = newSceneFilename #self.sceneFilename = newSceneFilename self.journalFilename = newJournalFilename self.inventoryMapFilename = newInventoryMapFilename self.lib.moveTo(newDir) self.saveToFile()
def saveAs(self, newDir, newName, keepOld=False): if keepOld: shutil.copytree(self.dir.toOsSpecific(), newDir.toOsSpecific()) else: if not os.path.exists(newDir.toOsSpecific()): os.makedirs(newDir.toOsSpecific()) for x in os.listdir(self.dir.toOsSpecific()): shutil.move((self.dir + '/' + x).toOsSpecific(), (newDir + '/' + x).toOsSpecific()) #make sure everything in the new directory is not marked read only for root, dirs, files in os.walk(newDir.toOsSpecific()): for name in files: os.chmod(os.path.join(root, name), stat.S_IWRITE) newFilename = newDir + '/' +newName + '.proj' newSceneFilename = Filename(newName + '.scene') newJournalFilename = Filename(newName + '.journal') newInventoryMapFilename = Filename(newName + '.inventory') f = Filename(self.filename) f.setDirname(newDir.getFullpath()) f2 = Filename(self.scenes[self.sceneName])#self.sceneFilename) f2.setDirname(newDir.getFullpath()) f3 = Filename(self.journalFilename) f3.setDirname(newDir.getFullpath()) f4 = Filename(self.inventoryMapFilename) f4.setDirname(newDir.getFullpath()) #make sure we don't end up with a project or scene file with the old name #in the new directory if os.path.exists(f.toOsSpecific()): os.remove(f.toOsSpecific()) if os.path.exists(f2.toOsSpecific()): os.remove(f2.toOsSpecific()) if os.path.exists(f3.toOsSpecific()): os.remove(f3.toOsSpecific()) if os.path.exists(f4.toOsSpecific()): os.remove(f4.toOsSpecific()) self.name = newName self.dir = newDir self.filename = newFilename #self.scenes["default"] = newSceneFilename #self.sceneFilename = newSceneFilename self.journalFilename = newJournalFilename self.inventoryMapFilename = newInventoryMapFilename self.lib.moveTo(newDir) self.saveToFile()