Return a name-to-key-list dictionary to define each sequence.
(self)
| 1145 | os.rmdir(path) |
| 1146 | |
| 1147 | def get_sequences(self): |
| 1148 | """Return a name-to-key-list dictionary to define each sequence.""" |
| 1149 | results = {} |
| 1150 | with open(os.path.join(self._path, '.mh_sequences'), 'r', encoding='ASCII') as f: |
| 1151 | all_keys = set(self.keys()) |
| 1152 | for line in f: |
| 1153 | try: |
| 1154 | name, contents = line.split(':') |
| 1155 | keys = set() |
| 1156 | for spec in contents.split(): |
| 1157 | if spec.isdigit(): |
| 1158 | keys.add(int(spec)) |
| 1159 | else: |
| 1160 | start, stop = (int(x) for x in spec.split('-')) |
| 1161 | keys.update(range(start, stop + 1)) |
| 1162 | results[name] = [key for key in sorted(keys) \ |
| 1163 | if key in all_keys] |
| 1164 | if len(results[name]) == 0: |
| 1165 | del results[name] |
| 1166 | except ValueError: |
| 1167 | raise FormatError('Invalid sequence specification: %s' % |
| 1168 | line.rstrip()) |
| 1169 | return results |
| 1170 | |
| 1171 | def set_sequences(self, sequences): |
| 1172 | """Set sequences using the given name-to-key-list dictionary.""" |