Changeset 464

Show
Ignore:
Timestamp:
05/16/08 15:44:15 (8 months ago)
Author:
jmowery
Message:

incremental check-in for new storage (9 functions remaining)

Files:

Legend:

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

    r463 r464  
    224224        def remove_dir(self, name): 
    225225                '''Remove a directory from control by the store. Note: this removes its entry not its control files unless the directory is "."''' 
    226                 raise NotImplementedError 
    227  
    228         def add_node(self, id): 
    229                 '''Add a node with the given id to the store if not already present. Create entries for each known file with an applied time of 0 for that node.''' 
    230                  
    231226                raise NotImplementedError 
    232227 
     
    418413                        if os.path.isdir(path): 
    419414                                e = self.storage.add_dir(name) 
    420                                 if recursive: 
    421                                         l = Layer(os.path.join(self.storage.path, name)) 
    422                                         l.add('.', recursive) 
    423                                         l.update() 
     415                                l = Layer(os.path.join(self.storage.path, name)) 
     416                                l.add('.', recursive) 
     417                                l.update() 
    424418                        else: 
    425419                                e = self.storage.add_file(name) 
     
    682676                if id in self.list_nodes(): 
    683677                        return # already there 
     678                if self.entries['.'].type == 'LOCAL' and id != os.path.basename(self.name): 
     679                        raise RuntimeError, 'Cannot add additional nodes to local customization layer' 
    684680                if not self.storage: 
    685681                        raise RuntimeError, 'Cannot add node \'' + id + '\' to uncontrolled layer \'' + self.name + '\'.' 
    686         #XXX    FIXME 
    687                 self.storage.add_node(id) 
     682                n = Node(id, self.storage.root) 
     683                for e in self.list_controlled_files(): 
     684                        n.set_file_status(e, self.storage.path, 0) 
     685                n.update() 
     686                return n 
    688687 
    689688        #TODO should there be a remove node? 
     
    785784        def list_layers(self): 
    786785                '''Return a list of all layers in which this node is present.''' 
    787                 raise NotImplementedError 
     786                return self.layers.keys() 
    788787 
    789788        def check_updates(self) 
     
    797796                self.modified = False 
    798797 
    799         def set_file_status(self, name, layer, version, local=True) 
    800                 raise NotImplementedError 
     798        def set_file_status(self, name, layer_path, version, local=True) 
     799                '''Record that a new version of module name from layer has been successfully sent to the node system.''' 
     800                l = Layer(layer_path) 
     801                if name not in l.list_controlled_files(): 
     802                        raise ValueError, 'No entry for \'' + name + '\' in layer \'' + l.name + '\'.' 
     803                if not local and os.path.basename(l.name) != self.id: 
     804                        raise RuntimeError, 'Cannot set customized change for layers above custom layer.' 
     805                if self.entries.has_key(name): 
     806                        if self.entries[name].group != l.name and l.name.count('/') < self.entries[name].group.count('/'): #less specific group; ignore 
     807                                return 
     808                        self.entries[name] = Entry(name) 
     809                        self.entries[name].group = l.name 
     810                if self.entries[name].applied != version 
     811                        self.entries[name].local = local 
     812                        self.entries[name].applied = version 
     813                        self.modified = True 
     814 
     815        def set_bool_status(self, bool_name, value): 
     816                '''Record the status of a conditional boolean on the node system.''' 
     817                if self.bools.has_key(bool_name): 
     818                        if self.bools[bool_name] == value: 
     819                                return #not changing anything 
     820                self.bools[bool_name] = value 
     821                self.modified = True 
    801822 
    802823        def update(self): 
     
    819840                        l = Layer(self.root) 
    820841                        if self.id not in l.list_nodes(): #only possible on initial addition of a node 
    821                                 self.layers[self.root] = NodeLayerData(self.id, self.root) 
    822                                 self.layers[self.root].write() #create empty config to be filled in by layer.add_node() 
    823842                                return 
    824                 raise NotImplementedError 
     843                        for b in self.layers[self.root].config.get_options('bools'): 
     844                                self.bools[b] = self.layers[self.root].config.getboolean('bools', b) 
     845                        self.enforcing = self.layers[self.root].config.get('general', 'enforcing') 
     846                        self.description = self.layers[self.root].config.get('general', 'description') 
     847                        while l: 
     848                                self.classification = l.name 
     849                                self.layers[l.storage.path] = NodeLayerData(self.id, l.storage.path) 
     850                                for e in self.layers[l.storage.path].config.get_options('entries'): 
     851                                        self.entries[e] = pickle.loads(self.layers[l.storage.path].config.get('entries', e)) 
     852                                        self.entries[e].group = l.name #keep the most specific group per module for check_update() 
     853                                for sl in l.list_controlled_dirs(): 
     854                                        sub_layer = Layer(os.path.join(l.storage.path, sl)) 
     855                                        l = None 
     856                                        if self.id in sub_layer.list_nodes(): 
     857                                                l = sub_layer 
     858                                                break 
     859                        else: #setting new classification 
     860                                if classification == self.classification: 
     861                                        return #no change nothing to do 
     862                                self.modified = True 
     863                                if os.path.basename(classification) == self.id: #strip local customization directory for now 
     864                                        classification = os.path.dirname(classification) 
     865                                old_classification = self.classification 
     866                                old_dirs = self.list_layers() 
     867                                l = get_layer_by_group(self.root, classification) 
     868                                new_dirs = collect_dirs(l.storage.path, l.storage.root) 
     869                                new_dirs.sort() 
     870                                cl = Layer(os.path.join(os.path.dirname(self.root), classification)) 
     871                                if os.path.basename(old_classification) == self.id: 
     872                                        shutil.copytree(l.storage.path, os.path.join(os.path.dirname(self.root), classification, self.id)) 
     873                                else: 
     874                                        os.mkdir(os.path.join(os.path.dirname(self.root), classification, self.id)) 
     875                                cl.add(os.path.join(os.path.dirname(self.root), classification, self.id)) 
     876                                for o in old_dirs: 
     877                                        if o not in new_dirs: 
     878                                                del self.layers[o] 
     879                                                ol = Layer(o) 
     880                                                if os.path.exists(os.path.join(ol.storage.nodes_dir, self.id)) 
     881                                                        os.remove(os.path.join(ol.storage.nodes_dir, self.id)) 
     882                                for n in new_dirs: 
     883                                        nl = Layer(n) 
     884                                        n.add_node(self.id) 
     885                                self.entries.clear() 
     886                                self.classify() 
     887                                sefl.update() 
    825888 
    826889        #TODO likely needs more functionality than this