コード例 #1
0
ファイル: command.py プロジェクト: Antexa/htpc_ynh
 def command(self):
     good = 0
     bad = 0
     missing_tables = 0
     columnsFromSchema_warning = False
     for soClass in self.classes(require_some=True):
         conn = soClass._connection
         self.printed = False
         if self.options.verbose:
             self.print_class(soClass)
         if not conn.tableExists(soClass.sqlmeta.table):
             self.print_class(soClass)
             print '  Does not exist in database'
             missing_tables += 1
             continue
         try:
             columns = conn.columnsFromSchema(soClass.sqlmeta.table,
                                              soClass)
         except AttributeError:
             if not columnsFromSchema_warning:
                 print 'Database does not support reading columns'
                 columnsFromSchema_warning = True
             good += 1
             continue
         except AssertionError, e:
             print 'Cannot read db table %s: %s' % (
                 soClass.sqlmeta.table, e)
             continue
         existing = {}
         for col in columns:
             col = col.withClass(soClass)
             existing[col.dbName] = col
         missing = {}
         for col in soClass.sqlmeta.columnList:
             if col.dbName in existing:
                 del existing[col.dbName]
             else:
                 missing[col.dbName] = col
         if existing:
             self.print_class(soClass)
             for col in existing.values():
                 print '  Database has extra column: %s' % col.dbName
         if missing:
             self.print_class(soClass)
             for col in missing.values():
                 print '  Database missing column: %s' % col.dbName
         if existing or missing:
             bad += 1
         else:
             good += 1
コード例 #2
0
ファイル: command.py プロジェクト: Antexa/htpc_ynh
def db_differences(soClass, conn):
    """
    Returns the differences between a class and the table in a
    connection.  Returns [] if no differences are found.  This
    function does the best it can; it can miss many differences.
    """
    # @@: Repeats a lot from CommandStatus.command, but it's hard
    # to actually factor out the display logic.  Or I'm too lazy
    # to do so.
    diffs = []
    if not conn.tableExists(soClass.sqlmeta.table):
        if soClass.sqlmeta.columns:
            diffs.append('Does not exist in database')
    else:
        try:
            columns = conn.columnsFromSchema(soClass.sqlmeta.table,
                                             soClass)
        except AttributeError:
            # Database does not support reading columns
            pass
        else:
            existing = {}
            for col in columns:
                col = col.withClass(soClass)
                existing[col.dbName] = col
            missing = {}
            for col in soClass.sqlmeta.columnList:
                if col.dbName in existing:
                    del existing[col.dbName]
                else:
                    missing[col.dbName] = col
            for col in existing.values():
                diffs.append('Database has extra column: %s'
                             % col.dbName)
            for col in missing.values():
                diffs.append('Database missing column: %s' % col.dbName)
    return diffs