Show More
@@ -1195,24 +1195,7 def opener(base, audit=True): | |||||
1195 | except: pass |
|
1195 | except: pass | |
1196 | posixfile.close(self) |
|
1196 | posixfile.close(self) | |
1197 |
|
1197 | |||
1198 | class atomicfile(atomictempfile): |
|
1198 | def o(path, mode="r", text=False, atomictemp=False): | |
1199 | """the file will only be copied on close""" |
|
|||
1200 | def __init__(self, name, mode): |
|
|||
1201 | self._err = False |
|
|||
1202 | atomictempfile.__init__(self, name, mode) |
|
|||
1203 | def write(self, s): |
|
|||
1204 | try: |
|
|||
1205 | atomictempfile.write(self, s) |
|
|||
1206 | except: |
|
|||
1207 | self._err = True |
|
|||
1208 | raise |
|
|||
1209 | def close(self): |
|
|||
1210 | self.rename() |
|
|||
1211 | def __del__(self): |
|
|||
1212 | if not self._err: |
|
|||
1213 | self.rename() |
|
|||
1214 |
|
||||
1215 | def o(path, mode="r", text=False, atomic=False, atomictemp=False): |
|
|||
1216 | if audit_p: |
|
1199 | if audit_p: | |
1217 | audit_path(path) |
|
1200 | audit_path(path) | |
1218 | f = os.path.join(p, path) |
|
1201 | f = os.path.join(p, path) | |
@@ -1228,9 +1211,7 def opener(base, audit=True): | |||||
1228 | d = os.path.dirname(f) |
|
1211 | d = os.path.dirname(f) | |
1229 | if not os.path.isdir(d): |
|
1212 | if not os.path.isdir(d): | |
1230 | os.makedirs(d) |
|
1213 | os.makedirs(d) | |
1231 | if atomic: |
|
1214 | if atomictemp: | |
1232 | return atomicfile(f, mode) |
|
|||
1233 | elif atomictemp: |
|
|||
1234 | return atomictempfile(f, mode) |
|
1215 | return atomictempfile(f, mode) | |
1235 | if nlink > 1: |
|
1216 | if nlink > 1: | |
1236 | rename(mktempcopy(f), f) |
|
1217 | rename(mktempcopy(f), f) |
General Comments 0
You need to be logged in to leave comments.
Login now