예제 #1
0
    def execute(self):
        """The main method that splits the arguments and starts the magic"""
        options = self.options

        # search exact match of connection
        connection, opts = find_connection(Source.connections(), options,
                                           lambda con, opts: con.matches(opts))

        if connection is None:
            raise UnknownConnectionException(
                options.uri,
                map(lambda c: c.autocomplete(), Source.connections()))

        if opts.show not in ('values', 'columns') or opts.filter is None:
            raise Exception('Specify the complete URI to a table')

        try:
            connection.connect(opts.database)
            tables = connection.tables()
            if opts.table not in tables:
                raise UnknownTableException(opts.table, tables.keys())
            table = tables[opts.table]
            items = create_items(
                connection,
                connection.rows(table, opts.filter, opts.limit,
                                simplify=False), opts.include, opts.exclude,
                opts.substitutes)
            # remove duplicates
            return list(OrderedDict.fromkeys(items))
        finally:
            connection.close()
예제 #2
0
    def execute(self):
        """The main method that splits the arguments and starts the magic"""
        left, right = self.left, self.right

        lcon = Source.connection(left)
        if not lcon:
            raise UnknownConnectionException(
                left.uri,
                map(lambda c: c.autocomplete(), Source.connections()))
        lopts = left.get(lcon.dbms)
        rcon = Source.connection(right)
        if not rcon:
            raise UnknownConnectionException(
                right.uri,
                map(lambda c: c.autocomplete(), Source.connections()))
        ropts = right.get(rcon.dbms)

        try:
            lcon.connect(lopts.database)
            rcon.connect(ropts.database)
            ltables = lcon.tables()
            if lopts.table not in ltables:
                raise UnknownTableException(lopts.table, ltables.keys())
            ltable = ltables[lopts.table]
            rtables = rcon.tables()
            if ropts.table not in rtables:
                raise UnknownTableException(ropts.table, rtables.keys())
            rtable = rtables[ropts.table]

            lcols = map(
                column_ddl if left.compare_ddl else column_name,
                ltable.columns())
            rcols = map(
                column_ddl if right.compare_ddl else column_name,
                rtable.columns())

            lplus = dict(map(
                lambda c: (c.split()[0], ltable.column(c.split()[0])),
                list(set(lcols) - set(rcols))))
            rplus = dict(map(
                lambda c: (c.split()[0], rtable.column(c.split()[0])),
                list(set(rcols) - set(lcols))))

            r = {}
            for k, v in lplus.iteritems():
                if k in rplus:
                    r[k] = (v, rplus[k])
                else:
                    r[k] = (v, None)
            for k, v in rplus.iteritems():
                if k not in lplus:
                    r[k] = (None, v)

            return to_dto(map(lambda (k, v): v, r.iteritems()))
        finally:
            lcon.close()
            rcon.close()
예제 #3
0
    def execute(self):
        """The main method that splits the arguments and starts the magic"""
        left, right = self.left, self.right

        lcon = Source.connection(left)
        if not lcon:
            raise UnknownConnectionException(
                left.uri, map(lambda c: c.autocomplete(),
                              Source.connections()))
        lopts = left.get(lcon.dbms)
        rcon = Source.connection(right)
        if not rcon:
            raise UnknownConnectionException(
                right.uri, map(lambda c: c.autocomplete(),
                               Source.connections()))
        ropts = right.get(rcon.dbms)

        try:
            lcon.connect(lopts.database)
            rcon.connect(ropts.database)
            ltables = lcon.tables()
            if lopts.table not in ltables:
                raise UnknownTableException(lopts.table, ltables.keys())
            ltable = ltables[lopts.table]
            rtables = rcon.tables()
            if ropts.table not in rtables:
                raise UnknownTableException(ropts.table, rtables.keys())
            rtable = rtables[ropts.table]

            lcols = map(column_ddl if left.compare_ddl else column_name,
                        ltable.columns())
            rcols = map(column_ddl if right.compare_ddl else column_name,
                        rtable.columns())

            lplus = dict(
                map(lambda c: (c.split()[0], ltable.column(c.split()[0])),
                    list(set(lcols) - set(rcols))))
            rplus = dict(
                map(lambda c: (c.split()[0], rtable.column(c.split()[0])),
                    list(set(rcols) - set(lcols))))

            r = {}
            for k, v in lplus.iteritems():
                if k in rplus:
                    r[k] = (v, rplus[k])
                else:
                    r[k] = (v, None)
            for k, v in rplus.iteritems():
                if k not in lplus:
                    r[k] = (None, v)

            return to_dto(map(lambda (k, v): v, r.iteritems()))
        finally:
            lcon.close()
            rcon.close()
예제 #4
0
    def execute(self):
        """The main method that splits the arguments and starts the magic"""
        options = self.options

        # search exact match of connection
        connection, opts = find_connection(
            Source.connections(), options, lambda con, opts:
            (con.matches(opts) and opts.show in
             ['databases', 'tables', 'columns', 'values']))

        if connection is None:
            raise UnknownConnectionException(
                options.uri,
                map(lambda c: c.autocomplete(), Source.connections()))

        return self.process(connection, opts)
예제 #5
0
    def execute(self):
        """The main method that splits the arguments and starts the magic"""
        options = self.options

        # search exact match of connection
        connection, opts = find_connection(Source.connections(), options,
                                           lambda con, opts: con.matches(opts))

        if connection is None:
            raise UnknownConnectionException(
                options.uri,
                map(lambda c: c.autocomplete(), Source.connections()))

        if opts.show not in ['tables', 'columns', 'values']:
            raise Exception('Specify the complete URI to a table')

        return to_dto(self.build(connection, opts))
예제 #6
0
    def execute(self):
        """The main method that splits the arguments and starts the magic"""
        options = self.options

        # search exact match of connection
        connection, opts = find_connection(
            Source.connections(),
            options,
            lambda con, opts: (
                con.matches(opts)
                and opts.show in ['databases', 'tables', 'columns', 'values']))

        if connection is None:
            raise UnknownConnectionException(
                options.uri,
                map(lambda c: c.autocomplete(), Source.connections()))

        return self.process(connection, opts)
예제 #7
0
    def execute(self):
        """The main method that splits the arguments and starts the magic"""
        options = self.options

        # search exact match of connection
        connection, opts = find_connection(
            Source.connections(),
            options,
            lambda con, opts: con.matches(opts))

        if connection is None:
            raise UnknownConnectionException(
                options.uri,
                map(lambda c: c.autocomplete(), Source.connections()))

        if opts.show not in ['tables', 'columns', 'values']:
            raise Exception('Specify the complete URI to a table')

        return to_dto(self.build(connection, opts))
예제 #8
0
    def execute(self):
        """The main method that splits the arguments and starts the magic"""
        options = self.options

        # search exact match of connection
        connection, opts = find_connection(
            Source.connections(),
            options,
            lambda con, opts: con.matches(opts))

        if connection is None:
            raise UnknownConnectionException(
                options.uri,
                map(lambda c: c.autocomplete(), Source.connections()))

        if opts.show not in ('values', 'columns') or opts.filter is None:
            raise Exception('Specify the complete URI to a table')

        try:
            connection.connect(opts.database)
            tables = connection.tables()
            if opts.table not in tables:
                raise UnknownTableException(opts.table, tables.keys())
            table = tables[opts.table]
            items = create_items(
                connection,
                connection.rows(
                    table,
                    opts.filter,
                    opts.limit,
                    simplify=False),
                opts.include,
                opts.exclude,
                opts.substitutes)
            # remove duplicates
            return list(OrderedDict.fromkeys(items))
        finally:
            connection.close()
예제 #9
0
    def build(self, options):
        cons = Source.connections()

        # search exact match of connection
        connection, opts = find_connection(
            cons, options, lambda con, opts:
            (opts.show != 'connections' and con.matches(opts)))

        if connection is not None:
            return create(connection, opts)

        # print all connections
        return sorted([c for c in cons if c.filter_(options)],
                      key=lambda c: c.title().lower())
예제 #10
0
    def build(self, options):
        cons = Source.connections()

        # search exact match of connection
        connection, opts = find_connection(
            cons,
            options,
            lambda con, opts: (
                opts.show != 'connections' and con.matches(opts)))

        if connection is not None:
            return create(connection, opts)

        # print all connections
        return sorted(
            [c for c in cons if c.filter_(options)],
            key=lambda c: c.title().lower())
예제 #11
0
    def execute(self):
        options = self.options

        options.pattern = sanitise(options.pattern)

        cons = Source.connections()

        # search exact match of connection
        for connection in cons:
            opts = options.get(connection.dbms)
            if opts.show_code > 1 and connection.matches(opts):
                try:
                    connection.connect(opts.database)
                    return to_dto(map(
                        RowItem, opts.statement_activity(connection)))
                finally:
                    connection.close()

        raise Exception('Specify the complete URI of the connection')
예제 #12
0
 def __init__(self, uri, file_, key, con_creator):
     Source.__init__(self)
     self.uri = uri
     self.file = file_
     self.key = key
     self.con_creator = con_creator
예제 #13
0
 def __init__(self, driver, file_, scheme, con_creator):
     Source.__init__(self)
     self.driver = driver
     self.file = file_
     self.scheme = scheme
     self.con_creator = con_creator
예제 #14
0
 def __init__(self, driver, file_, scheme, con_creator):
     Source.__init__(self)
     self.driver = driver
     self.file = file_
     self.scheme = scheme
     self.con_creator = con_creator
예제 #15
0
 def __init__(self, uri, file_, key, con_creator):
     Source.__init__(self)
     self.uri = uri
     self.file = file_
     self.key = key
     self.con_creator = con_creator