Skip to content

Commit

Permalink
Merge pull request #2386 from rleigh-dundee/python-isdir-dev50
Browse files Browse the repository at this point in the history
OmeroPy: Fix path handling and renaming for Python 2.7 on Windows
  • Loading branch information
joshmoore committed Apr 29, 2014
2 parents 069ca5d + 1c2c34a commit 74c04c6
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 11 deletions.
7 changes: 6 additions & 1 deletion components/tools/OmeroPy/src/omero/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@
import logging
import portalocker

# To avoid conflict with omero.sys
sys = __import__("sys")

import xml.dom.minidom

from xml.etree.ElementTree import XML, Element, SubElement, Comment, ElementTree, tostring
Expand Down Expand Up @@ -102,6 +105,7 @@ def __init__(self, filename, env_config=None, exclusive=True, read_only=False):

self.source.seek(0)
text = self.source.read()
self.source.close()

if text:
self.XML = XML(text)
Expand Down Expand Up @@ -277,12 +281,13 @@ def save(self):
temp_file = path.path(self.filename + ".temp")
try:
temp_file.write_text(self.element_to_xml(icegrid))
if sys.platform == "win32":
os.remove(self.filename)
temp_file.rename(self.filename)
try:
self._close_lock()
except:
self.logger.error("Failed to close lock", exc_info=1)
self.open_source()
except Exception, e:
try:
temp_file.remove()
Expand Down
26 changes: 16 additions & 10 deletions components/tools/OmeroPy/src/path.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@
* Improved listdir to handle unreadable directories. See #9156. (2013/03/06)
* Merged changes from https://github.com/jaraco/path.py/commit/bee13d0de4d44599d397b603e1c83dce1ce9818d (2014/04/28)
"""


Expand Down Expand Up @@ -817,33 +819,37 @@ def read_md5(self):
raise Exception("read_md5 has been removed from this installation of path.py")

# --- Methods for querying the filesystem.
# N.B. On some platforms, the os.path functions may be implemented in C
# (e.g. isdir on Windows, Python 3.2.2), and compiled functions don't get
# bound. Playing it safe and wrapping them all in method calls.

exists = os.path.exists
isdir = os.path.isdir
isfile = os.path.isfile
islink = os.path.islink
ismount = os.path.ismount
def isabs(self): return os.path.isabs(self)
def exists(self): return os.path.exists(self)
def isdir(self): return os.path.isdir(self)
def isfile(self): return os.path.isfile(self)
def islink(self): return os.path.islink(self)
def ismount(self): return os.path.ismount(self)

if hasattr(os.path, 'samefile'):
samefile = os.path.samefile
def samefile(self): return os.path.samefile(self)

getatime = os.path.getatime
def getatime(self): return os.path.getatime(self)
atime = property(
getatime, None, None,
""" Last access time of the file. """)

getmtime = os.path.getmtime
def getmtime(self): return os.path.getmtime(self)
mtime = property(
getmtime, None, None,
""" Last-modified time of the file. """)

if hasattr(os.path, 'getctime'):
getctime = os.path.getctime
def getctime(self): return os.path.getctime(self)
ctime = property(
getctime, None, None,
""" Creation time of the file. """)

getsize = os.path.getsize
def getsize(self): return os.path.getsize(self)
size = property(
getsize, None, None,
""" Size of the file, in bytes. """)
Expand Down

0 comments on commit 74c04c6

Please sign in to comment.