示例#1
0
    def _detect_database(self, tag):
        match = re.match('^{([^}]+)}', tag)
        if not match:
            return None

        namespace = match.group(1)
        for db in Database.list():
            if namespace == db.__xmlns__:
                return db
        return None
示例#2
0
    def execute(self, args, options):
        filters = {}
        if options.filter:
            if not os.path.exists(options.filter):
                self.parser().error('filter: unable to open for reading')
            filters = create_filter(options.filter, options.include_tags, options.exclude_tags)

        source_location, target_location = args
        source = target = None

        # load the source state
        for provider in PROVIDERS:
            if provider.can_load(source_location):
                source = provider.load(source_location, filters)
                break
        else:
            self.parser().error('source: unable to open for reading')

        # load the target state
        for provider in PROVIDERS:
            if provider.can_load(target_location):
                target = provider.load(target_location, filters)
                break
        else:
            self.parser().error('target: unable to open for reading')

        if not source.__class__ == target.__class__:
            self.parser().error('source and target represent different databases')

        source.setdefault('name')
        target.setdefault('name')

        self.source_version, self.target_version = source.name, target.name
        source.name = target.name = None
        if source == target:
            return

        for db in Database.list():
            if db.__state__ == source.__class__:
                self.db = db

        self.builders = {}
        self.tags = {}
        for builder in self.db.__builders__:
            self.builders[builder.DbClass] = builder
            self.tags[builder.DbClass] = builder.XmlTag

        self.diff = []
        self.compute_diff([], source, target)
        if not options.html:
            self.print_simple_diff()
        else:
            self.print_html_diff(source, target, options.lines)
示例#3
0
 def _lookup_database(self, dbclass):
     for db in Database.list():
         if dbclass == db.__state__:
             return db
     return None