Changeset 468

Show
Ignore:
Timestamp:
05/19/08 15:46:34 (8 months ago)
Author:
jmowery
Message:

incremental check-in of storage: clean and check-update

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/trunk-pmd-intproto/server/storage.py

    r467 r468  
    527527        def clean(self, names, recursive=False): 
    528528                '''For each file or directory in names remove all storage files with timestamps newer than the applied time.''' 
    529                 raise NotImplementedError 
     529                if not storage: 
     530                        raise RuntimeError, 'Attempt to clean uncontrolled layer.' 
     531                if names.__class__ == [].__class__: 
     532                        if '.' in names: 
     533                                self.clean('.', recursive) 
     534                                return 
     535                        else: 
     536                                for name in names: 
     537                                        self.clean(name, recursive) 
     538                                return 
     539                name = os.path.basename(names) 
     540                if not self.entries.has_key(name): 
     541                        raise ValueError, 'Layer \'' + self.name + '\' has no entry for \'' + name +'\'.' 
     542                self.update() #call this first to be sure versions are pointing at real storage files 
     543                if name == '.': 
     544                        self.clean(self.list_controlled_files()) 
     545                        if recursive: 
     546                                self.clean(self.list_controlled_dirs(), recursive) 
     547                        return 
     548                elif self.entries[name].type == 'DIR' or self.entries[name].type == 'LOCAL': 
     549                        l = Layer(os.path.join(self.storage.path, name)) 
     550                        l.clean('.', recursive) 
     551                        l.update() 
     552                        return 
     553                else: 
     554                        if self.get_current(name) == self.get_latest(name): 
     555                                return #nothing more recent than current, nothing to do 
     556                        if not self.get_current(name): #i.e. applied before initially added 
     557                                self.remove(name) 
     558                        for f in os.listdir(self.storage.storage_dir): 
     559                                if f.startswith(name): 
     560                                        if int(get_timestamp(f)) > self.entries[name].applied: 
     561                                                os.remove(f) 
     562                self.update() #call again to update latest entries 
    530563 
    531564        #list and printing functions 
     
    922955 
    923956        def check_updates(self): 
    924                 '''Compare the status of all files in each layer to which this node belongs and return a list of those that need to be sent to it.''' 
    925                 raise NotImplementedError 
     957                '''Compare the status of all files in each layer to which this node belongs and return a dictionary of those that need to be sent to it. 
     958                   Where the key is the file base name and the value is the path to be sent; if path is empty it will be deleted.''' 
     959                self.update() #make sure any local changes are written before calculating 
     960                mod_groups = {} 
     961                updates = {} 
     962                layers = self.list_layers() 
     963                layers.sort() #make sure they are in sorted order 
     964                for layer in layers: #calculate the most specific layer for each module 
     965                        l = Layer(layer) 
     966                        for name in l.list_controlled_files(): 
     967                                if l.entries[name].applied: #skip disabled modules 
     968                                        mod_groups[name] = (l.name, l.get_current(name)) 
     969                for e in self.entries.keys(): 
     970                        if not mod_groups.has_key(e): 
     971                                updates[e] = '' 
     972                        elif self.entries[e].group != mod_groups[e][0]: 
     973                                updates[e] = mod_groups[e][1] 
     974                        elif self.entries[e].applied != int(get_timestamp(mod_groups[e][1])): 
     975                                updates[e] = mod_groups[e][1] 
     976                for e in mod_groups.keys(): 
     977                        if not self.entries.has_key(e): 
     978                                updates[e] = mod_groups[e][1] 
     979                return updates 
    926980 
    927981        def write(self): 
     
    939993                        raise RuntimeError, 'Cannot set customized change for layers above custom layer.' 
    940994                if self.entries.has_key(name): 
    941                         if self.entries[name].group != l.name and l.name.count('/') < self.entries[name].group.count('/'): #less specific group; ignore 
    942                                 return 
     995                        if self.entries[name].group != l.name and l.name.count('/') < self.entries[name].group.count('/'): #less specific group; 
     996                                l2 = get_layer_by_group(self.root, self.entries[name].group) 
     997                                cur_entry = l2.get_entry(name) 
     998                                if not cur_entry is None and cur_entry.applied != 0: #more specific one is still active 
     999                                        l2.update() 
     1000                                        return 
     1001                                l2.update() 
    9431002                        self.entries[name] = Entry(name) 
    9441003                        self.entries[name].group = l.name