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