Beispiel #1
0
def wait_for_file_mtime_change(filename):
    """This function is typically called before a file save operation,
    waiting if necessary for the file modification time to change. The
    purpose is to avoid successive file updates going undetected by the
    caching mechanism that depends on a change in the file modification
    time to know when the file should be reparsed."""

    from trac.util import touch_file
    try:
        mtime = os.stat(filename).st_mtime
        touch_file(filename)
        while mtime == os.stat(filename).st_mtime:
            time.sleep(1e-3)
            touch_file(filename)
    except OSError:
        pass  # file doesn't exist (yet)
Beispiel #2
0
def wait_for_file_mtime_change(filename):
    """This function is typically called before a file save operation,
    waiting if necessary for the file modification time to change. The
    purpose is to avoid successive file updates going undetected by the
    caching mechanism that depends on a change in the file modification
    time to know when the file should be reparsed."""

    from trac.util import touch_file
    try:
        mtime = os.stat(filename).st_mtime
        touch_file(filename)
        while mtime == os.stat(filename).st_mtime:
            time.sleep(1e-3)
            touch_file(filename)
    except OSError:
        pass  # file doesn't exist (yet)
Beispiel #3
0
 def test_missing(self):
     util.touch_file(self.filename)
     self.assertTrue(os.path.isfile(self.filename))
     self.assertEqual(0, os.path.getsize(self.filename))
Beispiel #4
0
 def test_touch_file(self):
     util.create_file(self.filename, self.data, 'wb')
     util.touch_file(self.filename)
     with open(self.filename, 'rb') as f:
         self.assertEqual(self.data, f.read())
Beispiel #5
0
 def test_missing(self):
     util.touch_file(self.filename)
     self.assertTrue(os.path.isfile(self.filename))
     self.assertEqual(0, os.path.getsize(self.filename))
Beispiel #6
0
 def test_touch_file(self):
     util.create_file(self.filename, self.data, 'wb')
     util.touch_file(self.filename)
     with open(self.filename, 'rb') as f:
         self.assertEqual(self.data, f.read())