Changeset 4473:240f731eacd9 in livinglogic.python.xist

Show
Ignore:
Timestamp:
05/02/11 16:18:45 (8 years ago)
Author:
Walter Doerwald <walter@…>
Branch:
default
Message:

Rename argument user to owner.

Files:
6 modified

Legend:

Unmodified
Added
Removed
  • NEWS.rst

    r4470 r4473  
    1010 
    1111*   The :var:`schema` argument used by various methods in :mod:`ll.orasql` has 
    12     been replace be a :var:`user` argument that can be ``None`` (for the current 
     12    been replace be a :var:`owner` argument that can be ``None`` (for the current 
    1313    user), the constant ``ALL`` for all users (which uses the ``DBA_*`` variant 
    14     of various meta data views if possible or the ``ALL_*`` variants other wise) 
     14    of various meta data views if possible or the ``ALL_*`` variants otherwise) 
    1515    and a specific user name. 
    1616 
    17     These views are also used if possible in all spot where the ``ALL_`` views 
     17    These views are also used if possible in all spots where the ``ALL_`` views 
    1818    where used before. 
    1919 
     
    2222*   :class:`ll.orasql.Table` has a new method :meth:`pk` that returns the primary 
    2323    key contraint (or ``None`` if the table has now primary key contraint). 
     24 
     25*   Fixed a bug in :class:`ll.xist.xsc.Pool`: Registered elements/entities etc. 
     26    now show up as attributes of the pool object. 
    2427 
    2528*   :mod:`ipipe` support has been removed from :mod:`ll.orasql`. 
  • src/ll/orasql/__init__.py

    r4470 r4473  
    434434        return "<{}.{} object db={!r} at {:#x}>".format(self.__class__.__module__, self.__class__.__name__, self.connectstring(), id(self)) 
    435435 
    436     def itertables(self, user=ALL, mode="flat"): 
     436    def itertables(self, owner=ALL, mode="flat"): 
    437437        """ 
    438438        Generator that yields all table definitions in the current users schema 
     
    472472        cursor = self.cursor() 
    473473 
    474         tables = Table.iterobjects(self, user) 
     474        tables = Table.iterobjects(self, owner) 
    475475 
    476476        if mode == "flat": 
     
    498498                    yield t 
    499499 
    500     def itersequences(self, user=ALL): 
    501         """ 
    502         Generator that yields sequences. :var:`user` can be ``None``, ``ALL`` 
     500    def itersequences(self, owner=ALL): 
     501        """ 
     502        Generator that yields sequences. :var:`owner` can be ``None``, ``ALL`` 
    503503        (the default) or a user name. 
    504504        """ 
    505         return Sequence.iterobjects(self, user) 
    506  
    507     def iterfks(self, user=ALL): 
    508         """ 
    509         Generator that yields all foreign key constraints. :var:`user` can be 
     505        return Sequence.iterobjects(self, owner) 
     506 
     507    def iterfks(self, owner=ALL): 
     508        """ 
     509        Generator that yields all foreign key constraints. :var:`owner` can be 
    510510        ``None``, ``ALL`` (the default) or a user name. 
    511511        """ 
    512         return ForeignKey.iterobjects(self, user) 
    513  
    514     def iterprivileges(self, user=ALL): 
    515         """ 
    516         Generator that yields object privileges. :var:`user` can be ``None``, 
     512        return ForeignKey.iterobjects(self, owner) 
     513 
     514    def iterprivileges(self, owner=ALL): 
     515        """ 
     516        Generator that yields object privileges. :var:`owner` can be ``None``, 
    517517        ``ALL`` (the default) or a user name. 
    518518        """ 
    519         return Privilege.iterobjects(self, user) 
    520  
    521     def iterobjects(self, user=ALL, mode="create"): 
     519        return Privilege.iterobjects(self, owner) 
     520 
     521    def iterobjects(self, owner=ALL, mode="create"): 
    522522        """ 
    523523        Generator that yields the sequences, tables, primary keys, foreign keys, 
     
    572572 
    573573        def dosequences(): 
    574             for sequence in Sequence.iterobjects(self, user): 
     574            for sequence in Sequence.iterobjects(self, owner): 
    575575                for obj in do(sequence): 
    576576                    yield obj 
    577577 
    578578        def dotables(): 
    579             for table in Table.iterobjects(self, user): 
     579            for table in Table.iterobjects(self, owner): 
    580580                if mode == "create" or mode == "flat": 
    581581                    for obj in do(table): 
    582582                        yield obj 
    583583 
    584                 if not table.ismview(self): 
    585                     # Primary key 
    586                     pk = table.pk() 
    587                     if pk is not None: 
    588                         for obj in do(pk): 
    589                             yield obj 
    590  
    591                     # Comments 
    592                     for comment in table.itercomments(): 
    593                         # No dependency checks neccessary, but use ``do`` anyway 
    594                         for obj in do(comment): 
    595                             yield obj 
     584                # Primary key 
     585                pk = table.pk() 
     586                if pk is not None: 
     587                    for obj in do(pk): 
     588                        yield obj 
     589 
     590                # Comments 
     591                for comment in table.itercomments(): 
     592                    # No dependency checks neccessary, but use ``do`` anyway 
     593                    for obj in do(comment): 
     594                        yield obj 
    596595 
    597596                if mode == "drop": 
     
    599598                        yield obj 
    600599 
    601         def doconstraints(): 
    602             if user is None: 
    603                 cursor.execute("select constraint_type, null as owner, constraint_name from user_constraints where constraint_type in ('R', 'U') order by table_name, constraint_type, constraint_name") 
    604             elif user is ALL: 
    605                 cursor.execute("select constraint_type, decode(owner, user, null, owner) as owner, constraint_name from {}_constraints where constraint_type in ('R', 'U') order by owner, table_name, constraint_type, constraint_name".format(cursor.ddprefix())) 
    606             else: 
    607                 cursor.execute("select constraint_type, decode(owner, user, null, owner) as owner, constraint_name from {}_constraints where constraint_type in ('R', 'U') and owner=:owner order by table_name, constraint_type, constraint_name".format(cursor.ddprefix()), owner=user) 
    608             types = {"U": UniqueConstraint, "R": ForeignKey} 
    609             for rec in cursor.fetchall(): 
    610                 for subobj in do(types[rec.constraint_type](rec.constraint_name, rec.owner, self)): 
    611                     yield subobj 
    612  
    613         def doindexes(): 
    614             for index in Index.iterobjects(self, user): 
    615                 for obj in do(index): 
    616                     yield obj 
    617  
    618         def dosynonyms(): 
    619             for synonym in Synonym.iterobjects(self, user): 
    620                 for obj in do(synonym): 
    621                     yield obj 
    622  
    623         def doviews(): 
    624             for view in View.iterobjects(self, user): 
    625                 for obj in do(view): 
    626                     yield obj 
    627  
    628         def domviews(): 
    629             if user is None: 
    630                 cursor.execute("select null as owner, mview_name from user_mviews") 
    631             elif user is ALL: 
    632                 cursor.execute("select decode(owner, user, null, owner) as owner, mview_name from {}_mviews".format(cursor.ddprefix())) 
    633             else: 
    634                 cursor.execute("select decode(owner, user, null, owner) as owner, mview_name from {}_mviews where owner=:owner".format(cursor.ddprefix()), owner=user) 
    635             for rec in cursor.fetchall(): 
    636                 for subobj in do(MaterializedView(rec.mview_name, rec.owner, self)): 
    637                     yield subobj 
    638  
    639         def docode(): 
    640             for type in (Function, Procedure, Package, PackageBody, Type, Trigger, JavaSource): 
    641                 for obj in type.iterobjects(self, user): 
     600        def dorest(): 
     601            for type in (UniqueConstraint, ForeignKey, Index, Synonym, View, MaterializedView, Function, Procedure, Package, PackageBody, Type, Trigger, JavaSource): 
     602                for obj in type.iterobjects(self, owner): 
    642603                    for subobj in do(obj): 
    643604                        yield subobj 
    644605 
    645         funcs = [dosequences, dotables, doconstraints, doindexes, dosynonyms, doviews, domviews, docode] 
     606        funcs = [dosequences, dotables, dorest] 
    646607        if mode == "drop": 
    647608            funcs = reversed(funcs) 
     
    10731034 
    10741035    @classmethod 
    1075     def iternames(cls, connection, user=ALL): 
     1036    def iternames(cls, connection, owner=ALL): 
    10761037        """ 
    10771038        Generator that yields the names of all objects of this type. The argument 
    1078         :var:`user` specifies whos objects are yielded: 
     1039        :var:`owner` specifies whos objects are yielded: 
    10791040         
    10801041            ``None`` 
     
    10901051        """ 
    10911052        cursor = connection.cursor() 
    1092         if user is None: 
     1053        if owner is None: 
    10931054            cursor.execute("select null as owner, object_name from user_objects where lower(object_type) = :type and object_name not like 'BIN$%' order by object_name", type=cls.type) 
    1094         elif user is ALL: 
     1055        elif owner is ALL: 
    10951056            cursor.execute("select decode(owner, user, null, owner) as owner, object_name from {}_objects where lower(object_type) = :type and object_name not like 'BIN$%' order by owner, object_name".format(cursor.ddprefix()), type=cls.type) 
    10961057        else: 
    1097             cursor.execute("select decode(owner, user, null, owner) as owner, object_name from {}_objects where lower(object_type) = :type and object_name not like 'BIN$%' and owner=:owner order by owner, object_name".format(cursor.ddprefix()), type=cls.type, owner=user) 
     1058            cursor.execute("select decode(owner, user, null, owner) as owner, object_name from {}_objects where lower(object_type) = :type and object_name not like 'BIN$%' and owner=:owner order by owner, object_name".format(cursor.ddprefix()), type=cls.type, owner=owner) 
    10981059        return ((row.object_name, row.owner) for row in cursor) 
    10991060 
    11001061    @classmethod 
    1101     def iterobjects(cls, connection, user=ALL): 
     1062    def iterobjects(cls, connection, owner=ALL): 
    11021063        """ 
    11031064        Generator that yields all objects of this type in the current users schema. 
    1104         The argument :var:`user` specifies whos objects are yielded: 
     1065        The argument :var:`owner` specifies whos objects are yielded: 
    11051066         
    11061067            ``None`` 
     
    11151076                All objects belonging the the specified user 
    11161077        """ 
    1117         return (cls(name[0], name[1], connection) for name in cls.iternames(connection, user)) 
     1078        return (cls(name[0], name[1], connection) for name in cls.iternames(connection, owner)) 
    11181079 
    11191080 
     
    12971258 
    12981259    @classmethod 
    1299     def iternames(cls, connection, user=ALL): 
     1260    def iternames(cls, connection, owner=ALL): 
    13001261        # Skip tables that are materialized views 
    13011262        cursor = connection.cursor() 
    1302         if user is None: 
     1263        if owner is None: 
    13031264            cursor.execute("select null as owner, table_name from user_tables where table_name not like 'BIN$%' minus select null as owner, mview_name as table_name from user_mviews order by table_name") 
    1304         elif user is ALL: 
     1265        elif owner is ALL: 
    13051266            cursor.execute("select decode(owner, user, null, owner) as owner, table_name from {0}_tables where table_name not like 'BIN$%' order by owner, table_name minus select decode(owner, user, null, owner) as owner, mview_name as table_name from {0}_mviews".format(cursor.ddprefix())) 
    13061267        else: 
    1307             cursor.execute("select decode(owner, user, null, owner) as owner, table_name from {0}_tables where table_name not like 'BIN$%' and owner=:owner order by table_name minus select decode(owner, user, null, owner) as owner, mview_name as table_name from {0}_mviews where owner=:owner".format(cursor.ddprefix()), owner=user) 
     1268            cursor.execute("select decode(owner, user, null, owner) as owner, table_name from {0}_tables where table_name not like 'BIN$%' and owner=:owner order by table_name minus select decode(owner, user, null, owner) as owner, mview_name as table_name from {0}_mviews where owner=:owner".format(cursor.ddprefix()), owner=owner) 
    13081269        return ((row.table_name, row.owner) for row in cursor) 
    13091270 
     
    13951356 
    13961357    @classmethod 
    1397     def iternames(cls, connection, user=ALL): 
     1358    def iternames(cls, connection, owner=ALL): 
    13981359        cursor = connection.cursor() 
    1399         if user is None: 
     1360        if owner is None: 
    14001361            cursor.execute("select null as owner, constraint_name from user_constraints where constraint_type=:type and constraint_name not like 'BIN$%' order by constraint_name", type=cls.constraint_type) 
    1401         elif user is ALL: 
     1362        elif owner is ALL: 
    14021363            cursor.execute("select decode(owner, user, null, owner) as owner, constraint_name from {}_constraints where constraint_type=:type and constraint_name not like 'BIN$%' order by owner, constraint_name".format(cursor.ddprefix()), type=cls.constraint_type) 
    14031364        else: 
    1404             cursor.execute("select decode(owner, user, null, owner) as owner, constraint_name from {}_constraints where constraint_type=:type and constraint_name not like 'BIN$%' and owner=:owner order by owner, constraint_name".format(cursor.ddprefix()), type=cls.constraint_type, owner=user) 
     1365            cursor.execute("select decode(owner, user, null, owner) as owner, constraint_name from {}_constraints where constraint_type=:type and constraint_name not like 'BIN$%' and owner=:owner order by owner, constraint_name".format(cursor.ddprefix()), type=cls.constraint_type, owner=owner) 
    14051366        return ((row.constraint_name, row.owner) for row in cursor) 
    14061367 
     
    16731634 
    16741635    @classmethod 
    1675     def iternames(cls, connection, user=ALL): 
     1636    def iternames(cls, connection, owner=ALL): 
    16761637        # We skip those indexes that are generated by a constraint 
    16771638        cursor = connection.cursor() 
    1678         if user is None: 
     1639        if owner is None: 
    16791640            cursor.execute("select null as owner, object_name from (select object_name from user_objects where object_type = 'INDEX' minus select constraint_name as object_name from user_constraints where constraint_type in ('U', 'P')) where object_name not like 'BIN$%' order by object_name") 
    1680         elif user is ALL: 
     1641        elif owner is ALL: 
    16811642            cursor.execute("select decode(owner, user, null, owner) as owner, object_name from (select owner, object_name from {0}_objects where object_type = 'INDEX' minus select owner, constraint_name as object_name from {0}_constraints where constraint_type in ('U', 'P')) where object_name not like 'BIN$%' order by owner, object_name".format(cursor.ddprefix())) 
    16821643        else: 
    1683             cursor.execute("select decode(owner, user, null, owner) as owner, object_name from (select owner, object_name from {0}_objects where object_type = 'INDEX' and owner=:owner minus select owner, constraint_name as object_name from {0}_constraints where constraint_type in ('U', 'P')) and owner=:owner where object_name not like 'BIN$%' order by owner, object_name".format(cursor.ddprefix()), owner=user) 
     1644            cursor.execute("select decode(owner, user, null, owner) as owner, object_name from (select owner, object_name from {0}_objects where object_type = 'INDEX' and owner=:owner minus select owner, constraint_name as object_name from {0}_constraints where constraint_type in ('U', 'P')) and owner=:owner where object_name not like 'BIN$%' order by owner, object_name".format(cursor.ddprefix()), owner=owner) 
    16841645        return ((row.object_name, row.owner) for row in cursor) 
    16851646 
     
    23272288 
    23282289    @classmethod 
    2329     def iterobjects(cls, connection, user=ALL): 
    2330         """ 
    2331         Generator that yields object privileges. For the meaning of :var:`user` 
     2290    def iterobjects(cls, connection, owner=ALL): 
     2291        """ 
     2292        Generator that yields object privileges. For the meaning of :var:`owner` 
    23322293        see :meth:`Object.iternames`. 
    23332294        """ 
    23342295        cursor = connection.cursor() # can't use :meth:`getcursor` as we're in a classmethod 
    23352296 
    2336         if user is None: 
     2297        if owner is None: 
    23372298            cursor.execute("select null as owner, privilege, table_name as object, decode(grantor, user, null, grantor) as grantor, grantee from user_tab_privs where owner=user order by table_name, privilege") 
    2338         elif user is ALL: 
     2299        elif owner is ALL: 
    23392300            ddprefix = cursor.ddprefix() 
    23402301            # The column names in ``ALL_TAB_PRIVS`` and ``DBA_TAB_PRIVS`` are different, so we have to use two different queries 
     
    23442305                cursor.execute("select decode(owner, user, null, owner) as owner, privilege, table_name as object, decode(grantor, user, null, grantor) as grantor, grantee from dba_tab_privs order by table_name, privilege") 
    23452306        else: 
    2346             cursor.execute("select decode(table_schema, user, null, table_schema) as owner, privilege, table_name as object, decode(grantor, user, null, grantor) as grantor, grantee from {}_tab_privs where table_schema=:owner order by table_schema, table_name, privilege".format(cursor.ddprefix()), owner=user) 
     2307            cursor.execute("select decode(table_schema, user, null, table_schema) as owner, privilege, table_name as object, decode(grantor, user, null, grantor) as grantor, grantee from {}_tab_privs where table_schema=:owner order by table_schema, table_name, privilege".format(cursor.ddprefix()), owner=owner) 
    23472308        return (Privilege(rec.privilege, rec.object, rec.grantor, rec.grantee, rec.owner, connection) for rec in cursor) 
    23482309 
  • src/ll/orasql/scripts/oracreate.py

    r4470 r4473  
    131131        return True 
    132132 
    133     for (i, obj) in enumerate(connection.iterobjects(user=None, mode="create")): 
     133    for (i, obj) in enumerate(connection.iterobjects(owner=None, mode="create")): 
    134134        keepobj = keep(obj) 
    135135        if args.verbose: 
  • src/ll/orasql/scripts/oradiff.py

    r4470 r4473  
    215215            return True 
    216216 
    217         for (i, obj) in enumerate(connection.iterobjects(user=None, mode="flat")): 
     217        for (i, obj) in enumerate(connection.iterobjects(owner=None, mode="flat")): 
    218218            keepdef = keep(obj) 
    219219            if args.verbose: 
  • src/ll/orasql/scripts/oradrop.py

    r4470 r4473  
    114114 
    115115    ddls = [] 
    116     for (i, obj) in enumerate(connection.iterobjects(user=None, mode="drop")): 
     116    for (i, obj) in enumerate(connection.iterobjects(owner=None, mode="drop")): 
    117117        keepdef = keep(obj) 
    118118        # Get DDL 
  • src/ll/orasql/scripts/oramerge.py

    r4470 r4473  
    173173        objects = set() 
    174174 
    175         for (i, obj) in enumerate(connection.iterobjects(user=None, mode="flat")): 
     175        for (i, obj) in enumerate(connection.iterobjects(owner=None, mode="flat")): 
    176176            keep = ("$" not in obj.name and not obj.name.startswith("SYS_EXPORT_SCHEMA_")) or args.keepjunk 
    177177            if args.verbose: