os.path.setmtime ?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Richard Wesley

    os.path.setmtime ?

    I am trying to set the mod date on a file (Linux) as part of a unit test
    run. I can just wait one second, but that slows the test down. A
    better solution would be to tweak the mod date on a file, but os.path
    does not seem to have setmtime.

    Is there any simple way to do this?

    TIA,

    --

    - rmgw

    <http://www.electricfis h.com/>

    ----------------------------------------------------------------------------
    Richard Wesley Electric Fish, Inc.

    "Violence is the last refuge of the incompetent."
    - Isaac Azimov, _Foundation_
  • Holger Krekel

    #2
    Re: os.path.setmtim e ?

    Richard Wesley wrote:[color=blue]
    > I am trying to set the mod date on a file (Linux) as part of a unit test
    > run. I can just wait one second, but that slows the test down. A
    > better solution would be to tweak the mod date on a file, but os.path
    > does not seem to have setmtime.
    >
    > Is there any simple way to do this?[/color]

    it is spelled

    os.utime

    in python.

    os.utime(path, None)

    will set a/mtime to current time and

    os.utime (path, (-1, newtime))

    will set mtime to newtime. Note, however, that the effects and the
    actual time resolution of this call are very platform independant.

    cheers,

    holger

    Comment

    • Richard Wesley

      #3
      Re: os.path.setmtim e ?

      In article <mailman.67.106 6071133.2192.py thon-list@python.org >,
      Holger Krekel <pyth@devel.tri llke.net> wrote:
      [color=blue]
      > Richard Wesley wrote:[color=green]
      > > I am trying to set the mod date on a file (Linux) as part of a unit test
      > > run. I can just wait one second, but that slows the test down. A
      > > better solution would be to tweak the mod date on a file, but os.path
      > > does not seem to have setmtime.
      > >
      > > Is there any simple way to do this?[/color]
      >
      > it is spelled
      >
      > os.utime[/color]

      Thanks, that did the trick. Saves me 2-3 seconds per test.
      [color=blue]
      >
      > in python.
      >
      > os.utime(path, None)
      >
      > will set a/mtime to current time and
      >
      > os.utime (path, (-1, newtime))
      >
      > will set mtime to newtime. Note, however, that the effects and the
      > actual time resolution of this call are very platform independant.[/color]

      I am making relative changes under Linux, so this is pretty well
      controlled.

      --

      - rmgw

      <http://www.trustedmedi anetworks.com/>

      ----------------------------------------------------------------------------
      Richard Wesley Trusted Media Networks, Inc.

      "The professor is teaching me about 'tea'. It's very complicated."
      - Leela in "Dr. Who: The Talons of Weng-Chiang"

      Comment

      Working...