changeset 3443:4ee64d58e801

move platform dependent filesystem routines to util.filesys
author Thomas Waldmann <tw AT waldmann-edv DOT de>
date Sun, 30 Mar 2008 04:26:40 +0200
parents fe130d233204
children 4d7e493a6e71
files MoinMoin/search/builtin.py MoinMoin/util/filesys.py
diffstat 2 files changed, 26 insertions(+), 34 deletions(-) [+]
line wrap: on
line diff
--- a/MoinMoin/search/builtin.py	Sun Mar 30 04:24:38 2008 +0200
+++ b/MoinMoin/search/builtin.py	Sun Mar 30 04:26:40 2008 +0200
@@ -10,17 +10,14 @@
     @license: GNU GPL, see COPYING for details
 """
 
-import time, os, errno, codecs
-import sys
-if sys.platform == 'win32':
-    import win32file, win32con, pywintypes
+import sys, os, time, errno, codecs
 
 from MoinMoin import log
 logging = log.getLogger(__name__)
 
 from MoinMoin import wikiutil, config
 from MoinMoin.Page import Page
-from MoinMoin.util import lock
+from MoinMoin.util import lock, filesys
 from MoinMoin.search.results import getSearchResults
 from MoinMoin.search.queryparser import Match, TextMatch, TitleMatch
 
@@ -207,34 +204,7 @@
 
     def touch(self):
         """ Touch the index """
-        if sys.platform == 'win32':
-            access=win32file.GENERIC_WRITE
-            share=win32file.FILE_SHARE_DELETE | \
-                  win32file.FILE_SHARE_READ | \
-                  win32file.FILE_SHARE_WRITE
-            create=win32file.OPEN_EXISTING
-            mtime = time.gmtime()
-            try:
-                handle=win32file.CreateFile(self.dir,
-                                            access,
-                                            share,
-                                            None,
-                                            create,
-                                            win32file.FILE_ATTRIBUTE_NORMAL |
-                                            win32con.FILE_FLAG_BACKUP_SEMANTICS,
-                                            None)
-            except pywintypes.error:
-                raise error, 'open("%s") for touch failed' % self.dir
-            try:
-                newTime = pywintypes.Time(mtime)
-                win32file.SetFileTime(handle,
-                                      newTime,
-                                      newTime,
-                                      newTime)
-            finally:
-                 win32file.CloseHandle(handle)
-        else:
-            os.utime(self.dir, None)
+        filesys.touch(self.dir)
 
     def _search(self, query):
         """ Actually perfom the search (read-lock acquired)
--- a/MoinMoin/util/filesys.py	Sun Mar 30 04:24:38 2008 +0200
+++ b/MoinMoin/util/filesys.py	Sun Mar 30 04:26:40 2008 +0200
@@ -6,7 +6,7 @@
     @license: GNU GPL, see COPYING for details.
 """
 
-import sys, os, shutil
+import sys, os, shutil, time
 from stat import S_ISDIR, ST_MODE, S_IMODE
 
 #############################################################################
@@ -45,6 +45,28 @@
                 pass # let os.rename give us the error (if any)
     os.rename(oldname, newname)
 
+def touch(name):
+    if sys.platform == 'win32':
+        import win32file, win32con, pywintypes
+
+        access = win32file.GENERIC_WRITE
+        share = (win32file.FILE_SHARE_DELETE |
+                 win32file.FILE_SHARE_READ |
+                 win32file.FILE_SHARE_WRITE)
+        create = win32file.OPEN_EXISTING
+        mtime = time.gmtime()
+        handle = win32file.CreateFile(name, access, share, None, create,
+                                      win32file.FILE_ATTRIBUTE_NORMAL |
+                                      win32con.FILE_FLAG_BACKUP_SEMANTICS,
+                                      None)
+        try:
+            newTime = pywintypes.Time(mtime)
+            win32file.SetFileTime(handle, newTime, newTime, newTime)
+        finally:
+            win32file.CloseHandle(handle)
+    else:
+        os.utime(name, None)
+
 
 def copystat(src, dst):
     """Copy stat bits from src to dst