Browse Source

Updates to cluster code to allow cluster object to execute commands
Changed the use of the builtins class

Mark Mine 23 years ago
parent
commit
864e7edf9a

+ 6 - 6
direct/src/cluster/ClusterClient.py

@@ -105,21 +105,21 @@ class ClusterClient(DirectObject.DirectObject):
             return rootName
             return rootName
 
 
     def selectNodePath(self, nodePath):
     def selectNodePath(self, nodePath):
-        self.cmd(self.getNodePathFindCmd(nodePath) + '.select()', 0)
+        self(self.getNodePathFindCmd(nodePath) + '.select()', 0)
 
 
     def deselectNodePath(self, nodePath):
     def deselectNodePath(self, nodePath):
-        self.cmd(self.getNodePathFindCmd(nodePath) + '.deselect()', 0)
+        self(self.getNodePathFindCmd(nodePath) + '.deselect()', 0)
 
 
     def loadModel(self, nodePath):
     def loadModel(self, nodePath):
         pass
         pass
 
 
-    def cmd(self, commandString, fLocally = 1):
+    def __call__(self, commandString, fLocally = 1):
         # Execute remotely
         # Execute remotely
         for server in self.serverList:
         for server in self.serverList:
             server.sendCommandString(commandString)
             server.sendCommandString(commandString)
         if fLocally:
         if fLocally:
             # Execute locally
             # Execute locally
-            exec( commandString, globals() )
+            exec( commandString, __builtins__ )
 
 
     def exit(self):
     def exit(self):
         # Execute remotely
         # Execute remotely
@@ -349,9 +349,9 @@ class DummyClusterClient(DirectObject.DirectObject):
     def __init__(self):
     def __init__(self):
         pass
         pass
 
 
-    def cmd(self, commandString, fLocally = 1):
+    def __call__(self, commandString, fLocally = 1):
         if fLocally:
         if fLocally:
             # Execute locally
             # Execute locally
-            exec( commandString, globals() )
+            exec( commandString, __builtins__ )
 
 
 
 

+ 4 - 0
direct/src/cluster/ClusterMsgs.py

@@ -23,6 +23,10 @@ CLUSTER_SERVER_PORT = 1970
 CLUSTER_DAEMON_PORT = 8001
 CLUSTER_DAEMON_PORT = 8001
 
 
 # Precede command string with ! to tell server to execute command string
 # Precede command string with ! to tell server to execute command string
+# NOTE: Had to stick with the import __builtin__ scheme, at startup,
+# __builtins__ is a module, not a dictionary, like it is inside of a module
+# Note, this startup string obviates the need to set any cluster related
+# config variables in the client Configrc files
 SERVER_STARTUP_STRING = (
 SERVER_STARTUP_STRING = (
     '!bash ppython -c ' + 
     '!bash ppython -c ' + 
     '"import __builtin__; ' +
     '"import __builtin__; ' +

+ 2 - 2
direct/src/cluster/ClusterServer.py

@@ -55,7 +55,7 @@ class ClusterServer(DirectObject.DirectObject):
         # Send verification of startup to client
         # Send verification of startup to client
         self.daemon = DirectD()
         self.daemon = DirectD()
         # These must be passed in as bootstrap arguments and stored in
         # These must be passed in as bootstrap arguments and stored in
-        # the __builtin__ namespace
+        # the __builtins__ namespace
         try:
         try:
             clusterDaemonClient
             clusterDaemonClient
         except NameError:
         except NameError:
@@ -202,7 +202,7 @@ class ClusterServer(DirectObject.DirectObject):
         """ Handle arbitrary command string from client """
         """ Handle arbitrary command string from client """
         command = self.msgHandler.parseCommandStringDatagram(dgi)
         command = self.msgHandler.parseCommandStringDatagram(dgi)
         try:
         try:
-            exec( command, globals() )
+            exec( command, __builtins__ )
         except:
         except:
             pass
             pass
         
         

+ 4 - 4
direct/src/directtools/DirectManipulation.py

@@ -112,7 +112,7 @@ class DirectManipulationControl(PandaObject):
         direct.selected.highlightAll()
         direct.selected.highlightAll()
         self.objectHandles.showAllHandles()
         self.objectHandles.showAllHandles()
         if direct.clusterMode == 'client':
         if direct.clusterMode == 'client':
-            direct.cluster.cmd(
+            cluster(
                 'direct.manipulationControl.objectHandles.showAllHandles()')
                 'direct.manipulationControl.objectHandles.showAllHandles()')
         self.objectHandles.hideGuides()
         self.objectHandles.hideGuides()
         # Restart followSelectedNodePath task
         # Restart followSelectedNodePath task
@@ -180,9 +180,9 @@ class DirectManipulationControl(PandaObject):
             self.objectHandles.showHandle(self.constraint)
             self.objectHandles.showHandle(self.constraint)
             if direct.clusterMode == 'client':
             if direct.clusterMode == 'client':
                 oh = 'direct.manipulationControl.objectHandles' 
                 oh = 'direct.manipulationControl.objectHandles' 
-                direct.cluster.cmd(oh + '.showGuides()', 0)
-                direct.cluster.cmd(oh + '.hideAllHandles()', 0)
-                direct.cluster.cmd(oh + ('.showHandle("%s")'% self.constraint))
+                cluster(oh + '.showGuides()', 0)
+                cluster(oh + '.hideAllHandles()', 0)
+                cluster(oh + ('.showHandle("%s")'% self.constraint), 0)
             # Record relationship between selected nodes and widget
             # Record relationship between selected nodes and widget
             direct.selected.getWrtAll()
             direct.selected.getWrtAll()
             # hide the bbox of the selected objects during interaction
             # hide the bbox of the selected objects during interaction

+ 5 - 6
direct/src/directtools/DirectSelection.py

@@ -3,7 +3,6 @@ from DirectGlobals import *
 from DirectUtil import *
 from DirectUtil import *
 from DirectGeometry import *
 from DirectGeometry import *
 from DirectSelection import *
 from DirectSelection import *
-import __builtin__
 
 
 # MRM: To do: handle broken node paths in selected and deselected dicts
 # MRM: To do: handle broken node paths in selected and deselected dicts
 class DirectNodePath(NodePath):
 class DirectNodePath(NodePath):
@@ -48,7 +47,7 @@ class SelectedNodePaths(PandaObject):
     def reset(self):
     def reset(self):
         self.selectedDict = {}
         self.selectedDict = {}
         self.deselectedDict = {}
         self.deselectedDict = {}
-        __builtin__.last = self.last = None
+        __builtins__["last"] = self.last = None
 
 
     def select(self, nodePath, fMultiSelect = 0):
     def select(self, nodePath, fMultiSelect = 0):
         """ Select the specified node path.  Multiselect as required """
         """ Select the specified node path.  Multiselect as required """
@@ -82,10 +81,10 @@ class SelectedNodePaths(PandaObject):
             # Add it to the selected dictionary
             # Add it to the selected dictionary
             self.selectedDict[dnp.id()] = dnp
             self.selectedDict[dnp.id()] = dnp
         # And update last
         # And update last
-        __builtin__.last = self.last = dnp
+        __builtins__["last"] = self.last = dnp
         # Update cluster servers if this is a cluster client
         # Update cluster servers if this is a cluster client
         if direct.clusterMode == 'client':
         if direct.clusterMode == 'client':
-            direct.cluster.selectNodePath(dnp)
+            cluster.selectNodePath(dnp)
         return dnp
         return dnp
 
 
     def deselect(self, nodePath):
     def deselect(self, nodePath):
@@ -106,7 +105,7 @@ class SelectedNodePaths(PandaObject):
             messenger.send('DIRECT_deselectedNodePath', [dnp])
             messenger.send('DIRECT_deselectedNodePath', [dnp])
             # Update cluster servers if this is a cluster client
             # Update cluster servers if this is a cluster client
             if direct.clusterMode == 'client':
             if direct.clusterMode == 'client':
-                direct.cluster.deselectNodePath(dnp)
+                cluster.deselectNodePath(dnp)
         return dnp
         return dnp
 
 
     def getSelectedAsList(self):
     def getSelectedAsList(self):
@@ -188,7 +187,7 @@ class SelectedNodePaths(PandaObject):
         selected = self.last
         selected = self.last
         if selected:
         if selected:
             selected.remove()
             selected.remove()
-        __builtin__.last = self.last = None
+        __builtins__["last"] = self.last = None
         
         
     def removeAll(self):
     def removeAll(self):
         # Remove all selected nodePaths from the Scene Graph
         # Remove all selected nodePaths from the Scene Graph

+ 4 - 5
direct/src/directtools/DirectSession.py

@@ -17,14 +17,13 @@ import SceneGraphExplorer
 import OnscreenText
 import OnscreenText
 import types
 import types
 import string
 import string
-import __builtin__
 
 
 class DirectSession(PandaObject):
 class DirectSession(PandaObject):
 
 
     def __init__(self):
     def __init__(self):
         # Establish a global pointer to the direct object early on
         # Establish a global pointer to the direct object early on
         # so dependant classes can access it in their code
         # so dependant classes can access it in their code
-        __builtin__.direct = self
+        __builtins__["direct"] = self
         # These come early since they are used later on
         # These come early since they are used later on
         self.group = render.attachNewNode('DIRECT')
         self.group = render.attachNewNode('DIRECT')
         # Set priority to 100 so it always is textured
         # Set priority to 100 so it always is textured
@@ -186,7 +185,7 @@ class DirectSession(PandaObject):
             self.cluster = ClusterServer(base.cameraList[0], base.camList[0])
             self.cluster = ClusterServer(base.cameraList[0], base.camList[0])
         else:
         else:
             self.cluster = DummyClusterClient()
             self.cluster = DummyClusterClient()
-        __builtin__.cluster = self.cluster
+        __builtins__['cluster'] = self.cluster
             
             
     def enable(self):
     def enable(self):
         # Make sure old tasks are shut down
         # Make sure old tasks are shut down
@@ -408,7 +407,7 @@ class DirectSession(PandaObject):
         if self.clusterMode == 'client':
         if self.clusterMode == 'client':
             if input in ('v','b','l','p', 'r', 'shift-r', 's', 't',
             if input in ('v','b','l','p', 'r', 'shift-r', 's', 't',
                          'shift-a', 'w'):
                          'shift-a', 'w'):
-                self.cluster.cmd('messenger.send("%s")' % input,0)
+                self.cluster('messenger.send("%s")' % input,0)
         
         
     def getModifiers(self, input, base):
     def getModifiers(self, input, base):
         modifiers = DIRECT_NO_MOD
         modifiers = DIRECT_NO_MOD
@@ -990,7 +989,7 @@ class DisplayRegionContext:
                          (self.nearHeight*0.5) * self.mouseY)
                          (self.nearHeight*0.5) * self.mouseY)
 
 
 # Create one
 # Create one
-__builtin__.direct = base.direct = DirectSession()
+__builtins__['direct'] = base.direct = DirectSession()
 
 
 
 
 
 

+ 5 - 4
direct/src/leveleditor/LevelEditor.py

@@ -17,10 +17,10 @@ import os
 import getopt
 import getopt
 import sys
 import sys
 import whrandom
 import whrandom
-import __builtin__
 
 
 visualizeZones = base.config.GetBool("visualize-zones", 0)
 visualizeZones = base.config.GetBool("visualize-zones", 0)
 dnaDirectory = Filename.expandFrom(base.config.GetString("dna-directory", "$TTMODELS/src/dna"))
 dnaDirectory = Filename.expandFrom(base.config.GetString("dna-directory", "$TTMODELS/src/dna"))
+fUseCVS = base.config.GetBool("level-editor-use-cvs", 1)
 
 
 # Colors used by all color menus
 # Colors used by all color menus
 DEFAULT_COLORS = [
 DEFAULT_COLORS = [
@@ -205,7 +205,7 @@ try:
 except NameError:
 except NameError:
     print "Loading LevelEditor for hoods: ", hoods
     print "Loading LevelEditor for hoods: ", hoods
     # DNAStorage instance for storing level DNA info
     # DNAStorage instance for storing level DNA info
-    __builtin__.DNASTORE = DNASTORE = DNAStorage()
+    __builtins__["DNASTORE"] = DNASTORE = DNAStorage()
     # Load the generic storage files
     # Load the generic storage files
     loadDNAFile(DNASTORE, 'phase_4/dna/storage.dna', CSDefault, 1)
     loadDNAFile(DNASTORE, 'phase_4/dna/storage.dna', CSDefault, 1)
     loadDNAFile(DNASTORE, 'phase_5/dna/storage_town.dna', CSDefault, 1)
     loadDNAFile(DNASTORE, 'phase_5/dna/storage_town.dna', CSDefault, 1)
@@ -234,7 +234,7 @@ except NameError:
         loadDNAFile(DNASTORE, 'phase_8/dna/storage_DL.dna', CSDefault, 1)
         loadDNAFile(DNASTORE, 'phase_8/dna/storage_DL.dna', CSDefault, 1)
         loadDNAFile(DNASTORE, 'phase_8/dna/storage_DL_sz.dna', CSDefault, 1)
         loadDNAFile(DNASTORE, 'phase_8/dna/storage_DL_sz.dna', CSDefault, 1)
         loadDNAFile(DNASTORE, 'phase_8/dna/storage_DL_town.dna', CSDefault, 1)
         loadDNAFile(DNASTORE, 'phase_8/dna/storage_DL_town.dna', CSDefault, 1)
-    __builtin__.dnaLoaded = 1
+    __builtins__["dnaLoaded"] = 1
 
 
 # Precompute class types for type comparisons
 # Precompute class types for type comparisons
 DNA_CORNICE = DNACornice.getClassType()
 DNA_CORNICE = DNACornice.getClassType()
@@ -2476,7 +2476,8 @@ class LevelEditor(NodePath, PandaObject):
         self.reset(fDeleteToplevel = 1, fCreateToplevel = 0,
         self.reset(fDeleteToplevel = 1, fCreateToplevel = 0,
                    fUpdateExplorer = 0)
                    fUpdateExplorer = 0)
         # Now load in new file
         # Now load in new file
-        self.cvsUpdate(filename)
+        if fUseCVS:
+            self.cvsUpdate(filename)
         node = loadDNAFile(DNASTORE, Filename.fromOsSpecific(filename).cStr(), CSDefault, 1)
         node = loadDNAFile(DNASTORE, Filename.fromOsSpecific(filename).cStr(), CSDefault, 1)
         if node.getNumParents() == 1:
         if node.getNumParents() == 1:
             # If the node already has a parent arc when it's loaded, we must
             # If the node already has a parent arc when it's loaded, we must

+ 19 - 20
direct/src/showbase/ShowBase.py

@@ -22,10 +22,9 @@ import Loader
 import time
 import time
 import FSM
 import FSM
 import State
 import State
-import __builtin__
 
 
-__builtin__.FADE_SORT_INDEX = 1000
-__builtin__.NO_FADE_SORT_INDEX = 2000
+__builtins__["FADE_SORT_INDEX"] = 1000
+__builtins__["NO_FADE_SORT_INDEX"] = 2000
 
 
 class ShowBase:
 class ShowBase:
 
 
@@ -138,22 +137,22 @@ class ShowBase:
 
 
         self.AppHasAudioFocus = 1
         self.AppHasAudioFocus = 1
 
 
-        __builtin__.base = self
-        __builtin__.render2d = self.render2d
-        __builtin__.aspect2d = self.aspect2d
-        __builtin__.render = self.render
-        __builtin__.hidden = self.hidden
-        __builtin__.camera = self.camera
-        __builtin__.loader = self.loader
-        __builtin__.taskMgr = self.taskMgr
-        __builtin__.eventMgr = self.eventMgr
-        __builtin__.messenger = self.messenger
-        __builtin__.config = self.config
-        __builtin__.run = self.run
-        __builtin__.ostream = Notify.out()
-        __builtin__.directNotify = directNotify
-        __builtin__.globalClock = ClockObject.getGlobalClock()
-        __builtin__.vfs = vfs
+        __builtins__["base"] = self
+        __builtins__["render2d"] = self.render2d
+        __builtins__["aspect2d"] = self.aspect2d
+        __builtins__["render"] = self.render
+        __builtins__["hidden"] = self.hidden
+        __builtins__["camera"] = self.camera
+        __builtins__["loader"] = self.loader
+        __builtins__["taskMgr"] = self.taskMgr
+        __builtins__["eventMgr"] = self.eventMgr
+        __builtins__["messenger"] = self.messenger
+        __builtins__["config"] = self.config
+        __builtins__["run"] = self.run
+        __builtins__["ostream"] = Notify.out()
+        __builtins__["directNotify"] = directNotify
+        __builtins__["globalClock"] = ClockObject.getGlobalClock()
+        __builtins__["vfs"] = vfs
 
 
         # Transition effects (fade, iris, etc)
         # Transition effects (fade, iris, etc)
         import Transitions
         import Transitions
@@ -166,7 +165,7 @@ class ShowBase:
             import DirectSession
             import DirectSession
             direct.enable()
             direct.enable()
         else:
         else:
-            __builtin__.direct = self.direct = None
+            __builtins__["direct"] = self.direct = None
 
 
         self.restart()
         self.restart()
 
 

+ 1 - 2
direct/src/showbase/ShowBaseGlobal.py

@@ -12,6 +12,5 @@ def inspect(anObject):
     import Inspector
     import Inspector
     return Inspector.inspect(anObject)
     return Inspector.inspect(anObject)
 
 
-import __builtin__
-__builtin__.inspect = inspect
+__builtins__["inspect"] = inspect
 
 

+ 1 - 2
direct/src/showbase/TkGlobal.py

@@ -2,8 +2,7 @@
 from Tkinter import *
 from Tkinter import *
 import Pmw
 import Pmw
 
 
-import __builtin__
-__builtin__.tkroot = Pmw.initialise()
+__builtins__["tkroot"] = Pmw.initialise()
 
 
 def tkloop(self):
 def tkloop(self):
     # Do all the tkinter events waiting on this frame
     # Do all the tkinter events waiting on this frame

+ 1 - 2
direct/src/showbase/VerboseImport.py

@@ -21,5 +21,4 @@ def newimport(*args, **kw):
     return result
     return result
 
 
 # Replace the builtin import with our new import
 # Replace the builtin import with our new import
-import __builtin__
-__builtin__.__import__ = newimport
+__builtins__["__import__"] = newimport

+ 8 - 9
direct/src/tkwidgets/AppShell.py

@@ -15,7 +15,6 @@ import EntryScale
 import VectorWidgets
 import VectorWidgets
 import sys, string
 import sys, string
 import ProgressBar
 import ProgressBar
-import __builtin__
 
 
 """
 """
 TO FIX:
 TO FIX:
@@ -24,19 +23,19 @@ Radiobutton ordering change
 
 
 # Create toplevel widget dictionary
 # Create toplevel widget dictionary
 try:
 try:
-    __builtin__.widgetDict
-except AttributeError:
-    __builtin__.widgetDict = {}
+    __builtins__["widgetDict"]
+except KeyError:
+    __builtins__["widgetDict"] = {}
 # Create toplevel variable dictionary
 # Create toplevel variable dictionary
 try:
 try:
-    __builtin__.variableDict
-except AttributeError:
-    __builtin__.variableDict = {}
+    __builtins__["variableDict"]
+except KeyError:
+    __builtins__["variableDict"] = {}
 
 
 def resetWidgetDict():
 def resetWidgetDict():
-    __builtin__.widgetDict = {}
+    __builtins__["widgetDict"] = {}
 def resetVariableDict():
 def resetVariableDict():
-    __builtin__.variableDict = {}
+    __builtins__["variableDict"] = {}
 
 
 # Inherit from MegaWidget instead of Toplevel so you can pass in a toplevel
 # Inherit from MegaWidget instead of Toplevel so you can pass in a toplevel
 # to use as a container if you wish.  If no toplevel passed in, create one
 # to use as a container if you wish.  If no toplevel passed in, create one