| 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() |
|---|