Changeset 477

Show
Ignore:
Timestamp:
05/21/08 15:41:48 (8 months ago)
Author:
jmowery
Message:

fix to nodes in storage: can now create, classify and reclassify nodes
(probably could use more testing to be sure it works in all cases)
cli does not have options for the above

Files:

Legend:

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

    r476 r477  
    10221022                self.config_path = os.path.join(l.storage.nodes_dir, id) 
    10231023                self.config.add_section('entries') 
    1024                 if l.storage.path == l.root: 
     1024                if l.storage.path == l.storage.root: 
    10251025                        self.config.add_section('general') 
    10261026                        self.config.add_section('bools') 
     
    10301030                node_data_file = open(self.config_path, 'w') 
    10311031                self.config.write(node_data_file) 
    1032                 node_date_file.close() 
     1032                node_data_file.close() 
    10331033 
    10341034class Node: 
     
    10481048                        raise ValueError, 'Node must have a valid id.' 
    10491049                self.root = find_control_root(root) #make sure root really is the root 
     1050                self.id = id 
    10501051                self.classify() 
    10511052                self.update() 
     
    11071108                        self.entries[name] = Entry(name) 
    11081109                        self.entries[name].group = l.name 
     1110                else: 
     1111                        self.entries[name] = Entry(name) 
     1112                        self.entries[name].group = l.name 
    11091113                if self.entries[name].applied != version: 
    11101114                        self.entries[name].local = local 
     
    11401144                        if self.id not in l.list_nodes(): #only possible on initial addition of a node 
    11411145                                return 
    1142                         for b in self.layers[self.root].config.get_options('bools'): 
    1143                                 self.bools[b] = self.layers[self.root].config.getboolean('bools', b) 
    1144                         self.enforcing = self.layers[self.root].config.get('general', 'enforcing') 
    1145                         self.description = self.layers[self.root].config.get('general', 'description') 
    11461146                        while l: 
    11471147                                self.classification = l.name 
    11481148                                self.layers[l.storage.path] = NodeLayerData(self.id, l.storage.path) 
    1149                                 for e in self.layers[l.storage.path].config.get_options('entries'): 
     1149                                for e in self.layers[l.storage.path].config.options('entries'): 
    11501150                                        self.entries[e] = pickle.loads(self.layers[l.storage.path].config.get('entries', e)) 
    11511151                                        self.entries[e].group = l.name #keep the most specific group per module for check_update() 
    1152                                 for sl in l.list_controlled_dirs(): 
    1153                                         sub_layer = Layer(os.path.join(l.storage.path, sl)) 
    1154                                         l = None 
     1152                                dirs = l.list_controlled_dirs() 
     1153                                sp = l.storage.path 
     1154                                l = None 
     1155                                for sl in dirs: 
     1156                                        sub_layer = Layer(os.path.join(sp, sl)) 
    11551157                                        if self.id in sub_layer.list_nodes(): 
    11561158                                                l = sub_layer 
    11571159                                                break 
    1158                         else: #setting new classification 
    1159                                 if classification == self.classification: 
    1160                                         return #no change nothing to do 
    1161                                 self.modified = True 
    1162                                 if os.path.basename(classification) == self.id: #strip local customization directory for now 
    1163                                         classification = os.path.dirname(classification) 
    1164                                 old_classification = self.classification 
    1165                                 old_dirs = self.list_layers() 
    1166                                 l = get_layer_by_group(self.root, classification) 
    1167                                 new_dirs = collect_dirs(l.storage.path, l.storage.root) 
    1168                                 new_dirs.sort() 
    1169                                 cl = Layer(os.path.join(os.path.dirname(self.root), classification)) 
    1170                                 if os.path.basename(old_classification) == self.id: 
    1171                                         shutil.copytree(l.storage.path, os.path.join(os.path.dirname(self.root), classification, self.id)) 
    1172                                 else: 
    1173                                         os.mkdir(os.path.join(os.path.dirname(self.root), classification, self.id)) 
    1174                                 cl.add(os.path.join(os.path.dirname(self.root), classification, self.id)) 
    1175                                 for o in old_dirs: 
    1176                                         if o not in new_dirs: 
    1177                                                 del self.layers[o] 
    1178                                                 ol = Layer(o) 
    1179                                                 if os.path.exists(os.path.join(ol.storage.nodes_dir, self.id)): 
    1180                                                         os.remove(os.path.join(ol.storage.nodes_dir, self.id)) 
    1181                                 for n in new_dirs: 
    1182                                         nl = Layer(n) 
    1183                                         n.add_node(self.id) 
    1184                                 self.entries.clear() 
    1185                                 self.classify() 
    1186                                 sefl.update() 
     1160                        for b in self.layers[self.root].config.options('bools'): 
     1161                                self.bools[b] = self.layers[self.root].config.getboolean('bools', b) 
     1162                        if self.layers[self.root].config.has_option('general', 'enforcing'): 
     1163                                self.enforcing = self.layers[self.root].config.get('general', 'enforcing') 
     1164                        if self.layers[self.root].config.has_option('general', 'description'): 
     1165                                self.description = self.layers[self.root].config.get('general', 'description') 
     1166                else: #setting new classification 
     1167                        if classification == self.classification: 
     1168                                return #no change nothing to do 
     1169                        self.modified = True 
     1170                        if os.path.basename(classification) == self.id: #strip local customization directory for now 
     1171                                classification = os.path.dirname(classification) 
     1172                        old_classification = self.classification 
     1173                        old_dirs = self.list_layers() 
     1174                        _l = get_layer_by_group(self.root, classification) 
     1175                        new_dirs = collect_dirs(_l.storage.path, _l.storage.root) 
     1176                        new_dirs.append(_l.storage.path) 
     1177                        new_dirs.append(os.path.join(os.path.dirname(self.root), classification, self.id)) 
     1178                        new_dirs.sort() 
     1179                        cl = Layer(os.path.join(os.path.dirname(self.root), classification)) 
     1180                        if os.path.basename(old_classification) == self.id: 
     1181                                shutil.copytree(_l.storage.path, os.path.join(os.path.dirname(self.root), classification, self.id)) 
     1182                        else: 
     1183                                os.mkdir(os.path.join(os.path.dirname(self.root), classification, self.id)) 
     1184                        cl.add(os.path.join(os.path.dirname(self.root), classification, self.id)) 
     1185                        for o in old_dirs: 
     1186                                if o not in new_dirs: 
     1187                                        del self.layers[o] 
     1188                                        ol = Layer(o) 
     1189                                        if os.path.exists(os.path.join(ol.storage.nodes_dir, self.id)): 
     1190                                                os.remove(os.path.join(ol.storage.nodes_dir, self.id)) 
     1191                                        for i in self.entries.keys(): 
     1192                                                if self.entries[i].group == ol.name: 
     1193                                                        del self.entries[i] 
     1194                                        ol.update() 
     1195                        for n in new_dirs: 
     1196                                nl = Layer(n) 
     1197                                nl.add_node(self.id) 
     1198                                if n not in old_dirs: 
     1199                                        self.layers[n] = NodeLayerData(self.id, n) 
     1200                                        for f in nl.list_controlled_files(): 
     1201                                                self.set_file_status(f, nl.storage.path, 0) 
     1202                                        self.layers[n].write() #create the file 
     1203                                nl.update() 
     1204                        self.classify() 
     1205                        self.update() 
    11871206 
    11881207        #TODO likely needs more functionality than this