Anonymous avatar Anonymous committed dc40cb5

Change the Action object execute() methods to __call__() methods.

Comments (0)

Files changed (6)

src/engine/SCons/Action.py

     def __init__(self, cmd):
         self.cmd_list = cmd
 
-    def execute(self, target, source, env):
+    def __call__(self, target, source, env):
         """Execute a command action.
 
         This will handle lists of commands as well as individual commands,
             raise SCons.Errors.UserError("Object returned from command generator: %s cannot be used to create an Action." % repr(ret))
         return gen_cmd
 
-    def execute(self, target, source, env):
+    def __call__(self, target, source, env):
         if not SCons.Util.is_List(source):
             source = [source]
         rsources = map(rfile, source)
-        return self.__generate(target, source, env, 0).execute(target, rsources, env)
+        act = self.__generate(target, source, env, 0)
+        return act(target, rsources, env)
 
     def get_contents(self, target, source, env):
         """Return the signature contents of this action's command line.
                 return "%s(%s, %s)" % (name, tstr, sstr)
         self.strfunction = strfunction
 
-    def execute(self, target, source, env):
+    def __call__(self, target, source, env):
         r = 0
         if not SCons.Util.is_List(target):
             target = [target]
     def get_actions(self):
         return self.list
 
-    def execute(self, target, source, env):
+    def __call__(self, target, source, env):
         for l in self.list:
-            r = l.execute(target, source, env)
+            r = l(target, source, env)
             if r:
                 return r
         return 0

src/engine/SCons/ActionTests.py

         cmd1 = r'%s %s %s xyzzy' % (python, act_py, outfile)
 
         act = SCons.Action.CommandAction(cmd1)
-        r = act.execute([], [], Environment())
+        r = act([], [], Environment())
         assert r == 0
         c = test.read(outfile, 'r')
         assert c == "act.py: 'xyzzy'\n", c
         cmd2 = r'%s %s %s $TARGET' % (python, act_py, outfile)
 
         act = SCons.Action.CommandAction(cmd2)
-        r = act.execute('foo', [], Environment())
+        r = act('foo', [], Environment())
         assert r == 0
         c = test.read(outfile, 'r')
         assert c == "act.py: 'foo'\n", c
         cmd3 = r'%s %s %s ${TARGETS}' % (python, act_py, outfile)
 
         act = SCons.Action.CommandAction(cmd3)
-        r = act.execute(['aaa', 'bbb'], [], Environment())
+        r = act(['aaa', 'bbb'], [], Environment())
         assert r == 0
         c = test.read(outfile, 'r')
         assert c == "act.py: 'aaa' 'bbb'\n", c
         cmd4 = r'%s %s %s $SOURCES' % (python, act_py, outfile)
 
         act = SCons.Action.CommandAction(cmd4)
-        r = act.execute([], ['one', 'two'], Environment())
+        r = act([], ['one', 'two'], Environment())
         assert r == 0
         c = test.read(outfile, 'r')
         assert c == "act.py: 'one' 'two'\n", c
         cmd4 = r'%s %s %s ${SOURCES[:2]}' % (python, act_py, outfile)
 
         act = SCons.Action.CommandAction(cmd4)
-        r = act.execute([],
+        r = act([],
                         source = ['three', 'four', 'five'],
                         env = Environment())
         assert r == 0
         cmd5 = r'%s %s %s $TARGET XYZZY' % (python, act_py, outfile)
 
         act = SCons.Action.CommandAction(cmd5)
-        r = act.execute(target = 'out5',
+        r = act(target = 'out5',
                         source = [],
                         env = Environment(ENV = {'XYZZY' : 'xyzzy'}))
         assert r == 0
         cmd6 = r'%s %s %s ${TARGETS[1]} $TARGET ${SOURCES[:2]}' % (python, act_py, outfile)
 
         act = SCons.Action.CommandAction(cmd6)
-        r = act.execute(target = [Obj('111'), Obj('222')],
+        r = act(target = [Obj('111'), Obj('222')],
                         source = [Obj('333'), Obj('444'), Obj('555')],
                         env = Environment())
         assert r == 0
             show_string = show_string + string + "\n"
         act.show = my_show
 
-        r = act.execute([], [], Environment())
+        r = act([], [], Environment())
         assert r == 0
         assert show_string == expect7, show_string
 
 
         # Test that a nonexistent command returns 127
         act = SCons.Action.CommandAction(python + "_XyZzY_")
-        r = act.execute([], [], Environment(out = outfile))
+        r = act([], [], Environment(out = outfile))
         assert r == expect_nonexistent, "r == %d" % r
 
         # Test that trying to execute a directory returns 126
         dir, tail = os.path.split(python)
         act = SCons.Action.CommandAction(dir)
-        r = act.execute([], [], Environment(out = outfile))
+        r = act([], [], Environment(out = outfile))
         assert r == expect_nonexecutable, "r == %d" % r
 
         # Test that trying to execute a non-executable file returns 126
         act = SCons.Action.CommandAction(outfile)
-        r = act.execute([], [], Environment(out = outfile))
+        r = act([], [], Environment(out = outfile))
         assert r == expect_nonexecutable, "r == %d" % r
 
     def test_set_handler(self):
             assert 0, "should have gotten user error"
             
         a = SCons.Action.CommandAction(["xyzzy"])
-        a.execute([], [], Environment(SPAWN = func))
+        a([], [], Environment(SPAWN = func))
         assert t.executed == [ 'xyzzy' ]
 
         a = SCons.Action.CommandAction(["xyzzy"])
-        a.execute([], [], Environment(SPAWN = func, SHELL = 'fake shell'))
+        a([], [], Environment(SPAWN = func, SHELL = 'fake shell'))
         assert t.executed == [ 'xyzzy' ]
         assert t.shell == 'fake shell'
 
         a = SCons.Action.CommandAction([ LiteralStr("xyzzy") ])
-        a.execute([], [], Environment(SPAWN = func, ESCAPE = escape_func))
+        a([], [], Environment(SPAWN = func, ESCAPE = escape_func))
         assert t.executed == [ '**xyzzy**' ], t.executed
 
     def test_get_raw_contents(self):
         self.dummy = 0
         self.cmd = []
         self.args = []
-        a.execute([], [], env=Environment(FOO = 'foo baz\nbar ack',
+        a([], [], env=Environment(FOO = 'foo baz\nbar ack',
                                           dummy = 1,
                                           SPAWN = ch))
         assert self.dummy == 1, self.dummy
 
         b = SCons.Action.CommandGeneratorAction(f2)
         self.dummy = 0
-        b.execute(target=[], source=[], env=Environment(foo =  'bar',
+        b(target=[], source=[], env=Environment(foo =  'bar',
                                                         dummy =  2 ))
         assert self.dummy==2, self.dummy
         del self.dummy
         def f3(target, source, env, for_signature):
             return ''
         c = SCons.Action.CommandGeneratorAction(f3)
-        c.execute(target=[], source=DummyFile(self), env=Environment())
+        c(target=[], source=DummyFile(self), env=Environment())
         assert self.rfile_called
 
     def test_get_contents(self):
             assert env.subst("$BAR") == 'foo bar', env.subst("$BAR")
             return 0
         a = SCons.Action.FunctionAction(f)
-        a.execute(target=1, source=2, env=Environment(BAR = 'foo bar',
+        a(target=1, source=2, env=Environment(BAR = 'foo bar',
                                                       s = self))
         assert self.inc == 1, self.inc
         assert self.source == [2], self.source
         act = SCons.Action.FunctionAction(function1)
         r = None
         try:
-            r = act.execute(target = [outfile, outfile2],
-                            source=[],
-                            env=Environment())
+            r = act(target = [outfile, outfile2], source=[], env=Environment())
         except SCons.Errors.BuildError:
             pass
         assert r == 1
                 open(env['out'], 'w').write("class1a\n")
 
         act = SCons.Action.FunctionAction(class1a)
-        r = act.execute([], [], Environment(out = outfile))
+        r = act([], [], Environment(out = outfile))
         assert r.__class__ == class1a
         c = test.read(outfile, 'r')
         assert c == "class1a\n", c
                 return 2
 
         act = SCons.Action.FunctionAction(class1b())
-        r = act.execute([], [], Environment(out = outfile))
+        r = act([], [], Environment(out = outfile))
         assert r == 2
         c = test.read(outfile, 'r')
         assert c == "class1b\n", c
             self.string_it = 1
             return None
         act = SCons.Action.FunctionAction(build_it, string_it)
-        r = act.execute([], [], Environment())
+        r = act([], [], Environment())
         assert r == 0, r
         assert self.build_it
         assert self.string_it
             s = env['s']
             s.inc = s.inc + 1
         a = SCons.Action.ListAction([f, f, f])
-        a.execute([], [], Environment(s = self))
+        a([], [], Environment(s = self))
         assert self.inc == 3, self.inc
 
         cmd2 = r'%s %s %s syzygy' % (python, act_py, outfile)
             def __init__(self, target, source, env):
                 open(env['out'], 'a').write("class2b\n")
         act = SCons.Action.ListAction([cmd2, function2, class2a(), class2b])
-        r = act.execute([], [], Environment(out = outfile))
+        r = act([], [], Environment(out = outfile))
         assert r.__class__ == class2b
         c = test.read(outfile, 'r')
         assert c == "act.py: 'syzygy'\nfunction2\nclass2a\nclass2b\n", c
             s.test=1
             return 0
         a = SCons.Action.Action('$BAR')
-        a.execute([], [], env=Environment(BAR = f, s = self))
+        a([], [], env=Environment(BAR = f, s = self))
         assert self.test == 1, self.test
 
     def test_get_contents(self):

src/engine/SCons/Node/FS.py

             os.chmod(dest, stat.S_IMODE(st[stat.ST_MODE]) | stat.S_IWRITE)
     return 0
 
-LinkAction = SCons.Action.Action(LinkFunc, None)
+Link = SCons.Action.Action(LinkFunc, None)
 
 def LocalString(target, source):
     return 'Local copy of %s from %s' % (target[0], source[0])
     os.unlink(target[0].path)
     return 0
 
-UnlinkAction = SCons.Action.Action(UnlinkFunc, None)
+Unlink = SCons.Action.Action(UnlinkFunc, None)
 
 def MkdirFunc(target, source, env):
     os.mkdir(target[0].path)
     return 0
 
-MkdirAction = SCons.Action.Action(MkdirFunc, None)
+Mkdir = SCons.Action.Action(MkdirFunc, None)
 
 #
 class ParentOfRoot:
         for dirnode in listDirs:
             dirnode._exists = 1
             try:
-                MkdirAction.execute(dirnode, None, None)
+                Mkdir(dirnode, None, None)
             except OSError:
                 pass
 
 
         if self.exists():
             if self.builder and not self.precious:
-                UnlinkAction.execute(self, None, None)
+                Unlink(self, None, None)
                 if hasattr(self, '_exists'):
                     delattr(self, '_exists')
         else:
             if src.exists() and src.abspath != self.abspath:
                 self._createDir()
                 try:
-                    UnlinkAction.execute(self, None, None)
+                    Unlink(self, None, None)
                 except OSError:
                     pass
-                LinkAction.execute(self, src, None)
+                Link(self, src, None)
                 self.created = 1
 
                 # Set our exists cache accordingly
                     # ...and it's even up-to-date...
                     if self._local:
                         # ...and they'd like a local copy.
-                        LocalCopy.execute(self, r, None)
+                        LocalCopy(self, r, None)
                         self.set_bsig(bsig)
                         self.store_bsig()
                     return 1

src/engine/SCons/Node/FSTests.py

 
     def get_actions(self):
         class Action:
-            def execute(self, targets, sources, env):
+            def __call__(self, targets, sources, env):
                 global built_it
                 built_it = 1
                 return 0
         assert f8.rfile().path == os.path.normpath(test.workpath('rep1/build/var2/test2.out')),\
                f8.rfile().path
         
-        # Test to see if LinkAction() works...
+        # Test to see if Link() works...
         test.subdir('src','build')
         test.write('src/foo', 'src/foo\n')
         os.chmod(test.workpath('src/foo'), stat.S_IRUSR)
-        SCons.Node.FS.LinkAction.execute(fs.File(test.workpath('build/foo')),
-                                         fs.File(test.workpath('src/foo')),
-                                         None)
+        SCons.Node.FS.Link(fs.File(test.workpath('build/foo')),
+                           fs.File(test.workpath('src/foo')),
+                           None)
         os.chmod(test.workpath('src/foo'), stat.S_IRUSR | stat.S_IWRITE)
         st=os.stat(test.workpath('build/foo'))
         assert (stat.S_IMODE(st[stat.ST_MODE]) & stat.S_IWRITE), \
 
         test.write('src/foo', 'src/foo\n')
         os.chmod(test.workpath('src/foo'), stat.S_IRUSR)
-        SCons.Node.FS.LinkAction.execute(fs.File(test.workpath('build/foo')),
-                                         fs.File(test.workpath('src/foo')),
-                                         None)
+        SCons.Node.FS.Link(fs.File(test.workpath('build/foo')),
+                           fs.File(test.workpath('src/foo')),
+                           None)
         test.unlink( "src/foo" )
         test.unlink( "build/foo" )
 

src/engine/SCons/Node/NodeTests.py

 cycle_detected = None
 
 class MyAction:
-    def execute(self, target, source, env):
+    def __call__(self, target, source, env):
         global built_it, built_target, built_source, built_args
         built_it = 1
         built_target = target

src/engine/SCons/Node/__init__.py

         targets = self.builder.targets(self)
         env = self.generate_build_env()
         for action in action_list:
-            stat = action.execute(targets, self.sources, env)
+            stat = action(targets, self.sources, env)
             if stat:
                 raise SCons.Errors.BuildError(node = self,
                                               errstr = "Error %d" % stat)
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.