345 |
_extractor = FlatExtractor # Override to class that iterates objects |
_extractor = FlatExtractor # Override to class that iterates objects |
346 |
_object_to_record = None # Set to function converting object to record |
_object_to_record = None # Set to function converting object to record |
347 |
_prefix = None # Set to required prefix |
_prefix = None # Set to required prefix |
348 |
def __init__(self, rp, mode): |
def __init__(self, rp, mode, check_path = 1, compress = 1): |
349 |
"""Open rp for reading ('r') or writing ('w')""" |
"""Open rp for reading ('r') or writing ('w')""" |
350 |
self.rp = rp |
self.rp = rp |
351 |
self.mode = mode |
self.mode = mode |
352 |
self._record_buffer = [] |
self._record_buffer = [] |
353 |
assert rp.isincfile() and rp.getincbase_str() == self._prefix, rp |
if check_path: |
354 |
|
assert rp.isincfile() and rp.getincbase_str() == self._prefix, rp |
355 |
|
compress = rp.isinccompressed() |
356 |
if mode == 'r': |
if mode == 'r': |
357 |
self.fileobj = self.rp.open("rb", rp.isinccompressed()) |
self.fileobj = self.rp.open("rb", compress) |
358 |
else: |
else: |
359 |
assert mode == 'w' and not self.rp.lstat(), (mode, rp) |
assert mode == 'w' and not self.rp.lstat(), (mode, rp) |
360 |
self.fileobj = self.rp.open("wb", rp.isinccompressed()) |
self.fileobj = self.rp.open("wb", compress) |
361 |
|
|
362 |
def write_record(self, record): |
def write_record(self, record): |
363 |
"""Write a (text) record into the file""" |
"""Write a (text) record into the file""" |
558 |
# exact compare here, can't use == on rorps |
# exact compare here, can't use == on rorps |
559 |
yield old_rorp |
yield old_rorp |
560 |
|
|
561 |
def sorted_meta_inclist(self, min_time = 0): |
def sorted_prefix_inclist(self, prefix, min_time = 0): |
562 |
"""Return list of mirror_metadata incs, reverse sorted by time""" |
"""Return reverse sorted (by time) list of incs with given prefix""" |
563 |
if not self.prefixmap.has_key('mirror_metadata'): return [] |
if not self.prefixmap.has_key(prefix): return [] |
564 |
sortlist = [(rp.getinctime(), rp) |
sortlist = [(rp.getinctime(), rp) for rp in self.prefixmap[prefix]] |
|
for rp in self.prefixmap['mirror_metadata']] |
|
565 |
sortlist.sort() |
sortlist.sort() |
566 |
sortlist.reverse() |
sortlist.reverse() |
567 |
return [rp for (time, rp) in sortlist if time >= min_time] |
return [rp for (time, rp) in sortlist if time >= min_time] |
568 |
|
|
569 |
def check_needs_diff(self): |
def check_needs_diff(self): |
570 |
"""Check if we should diff, returns (new, old) rps, or (None, None)""" |
"""Check if we should diff, returns (new, old) rps, or (None, None)""" |
571 |
inclist = self.sorted_meta_inclist() |
inclist = self.sorted_prefix_inclist('mirror_metadata') |
572 |
assert len(inclist) >= 1 |
assert len(inclist) >= 1 |
573 |
if len(inclist) == 1: return (None, None) |
if len(inclist) == 1: return (None, None) |
574 |
newrp, oldrp = inclist[:2] |
newrp, oldrp = inclist[:2] |
605 |
|
|
606 |
def relevant_meta_incs(self, time): |
def relevant_meta_incs(self, time): |
607 |
"""Return list [snapshotrp, diffrps ...] time sorted""" |
"""Return list [snapshotrp, diffrps ...] time sorted""" |
608 |
inclist = self.sorted_meta_inclist(min_time = time) |
inclist = self.sorted_prefix_inclist('mirror_metadata', min_time=time) |
609 |
if not inclist: return inclist |
if not inclist: return inclist |
610 |
assert inclist[-1].getinctime() == time, inclist[-1] |
assert inclist[-1].getinctime() == time, inclist[-1] |
611 |
for i in range(len(inclist)-1, -1, -1): |
for i in range(len(inclist)-1, -1, -1): |
632 |
def SetManager(): |
def SetManager(): |
633 |
global ManagerObj |
global ManagerObj |
634 |
ManagerObj = PatchDiffMan() |
ManagerObj = PatchDiffMan() |
635 |
|
return ManagerObj |
636 |
|
|
637 |
|
|
638 |
import eas_acls # put at bottom to avoid python circularity bug |
import eas_acls # put at bottom to avoid python circularity bug |