1. SCons
  2. Core
  3. SCons

Commits

Steven Knight  committed c4577b4

Check in a new TestCmd.py with chmod() and touch() methods.

  • Participants
  • Parent commits 935413f
  • Branches default

Comments (0)

Files changed (2)

File etc/TestCmd.py

View file
 # SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
 
 __author__ = "Steven Knight <knight at baldmt dot com>"
-__revision__ = "TestCmd.py 0.21.D001 2006/02/21 21:18:43 knight"
-__version__ = "0.21"
+__revision__ = "TestCmd.py 0.22.D001 2006/02/26 15:45:18 knight"
+__version__ = "0.22"
 
 import os
 import os.path
                 arg = '"' + arg + '"'
             return arg
 
+    def canonicalize(self, path):
+        if is_List(path):
+            path = apply(os.path.join, tuple(path))
+        if not os.path.isabs(path):
+            path = os.path.join(self.workdir, path)
+        return path
+
     def cleanup(self, condition = None):
         """Removes any temporary working directories for the specified
         TestCmd environment.  If the environment variable PRESERVE was
         except (AttributeError, ValueError):
             pass
 
+    def chmod(self, path, mode):
+        """Changes permissions on the specified file or directory
+        path name."""
+        path = self.canonicalize(path)
+        os.chmod(path, mode)
+
     def description_set(self, description):
         """Set the description of the functionality being tested.
         """
         be specified; it must begin with an 'r'.  The default is
         'rb' (binary read).
         """
-        if is_List(file):
-            file = apply(os.path.join, tuple(file))
-        if not os.path.isabs(file):
-            file = os.path.join(self.workdir, file)
+        file = self.canonicalize(file)
         if mode[0] != 'r':
             raise ValueError, "mode must begin with 'r'"
         return open(file, mode).read()
         is an absolute path name. The target is *not* assumed to be
         under the temporary working directory.
         """
-        if is_List(link):
-            link = apply(os.path.join, tuple(link))
-        if not os.path.isabs(link):
-            link = os.path.join(self.workdir, link)
+        link = self.canonicalize(link)
         os.symlink(target, link)
 
+    def touch(self, path, mtime=None):
+        """Updates the modification time on the specified file or
+        directory path name.  The default is to update to the
+        current time if no explicit modification time is specified.
+        """
+        path = self.canonicalize(path)
+        atime = os.path.getatime(path)
+        if mtime is None:
+            mtime = time.time()
+        os.utime(path, (atime, mtime))
+
     def unlink(self, file):
         """Unlinks the specified file name.
         The file name may be a list, in which case the elements are
         assumed to be under the temporary working directory unless it
         is an absolute path name.
         """
-        if is_List(file):
-            file = apply(os.path.join, tuple(file))
-        if not os.path.isabs(file):
-            file = os.path.join(self.workdir, file)
+        file = self.canonicalize(file)
         os.unlink(file)
 
     def verbose_set(self, verbose):
         exist.  The I/O mode for the file may be specified; it must
         begin with a 'w'.  The default is 'wb' (binary write).
         """
-        if is_List(file):
-            file = apply(os.path.join, tuple(file))
-        if not os.path.isabs(file):
-            file = os.path.join(self.workdir, file)
+        file = self.canonicalize(file)
         if mode[0] != 'w':
             raise ValueError, "mode must begin with 'w'"
         open(file, mode).write(content)

File etc/TestCommon.py

View file
 # SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
 
 __author__ = "Steven Knight <knight at baldmt dot com>"
-__revision__ = "TestCommon.py 0.21.D001 2006/02/21 21:18:43 knight"
-__version__ = "0.21"
+__revision__ = "TestCommon.py 0.22.D001 2006/02/26 15:45:18 knight"
+__version__ = "0.22"
 
 import os
 import os.path
     #  $test->subdir('subdir', ...);
     #
     #  $test->copy('src_file', 'dst_file');
-    #
-    #  $test->chmod($mode, 'file', ...);
-    #
-    #  $test->touch('file', ...);
 
     def __init__(self, **kw):
         """Initialize a new TestCommon instance.  This involves just