<s> import os <EOL> import uuid <EOL> import re <EOL> import pickle <EOL> import urllib <EOL> import glob <EOL> from gluon . admin import app_create , plugin_install <EOL> from gluon . fileutils import abspath , read_file , write_file <EOL> def reset ( session ) : <EOL> session . app = { <EOL> '<STR_LIT:name>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : [ ( '<STR_LIT:title>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT:description>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , str ( uuid . uuid4 ( ) ) ) , <EOL> ( '<STR_LIT>' , '<STR_LIT:localhost>' ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , [ ] ) ] , <EOL> '<STR_LIT>' : [ '<STR_LIT>' ] , <EOL> '<STR_LIT>' : [ '<STR_LIT:username>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT:email>' , '<STR_LIT:password>' ] , <EOL> '<STR_LIT>' : [ '<STR_LIT:index>' , '<STR_LIT:error>' ] , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> } <EOL> if not session . app : <EOL> reset ( session ) <EOL> def listify ( x ) : <EOL> if not isinstance ( x , ( list , tuple ) ) : <EOL> return x and [ x ] or [ ] <EOL> return x <EOL> def clean ( name ) : <EOL> return re . sub ( '<STR_LIT>' , '<STR_LIT:_>' , name . strip ( ) . lower ( ) ) <EOL> def index ( ) : <EOL> response . view = '<STR_LIT>' <EOL> reset ( session ) <EOL> apps = os . listdir ( os . path . join ( request . folder , '<STR_LIT:..>' ) ) <EOL> form = SQLFORM . factory ( Field ( '<STR_LIT:name>' , requires = [ IS_NOT_EMPTY ( ) , <EOL> IS_ALPHANUMERIC ( ) ] ) , _class = '<STR_LIT>' ) <EOL> if form . accepts ( request . vars ) : <EOL> app = form . vars . name <EOL> session . app [ '<STR_LIT:name>' ] = app <EOL> if MULTI_USER_MODE and db ( db . app . name == app ) ( db . app . owner != auth . user . id ) . count ( ) : <EOL> session . flash = '<STR_LIT>' <EOL> elif app in apps : <EOL> meta = os . path . normpath ( <EOL> os . path . join ( os . path . normpath ( request . folder ) , <EOL> '<STR_LIT:..>' , app , '<STR_LIT>' ) ) <EOL> if os . path . exists ( meta ) : <EOL> try : <EOL> metafile = open ( meta , '<STR_LIT:rb>' ) <EOL> try : <EOL> session . app = pickle . load ( metafile ) <EOL> finally : <EOL> metafile . close ( ) <EOL> session . flash = T ( "<STR_LIT>" ) <EOL> except : <EOL> session . flash = T ( "<STR_LIT>" ) <EOL> redirect ( URL ( '<STR_LIT>' ) ) <EOL> return dict ( step = '<STR_LIT>' , form = form ) <EOL> def step1 ( ) : <EOL> from gluon . contrib . simplejson import loads <EOL> import urllib <EOL> if not session . themes : <EOL> session . themes = [ '<STR_LIT>' ] <EOL> themes = session . themes <EOL> if not session . plugins : <EOL> session . plugins = [ ] <EOL> plugins = [ x . split ( '<STR_LIT:.>' ) [ <NUM_LIT:2> ] for x in session . plugins ] <EOL> response . view = '<STR_LIT>' <EOL> params = dict ( session . app [ '<STR_LIT>' ] ) <EOL> form = SQLFORM . factory ( <EOL> Field ( '<STR_LIT:title>' , default = params . get ( '<STR_LIT:title>' , None ) , <EOL> requires = IS_NOT_EMPTY ( ) ) , <EOL> Field ( '<STR_LIT>' , default = params . get ( '<STR_LIT>' , None ) ) , <EOL> Field ( '<STR_LIT>' , default = params . get ( '<STR_LIT>' , None ) ) , <EOL> Field ( <EOL> '<STR_LIT>' , default = params . get ( '<STR_LIT>' , None ) ) , <EOL> Field ( '<STR_LIT>' , default = params . get ( '<STR_LIT>' , None ) ) , <EOL> Field ( '<STR_LIT:description>' , '<STR_LIT:text>' , <EOL> default = params . get ( '<STR_LIT:description>' , None ) ) , <EOL> Field ( '<STR_LIT>' , requires = IS_IN_SET ( themes ) , <EOL> default = params . get ( '<STR_LIT>' , themes [ <NUM_LIT:0> ] ) ) , <EOL> Field ( <EOL> '<STR_LIT>' , default = params . get ( '<STR_LIT>' , None ) ) , <EOL> Field ( <EOL> '<STR_LIT>' , default = params . get ( '<STR_LIT>' , None ) ) , <EOL> Field ( <EOL> '<STR_LIT>' , default = params . get ( '<STR_LIT>' , None ) ) , <EOL> Field ( <EOL> '<STR_LIT>' , default = params . get ( '<STR_LIT>' , None ) ) , <EOL> Field ( '<STR_LIT>' , default = params . get ( '<STR_LIT>' , None ) ) , <EOL> Field ( '<STR_LIT>' , requires = IS_IN_SET ( ( '<STR_LIT>' , '<STR_LIT>' ) ) , <EOL> default = params . get ( '<STR_LIT>' , '<STR_LIT>' ) ) , <EOL> Field ( <EOL> '<STR_LIT>' , default = params . get ( '<STR_LIT>' , None ) ) , <EOL> Field ( '<STR_LIT>' , '<STR_LIT>' , requires = IS_IN_SET ( plugins , multiple = True ) ) , <EOL> _class = '<STR_LIT>' ) <EOL> if form . accepts ( request . vars ) : <EOL> session . app [ '<STR_LIT>' ] = [ ( key , form . vars . get ( key , None ) ) <EOL> for key , value in session . app [ '<STR_LIT>' ] ] <EOL> redirect ( URL ( '<STR_LIT>' ) + '<STR_LIT>' ) <EOL> return dict ( step = '<STR_LIT>' , form = form ) <EOL> def step2 ( ) : <EOL> response . view = '<STR_LIT>' <EOL> form = SQLFORM . factory ( Field ( '<STR_LIT>' , '<STR_LIT>' , <EOL> default = session . app [ '<STR_LIT>' ] ) , _class = "<STR_LIT>" ) <EOL> if form . accepts ( request . vars ) : <EOL> table_names = [ clean ( t ) for t in listify ( form . vars . table_names ) <EOL> if t . strip ( ) ] <EOL> if [ t for t in table_names if t . startswith ( '<STR_LIT>' ) and <EOL> not t == '<STR_LIT>' ] : <EOL> form . error . table_names = T ( '<STR_LIT>' ) <EOL> else : <EOL> session . app [ '<STR_LIT>' ] = table_names <EOL> for table in session . app [ '<STR_LIT>' ] : <EOL> if not '<STR_LIT>' + table in session . app : <EOL> session . app [ '<STR_LIT>' + table ] = [ '<STR_LIT:name>' ] <EOL> if not table == '<STR_LIT>' : <EOL> name = table + '<STR_LIT>' <EOL> if not name in session . app [ '<STR_LIT>' ] : <EOL> session . app [ '<STR_LIT>' ] . append ( name ) <EOL> session . app [ '<STR_LIT>' + name ] = '<STR_LIT>' % ( table ) <EOL> if session . app [ '<STR_LIT>' ] : <EOL> redirect ( URL ( '<STR_LIT>' , args = <NUM_LIT:0> ) + '<STR_LIT>' ) <EOL> else : <EOL> redirect ( URL ( '<STR_LIT>' ) + '<STR_LIT>' ) <EOL> return dict ( step = '<STR_LIT>' , form = form ) <EOL> def step3 ( ) : <EOL> response . view = '<STR_LIT>' <EOL> n = int ( request . args ( - <NUM_LIT:1> ) or <NUM_LIT:0> ) <EOL> m = len ( session . app [ '<STR_LIT>' ] ) <EOL> if n >= m : <EOL> redirect ( URL ( '<STR_LIT>' ) ) <EOL> table = session . app [ '<STR_LIT>' ] [ n ] <EOL> form = SQLFORM . factory ( Field ( '<STR_LIT>' , '<STR_LIT>' , <EOL> default = session . app . get ( '<STR_LIT>' + table , [ ] ) ) , _class = "<STR_LIT>" ) <EOL> if form . accepts ( request . vars ) and form . vars . field_names : <EOL> fields = listify ( form . vars . field_names ) <EOL> if table == '<STR_LIT>' : <EOL> for field in [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT:username>' , '<STR_LIT:email>' , '<STR_LIT:password>' ] : <EOL> if not field in fields : <EOL> fields . append ( field ) <EOL> session . app [ '<STR_LIT>' + table ] = [ t . strip ( ) . lower ( ) <EOL> for t in listify ( form . vars . field_names ) <EOL> if t . strip ( ) ] <EOL> try : <EOL> tables = sort_tables ( session . app [ '<STR_LIT>' ] ) <EOL> except RuntimeError : <EOL> response . flash = T ( '<STR_LIT>' ) <EOL> else : <EOL> if n < m - <NUM_LIT:1> : <EOL> redirect ( URL ( '<STR_LIT>' , args = n + <NUM_LIT:1> ) + '<STR_LIT>' ) <EOL> else : <EOL> redirect ( URL ( '<STR_LIT>' ) + '<STR_LIT>' ) <EOL> return dict ( step = '<STR_LIT>' <EOL> % ( table , n + <NUM_LIT:1> , m ) , table = table , form = form ) <EOL> def step4 ( ) : <EOL> response . view = '<STR_LIT>' <EOL> form = SQLFORM . factory ( Field ( '<STR_LIT>' , '<STR_LIT>' , <EOL> default = session . app [ '<STR_LIT>' ] ) , _class = "<STR_LIT>" ) <EOL> if form . accepts ( request . vars ) : <EOL> session . app [ '<STR_LIT>' ] = [ clean ( t ) <EOL> for t in listify ( form . vars . pages ) <EOL> if t . strip ( ) ] <EOL> if session . app [ '<STR_LIT>' ] : <EOL> redirect ( URL ( '<STR_LIT>' , args = <NUM_LIT:0> ) + '<STR_LIT>' ) <EOL> else : <EOL> redirect ( URL ( '<STR_LIT>' ) + '<STR_LIT>' ) <EOL> return dict ( step = '<STR_LIT>' , form = form ) <EOL> def step5 ( ) : <EOL> response . view = '<STR_LIT>' <EOL> n = int ( request . args ( - <NUM_LIT:1> ) or <NUM_LIT:0> ) <EOL> m = len ( session . app [ '<STR_LIT>' ] ) <EOL> if n >= m : <EOL> redirect ( URL ( '<STR_LIT>' ) ) <EOL> page = session . app [ '<STR_LIT>' ] [ n ] <EOL> markmin_url = '<STR_LIT>' <EOL> form = SQLFORM . factory ( Field ( '<STR_LIT:content>' , '<STR_LIT:text>' , <EOL> default = session . app . get ( '<STR_LIT>' + page , [ ] ) , <EOL> comment = A ( '<STR_LIT>' , <EOL> _href = markmin_url , _target = '<STR_LIT>' ) ) , <EOL> formstyle = '<STR_LIT>' , _class = "<STR_LIT>" ) <EOL> if form . accepts ( request . vars ) : <EOL> session . app [ '<STR_LIT>' + page ] = form . vars . content <EOL> if n < m - <NUM_LIT:1> : <EOL> redirect ( URL ( '<STR_LIT>' , args = n + <NUM_LIT:1> ) + '<STR_LIT>' ) <EOL> else : <EOL> redirect ( URL ( '<STR_LIT>' ) + '<STR_LIT>' ) <EOL> return dict ( step = '<STR_LIT>' % ( page , n + <NUM_LIT:1> , m ) , form = form ) <EOL> def step6 ( ) : <EOL> response . view = '<STR_LIT>' <EOL> params = dict ( session . app [ '<STR_LIT>' ] ) <EOL> app = session . app [ '<STR_LIT:name>' ] <EOL> form = SQLFORM . factory ( <EOL> Field ( '<STR_LIT>' , '<STR_LIT>' , default = True ) , <EOL> Field ( '<STR_LIT>' , '<STR_LIT>' , default = True ) , <EOL> Field ( '<STR_LIT>' , '<STR_LIT>' , default = True ) , <EOL> Field ( '<STR_LIT>' , '<STR_LIT>' , default = True ) , <EOL> Field ( '<STR_LIT>' , '<STR_LIT>' , default = True ) , <EOL> Field ( '<STR_LIT>' , '<STR_LIT>' , default = True ) , <EOL> Field ( '<STR_LIT>' , '<STR_LIT>' , default = True ) , <EOL> _id = "<STR_LIT>" , _class = "<STR_LIT>" ) <EOL> if form . accepts ( request . vars ) : <EOL> if DEMO_MODE : <EOL> session . flash = T ( '<STR_LIT>' ) <EOL> redirect ( URL ( '<STR_LIT:index>' ) ) <EOL> create ( form . vars ) <EOL> session . flash = '<STR_LIT>' % app <EOL> redirect ( URL ( '<STR_LIT>' ) ) <EOL> return dict ( step = '<STR_LIT>' % app , form = form ) <EOL> def generated ( ) : <EOL> return dict ( app = session . app [ '<STR_LIT:name>' ] ) <EOL> def sort_tables ( tables ) : <EOL> import re <EOL> regex = re . compile ( '<STR_LIT>' % '<STR_LIT:|>' . join ( tables ) ) <EOL> is_auth_user = '<STR_LIT>' in tables <EOL> d = { } <EOL> for table in tables : <EOL> d [ table ] = [ ] <EOL> for field in session . app [ '<STR_LIT>' % table ] : <EOL> d [ table ] += regex . findall ( field ) <EOL> tables = [ ] <EOL> if is_auth_user : <EOL> tables . append ( '<STR_LIT>' ) <EOL> def append ( table , trail = [ ] ) : <EOL> if table in trail : <EOL> raise RuntimeError <EOL> for t in d [ table ] : <EOL> append ( t , trail = trail + [ table ] ) <EOL> if not table in tables : <EOL> tables . append ( table ) <EOL> for table in d : <EOL> append ( table ) <EOL> return tables <EOL> def make_table ( table , fields ) : <EOL> rawtable = table <EOL> if table != '<STR_LIT>' : <EOL> table = '<STR_LIT>' + table <EOL> s = '<STR_LIT>' <EOL> s += '<STR_LIT:\n>' + '<STR_LIT:#>' * <NUM_LIT> + '<STR_LIT:\n>' <EOL> s += "<STR_LIT>" % table <EOL> first_field = '<STR_LIT:id>' <EOL> for field in fields : <EOL> items = [ x . lower ( ) for x in field . split ( ) ] <EOL> has = { } <EOL> keys = [ ] <EOL> for key in [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT:float>' , <EOL> '<STR_LIT>' , '<STR_LIT:date>' , '<STR_LIT:time>' , '<STR_LIT>' , '<STR_LIT:text>' , '<STR_LIT>' , <EOL> '<STR_LIT:html>' , '<STR_LIT:file>' , '<STR_LIT>' , '<STR_LIT:image>' , '<STR_LIT:true>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' ] : <EOL> if key in items [ <NUM_LIT:1> : ] : <EOL> keys . append ( key ) <EOL> has [ key ] = True <EOL> tables = session . app [ '<STR_LIT>' ] <EOL> refs = [ t for t in tables if t in items ] <EOL> items = items [ : <NUM_LIT:1> ] + [ x for x in items [ <NUM_LIT:1> : ] <EOL> if not x in keys and not x in tables ] <EOL> barename = name = '<STR_LIT:_>' . join ( items ) <EOL> if table [ : <NUM_LIT:2> ] == '<STR_LIT>' : name = '<STR_LIT>' + name <EOL> if first_field == '<STR_LIT:id>' : <EOL> first_field = name <EOL> ftype = '<STR_LIT:string>' <EOL> deftypes = { '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT:float>' : '<STR_LIT>' , '<STR_LIT:bool>' : '<STR_LIT>' , <EOL> '<STR_LIT:date>' : '<STR_LIT:date>' , '<STR_LIT:time>' : '<STR_LIT:time>' , '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT:text>' : '<STR_LIT:text>' , '<STR_LIT:file>' : '<STR_LIT>' , '<STR_LIT:image>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT:text>' , '<STR_LIT:html>' : '<STR_LIT:text>' } <EOL> for key , t in deftypes . items ( ) : <EOL> if key in has : <EOL> ftype = t <EOL> if refs : <EOL> key = refs [ <NUM_LIT:0> ] <EOL> if not key == '<STR_LIT>' : <EOL> key = '<STR_LIT>' + key <EOL> if '<STR_LIT>' in has : <EOL> ftype = '<STR_LIT>' % key <EOL> else : <EOL> ftype = '<STR_LIT>' % key <EOL> if ftype == '<STR_LIT:string>' and '<STR_LIT>' in has : <EOL> ftype = '<STR_LIT>' <EOL> elif ftype == '<STR_LIT>' and '<STR_LIT>' in has : <EOL> ftype = '<STR_LIT>' <EOL> elif name == '<STR_LIT:password>' : <EOL> ftype = '<STR_LIT:password>' <EOL> s += "<STR_LIT>" % ( name , ftype ) <EOL> if '<STR_LIT>' in has or '<STR_LIT>' in has or '<STR_LIT>' in has : <EOL> s += '<STR_LIT>' <EOL> if '<STR_LIT>' in has : <EOL> s += '<STR_LIT>' <EOL> if ftype == '<STR_LIT>' and '<STR_LIT:true>' in has : <EOL> s += "<STR_LIT>" <EOL> elif '<STR_LIT>' in has : <EOL> s += "<STR_LIT>" <EOL> s += "<STR_LIT>" <EOL> elif '<STR_LIT:html>' in has : <EOL> s += "<STR_LIT>" <EOL> s += "<STR_LIT>" <EOL> if name == '<STR_LIT:password>' or '<STR_LIT>' in has : <EOL> s += "<STR_LIT>" <EOL> elif '<STR_LIT>' in has : <EOL> s += "<STR_LIT>" <EOL> elif '<STR_LIT>' in has : <EOL> s += "<STR_LIT>" <EOL> s += "<STR_LIT>" % '<STR_LIT:U+0020>' . join ( x . capitalize ( ) for x in barename . split ( '<STR_LIT:_>' ) ) <EOL> if table == '<STR_LIT>' : <EOL> s += "<STR_LIT>" <EOL> s += "<STR_LIT>" <EOL> s += "<STR_LIT>" <EOL> s += "<STR_LIT>" <EOL> s += "<STR_LIT>" <EOL> s += "<STR_LIT>" <EOL> s += "<STR_LIT>" <EOL> s += "<STR_LIT>" <EOL> s += "<STR_LIT>" <EOL> s += "<STR_LIT>" <EOL> s += "<STR_LIT>" <EOL> elif '<STR_LIT>' in session . app [ '<STR_LIT>' ] : <EOL> s += "<STR_LIT>" <EOL> s += "<STR_LIT>" + first_field + "<STR_LIT>" <EOL> s += "<STR_LIT>" <EOL> if table == '<STR_LIT>' : <EOL> s += """<STR_LIT>""" <EOL> else : <EOL> s += "<STR_LIT>" % ( table , table , table ) <EOL> return s <EOL> def fix_db ( filename ) : <EOL> params = dict ( session . app [ '<STR_LIT>' ] ) <EOL> content = read_file ( filename , '<STR_LIT:rb>' ) <EOL> if '<STR_LIT>' in session . app [ '<STR_LIT>' ] : <EOL> auth_user = make_table ( '<STR_LIT>' , session . app [ '<STR_LIT>' ] ) <EOL> content = content . replace ( '<STR_LIT>' , <EOL> params [ '<STR_LIT>' ] ) <EOL> content = content . replace ( '<STR_LIT>' , <EOL> auth_user + '<STR_LIT>' ) <EOL> content += """<STR_LIT>""" <EOL> if params [ '<STR_LIT>' ] == '<STR_LIT>' : <EOL> content += """<STR_LIT>""" <EOL> write_file ( filename , content , '<STR_LIT:wb>' ) <EOL> def make_menu ( pages ) : <EOL> s = '<STR_LIT>' <EOL> s += '<STR_LIT>' <EOL> s += '<STR_LIT>' <EOL> s += "<STR_LIT>" <EOL> s += '<STR_LIT>' <EOL> s += '<STR_LIT>' <EOL> s += '<STR_LIT>' <EOL> for page in pages : <EOL> if not page . startswith ( '<STR_LIT:error>' ) : <EOL> if page . endswith ( '<STR_LIT>' ) : <EOL> page_name = page [ : - <NUM_LIT:7> ] <EOL> else : <EOL> page_name = page <EOL> page_name = '<STR_LIT:U+0020>' . join ( x . capitalize ( ) for x in page_name . split ( '<STR_LIT:_>' ) ) <EOL> s += "<STR_LIT>" % ( page_name , page , page ) <EOL> s += '<STR_LIT:]>' <EOL> return s <EOL> def make_page ( page , contents ) : <EOL> if '<STR_LIT>' in session . app [ '<STR_LIT>' ] and not page in ( '<STR_LIT:index>' , '<STR_LIT:error>' ) : <EOL> s = "<STR_LIT>" % page <EOL> else : <EOL> s = "<STR_LIT>" % page <EOL> items = page . rsplit ( '<STR_LIT:_>' , <NUM_LIT:1> ) <EOL> if items [ <NUM_LIT:0> ] in session . app [ '<STR_LIT>' ] and len ( items ) == <NUM_LIT:2> and items [ <NUM_LIT:1> ] == '<STR_LIT>' : <EOL> s += "<STR_LIT>" % items [ <NUM_LIT:0> ] <EOL> s += "<STR_LIT>" <EOL> else : <EOL> s += "<STR_LIT>" <EOL> return s <EOL> def make_view ( page , contents ) : <EOL> s = "<STR_LIT>" <EOL> s += str ( MARKMIN ( contents ) ) <EOL> return s <EOL> def populate ( tables ) : <EOL> s = '<STR_LIT>' <EOL> s += '<STR_LIT>' <EOL> for table in sort_tables ( tables ) : <EOL> t = table == '<STR_LIT>' and '<STR_LIT>' or '<STR_LIT>' + table <EOL> s += "<STR_LIT>" % t <EOL> return s <EOL> def create ( options ) : <EOL> if DEMO_MODE : <EOL> session . flash = T ( '<STR_LIT>' ) <EOL> redirect ( URL ( '<STR_LIT>' ) ) <EOL> params = dict ( session . app [ '<STR_LIT>' ] ) <EOL> app = session . app [ '<STR_LIT:name>' ] <EOL> if app_create ( app , request , force = True , key = params [ '<STR_LIT>' ] ) : <EOL> if MULTI_USER_MODE : <EOL> db . app . insert ( name = app , owner = auth . user . id ) <EOL> else : <EOL> session . flash = '<STR_LIT>' <EOL> redirect ( URL ( '<STR_LIT>' ) ) <EOL> try : <EOL> meta = os . path . join ( request . folder , '<STR_LIT:..>' , app , '<STR_LIT>' ) <EOL> file = open ( meta , '<STR_LIT:wb>' ) <EOL> pickle . dump ( session . app , file ) <EOL> file . close ( ) <EOL> except IOError : <EOL> session . flash = '<STR_LIT>' <EOL> redirect ( URL ( '<STR_LIT>' ) ) <EOL> if options . apply_layout and params [ '<STR_LIT>' ] != '<STR_LIT>' : <EOL> try : <EOL> fn = '<STR_LIT>' % params [ '<STR_LIT>' ] <EOL> theme = urllib . urlopen ( <EOL> LAYOUTS_APP + '<STR_LIT>' + fn ) <EOL> plugin_install ( app , theme , request , fn ) <EOL> except : <EOL> session . flash = T ( "<STR_LIT>" ) <EOL> for plugin in params [ '<STR_LIT>' ] : <EOL> try : <EOL> plugin_name = '<STR_LIT>' + plugin + '<STR_LIT>' <EOL> stream = urllib . urlopen ( PLUGINS_APP + '<STR_LIT>' + plugin_name ) <EOL> plugin_install ( app , stream , request , plugin_name ) <EOL> except Exception , e : <EOL> session . flash = T ( "<STR_LIT>" % plugin ) <EOL> model = os . path . join ( request . folder , '<STR_LIT:..>' , app , '<STR_LIT>' , '<STR_LIT>' ) <EOL> file = open ( model , '<STR_LIT:wb>' ) <EOL> try : <EOL> file . write ( "<STR_LIT>" ) <EOL> file . write ( "<STR_LIT>" ) <EOL> file . write ( "<STR_LIT>" ) <EOL> for key , value in session . app [ '<STR_LIT>' ] : <EOL> file . write ( "<STR_LIT>" % ( key , repr ( value ) ) ) <EOL> finally : <EOL> file . close ( ) <EOL> if options . generate_menu : <EOL> model = os . path . join ( request . folder , '<STR_LIT:..>' , app , '<STR_LIT>' , '<STR_LIT>' ) <EOL> file = open ( model , '<STR_LIT:wb>' ) <EOL> try : <EOL> file . write ( make_menu ( session . app [ '<STR_LIT>' ] ) ) <EOL> finally : <EOL> file . close ( ) <EOL> model = os . path . join ( request . folder , '<STR_LIT:..>' , app , '<STR_LIT>' , '<STR_LIT>' ) <EOL> fix_db ( model ) <EOL> if options . generate_model : <EOL> model = os . path . join ( <EOL> request . folder , '<STR_LIT:..>' , app , '<STR_LIT>' , '<STR_LIT>' ) <EOL> file = open ( model , '<STR_LIT:wb>' ) <EOL> try : <EOL> file . write ( '<STR_LIT>' ) <EOL> tables = sort_tables ( session . app [ '<STR_LIT>' ] ) <EOL> for table in tables : <EOL> if table == '<STR_LIT>' : <EOL> continue <EOL> file . write ( make_table ( table , session . app [ '<STR_LIT>' + table ] ) ) <EOL> finally : <EOL> file . close ( ) <EOL> model = os . path . join ( request . folder , '<STR_LIT:..>' , app , <EOL> '<STR_LIT>' , '<STR_LIT>' ) <EOL> if os . path . exists ( model ) : <EOL> os . unlink ( model ) <EOL> if options . populate_database and session . app [ '<STR_LIT>' ] : <EOL> file = open ( model , '<STR_LIT:wb>' ) <EOL> try : <EOL> file . write ( populate ( session . app [ '<STR_LIT>' ] ) ) <EOL> finally : <EOL> file . close ( ) <EOL> if options . generate_controller : <EOL> controller = os . path . join ( <EOL> request . folder , '<STR_LIT:..>' , app , '<STR_LIT>' , '<STR_LIT>' ) <EOL> file = open ( controller , '<STR_LIT:wb>' ) <EOL> try : <EOL> file . write ( """<STR_LIT>""" ) <EOL> for page in session . app [ '<STR_LIT>' ] : <EOL> file . write ( <EOL> make_page ( page , session . app . get ( '<STR_LIT>' + page , '<STR_LIT>' ) ) ) <EOL> finally : <EOL> file . close ( ) <EOL> if options . generate_views : <EOL> for page in session . app [ '<STR_LIT>' ] : <EOL> view = os . path . join ( <EOL> request . folder , '<STR_LIT:..>' , app , '<STR_LIT>' , '<STR_LIT:default>' , page + '<STR_LIT>' ) <EOL> file = open ( view , '<STR_LIT:wb>' ) <EOL> try : <EOL> file . write ( <EOL> make_view ( page , session . app . get ( '<STR_LIT>' + page , '<STR_LIT>' ) ) ) <EOL> finally : <EOL> file . close ( ) <EOL> if options . erase_database : <EOL> path = os . path . join ( request . folder , '<STR_LIT:..>' , app , '<STR_LIT>' , '<STR_LIT:*>' ) <EOL> for file in glob . glob ( path ) : <EOL> os . unlink ( file ) </s>
