Changeset 186:5781b985e7df in livinglogic.python.orasql

Show
Ignore:
Timestamp:
02/15/07 20:02:29 (13 years ago)
Author:
Walter Doerwald <walter@…>
Branch:
default
Message:

Fix output in oradiff for -mfull.

Make (skipped) message in oradiff colored.

Add a test for "oradiff -m" and "oragrant".

Do output of all privileges via Privilege.iterobjects() (just like for
all other types too).

Files:
6 modified

Legend:

Unmodified
Added
Removed
  • NEWS.xml

    r183 r186  
     1<section><title>Changes in 1.15 (released 02/15/2007)</title> 
     2<ulist> 
     3<item>Fixed an output bug in <filename>oradiff.py</filename> when running 
     4in full output mode.</item> 
     5</ulist> 
     6</section> 
     7 
     8 
    19<section><title>Changes in 1.14 (released 02/01/2007)</title> 
    210<ulist> 
  • setup.py

    r182 r186  
    4747args=dict( 
    4848    name="ll-orasql", 
    49     version="1.14", 
     49    version="1.15", 
    5050    description="Utilities for working with cx_Oracle", 
    5151    long_description=DESCRIPTION, 
  • src/ll/orasql/__init__.py

    r185 r186  
    226226            if class_ is not None: 
    227227                yield _AllTypes(self, class_, schema, row.count) 
     228        if schema == "all": 
     229            cursor.execute("select object_type as type, count(*) as count from all_objects group by object_type") 
     230        else: 
     231            cursor.execute("select object_type as type, count(*) as count from user_objects group by object_type") 
     232        if schema == "all": 
     233            cursor.execute("select count(*) as count from all_tab_privs") 
     234        else: 
     235            cursor.execute("select count(*) as count from user_tab_privs where owner=user") 
     236        yield _AllTypes(self, Privilege, schema, cursor.fetchone().count) 
    228237 
    229238    def itertables(self, schema="user"): 
     
    443452        </dlist> 
    444453        """ 
    445         if schema not in ("user", "all"): 
    446             raise UnknownSchemaError(schema) 
    447  
    448         cursor = self.cursor() 
    449  
    450         if schema == "all": 
    451             cursor.execute("select decode(grantor, user, null, grantor) as owner, privilege, table_name as object, grantee from all_tab_privs order by table_schema, table_name, privilege") 
    452         else: 
    453             cursor.execute("select decode(grantor, user, null, grantor) as owner, privilege, table_name as object, grantee from user_tab_privs where owner=user order by table_name, privilege") 
    454         for rec in cursor.fetchall(): 
    455             yield Privilege(rec.privilege, rec.object, rec.grantee, rec.owner, cursor.connection) 
     454        return Privilege.iterobjects(self, schema) 
    456455 
    457456 
     
    18861885    Models a database object privilege (i.e. a grant). 
    18871886    """ 
    1888     def __init__(self, privilege, object, grantee, owner=None, connection=None): 
     1887    type = "privilege" # required by iterschema() 
     1888 
     1889    def __init__(self, privilege, name, grantor, grantee, owner=None, connection=None): 
    18891890        self.privilege = privilege 
    1890         self.object = object 
     1891        self.name = name 
     1892        self.grantor = grantor 
    18911893        self.grantee = grantee 
    18921894        self.owner = owner 
     
    18951897    def __repr__(self): 
    18961898        if self.owner is not None: 
    1897             return "%s.%s(%r, %r, %r, %r)" % (self.__class__.__module__, self.__class__.__name__, self.privilege, self.object, self.grantee, self.owner) 
    1898         else: 
    1899             return "%s.%s(%r, %r, %r)" % (self.__class__.__module__, self.__class__.__name__, self.privilege, self.object, self.grantee) 
     1899            return "%s.%s(%r, %r, %r, %r)" % (self.__class__.__module__, self.__class__.__name__, self.privilege, self.name, self.grantee, self.owner) 
     1900        else: 
     1901            return "%s.%s(%r, %r, %r)" % (self.__class__.__module__, self.__class__.__name__, self.privilege, self.name, self.grantee) 
    19001902 
    19011903    def __str__(self): 
    19021904        if self.owner is not None: 
    1903             return "%s(%r, %r, %r, %r)" % (self.__class__.__name__, self.privilege, self.object, self.grantee, self.owner) 
    1904         else: 
    1905             return "%s(%r, %r, %r)" % (self.__class__.__name__, self.privilege, self.object, self.grantee) 
     1905            return "%s(%r, %r, %r, %r)" % (self.__class__.__name__, self.privilege, self.name, self.grantee, self.owner) 
     1906        else: 
     1907            return "%s(%r, %r, %r)" % (self.__class__.__name__, self.privilege, self.name, self.grantee) 
    19061908 
    19071909    def getconnection(self, connection): 
     
    19211923        return None 
    19221924    connectstring = property(getconnectstring) 
     1925 
     1926    @classmethod 
     1927    def iterobjects(self, connection, schema="user"): 
     1928        """ 
     1929        <par>Generator that yields object privileges for the current users 
     1930        (or all users) objects.</par> 
     1931        <par><arg>schema</arg> specifies which privileges should be yielded:</par> 
     1932        <dlist> 
     1933        <term><lit>"user"</lit></term><item>Only object privileges for objects 
     1934        belonging to the current user will be yielded.</item> 
     1935        <term><lit>"all"</lit></term><item>All object privileges will be yielded.</item> 
     1936        </dlist> 
     1937        """ 
     1938        if schema not in ("user", "all"): 
     1939            raise UnknownSchemaError(schema) 
     1940 
     1941        cursor = connection.cursor() 
     1942 
     1943        if schema == "all": 
     1944            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 all_tab_privs order by table_schema, table_name, privilege") 
     1945        else: 
     1946            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") 
     1947        return (Privilege(rec.privilege, rec.object, rec.grantor, rec.grantee, rec.owner, cursor.connection) for rec in cursor) 
    19231948 
    19241949    def grantddl(self, connection=None, term=True, mapgrantee=True): 
     
    19451970        if grantee is None: 
    19461971            return "" 
    1947         code = "grant %s on %s to %s" % (self.privilege, self.object, grantee) 
     1972        code = "grant %s on %s to %s" % (self.privilege, self.name, grantee) 
    19481973        if term: 
    19491974            code += ";\n" 
     
    19511976 
    19521977    def __xattrs__(self, mode="default"): 
    1953         yield "privilege" 
    1954         yield "object" 
    1955         yield "grantee" 
    1956         yield "owner" 
    1957         yield "connection" 
     1978        yield ipipe.AttributeDescriptor("privilege", "the type of the privilege") 
     1979        yield ipipe.AttributeDescriptor("name", "the name of the object for which this privilege grants access") 
     1980        yield ipipe.AttributeDescriptor("owner", "the owner of the object") 
     1981        yield ipipe.AttributeDescriptor("grantor", "who granted this privilege?") 
     1982        yield ipipe.AttributeDescriptor("grantee", "to whom has this privilege been granted?") 
     1983        yield ipipe.AttributeDescriptor("connection") 
    19581984        if mode == "detail": 
    1959             yield "-grantddl()" 
     1985            yield ipipe.IterMethodDescriptor("grantddl", "the SQL statement to issue this privilege") 
    19601986 
    19611987 
  • src/ll/orasql/scripts/oradiff.py

    r182 r186  
    1515 
    1616 
     17s4warning = astyle.Style.fromenv("LL_ORASQL_REPRANSI_WARNING", "red:black") 
     18s4error = astyle.Style.fromenv("LL_ORASQL_REPRANSI_ERROR", "red:black") 
    1719s4comment = astyle.Style.fromenv("LL_ORASQL_REPRANSI_COMMENT", "black:black:bold") 
    1820s4addedfile = astyle.Style.fromenv("LL_ORASQL_REPRANSI_ADDEDFILE", "black:green") 
     
    3537 
    3638 
    37 def comment(msg, color): 
    38     return s4comment("-- ", msg) 
     39def comment(*texts): 
     40    return s4comment("-- ", *texts) 
    3941 
    4042 
     
    154156                msg = astyle.style_default("oradiff.py: ", cs(connection), ": fetching #%d " % (i+1), df(obj)) 
    155157                if not keepdef: 
    156                     msg += " (skipped)" 
     158                    msg = astyle.style_default(msg, " ", s4warning("(skipped)")) 
    157159                stderr.writeln(msg) 
    158160            if keepdef: 
  • src/ll/orasql/scripts/oragrant.py

    r182 r186  
    6363        if options.keepjunk: 
    6464            return True 
    65         if "$" in obj.object or "/" in obj.object or obj.object.startswith("SYS_EXPORT_SCHEMA_"): 
     65        if "$" in obj.name or "/" in obj.name or obj.name.startswith("SYS_EXPORT_SCHEMA_"): 
    6666            return False 
    6767        return True 
  • test/test_orasql.py

    r182 r186  
    1515 
    1616from ll import orasql 
    17 from ll.orasql.scripts import oracreate, oradrop, oradiff, oramerge 
     17from ll.orasql.scripts import oracreate, oradrop, oradiff, oramerge, oragrant 
    1818 
    1919 
     
    235235def test_scripts_oradiff(): 
    236236    # Test oradiff (not really: we will not get any differences) 
    237     args = "--color yes --verbose %s %s" % (dbname, dbname) 
    238     oradiff.main(args.split()) 
     237    allargs = [ 
     238        "--color yes --verbose %s %s" % (dbname, dbname), 
     239        args = "--color yes --verbose %s %s -mfull" % (dbname, dbname), 
     240    ] 
     241    for args in allargs: 
     242        oradiff.main(args.split()) 
    239243 
    240244 
     
    244248    args = "--color yes --verbose %s %s %s" % (dbname, dbname, dbname) 
    245249    oramerge.main(args.split()) 
     250 
     251 
     252@withbitbucket 
     253def test_scripts_oragrant(): 
     254    # Test oragrant 
     255    args = "--color yes %s" % dbname 
     256    oragrant.main(args.split()) 
    246257 
    247258