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