Return a name-to-key-list dictionary to define each sequence.
(self)
| 1215 | os.rmdir(path) |
| 1216 | |
| 1217 | def get_sequences(self): |
| 1218 | """Return a name-to-key-list dictionary to define each sequence.""" |
| 1219 | results = {} |
| 1220 | try: |
| 1221 | f = open(os.path.join(self._path, '.mh_sequences'), 'r', encoding='ASCII') |
| 1222 | except FileNotFoundError: |
| 1223 | return results |
| 1224 | with f: |
| 1225 | all_keys = set(self.keys()) |
| 1226 | for line in f: |
| 1227 | try: |
| 1228 | name, contents = line.split(':') |
| 1229 | keys = set() |
| 1230 | for spec in contents.split(): |
| 1231 | if spec.isdigit(): |
| 1232 | keys.add(int(spec)) |
| 1233 | else: |
| 1234 | start, stop = (int(x) for x in spec.split('-')) |
| 1235 | keys.update(range(start, stop + 1)) |
| 1236 | results[name] = [key for key in sorted(keys) \ |
| 1237 | if key in all_keys] |
| 1238 | if len(results[name]) == 0: |
| 1239 | del results[name] |
| 1240 | except ValueError: |
| 1241 | raise FormatError('Invalid sequence specification: %s' % |
| 1242 | line.rstrip()) |
| 1243 | return results |
| 1244 | |
| 1245 | def set_sequences(self, sequences): |
| 1246 | """Set sequences using the given name-to-key-list dictionary.""" |