def loadMultifilePrcFiles(self, mf, root): """ Loads any prc files in the root of the indicated Multifile, which is presumed to have been mounted already under root. """ # We have to load these prc files explicitly, since the # ConfigPageManager can't directly look inside the vfs. Use # the Multifile interface to find the prc files, rather than # vfs.scanDirectory(), so we only pick up the files in this # particular multifile. cpMgr = ConfigPageManager.getGlobalPtr() for f in mf.getSubfileNames(): fn = Filename(f) if fn.getDirname() == '' and fn.getExtension() == 'prc': pathname = '%s/%s' % (root, f) alreadyLoaded = False for cpi in range(cpMgr.getNumImplicitPages()): if cpMgr.getImplicitPage(cpi).getName() == pathname: # No need to load this file twice. alreadyLoaded = True break if not alreadyLoaded: data = file.open(Filename(pathname), 'r').read() cp = loadPrcFileData(pathname, data) # Set it to sort value 20, behind the implicit pages. cp.setSort(20)
def findNewsDir(self): """Returns the directory string for news content. Returns None if it cant find the directory """ if self.NewsOverHttp: # If we're running news-over-http, we dump the news into a # staging directory. return self.NewsStageDir searchPath = DSearchPath() if AppRunnerGlobal.appRunner: # In the web-publish runtime, it will always be here: searchPath.appendDirectory( Filename.expandFrom('$TT_3_5_ROOT/phase_3.5/models/news')) else: # In the launcher or dev environment, look here: basePath = os.path.expandvars('$TTMODELS') or './ttmodels' searchPath.appendDirectory( Filename.fromOsSpecific(basePath + '/built/' + self.NewsBaseDir)) searchPath.appendDirectory(Filename(self.NewsBaseDir)) pfile = Filename(self.NewsIndexFilename) found = vfs.resolveFilename(pfile, searchPath) if not found: self.notify.warning('findNewsDir - no path: %s' % self.NewsIndexFilename) self.setErrorMessage(TTLocalizer.NewsPageErrorDownloadingFile % self.NewsIndexFilename) return None self.notify.debug("found index file %s" % pfile) realDir = pfile.getDirname() return realDir
def onUpdateThumbnail(self, evt, item): if self.treeLibrary.GetItemParent(item) == self.meshes: asset = self.lib.meshes[self.treeLibrary.GetItemText(item)] elif self.treeLibrary.GetItemParent(item) == self.actors: asset = self.lib.actors[self.treeLibrary.GetItemText(item)] if asset.thumbnail: f = asset.getThumbnail() else: f = Filename(asset.getFullFilename().getDirname() + '/Thumbnails/' + asset.filename.getBasenameWoExtension() + '.jpg') camnode = self.editor.ui.perspView.cam.node() dr = camnode.getDisplayRegion(0) try: dr.saveScreenshot(f) except Exception: pass else: cwd = os.getcwd() os.chdir(Filename(f.getDirname()).toOsSpecific()) subprocess.call([ "image-resize", "-x 60", "-y 60", "-g 1", "-o" + f.getBasename(), f.getBasename() ]) os.chdir(cwd) if not asset.thumbnail: asset.thumbnail = f asset.thumbnail.makeRelativeTo(asset.projDir)
def loadMultifilePrcFiles(self, mf, root): """ Loads any prc files in the root of the indicated Multifile, which is presumed to have been mounted already under root. """ # We have to load these prc files explicitly, since the # ConfigPageManager can't directly look inside the vfs. Use # the Multifile interface to find the prc files, rather than # vfs.scanDirectory(), so we only pick up the files in this # particular multifile. for f in mf.getSubfileNames(): fn = Filename(f) if fn.getDirname() == '' and fn.getExtension() == 'prc': pathname = '%s/%s' % (root, f) data = file.open(Filename(pathname), 'r').read() loadPrcFileData(pathname, data)
def findNewsDir(self): if self.NewsOverHttp: return self.NewsStageDir searchPath = DSearchPath() if AppRunnerGlobal.appRunner: searchPath.appendDirectory(Filename.expandFrom("$TT_3_5_ROOT/phase_3.5/models/news")) else: basePath = os.path.expandvars("$TTMODELS") or "./ttmodels" searchPath.appendDirectory(Filename.fromOsSpecific(basePath + "/built/" + self.NewsBaseDir)) searchPath.appendDirectory(Filename(self.NewsBaseDir)) pfile = Filename(self.NewsIndexFilename) found = vfs.resolveFilename(pfile, searchPath) if not found: self.notify.warning("findNewsDir - no path: %s" % self.NewsIndexFilename) self.setErrorMessage(TTLocalizer.NewsPageErrorDownloadingFile % self.NewsIndexFilename) return None self.notify.debug("found index file %s" % pfile) realDir = pfile.getDirname() return realDir
def findNewsDir(self): if self.NewsOverHttp: return self.NewsStageDir searchPath = DSearchPath() if AppRunnerGlobal.appRunner: searchPath.appendDirectory(Filename.expandFrom('$TT_3_5_ROOT/phase_3.5/models/news')) else: basePath = os.path.expandvars('$TTMODELS') or './ttmodels' searchPath.appendDirectory(Filename.fromOsSpecific(basePath + '/built/' + self.NewsBaseDir)) searchPath.appendDirectory(Filename(self.NewsBaseDir)) pfile = Filename(self.NewsIndexFilename) found = vfs.resolveFilename(pfile, searchPath) if not found: self.notify.warning('findNewsDir - no path: %s' % self.NewsIndexFilename) self.setErrorMessage(TTLocalizer.NewsPageErrorDownloadingFile % self.NewsIndexFilename) return None self.notify.debug('found index file %s' % pfile) realDir = pfile.getDirname() return realDir
def onUpdateThumbnail(self, evt, item): if self.treeLibrary.GetItemParent(item) == self.meshes: asset = self.lib.meshes[self.treeLibrary.GetItemText(item)] elif self.treeLibrary.GetItemParent(item) == self.actors: asset = self.lib.actors[self.treeLibrary.GetItemText(item)] if asset.thumbnail: f = asset.getThumbnail() else: f = Filename(asset.getFullFilename().getDirname() + '/Thumbnails/' + asset.filename.getBasenameWoExtension() + '.jpg') camnode = self.editor.ui.perspView.cam.node() dr = camnode.getDisplayRegion(0) try: dr.saveScreenshot(f) except Exception: pass else: cwd = os.getcwd() os.chdir(Filename(f.getDirname()).toOsSpecific()) subprocess.call(["image-resize","-x 60", "-y 60", "-g 1", "-o" + f.getBasename(), f.getBasename()]) os.chdir(cwd) if not asset.thumbnail: asset.thumbnail = f asset.thumbnail.makeRelativeTo(asset.projDir)
def buildPKG(self, output, platform): appfn = self.buildAPP(output, platform) appname = "/Applications/" + appfn.getBasename() output = Filename(output) if output.isDirectory(): output = Filename(output, "%s %s.pkg" % (self.fullname, self.version)) Installer.notify.info("Creating %s..." % output) Filename(output, "Contents/Resources/en.lproj/").makeDir() if self.licensefile: shutil.copyfile( self.licensefile.toOsSpecific(), Filename(output, "Contents/Resources/License.txt").toOsSpecific() ) pkginfo = open(Filename(output, "Contents/PkgInfo").toOsSpecific(), "w") pkginfo.write("pkmkrpkg1") pkginfo.close() pkginfo = open(Filename(output, "Contents/Resources/package_version").toOsSpecific(), "w") pkginfo.write("major: 1\nminor: 9") pkginfo.close() # Although it might make more sense to use Python's plistlib here, # it is not available on non-OSX systems before Python 2.6. plist = open(Filename(output, "Contents/Info.plist").toOsSpecific(), "w") plist.write('<?xml version="1.0" encoding="UTF-8"?>\n') plist.write( '<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">\n' ) plist.write('<plist version="1.0">\n') plist.write("<dict>\n") plist.write("\t<key>CFBundleIdentifier</key>\n") plist.write("\t<string>%s.pkg.%s</string>\n" % (self.authorid, self.shortname)) plist.write("\t<key>CFBundleShortVersionString</key>\n") plist.write("\t<string>%s</string>\n" % self.version) plist.write("\t<key>IFMajorVersion</key>\n") plist.write("\t<integer>1</integer>\n") plist.write("\t<key>IFMinorVersion</key>\n") plist.write("\t<integer>9</integer>\n") plist.write("\t<key>IFPkgFlagAllowBackRev</key>\n") plist.write("\t<false/>\n") plist.write("\t<key>IFPkgFlagAuthorizationAction</key>\n") plist.write("\t<string>RootAuthorization</string>\n") plist.write("\t<key>IFPkgFlagDefaultLocation</key>\n") plist.write("\t<string>/</string>\n") plist.write("\t<key>IFPkgFlagFollowLinks</key>\n") plist.write("\t<true/>\n") plist.write("\t<key>IFPkgFlagIsRequired</key>\n") plist.write("\t<false/>\n") plist.write("\t<key>IFPkgFlagOverwritePermissions</key>\n") plist.write("\t<false/>\n") plist.write("\t<key>IFPkgFlagRelocatable</key>\n") plist.write("\t<false/>\n") plist.write("\t<key>IFPkgFlagRestartAction</key>\n") plist.write("\t<string>None</string>\n") plist.write("\t<key>IFPkgFlagRootVolumeOnly</key>\n") plist.write("\t<true/>\n") plist.write("\t<key>IFPkgFlagUpdateInstalledLanguages</key>\n") plist.write("\t<false/>\n") plist.write("\t<key>IFPkgFormatVersion</key>\n") plist.write("\t<real>0.10000000149011612</real>\n") plist.write("\t<key>IFPkgPathMappings</key>\n") plist.write("\t<dict>\n") plist.write("\t\t<key>%s</key>\n" % appname) plist.write("\t\t<string>{pkmk-token-2}</string>\n") plist.write("\t</dict>\n") plist.write("</dict>\n") plist.write("</plist>\n") plist.close() plist = open(Filename(output, "Contents/Resources/TokenDefinitions.plist").toOsSpecific(), "w") plist.write('<?xml version="1.0" encoding="UTF-8"?>\n') plist.write( '<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">\n' ) plist.write('<plist version="1.0">\n') plist.write("<dict>\n") plist.write("\t<key>pkmk-token-2</key>\n") plist.write("\t<array>\n") plist.write("\t\t<dict>\n") plist.write("\t\t\t<key>identifier</key>\n") plist.write("\t\t\t<string>%s.%s</string>\n" % (self.authorid, self.shortname)) plist.write("\t\t\t<key>path</key>\n") plist.write("\t\t\t<string>%s</string>\n" % appname) plist.write("\t\t\t<key>searchPlugin</key>\n") plist.write("\t\t\t<string>CommonAppSearch</string>\n") plist.write("\t\t</dict>\n") plist.write("\t</array>\n") plist.write("</dict>\n") plist.write("</plist>\n") plist.close() plist = open(Filename(output, "Contents/Resources/en.lproj/Description.plist").toOsSpecific(), "w") plist.write('<?xml version="1.0" encoding="UTF-8"?>\n') plist.write( '<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">\n' ) plist.write('<plist version="1.0">\n') plist.write("<dict>\n") plist.write("\t<key>IFPkgDescriptionDescription</key>\n") plist.write("\t<string></string>\n") plist.write("\t<key>IFPkgDescriptionTitle</key>\n") plist.write("\t<string>%s</string>\n" % self.fullname) plist.write("</dict>\n") plist.write("</plist>\n") plist.close() if hasattr(tarfile, "PAX_FORMAT"): archive = tarfile.open( Filename(output, "Contents/Archive.pax.gz").toOsSpecific(), "w:gz", format=tarfile.PAX_FORMAT, tarinfo=TarInfoRootOSX, ) else: archive = tarfile.open( Filename(output, "Contents/Archive.pax.gz").toOsSpecific(), "w:gz", tarinfo=TarInfoRootOSX ) archive.add(appfn.toOsSpecific(), appname) archive.close() # Put the .pkg into a zipfile archive = Filename(output.getDirname(), "%s %s.zip" % (self.fullname, self.version)) dir = Filename(output.getDirname()) dir.makeAbsolute() zip = zipfile.ZipFile(archive.toOsSpecific(), "w") for root, dirs, files in self.os_walk(output.toOsSpecific()): for name in files: file = Filename.fromOsSpecific(os.path.join(root, name)) file.makeAbsolute() file.makeRelativeTo(dir) zip.write(os.path.join(root, name), str(file)) zip.close() return output
def buildPKG(self, output, platform): appfn = self.buildAPP(output, platform) appname = "/Applications/" + appfn.getBasename() output = Filename(output) if output.isDirectory(): output = Filename(output, "%s %s.pkg" % (self.fullname, self.version)) Installer.notify.info("Creating %s..." % output) Filename(output, "Contents/Resources/en.lproj/").makeDir() if self.licensefile: shutil.copyfile( self.licensefile.toOsSpecific(), Filename(output, "Contents/Resources/License.txt").toOsSpecific()) pkginfo = open( Filename(output, "Contents/PkgInfo").toOsSpecific(), "w") pkginfo.write("pkmkrpkg1") pkginfo.close() pkginfo = open( Filename(output, "Contents/Resources/package_version").toOsSpecific(), "w") pkginfo.write("major: 1\nminor: 9") pkginfo.close() # Although it might make more sense to use Python's plistlib here, # it is not available on non-OSX systems before Python 2.6. plist = open( Filename(output, "Contents/Info.plist").toOsSpecific(), "w") plist.write('<?xml version="1.0" encoding="UTF-8"?>\n') plist.write( '<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">\n' ) plist.write('<plist version="1.0">\n') plist.write('<dict>\n') plist.write('\t<key>CFBundleIdentifier</key>\n') plist.write('\t<string>%s.pkg.%s</string>\n' % (self.authorid, self.shortname)) plist.write('\t<key>CFBundleShortVersionString</key>\n') plist.write('\t<string>%s</string>\n' % self.version) plist.write('\t<key>IFMajorVersion</key>\n') plist.write('\t<integer>1</integer>\n') plist.write('\t<key>IFMinorVersion</key>\n') plist.write('\t<integer>9</integer>\n') plist.write('\t<key>IFPkgFlagAllowBackRev</key>\n') plist.write('\t<false/>\n') plist.write('\t<key>IFPkgFlagAuthorizationAction</key>\n') plist.write('\t<string>RootAuthorization</string>\n') plist.write('\t<key>IFPkgFlagDefaultLocation</key>\n') plist.write('\t<string>/</string>\n') plist.write('\t<key>IFPkgFlagFollowLinks</key>\n') plist.write('\t<true/>\n') plist.write('\t<key>IFPkgFlagIsRequired</key>\n') plist.write('\t<false/>\n') plist.write('\t<key>IFPkgFlagOverwritePermissions</key>\n') plist.write('\t<false/>\n') plist.write('\t<key>IFPkgFlagRelocatable</key>\n') plist.write('\t<false/>\n') plist.write('\t<key>IFPkgFlagRestartAction</key>\n') plist.write('\t<string>None</string>\n') plist.write('\t<key>IFPkgFlagRootVolumeOnly</key>\n') plist.write('\t<true/>\n') plist.write('\t<key>IFPkgFlagUpdateInstalledLanguages</key>\n') plist.write('\t<false/>\n') plist.write('\t<key>IFPkgFormatVersion</key>\n') plist.write('\t<real>0.10000000149011612</real>\n') plist.write('\t<key>IFPkgPathMappings</key>\n') plist.write('\t<dict>\n') plist.write('\t\t<key>%s</key>\n' % appname) plist.write('\t\t<string>{pkmk-token-2}</string>\n') plist.write('\t</dict>\n') plist.write('</dict>\n') plist.write('</plist>\n') plist.close() plist = open( Filename( output, "Contents/Resources/TokenDefinitions.plist").toOsSpecific(), "w") plist.write('<?xml version="1.0" encoding="UTF-8"?>\n') plist.write( '<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">\n' ) plist.write('<plist version="1.0">\n') plist.write('<dict>\n') plist.write('\t<key>pkmk-token-2</key>\n') plist.write('\t<array>\n') plist.write('\t\t<dict>\n') plist.write('\t\t\t<key>identifier</key>\n') plist.write('\t\t\t<string>%s.%s</string>\n' % (self.authorid, self.shortname)) plist.write('\t\t\t<key>path</key>\n') plist.write('\t\t\t<string>%s</string>\n' % appname) plist.write('\t\t\t<key>searchPlugin</key>\n') plist.write('\t\t\t<string>CommonAppSearch</string>\n') plist.write('\t\t</dict>\n') plist.write('\t</array>\n') plist.write('</dict>\n') plist.write('</plist>\n') plist.close() plist = open( Filename(output, "Contents/Resources/en.lproj/Description.plist"). toOsSpecific(), "w") plist.write('<?xml version="1.0" encoding="UTF-8"?>\n') plist.write( '<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">\n' ) plist.write('<plist version="1.0">\n') plist.write('<dict>\n') plist.write('\t<key>IFPkgDescriptionDescription</key>\n') plist.write('\t<string></string>\n') plist.write('\t<key>IFPkgDescriptionTitle</key>\n') plist.write('\t<string>%s</string>\n' % self.fullname) plist.write('</dict>\n') plist.write('</plist>\n') plist.close() if hasattr(tarfile, "PAX_FORMAT"): archive = tarfile.open(Filename( output, "Contents/Archive.pax.gz").toOsSpecific(), "w:gz", format=tarfile.PAX_FORMAT, tarinfo=TarInfoRootOSX) else: archive = tarfile.open(Filename( output, "Contents/Archive.pax.gz").toOsSpecific(), "w:gz", tarinfo=TarInfoRootOSX) archive.add(appfn.toOsSpecific(), appname) archive.close() # Put the .pkg into a zipfile archive = Filename(output.getDirname(), "%s %s.zip" % (self.fullname, self.version)) dir = Filename(output.getDirname()) dir.makeAbsolute() zip = zipfile.ZipFile(archive.toOsSpecific(), 'w') for root, dirs, files in self.os_walk(output.toOsSpecific()): for name in files: file = Filename.fromOsSpecific(os.path.join(root, name)) file.makeAbsolute() file.makeRelativeTo(dir) zip.write(os.path.join(root, name), str(file)) zip.close() return output