def dummyAppRunner(tokens=[], argv=None): """ This function creates a dummy global AppRunner object, which is useful for testing running in a packaged environment without actually bothering to package up the application. Call this at the start of your application to enable it. It places the current working directory under /mf, as if it were mounted from a packed multifile. It doesn't convert egg files to bam files, of course; and there are other minor differences from running in an actual packaged environment. But it can be a useful first-look sanity check. """ if AppRunnerGlobal.appRunner: print "Already have AppRunner, not creating a new one." return AppRunnerGlobal.appRunner appRunner = AppRunner() appRunner.dummy = True AppRunnerGlobal.appRunner = appRunner platform = PandaSystem.getPlatform() version = PandaSystem.getPackageVersionString() hostUrl = PandaSystem.getPackageHostUrl() if platform.startswith('win'): rootDir = Filename(Filename.getUserAppdataDirectory(), 'Panda3D') elif platform.startswith('osx'): rootDir = Filename(Filename.getHomeDirectory(), 'Library/Caches/Panda3D') else: rootDir = Filename(Filename.getHomeDirectory(), '.panda3d') appRunner.rootDir = rootDir appRunner.logDirectory = Filename(rootDir, 'log') # Of course we will have the panda3d application loaded. appRunner.addPackageInfo('panda3d', platform, version, hostUrl) appRunner.tokens = tokens appRunner.tokenDict = dict(tokens) if argv is None: argv = sys.argv appRunner.argv = argv appRunner.altHost = appRunner.tokenDict.get('alt_host', None) appRunner.p3dInfo = None appRunner.p3dPackage = None # Mount the current directory under the multifileRoot, as if it # were coming from a multifile. cwd = ExecutionEnvironment.getCwd() vfs = VirtualFileSystem.getGlobalPtr() vfs.mount(cwd, appRunner.multifileRoot, vfs.MFReadOnly) appRunner.initPackedAppEnvironment() return appRunner
def dummyAppRunner(tokens = [], argv = None): """ This function creates a dummy global AppRunner object, which is useful for testing running in a packaged environment without actually bothering to package up the application. Call this at the start of your application to enable it. It places the current working directory under /mf, as if it were mounted from a packed multifile. It doesn't convert egg files to bam files, of course; and there are other minor differences from running in an actual packaged environment. But it can be a useful first-look sanity check. """ if AppRunnerGlobal.appRunner: print "Already have AppRunner, not creating a new one." return AppRunnerGlobal.appRunner appRunner = AppRunner() appRunner.dummy = True AppRunnerGlobal.appRunner = appRunner platform = PandaSystem.getPlatform() version = PandaSystem.getPackageVersionString() hostUrl = PandaSystem.getPackageHostUrl() if platform.startswith('win'): rootDir = Filename(Filename.getUserAppdataDirectory(), 'Panda3D') elif platform.startswith('osx'): rootDir = Filename(Filename.getHomeDirectory(), 'Library/Caches/Panda3D') else: rootDir = Filename(Filename.getHomeDirectory(), '.panda3d') appRunner.rootDir = rootDir appRunner.logDirectory = Filename(rootDir, 'log') # Of course we will have the panda3d application loaded. appRunner.addPackageInfo('panda3d', platform, version, hostUrl) appRunner.tokens = tokens appRunner.tokenDict = dict(tokens) if argv is None: argv = sys.argv appRunner.argv = argv appRunner.altHost = appRunner.tokenDict.get('alt_host', None) appRunner.p3dInfo = None appRunner.p3dPackage = None # Mount the current directory under the multifileRoot, as if it # were coming from a multifile. cwd = ExecutionEnvironment.getCwd() vfs = VirtualFileSystem.getGlobalPtr() vfs.mount(cwd, appRunner.multifileRoot, vfs.MFReadOnly) appRunner.initPackedAppEnvironment() return appRunner
def __init__(self, p3dfile, tokens={}): self.p3dfile = Filename(p3dfile) self.basename = self.p3dfile.getBasenameWoExtension() self.tokens = tokens self.tempDir = Filename.temporary("", self.basename, "") + "/" self.tempDir.makeDir() self.host = HostInfo( PandaSystem.getPackageHostUrl(), appRunner=appRunner, hostDir=self.tempDir, asMirror=False, perPlatform=True ) self.http = HTTPClient.getGlobalPtr() if not self.host.hasContentsFile: if not self.host.readContentsFile(): if not self.host.downloadContentsFile(self.http): Standalone.notify.error("couldn't read host") return
def __init__(self, p3dfile, tokens={}): self.p3dfile = Filename(p3dfile) self.basename = self.p3dfile.getBasenameWoExtension() self.tokens = tokens self.tempDir = Filename.temporary("", self.basename, "") + "/" self.tempDir.makeDir() self.host = HostInfo(PandaSystem.getPackageHostUrl(), appRunner=appRunner, hostDir=self.tempDir, asMirror=False, perPlatform=True) self.http = HTTPClient.getGlobalPtr() if not self.host.hasContentsFile: if not self.host.readContentsFile(): if not self.host.downloadContentsFile(self.http): Standalone.notify.error("couldn't read host") return
def __init__(self): DirectObject.__init__(self) # We direct both our stdout and stderr objects onto Panda's # Notify stream. This ensures that unadorned print statements # made within Python will get routed into the log properly. stream = StreamWriter(Notify.out(), False) sys.stdout = stream sys.stderr = stream # This is set true by dummyAppRunner(), below. self.dummy = False # These will be set from the application flags when # setP3DFilename() is called. self.allowPythonDev = False self.guiApp = False self.interactiveConsole = False self.initialAppImport = False self.trueFileIO = False self.verifyContents = self.P3DVCNone self.sessionId = 0 self.packedAppEnvironmentInitialized = False self.gotWindow = False self.gotP3DFilename = False self.started = False self.windowOpened = False self.windowPrc = None self.http = None if hasattr(PandaModules, 'HTTPClient'): self.http = PandaModules.HTTPClient.getGlobalPtr() self.Undefined = Undefined self.ConcreteStruct = ConcreteStruct # This is per session. self.nextScriptId = 0 # TODO: we need one of these per instance, not per session. self.instanceId = None # The root Panda3D install directory. This is filled in when # the instance starts up. self.rootDir = None # The log directory. Also filled in when the instance starts. self.logDirectory = None # self.superMirrorUrl, if nonempty, is the "super mirror" URL # that should be contacted first before trying the actual # host. This is primarily used for "downloading" from a # locally-stored Panda3D installation. This is also filled in # when the instance starts up. self.superMirrorUrl = None # A list of the Panda3D packages that have been loaded. self.installedPackages = [] # A list of the Panda3D packages that in the queue to be # downloaded. self.downloadingPackages = [] # A dictionary of HostInfo objects for the various download # hosts we have imported packages from. self.hosts = {} # The altHost string that is in effect from the HTML tokens, # if any, and the dictionary of URL remapping: orig host url # -> alt host url. self.altHost = None self.altHostMap = {} # The URL from which Panda itself should be downloaded. self.pandaHostUrl = PandaSystem.getPackageHostUrl() # Application code can assign a callable object here; if so, # it will be invoked when an uncaught exception propagates to # the top of the TaskMgr.run() loop. self.exceptionHandler = None # Managing packages for runtime download. self.downloadingPackages = [] self.downloadTask = None # The mount point for the multifile. For now, this is always # the current working directory, for convenience; but when we # move to multiple-instance sessions, it may have to be # different for each instance. self.multifileRoot = ExecutionEnvironment.getCwd().cStr() # The "main" object will be exposed to the DOM as a property # of the plugin object; that is, document.pluginobject.main in # JavaScript will be appRunner.main here. This may be # replaced with a direct reference to the JavaScript object # later, in setInstanceInfo(). self.main = ScriptAttributes() # By default, we publish a stop() method so the browser can # easy stop the plugin. A particular application can remove # this if it chooses. self.main.stop = self.stop # This will be the browser's toplevel window DOM object; # e.g. self.dom.document will be the document. self.dom = None # This is the list of expressions we will evaluate when # self.dom gets assigned. self.deferredEvals = [] # This is the default requestFunc that is installed if we # never call setRequestFunc(). def defaultRequestFunc(*args): if args[1] == 'notify': # Quietly ignore notifies. return self.notify.info("Ignoring request: %s" % (args, )) self.requestFunc = defaultRequestFunc # This will be filled in with the default WindowProperties for # this instance, e.g. the WindowProperties necessary to # re-embed a window in the browser frame. self.windowProperties = None # Store our pointer so DirectStart-based apps can find us. if AppRunnerGlobal.appRunner is None: AppRunnerGlobal.appRunner = self # We use this messenger hook to dispatch this __startIfReady() # call back to the main thread. self.accept('AppRunner_startIfReady', self.__startIfReady)
def __init__(self): DirectObject.__init__(self) # We direct both our stdout and stderr objects onto Panda's # Notify stream. This ensures that unadorned print statements # made within Python will get routed into the log properly. stream = StreamWriter(Notify.out(), False) sys.stdout = stream sys.stderr = stream # This is set true by dummyAppRunner(), below. self.dummy = False # These will be set from the application flags when # setP3DFilename() is called. self.allowPythonDev = False self.guiApp = False self.interactiveConsole = False self.initialAppImport = False self.trueFileIO = False self.verifyContents = self.P3DVCNone self.sessionId = 0 self.packedAppEnvironmentInitialized = False self.gotWindow = False self.gotP3DFilename = False self.started = False self.windowOpened = False self.windowPrc = None self.http = None if hasattr(PandaModules, 'HTTPClient'): self.http = PandaModules.HTTPClient.getGlobalPtr() self.Undefined = Undefined self.ConcreteStruct = ConcreteStruct # This is per session. self.nextScriptId = 0 # TODO: we need one of these per instance, not per session. self.instanceId = None # The root Panda3D install directory. This is filled in when # the instance starts up. self.rootDir = None # The log directory. Also filled in when the instance starts. self.logDirectory = None # self.superMirrorUrl, if nonempty, is the "super mirror" URL # that should be contacted first before trying the actual # host. This is primarily used for "downloading" from a # locally-stored Panda3D installation. This is also filled in # when the instance starts up. self.superMirrorUrl = None # A list of the Panda3D packages that have been loaded. self.installedPackages = [] # A list of the Panda3D packages that in the queue to be # downloaded. self.downloadingPackages = [] # A dictionary of HostInfo objects for the various download # hosts we have imported packages from. self.hosts = {} # The altHost string that is in effect from the HTML tokens, # if any, and the dictionary of URL remapping: orig host url # -> alt host url. self.altHost = None self.altHostMap = {} # The URL from which Panda itself should be downloaded. self.pandaHostUrl = PandaSystem.getPackageHostUrl() # Application code can assign a callable object here; if so, # it will be invoked when an uncaught exception propagates to # the top of the TaskMgr.run() loop. self.exceptionHandler = None # Managing packages for runtime download. self.downloadingPackages = [] self.downloadTask = None # The mount point for the multifile. For now, this is always # the current working directory, for convenience; but when we # move to multiple-instance sessions, it may have to be # different for each instance. self.multifileRoot = ExecutionEnvironment.getCwd().cStr() # The "main" object will be exposed to the DOM as a property # of the plugin object; that is, document.pluginobject.main in # JavaScript will be appRunner.main here. This may be # replaced with a direct reference to the JavaScript object # later, in setInstanceInfo(). self.main = ScriptAttributes() # By default, we publish a stop() method so the browser can # easy stop the plugin. A particular application can remove # this if it chooses. self.main.stop = self.stop # This will be the browser's toplevel window DOM object; # e.g. self.dom.document will be the document. self.dom = None # This is the list of expressions we will evaluate when # self.dom gets assigned. self.deferredEvals = [] # This is the default requestFunc that is installed if we # never call setRequestFunc(). def defaultRequestFunc(*args): if args[1] == 'notify': # Quietly ignore notifies. return self.notify.info("Ignoring request: %s" % (args,)) self.requestFunc = defaultRequestFunc # This will be filled in with the default WindowProperties for # this instance, e.g. the WindowProperties necessary to # re-embed a window in the browser frame. self.windowProperties = None # Store our pointer so DirectStart-based apps can find us. if AppRunnerGlobal.appRunner is None: AppRunnerGlobal.appRunner = self # We use this messenger hook to dispatch this __startIfReady() # call back to the main thread. self.accept('AppRunner_startIfReady', self.__startIfReady)
def __init__(self, p3dfile, shortname, fullname, version, tokens={}): if not shortname: shortname = p3dfile.getBasenameWoExtension() self.shortname = shortname self.fullname = fullname self.version = str(version) self.includeRequires = False self.licensename = "" self.licensefile = Filename() self.authorid = "org.panda3d" self.authorname = os.environ.get("DEBFULLNAME", "") self.authoremail = os.environ.get("DEBEMAIL", "") # Try to determine a default author name ourselves. uname = None if pwd is not None and hasattr(os, "getuid"): uinfo = pwd.getpwuid(os.getuid()) if uinfo: uname = uinfo.pw_name if not self.authorname: self.authorname = uinfo.pw_gecos.split(",", 1)[0] # Fallbacks in case that didn't work or wasn't supported. if not uname: uname = getpass.getuser() if not self.authorname: self.authorname = uname if not self.authoremail and " " not in uname: self.authoremail = "%s@%s" % (uname, socket.gethostname()) self.standalone = Standalone(p3dfile, tokens) self.tempDir = Filename.temporary("", self.shortname, "") + "/" self.tempDir.makeDir() self.__linuxRoot = None # Load the p3d file to read out the required packages mf = Multifile() if not mf.openRead(p3dfile): Installer.notify.error("Not a Panda3D application: %s" % (p3dFilename)) return # Now load the p3dInfo file. self.hostUrl = PandaSystem.getPackageHostUrl() if not self.hostUrl: self.hostUrl = self.standalone.host.hostUrl self.requires = [] i = mf.findSubfile("p3d_info.xml") if i >= 0: stream = mf.openReadSubfile(i) p3dInfo = readXmlStream(stream) mf.closeReadSubfile(stream) if p3dInfo: p3dPackage = p3dInfo.FirstChildElement("package") p3dHost = p3dPackage.FirstChildElement("host") if p3dHost.Attribute("url"): self.hostUrl = p3dHost.Attribute("url") p3dRequires = p3dPackage.FirstChildElement("requires") while p3dRequires: self.requires.append( (p3dRequires.Attribute("name"), p3dRequires.Attribute("version"), p3dRequires.Attribute("host")) ) p3dRequires = p3dRequires.NextSiblingElement("requires") if not self.fullname: p3dConfig = p3dPackage.FirstChildElement("config") if p3dConfig: self.fullname = p3dConfig.Attribute("display_name") if not self.fullname: self.fullname = self.shortname
def __init__(self, p3dfile, shortname, fullname, version, tokens={}): if not shortname: shortname = p3dfile.getBasenameWoExtension() self.shortname = shortname self.fullname = fullname self.version = str(version) self.includeRequires = False self.licensename = "" self.licensefile = Filename() self.authorid = "org.panda3d" self.authorname = os.environ.get("DEBFULLNAME", "") self.authoremail = os.environ.get("DEBEMAIL", "") # Try to determine a default author name ourselves. uname = None if pwd is not None and hasattr(os, 'getuid'): uinfo = pwd.getpwuid(os.getuid()) if uinfo: uname = uinfo.pw_name if not self.authorname: self.authorname = \ uinfo.pw_gecos.split(',', 1)[0] # Fallbacks in case that didn't work or wasn't supported. if not uname: uname = getpass.getuser() if not self.authorname: self.authorname = uname if not self.authoremail and ' ' not in uname: self.authoremail = "%s@%s" % (uname, socket.gethostname()) self.standalone = Standalone(p3dfile, tokens) self.tempDir = Filename.temporary("", self.shortname, "") + "/" self.tempDir.makeDir() self.__linuxRoot = None # Load the p3d file to read out the required packages mf = Multifile() if not mf.openRead(p3dfile): Installer.notify.error("Not a Panda3D application: %s" % (p3dFilename)) return # Now load the p3dInfo file. self.hostUrl = PandaSystem.getPackageHostUrl() if not self.hostUrl: self.hostUrl = self.standalone.host.hostUrl self.requires = [] i = mf.findSubfile('p3d_info.xml') if i >= 0: stream = mf.openReadSubfile(i) p3dInfo = readXmlStream(stream) mf.closeReadSubfile(stream) if p3dInfo: p3dPackage = p3dInfo.FirstChildElement('package') p3dHost = p3dPackage.FirstChildElement('host') if p3dHost.Attribute('url'): self.hostUrl = p3dHost.Attribute('url') p3dRequires = p3dPackage.FirstChildElement('requires') while p3dRequires: self.requires.append((p3dRequires.Attribute('name'), p3dRequires.Attribute('version'), p3dRequires.Attribute('host'))) p3dRequires = p3dRequires.NextSiblingElement('requires') if not self.fullname: p3dConfig = p3dPackage.FirstChildElement('config') if p3dConfig: self.fullname = p3dConfig.Attribute('display_name') if not self.fullname: self.fullname = self.shortname