equal
deleted
inserted
replaced
17 # with CubicWeb. If not, see <http://www.gnu.org/licenses/>. |
17 # with CubicWeb. If not, see <http://www.gnu.org/licenses/>. |
18 """utilities for instances migration""" |
18 """utilities for instances migration""" |
19 |
19 |
20 import sys |
20 import sys |
21 import os |
21 import os |
|
22 import string |
22 import logging |
23 import logging |
23 import tempfile |
24 import tempfile |
|
25 import itertools |
24 from os.path import exists, join, basename, splitext |
26 from os.path import exists, join, basename, splitext |
25 from itertools import chain |
27 from itertools import chain |
26 |
28 |
27 from logilab.common import IGNORED_EXTENSIONS |
29 from logilab.common import IGNORED_EXTENSIONS |
28 from logilab.common.decorators import cached |
30 from logilab.common.decorators import cached |
464 return a < b |
466 return a < b |
465 |
467 |
466 def max_version(a, b): |
468 def max_version(a, b): |
467 return str(max(Version(a), Version(b))) |
469 return str(max(Version(a), Version(b))) |
468 |
470 |
|
471 |
|
472 def split_constraint(constraint): |
|
473 oper = itertools.takewhile(lambda x: x in "<>=", constraint) |
|
474 version = itertools.dropwhile(lambda x: x not in string.digits + ".", constraint) |
|
475 |
|
476 return "".join(oper), "".join(version) |
|
477 |
|
478 |
469 class ConfigurationProblem(object): |
479 class ConfigurationProblem(object): |
470 """Each cube has its own list of dependencies on other cubes/versions. |
480 """Each cube has its own list of dependencies on other cubes/versions. |
471 |
481 |
472 The ConfigurationProblem is used to record the loaded cubes, then to detect |
482 The ConfigurationProblem is used to record the loaded cubes, then to detect |
473 inconsistencies in their dependencies. |
483 inconsistencies in their dependencies. |
497 for cube, dependencies in self.dependencies.items(): |
507 for cube, dependencies in self.dependencies.items(): |
498 for name, constraint in dependencies.items(): |
508 for name, constraint in dependencies.items(): |
499 self.reverse_dependencies.setdefault(name,set()) |
509 self.reverse_dependencies.setdefault(name,set()) |
500 if constraint: |
510 if constraint: |
501 try: |
511 try: |
502 oper, version = constraint.split() |
512 oper, version = split_constraint(constraint) |
503 self.reverse_dependencies[name].add( (oper, version, cube) ) |
513 self.reverse_dependencies[name].add( (oper, version, cube) ) |
504 except Exception: |
514 except Exception: |
505 self.warnings.append( |
515 self.warnings.append( |
506 'cube %s depends on %s but constraint badly ' |
516 'cube %s depends on %s but constraint badly ' |
507 'formatted: %s' % (cube, name, constraint)) |
517 'formatted: %s' % (cube, name, constraint)) |