<s> """<STR_LIT>""" <EOL> from pyrseas . dbobject import DbObjectDict , DbObject <EOL> from pyrseas . dbobject import quote_id , commentable <EOL> class Extension ( DbObject ) : <EOL> """<STR_LIT>""" <EOL> keylist = [ '<STR_LIT:name>' ] <EOL> objtype = "<STR_LIT>" <EOL> single_extern_file = True <EOL> def __init__ ( self , name , description , owner , schema , privileges = None , <EOL> version = None ) : <EOL> super ( Extension , self ) . __init__ ( name , description , owner , privileges ) <EOL> self . schema = schema <EOL> self . version = version <EOL> @ commentable <EOL> def create ( self ) : <EOL> """<STR_LIT>""" <EOL> opt_clauses = [ ] <EOL> if self . schema is not None and self . schema not in ( <EOL> '<STR_LIT>' , '<STR_LIT>' ) : <EOL> opt_clauses . append ( "<STR_LIT>" % quote_id ( self . schema ) ) <EOL> if self . version is not None : <EOL> opt_clauses . append ( "<STR_LIT>" % self . version ) <EOL> return [ "<STR_LIT>" % ( <EOL> quote_id ( self . name ) , ( '<STR_LIT>' + '<STR_LIT>' . join ( opt_clauses ) ) <EOL> if opt_clauses else '<STR_LIT>' ) ] <EOL> class ExtensionDict ( DbObjectDict ) : <EOL> "<STR_LIT>" <EOL> cls = Extension <EOL> query = """<STR_LIT>""" <EOL> def _from_catalog ( self ) : <EOL> """<STR_LIT>""" <EOL> if self . dbconn . version < <NUM_LIT> : <EOL> return <EOL> for ext in self . fetch ( ) : <EOL> self [ ext . key ( ) ] = ext <EOL> def from_map ( self , inexts , langtempls , newdb ) : <EOL> """<STR_LIT>""" <EOL> for key in inexts : <EOL> if not key . startswith ( '<STR_LIT>' ) : <EOL> raise KeyError ( "<STR_LIT>" % key ) <EOL> ext = key [ <NUM_LIT:10> : ] <EOL> inexten = inexts [ key ] <EOL> self [ ext ] = Extension ( name = ext , <EOL> description = inexten . get ( '<STR_LIT:description>' ) , <EOL> owner = inexten . get ( '<STR_LIT>' ) , <EOL> schema = inexten [ '<STR_LIT>' ] , <EOL> version = inexten . get ( '<STR_LIT:version>' ) ) <EOL> if self [ ext ] . name in langtempls : <EOL> lang = { '<STR_LIT>' % self [ ext ] . name : { '<STR_LIT>' : '<STR_LIT:e>' } } <EOL> newdb . languages . from_map ( lang ) <EOL> def diff_map ( self , inexts ) : <EOL> """<STR_LIT>""" <EOL> stmts = [ ] <EOL> for ext in inexts : <EOL> inexten = inexts [ ext ] <EOL> if ext not in self : <EOL> if not hasattr ( inexten , '<STR_LIT>' ) : <EOL> stmts . append ( inexten . create ( ) ) <EOL> else : <EOL> stmts . append ( self [ ext ] . rename ( inexten ) ) <EOL> else : <EOL> stmts . append ( self [ ext ] . diff_map ( inexten , no_owner = True ) ) <EOL> for ext in self : <EOL> exten = self [ ext ] <EOL> if ext not in inexts : <EOL> exten . dropped = False <EOL> return stmts <EOL> def _drop ( self ) : <EOL> """<STR_LIT>""" <EOL> stmts = [ ] <EOL> for ext in self : <EOL> if hasattr ( self [ ext ] , '<STR_LIT>' ) : <EOL> stmts . append ( self [ ext ] . drop ( ) ) <EOL> return stmts </s>
