<s> EXPERIMENTAL_STUFF = True <EOL> MAXNFILES = <NUM_LIT:1000> <EOL> if EXPERIMENTAL_STUFF : <EOL> if is_mobile : <EOL> response . view = response . view . replace ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> response . menu = [ ] <EOL> import re <EOL> from gluon . admin import * <EOL> from gluon . fileutils import abspath , read_file , write_file <EOL> from gluon . utils import web2py_uuid <EOL> from gluon . tools import Config <EOL> from gluon . compileapp import find_exposed_functions <EOL> from glob import glob <EOL> import shutil <EOL> import platform <EOL> try : <EOL> import git <EOL> if git . __version__ < '<STR_LIT>' : <EOL> raise ImportError ( "<STR_LIT>" % git . __version__ ) <EOL> have_git = True <EOL> except ImportError , e : <EOL> have_git = False <EOL> GIT_MISSING = '<STR_LIT>' % e <EOL> from gluon . languages import ( read_possible_languages , read_dict , write_dict , <EOL> read_plural_dict , write_plural_dict ) <EOL> if DEMO_MODE and request . function in [ '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] : <EOL> session . flash = T ( '<STR_LIT>' ) <EOL> redirect ( URL ( '<STR_LIT>' ) ) <EOL> if is_gae and request . function in ( '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) : <EOL> session . flash = T ( '<STR_LIT>' ) <EOL> redirect ( URL ( '<STR_LIT>' ) ) <EOL> if not is_manager ( ) and request . function in [ '<STR_LIT>' , '<STR_LIT>' ] : <EOL> session . flash = T ( '<STR_LIT>' ) <EOL> redirect ( URL ( '<STR_LIT>' ) ) <EOL> if FILTER_APPS and request . args ( <NUM_LIT:0> ) and not request . args ( <NUM_LIT:0> ) in FILTER_APPS : <EOL> session . flash = T ( '<STR_LIT>' ) <EOL> redirect ( URL ( '<STR_LIT>' ) ) <EOL> if not session . token : <EOL> session . token = web2py_uuid ( ) <EOL> def count_lines ( data ) : <EOL> return len ( [ line for line in data . split ( '<STR_LIT:\n>' ) if line . strip ( ) and not line . startswith ( '<STR_LIT:#>' ) ] ) <EOL> def log_progress ( app , mode = '<STR_LIT>' , filename = None , progress = <NUM_LIT:0> ) : <EOL> progress_file = os . path . join ( apath ( app , r = request ) , '<STR_LIT>' ) <EOL> now = str ( request . now ) [ : <NUM_LIT> ] <EOL> if not os . path . exists ( progress_file ) : <EOL> safe_open ( progress_file , '<STR_LIT:w>' ) . write ( '<STR_LIT>' % now ) <EOL> if filename : <EOL> safe_open ( progress_file , '<STR_LIT:a>' ) . write ( <EOL> '<STR_LIT>' % ( now , mode , filename , progress ) ) <EOL> def safe_open ( a , b ) : <EOL> if ( DEMO_MODE or is_gae ) and ( '<STR_LIT:w>' in b or '<STR_LIT:a>' in b ) : <EOL> class tmp : <EOL> def write ( self , data ) : <EOL> pass <EOL> def close ( self ) : <EOL> pass <EOL> return tmp ( ) <EOL> return open ( a , b ) <EOL> def safe_read ( a , b = '<STR_LIT:r>' ) : <EOL> safe_file = safe_open ( a , b ) <EOL> try : <EOL> return safe_file . read ( ) <EOL> finally : <EOL> safe_file . close ( ) <EOL> def safe_write ( a , value , b = '<STR_LIT:w>' ) : <EOL> safe_file = safe_open ( a , b ) <EOL> try : <EOL> safe_file . write ( value ) <EOL> finally : <EOL> safe_file . close ( ) <EOL> def get_app ( name = None ) : <EOL> app = name or request . args ( <NUM_LIT:0> ) <EOL> if ( app and os . path . exists ( apath ( app , r = request ) ) and <EOL> ( not MULTI_USER_MODE or is_manager ( ) or <EOL> db ( db . app . name == app ) ( db . app . owner == auth . user . id ) . count ( ) ) ) : <EOL> return app <EOL> session . flash = T ( '<STR_LIT>' ) <EOL> redirect ( URL ( '<STR_LIT>' ) ) <EOL> def index ( ) : <EOL> """<STR_LIT>""" <EOL> send = request . vars . send <EOL> if DEMO_MODE : <EOL> session . authorized = True <EOL> session . last_time = t0 <EOL> if not send : <EOL> send = URL ( '<STR_LIT>' ) <EOL> if session . authorized : <EOL> redirect ( send ) <EOL> elif request . vars . password : <EOL> if verify_password ( request . vars . password [ : <NUM_LIT> ] ) : <EOL> session . authorized = True <EOL> login_record ( True ) <EOL> if CHECK_VERSION : <EOL> session . check_version = True <EOL> else : <EOL> session . check_version = False <EOL> session . last_time = t0 <EOL> if isinstance ( send , list ) : <EOL> send = str ( send [ <NUM_LIT:0> ] ) <EOL> redirect ( send ) <EOL> else : <EOL> times_denied = login_record ( False ) <EOL> if times_denied >= allowed_number_of_attempts : <EOL> response . flash = T ( '<STR_LIT>' ) <EOL> elif times_denied == allowed_number_of_attempts - <NUM_LIT:1> : <EOL> response . flash = T ( '<STR_LIT>' ) <EOL> else : <EOL> response . flash = T ( '<STR_LIT>' ) <EOL> return dict ( send = send ) <EOL> def check_version ( ) : <EOL> """<STR_LIT>""" <EOL> session . forget ( ) <EOL> session . _unlock ( response ) <EOL> new_version , version = check_new_version ( request . env . web2py_version , <EOL> WEB2PY_VERSION_URL ) <EOL> if new_version == - <NUM_LIT:1> : <EOL> return A ( T ( '<STR_LIT>' ) , _href = WEB2PY_URL ) <EOL> elif new_version != True : <EOL> return A ( T ( '<STR_LIT>' ) , _href = WEB2PY_URL ) <EOL> elif platform . system ( ) . lower ( ) in ( '<STR_LIT>' , '<STR_LIT:win32>' , '<STR_LIT>' ) and os . path . exists ( "<STR_LIT>" ) : <EOL> return SPAN ( '<STR_LIT>' % version . split ( '<STR_LIT:(>' ) [ <NUM_LIT:0> ] ) <EOL> else : <EOL> return sp_button ( URL ( '<STR_LIT>' ) , T ( '<STR_LIT>' ) % version . split ( '<STR_LIT:(>' ) [ <NUM_LIT:0> ] ) <EOL> def logout ( ) : <EOL> """<STR_LIT>""" <EOL> session . authorized = None <EOL> if MULTI_USER_MODE : <EOL> redirect ( URL ( '<STR_LIT>' ) ) <EOL> redirect ( URL ( '<STR_LIT:index>' ) ) <EOL> def change_password ( ) : <EOL> if session . pam_user : <EOL> session . flash = T ( <EOL> '<STR_LIT>' ) <EOL> redirect ( URL ( '<STR_LIT>' ) ) <EOL> form = SQLFORM . factory ( Field ( '<STR_LIT>' , '<STR_LIT:password>' ) , <EOL> Field ( '<STR_LIT>' , <EOL> '<STR_LIT:password>' , requires = IS_STRONG ( ) ) , <EOL> Field ( '<STR_LIT>' , '<STR_LIT:password>' ) , <EOL> _class = "<STR_LIT>" ) <EOL> if form . accepts ( request . vars ) : <EOL> if not verify_password ( request . vars . current_admin_password ) : <EOL> form . errors . current_admin_password = T ( '<STR_LIT>' ) <EOL> elif form . vars . new_admin_password != form . vars . new_admin_password_again : <EOL> form . errors . new_admin_password_again = T ( '<STR_LIT>' ) <EOL> else : <EOL> path = abspath ( '<STR_LIT>' % request . env . server_port ) <EOL> safe_write ( path , '<STR_LIT>' % CRYPT ( ) ( <EOL> request . vars . new_admin_password ) [ <NUM_LIT:0> ] ) <EOL> session . flash = T ( '<STR_LIT>' ) <EOL> redirect ( URL ( '<STR_LIT>' ) ) <EOL> return dict ( form = form ) <EOL> def site ( ) : <EOL> """<STR_LIT>""" <EOL> myversion = request . env . web2py_version <EOL> file_or_appurl = '<STR_LIT:file>' in request . vars or '<STR_LIT>' in request . vars <EOL> class IS_VALID_APPNAME ( object ) : <EOL> def __call__ ( self , value ) : <EOL> if not re . compile ( '<STR_LIT>' ) . match ( value ) : <EOL> return ( value , T ( '<STR_LIT>' ) ) <EOL> if not request . vars . overwrite and os . path . exists ( os . path . join ( apath ( r = request ) , value ) ) : <EOL> return ( value , T ( '<STR_LIT>' ) ) <EOL> return ( value , None ) <EOL> is_appname = IS_VALID_APPNAME ( ) <EOL> form_create = SQLFORM . factory ( Field ( '<STR_LIT:name>' , requires = is_appname ) , <EOL> table_name = '<STR_LIT>' ) <EOL> form_update = SQLFORM . factory ( Field ( '<STR_LIT:name>' , requires = is_appname ) , <EOL> Field ( '<STR_LIT:file>' , '<STR_LIT>' , uploadfield = False ) , <EOL> Field ( '<STR_LIT:url>' ) , <EOL> Field ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> table_name = '<STR_LIT>' ) <EOL> form_create . process ( ) <EOL> form_update . process ( ) <EOL> if DEMO_MODE : <EOL> pass <EOL> elif form_create . accepted : <EOL> appname = cleanpath ( form_create . vars . name ) <EOL> created , error = app_create ( appname , request , info = True ) <EOL> if created : <EOL> if MULTI_USER_MODE : <EOL> db . app . insert ( name = appname , owner = auth . user . id ) <EOL> log_progress ( appname ) <EOL> session . flash = T ( '<STR_LIT>' , appname ) <EOL> redirect ( URL ( '<STR_LIT>' , args = appname ) ) <EOL> else : <EOL> session . flash = DIV ( T ( '<STR_LIT>' , appname ) , <EOL> PRE ( error ) ) <EOL> redirect ( URL ( r = request ) ) <EOL> elif form_update . accepted : <EOL> if ( form_update . vars . url or '<STR_LIT>' ) . endswith ( '<STR_LIT>' ) : <EOL> if not have_git : <EOL> session . flash = GIT_MISSING <EOL> redirect ( URL ( r = request ) ) <EOL> target = os . path . join ( apath ( r = request ) , form_update . vars . name ) <EOL> try : <EOL> new_repo = git . Repo . clone_from ( form_update . vars . url , target ) <EOL> session . flash = T ( '<STR_LIT>' , <EOL> form_update . vars . name ) <EOL> except git . GitCommandError , err : <EOL> session . flash = T ( '<STR_LIT>' ) <EOL> redirect ( URL ( r = request ) ) <EOL> elif form_update . vars . url : <EOL> try : <EOL> f = urllib . urlopen ( form_update . vars . url ) <EOL> if f . code == <NUM_LIT> : <EOL> raise Exception ( "<STR_LIT>" ) <EOL> except Exception , e : <EOL> session . flash = DIV ( T ( '<STR_LIT>' ) , PRE ( str ( e ) ) ) <EOL> redirect ( URL ( r = request ) ) <EOL> fname = form_update . vars . url <EOL> elif form_update . accepted and form_update . vars . file : <EOL> fname = request . vars . file . filename <EOL> f = request . vars . file . file <EOL> else : <EOL> session . flash = '<STR_LIT>' <EOL> redirect ( URL ( r = request ) ) <EOL> if f : <EOL> appname = cleanpath ( form_update . vars . name ) <EOL> installed = app_install ( appname , f , <EOL> request , fname , <EOL> overwrite = form_update . vars . overwrite ) <EOL> if f and installed : <EOL> msg = '<STR_LIT>' <EOL> if MULTI_USER_MODE : <EOL> db . app . insert ( name = appname , owner = auth . user . id ) <EOL> log_progress ( appname ) <EOL> session . flash = T ( msg , dict ( appname = appname , <EOL> digest = md5_hash ( installed ) ) ) <EOL> elif f and form_update . vars . overwrite : <EOL> msg = '<STR_LIT>' <EOL> session . flash = T ( msg , dict ( appname = form_update . vars . name ) ) <EOL> else : <EOL> msg = '<STR_LIT>' <EOL> session . flash = T ( msg , dict ( appname = form_update . vars . name ) ) <EOL> redirect ( URL ( r = request ) ) <EOL> regex = re . compile ( '<STR_LIT>' ) <EOL> if is_manager ( ) : <EOL> apps = [ f for f in os . listdir ( apath ( r = request ) ) if regex . match ( f ) ] <EOL> else : <EOL> apps = [ f . name for f in db ( db . app . owner == auth . user_id ) . select ( ) ] <EOL> if FILTER_APPS : <EOL> apps = [ f for f in apps if f in FILTER_APPS ] <EOL> apps = sorted ( apps , lambda a , b : cmp ( a . upper ( ) , b . upper ( ) ) ) <EOL> myplatform = platform . python_version ( ) <EOL> return dict ( app = None , apps = apps , myversion = myversion , myplatform = myplatform , <EOL> form_create = form_create , form_update = form_update ) <EOL> def report_progress ( app ) : <EOL> import datetime <EOL> progress_file = os . path . join ( apath ( app , r = request ) , '<STR_LIT>' ) <EOL> regex = re . compile ( '<STR_LIT>' ) <EOL> if not os . path . exists ( progress_file ) : <EOL> return [ ] <EOL> matches = regex . findall ( open ( progress_file , '<STR_LIT:r>' ) . read ( ) ) <EOL> events , counter = [ ] , <NUM_LIT:0> <EOL> for m in matches : <EOL> if not m : <EOL> continue <EOL> days = - ( request . now - datetime . datetime . strptime ( m [ <NUM_LIT:0> ] , <EOL> '<STR_LIT>' ) ) . days <EOL> counter += int ( m [ <NUM_LIT:1> ] ) <EOL> events . append ( [ days , counter ] ) <EOL> return events <EOL> def pack ( ) : <EOL> app = get_app ( ) <EOL> try : <EOL> if len ( request . args ) == <NUM_LIT:1> : <EOL> fname = '<STR_LIT>' % app <EOL> filename = app_pack ( app , request , raise_ex = True ) <EOL> else : <EOL> fname = '<STR_LIT>' % app <EOL> filename = app_pack_compiled ( app , request , raise_ex = True ) <EOL> except Exception , e : <EOL> filename = None <EOL> if filename : <EOL> response . headers [ '<STR_LIT:Content-Type>' ] = '<STR_LIT>' <EOL> disposition = '<STR_LIT>' % fname <EOL> response . headers [ '<STR_LIT>' ] = disposition <EOL> return safe_read ( filename , '<STR_LIT:rb>' ) <EOL> else : <EOL> session . flash = T ( '<STR_LIT>' , e ) <EOL> redirect ( URL ( '<STR_LIT>' ) ) <EOL> def pack_plugin ( ) : <EOL> app = get_app ( ) <EOL> if len ( request . args ) == <NUM_LIT:2> : <EOL> fname = '<STR_LIT>' % request . args [ <NUM_LIT:1> ] <EOL> filename = plugin_pack ( app , request . args [ <NUM_LIT:1> ] , request ) <EOL> if filename : <EOL> response . headers [ '<STR_LIT:Content-Type>' ] = '<STR_LIT>' <EOL> disposition = '<STR_LIT>' % fname <EOL> response . headers [ '<STR_LIT>' ] = disposition <EOL> return safe_read ( filename , '<STR_LIT:rb>' ) <EOL> else : <EOL> session . flash = T ( '<STR_LIT>' ) <EOL> redirect ( URL ( '<STR_LIT>' , args = request . args ) ) <EOL> def pack_custom ( ) : <EOL> app = get_app ( ) <EOL> base = apath ( app , r = request ) <EOL> if request . post_vars . file : <EOL> files = request . post_vars . file <EOL> files = [ files ] if not isinstance ( files , list ) else files <EOL> fname = '<STR_LIT>' % app <EOL> try : <EOL> filename = app_pack ( app , request , raise_ex = True , filenames = files ) <EOL> except Exception , e : <EOL> filename = None <EOL> if filename : <EOL> response . headers [ '<STR_LIT:Content-Type>' ] = '<STR_LIT>' <EOL> disposition = '<STR_LIT>' % fname <EOL> response . headers [ '<STR_LIT>' ] = disposition <EOL> return safe_read ( filename , '<STR_LIT:rb>' ) <EOL> else : <EOL> session . flash = T ( '<STR_LIT>' , e ) <EOL> redirect ( URL ( args = request . args ) ) <EOL> def ignore ( fs ) : <EOL> return [ f for f in fs if not ( <EOL> f [ : <NUM_LIT:1> ] in '<STR_LIT:#>' or f . endswith ( '<STR_LIT>' ) or f . endswith ( '<STR_LIT>' ) ) ] <EOL> files = { } <EOL> for ( r , d , f ) in os . walk ( base ) : <EOL> files [ r ] = { '<STR_LIT>' : ignore ( d ) , '<STR_LIT>' : ignore ( f ) } <EOL> return locals ( ) <EOL> def upgrade_web2py ( ) : <EOL> dialog = FORM . confirm ( T ( '<STR_LIT>' ) , <EOL> { T ( '<STR_LIT>' ) : URL ( '<STR_LIT>' ) } ) <EOL> if dialog . accepted : <EOL> ( success , error ) = upgrade ( request ) <EOL> if success : <EOL> session . flash = T ( '<STR_LIT>' ) <EOL> else : <EOL> session . flash = T ( '<STR_LIT>' , error ) <EOL> redirect ( URL ( '<STR_LIT>' ) ) <EOL> return dict ( dialog = dialog ) <EOL> def uninstall ( ) : <EOL> app = get_app ( ) <EOL> dialog = FORM . confirm ( T ( '<STR_LIT>' ) , <EOL> { T ( '<STR_LIT>' ) : URL ( '<STR_LIT>' ) } ) <EOL> dialog [ '<STR_LIT>' ] = '<STR_LIT>' <EOL> dialog [ '<STR_LIT>' ] = '<STR_LIT>' <EOL> for component in dialog . components : <EOL> component [ '<STR_LIT>' ] = '<STR_LIT>' <EOL> if dialog . accepted : <EOL> if MULTI_USER_MODE : <EOL> if is_manager ( ) and db ( db . app . name == app ) . delete ( ) : <EOL> pass <EOL> elif db ( db . app . name == app ) ( db . app . owner == auth . user . id ) . delete ( ) : <EOL> pass <EOL> else : <EOL> session . flash = T ( '<STR_LIT>' , app ) <EOL> redirect ( URL ( '<STR_LIT>' ) ) <EOL> try : <EOL> filename = app_pack ( app , request , raise_ex = True ) <EOL> except : <EOL> session . flash = T ( '<STR_LIT>' , app ) <EOL> else : <EOL> if app_uninstall ( app , request ) : <EOL> session . flash = T ( '<STR_LIT>' , app ) <EOL> else : <EOL> session . flash = T ( '<STR_LIT>' , app ) <EOL> redirect ( URL ( '<STR_LIT>' ) ) <EOL> return dict ( app = app , dialog = dialog ) <EOL> def cleanup ( ) : <EOL> app = get_app ( ) <EOL> clean = app_cleanup ( app , request ) <EOL> if not clean : <EOL> session . flash = T ( "<STR_LIT>" ) <EOL> else : <EOL> session . flash = T ( '<STR_LIT>' ) <EOL> redirect ( URL ( '<STR_LIT>' ) ) <EOL> def compile_app ( ) : <EOL> app = get_app ( ) <EOL> c = app_compile ( app , request ) <EOL> if not c : <EOL> session . flash = T ( '<STR_LIT>' ) <EOL> else : <EOL> session . flash = DIV ( T ( '<STR_LIT>' ) , <EOL> CODE ( c ) ) <EOL> redirect ( URL ( '<STR_LIT>' ) ) <EOL> def remove_compiled_app ( ) : <EOL> """<STR_LIT>""" <EOL> app = get_app ( ) <EOL> remove_compiled_application ( apath ( app , r = request ) ) <EOL> session . flash = T ( '<STR_LIT>' ) <EOL> redirect ( URL ( '<STR_LIT>' ) ) <EOL> def delete ( ) : <EOL> """<STR_LIT>""" <EOL> app = get_app ( ) <EOL> filename = '<STR_LIT:/>' . join ( request . args ) <EOL> sender = request . vars . sender <EOL> if isinstance ( sender , list ) : <EOL> sender = sender [ <NUM_LIT:0> ] <EOL> dialog = FORM . confirm ( T ( '<STR_LIT>' ) , <EOL> { T ( '<STR_LIT>' ) : URL ( sender , anchor = request . vars . id ) } ) <EOL> if dialog . accepted : <EOL> try : <EOL> full_path = apath ( filename , r = request ) <EOL> lineno = count_lines ( open ( full_path , '<STR_LIT:r>' ) . read ( ) ) <EOL> os . unlink ( full_path ) <EOL> log_progress ( app , '<STR_LIT>' , filename , progress = - lineno ) <EOL> session . flash = T ( '<STR_LIT>' , <EOL> dict ( filename = filename ) ) <EOL> except Exception : <EOL> session . flash = T ( '<STR_LIT>' , <EOL> dict ( filename = filename ) ) <EOL> redirect ( URL ( sender , anchor = request . vars . id2 ) ) <EOL> return dict ( dialog = dialog , filename = filename ) <EOL> def enable ( ) : <EOL> app = get_app ( ) <EOL> filename = os . path . join ( apath ( app , r = request ) , '<STR_LIT>' ) <EOL> if is_gae : <EOL> return SPAN ( T ( '<STR_LIT>' ) , _style = '<STR_LIT>' ) <EOL> elif os . path . exists ( filename ) : <EOL> os . unlink ( filename ) <EOL> return SPAN ( T ( '<STR_LIT>' ) , _style = '<STR_LIT>' ) <EOL> else : <EOL> safe_open ( filename , '<STR_LIT:wb>' ) . write ( '<STR_LIT>' % request . now ) <EOL> return SPAN ( T ( '<STR_LIT>' ) , _style = '<STR_LIT>' ) <EOL> def peek ( ) : <EOL> """<STR_LIT>""" <EOL> app = get_app ( request . vars . app ) <EOL> filename = '<STR_LIT:/>' . join ( request . args ) <EOL> if request . vars . app : <EOL> path = abspath ( filename ) <EOL> else : <EOL> path = apath ( filename , r = request ) <EOL> try : <EOL> data = safe_read ( path ) . replace ( '<STR_LIT:\r>' , '<STR_LIT>' ) <EOL> except IOError : <EOL> session . flash = T ( '<STR_LIT>' ) <EOL> redirect ( URL ( '<STR_LIT>' ) ) <EOL> extension = filename [ filename . rfind ( '<STR_LIT:.>' ) + <NUM_LIT:1> : ] . lower ( ) <EOL> return dict ( app = app , <EOL> filename = filename , <EOL> data = data , <EOL> extension = extension ) <EOL> def test ( ) : <EOL> """<STR_LIT>""" <EOL> app = get_app ( ) <EOL> if len ( request . args ) > <NUM_LIT:1> : <EOL> file = request . args [ <NUM_LIT:1> ] <EOL> else : <EOL> file = '<STR_LIT>' <EOL> controllers = listdir ( <EOL> apath ( '<STR_LIT>' % app , r = request ) , file + '<STR_LIT:$>' ) <EOL> return dict ( app = app , controllers = controllers ) <EOL> def keepalive ( ) : <EOL> return '<STR_LIT>' <EOL> def search ( ) : <EOL> keywords = request . vars . keywords or '<STR_LIT>' <EOL> app = get_app ( ) <EOL> def match ( filename , keywords ) : <EOL> filename = os . path . join ( apath ( app , r = request ) , filename ) <EOL> if keywords in read_file ( filename , '<STR_LIT:rb>' ) : <EOL> return True <EOL> return False <EOL> path = apath ( request . args [ <NUM_LIT:0> ] , r = request ) <EOL> files1 = glob ( os . path . join ( path , '<STR_LIT>' ) ) <EOL> files2 = glob ( os . path . join ( path , '<STR_LIT>' ) ) <EOL> files3 = glob ( os . path . join ( path , '<STR_LIT>' ) ) <EOL> files = [ x [ len ( path ) + <NUM_LIT:1> : ] . replace ( <EOL> '<STR_LIT:\\>' , '<STR_LIT:/>' ) for x in files1 + files2 + files3 if match ( x , keywords ) ] <EOL> return response . json ( dict ( files = files , message = T . M ( '<STR_LIT>' , len ( files ) ) ) ) <EOL> def edit ( ) : <EOL> """<STR_LIT>""" <EOL> app = get_app ( request . vars . app ) <EOL> app_path = apath ( app , r = request ) <EOL> preferences = { '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT:default>' , '<STR_LIT>' : '<STR_LIT:true>' , '<STR_LIT>' : '<STR_LIT:false>' , '<STR_LIT>' : '<STR_LIT:4>' , '<STR_LIT>' : '<STR_LIT:false>' , '<STR_LIT>' : '<STR_LIT:true>' , '<STR_LIT>' : '<STR_LIT:true>' } <EOL> config = Config ( os . path . join ( request . folder , '<STR_LIT>' ) , <EOL> section = '<STR_LIT>' , default_values = { } ) <EOL> preferences . update ( config . read ( ) ) <EOL> if not ( request . ajax ) and not ( is_mobile ) : <EOL> response . title = T ( '<STR_LIT>' ) % app <EOL> return response . render ( '<STR_LIT>' , dict ( app = app , editor_settings = preferences ) ) <EOL> if '<STR_LIT>' in request . vars : <EOL> if request . post_vars : <EOL> post_vars = request . post_vars . items ( ) <EOL> post_vars += [ ( opt , '<STR_LIT:false>' ) for opt in preferences if opt not in request . post_vars ] <EOL> if config . save ( post_vars ) : <EOL> response . headers [ "<STR_LIT>" ] = T ( '<STR_LIT>' ) <EOL> else : <EOL> response . headers [ "<STR_LIT>" ] = T ( '<STR_LIT>' ) <EOL> response . headers [ "<STR_LIT>" ] = "<STR_LIT>" % response . json ( config . read ( ) ) <EOL> return <EOL> else : <EOL> details = { '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT:filename>' : '<STR_LIT>' , '<STR_LIT:id>' : '<STR_LIT>' , '<STR_LIT>' : False } <EOL> details [ '<STR_LIT>' ] = response . render ( '<STR_LIT>' , { '<STR_LIT>' : preferences } ) <EOL> return response . json ( details ) <EOL> """<STR_LIT>""" <EOL> app = get_app ( request . vars . app ) <EOL> filename = '<STR_LIT:/>' . join ( request . args ) <EOL> realfilename = request . args [ - <NUM_LIT:1> ] <EOL> if request . vars . app : <EOL> path = abspath ( filename ) <EOL> else : <EOL> path = apath ( filename , r = request ) <EOL> if filename [ - <NUM_LIT:3> : ] == '<STR_LIT>' : <EOL> filetype = '<STR_LIT>' <EOL> elif filename [ - <NUM_LIT:5> : ] == '<STR_LIT>' : <EOL> filetype = '<STR_LIT:html>' <EOL> elif filename [ - <NUM_LIT:5> : ] == '<STR_LIT>' : <EOL> filetype = '<STR_LIT:html>' <EOL> elif filename [ - <NUM_LIT:4> : ] == '<STR_LIT>' : <EOL> filetype = '<STR_LIT>' <EOL> elif filename [ - <NUM_LIT:3> : ] == '<STR_LIT>' : <EOL> filetype = '<STR_LIT>' <EOL> else : <EOL> filetype = '<STR_LIT:html>' <EOL> if ( '<STR_LIT>' in request . vars ) and os . path . exists ( path + '<STR_LIT>' ) : <EOL> try : <EOL> data = safe_read ( path + '<STR_LIT>' ) <EOL> data1 = safe_read ( path ) <EOL> except IOError : <EOL> session . flash = T ( '<STR_LIT>' ) <EOL> if '<STR_LIT>' in request . vars : <EOL> return response . json ( { '<STR_LIT:error>' : str ( T ( '<STR_LIT>' ) ) } ) <EOL> else : <EOL> redirect ( URL ( '<STR_LIT>' ) ) <EOL> safe_write ( path , data ) <EOL> file_hash = md5_hash ( data ) <EOL> saved_on = time . ctime ( os . stat ( path ) [ stat . ST_MTIME ] ) <EOL> safe_write ( path + '<STR_LIT>' , data1 ) <EOL> response . flash = T ( '<STR_LIT>' , ( filename , saved_on ) ) <EOL> else : <EOL> try : <EOL> data = safe_read ( path ) <EOL> except IOError : <EOL> session . flash = T ( '<STR_LIT>' ) <EOL> if '<STR_LIT>' in request . vars : <EOL> return response . json ( { '<STR_LIT:error>' : str ( T ( '<STR_LIT>' ) ) } ) <EOL> else : <EOL> redirect ( URL ( '<STR_LIT>' ) ) <EOL> lineno_old = count_lines ( data ) <EOL> file_hash = md5_hash ( data ) <EOL> saved_on = time . ctime ( os . stat ( path ) [ stat . ST_MTIME ] ) <EOL> if request . vars . file_hash and request . vars . file_hash != file_hash : <EOL> session . flash = T ( '<STR_LIT>' ) <EOL> data = request . vars . data . replace ( '<STR_LIT:\r\n>' , '<STR_LIT:\n>' ) . strip ( ) + '<STR_LIT:\n>' <EOL> safe_write ( path + '<STR_LIT>' , data ) <EOL> if '<STR_LIT>' in request . vars : <EOL> return response . json ( { '<STR_LIT:error>' : str ( T ( '<STR_LIT>' ) ) , <EOL> '<STR_LIT>' : URL ( '<STR_LIT>' , <EOL> args = request . args ) } ) <EOL> else : <EOL> redirect ( URL ( '<STR_LIT>' , args = request . args ) ) <EOL> elif request . vars . data : <EOL> safe_write ( path + '<STR_LIT>' , data ) <EOL> data = request . vars . data . replace ( '<STR_LIT:\r\n>' , '<STR_LIT:\n>' ) . strip ( ) + '<STR_LIT:\n>' <EOL> safe_write ( path , data ) <EOL> lineno_new = count_lines ( data ) <EOL> log_progress ( <EOL> app , '<STR_LIT>' , filename , progress = lineno_new - lineno_old ) <EOL> file_hash = md5_hash ( data ) <EOL> saved_on = time . ctime ( os . stat ( path ) [ stat . ST_MTIME ] ) <EOL> response . flash = T ( '<STR_LIT>' , saved_on ) <EOL> data_or_revert = ( request . vars . data or request . vars . revert ) <EOL> highlight = None <EOL> if filetype == '<STR_LIT>' and request . vars . data : <EOL> import _ast <EOL> try : <EOL> code = request . vars . data . rstrip ( ) . replace ( '<STR_LIT:\r\n>' , '<STR_LIT:\n>' ) + '<STR_LIT:\n>' <EOL> compile ( code , path , "<STR_LIT>" , _ast . PyCF_ONLY_AST ) <EOL> except Exception , e : <EOL> start = sum ( [ len ( line ) + <NUM_LIT:1> for l , line <EOL> in enumerate ( request . vars . data . split ( "<STR_LIT:\n>" ) ) <EOL> if l < e . lineno - <NUM_LIT:1> ] ) <EOL> if e . text and e . offset : <EOL> offset = e . offset - ( len ( e . text ) - len ( <EOL> e . text . splitlines ( ) [ - <NUM_LIT:1> ] ) ) <EOL> else : <EOL> offset = <NUM_LIT:0> <EOL> highlight = { '<STR_LIT:start>' : start , '<STR_LIT:end>' : start + <EOL> offset + <NUM_LIT:1> , '<STR_LIT>' : e . lineno , '<STR_LIT>' : offset } <EOL> try : <EOL> ex_name = e . __class__ . __name__ <EOL> except : <EOL> ex_name = '<STR_LIT>' <EOL> response . flash = DIV ( T ( '<STR_LIT>' ) , BR ( ) , <EOL> B ( ex_name ) , '<STR_LIT:U+0020>' + T ( '<STR_LIT>' , e . lineno ) , <EOL> offset and '<STR_LIT:U+0020>' + <EOL> T ( '<STR_LIT>' , offset ) or '<STR_LIT>' , <EOL> PRE ( str ( e ) ) ) <EOL> if data_or_revert and request . args [ <NUM_LIT:1> ] == '<STR_LIT>' : <EOL> try : <EOL> mopath = '<STR_LIT:.>' . join ( request . args [ <NUM_LIT:2> : ] ) [ : - <NUM_LIT:3> ] <EOL> exec '<STR_LIT>' % ( <EOL> request . args [ <NUM_LIT:0> ] , mopath ) <EOL> reload ( sys . modules [ '<STR_LIT>' <EOL> % ( request . args [ <NUM_LIT:0> ] , mopath ) ] ) <EOL> except Exception , e : <EOL> response . flash = DIV ( <EOL> T ( '<STR_LIT>' ) , PRE ( str ( e ) ) ) <EOL> edit_controller = None <EOL> editviewlinks = None <EOL> view_link = None <EOL> if filetype == '<STR_LIT:html>' and len ( request . args ) >= <NUM_LIT:3> : <EOL> cfilename = os . path . join ( request . args [ <NUM_LIT:0> ] , '<STR_LIT>' , <EOL> request . args [ <NUM_LIT:2> ] + '<STR_LIT>' ) <EOL> if os . path . exists ( apath ( cfilename , r = request ) ) : <EOL> edit_controller = URL ( '<STR_LIT>' , args = [ cfilename . replace ( os . sep , "<STR_LIT:/>" ) ] ) <EOL> view = request . args [ <NUM_LIT:3> ] . replace ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> view_link = URL ( request . args [ <NUM_LIT:0> ] , request . args [ <NUM_LIT:2> ] , view ) <EOL> elif filetype == '<STR_LIT>' and request . args [ <NUM_LIT:1> ] == '<STR_LIT>' : <EOL> app = get_app ( ) <EOL> viewname = os . path . splitext ( request . args [ <NUM_LIT:2> ] ) [ <NUM_LIT:0> ] <EOL> viewpath = os . path . join ( app , '<STR_LIT>' , viewname ) <EOL> aviewpath = apath ( viewpath , r = request ) <EOL> viewlist = [ ] <EOL> if os . path . exists ( aviewpath ) : <EOL> if os . path . isdir ( aviewpath ) : <EOL> viewlist = glob ( os . path . join ( aviewpath , '<STR_LIT>' ) ) <EOL> elif os . path . exists ( aviewpath + '<STR_LIT>' ) : <EOL> viewlist . append ( aviewpath + '<STR_LIT>' ) <EOL> if len ( viewlist ) : <EOL> editviewlinks = [ ] <EOL> for v in viewlist : <EOL> vf = os . path . split ( v ) [ - <NUM_LIT:1> ] <EOL> vargs = "<STR_LIT:/>" . join ( [ viewpath . replace ( os . sep , "<STR_LIT:/>" ) , vf ] ) <EOL> editviewlinks . append ( A ( vf . split ( "<STR_LIT:.>" ) [ <NUM_LIT:0> ] , <EOL> _class = "<STR_LIT>" , <EOL> _href = URL ( '<STR_LIT>' , args = [ vargs ] ) ) ) <EOL> if len ( request . args ) > <NUM_LIT:2> and request . args [ <NUM_LIT:1> ] == '<STR_LIT>' : <EOL> controller = ( request . args [ <NUM_LIT:2> ] ) [ : - <NUM_LIT:3> ] <EOL> functions = find_exposed_functions ( data ) <EOL> else : <EOL> ( controller , functions ) = ( None , None ) <EOL> if '<STR_LIT>' in request . vars : <EOL> return response . json ( { '<STR_LIT>' : file_hash , '<STR_LIT>' : saved_on , '<STR_LIT>' : functions , '<STR_LIT>' : controller , '<STR_LIT>' : request . args [ <NUM_LIT:0> ] , '<STR_LIT>' : highlight } ) <EOL> else : <EOL> file_details = dict ( app = request . args [ <NUM_LIT:0> ] , <EOL> lineno = request . vars . lineno or <NUM_LIT:1> , <EOL> editor_settings = preferences , <EOL> filename = filename , <EOL> realfilename = realfilename , <EOL> filetype = filetype , <EOL> data = data , <EOL> edit_controller = edit_controller , <EOL> file_hash = file_hash , <EOL> saved_on = saved_on , <EOL> controller = controller , <EOL> functions = functions , <EOL> view_link = view_link , <EOL> editviewlinks = editviewlinks , <EOL> id = IS_SLUG ( ) ( filename ) [ <NUM_LIT:0> ] , <EOL> force = True if ( request . vars . restore or <EOL> request . vars . revert ) else False ) <EOL> plain_html = response . render ( '<STR_LIT>' , file_details ) <EOL> file_details [ '<STR_LIT>' ] = plain_html <EOL> if is_mobile : <EOL> return response . render ( '<STR_LIT>' , <EOL> file_details , editor_settings = preferences ) <EOL> else : <EOL> return response . json ( file_details ) <EOL> def todolist ( ) : <EOL> """<STR_LIT>""" <EOL> app = request . vars . app or '<STR_LIT>' <EOL> app_path = apath ( '<STR_LIT>' % { '<STR_LIT>' : app } , r = request ) <EOL> dirs = [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> def listfiles ( app , dir , regexp = '<STR_LIT>' ) : <EOL> files = sorted ( listdir ( apath ( '<STR_LIT>' % { '<STR_LIT>' : app , '<STR_LIT>' : dir } , r = request ) , regexp ) ) <EOL> files = [ x . replace ( os . path . sep , '<STR_LIT:/>' ) for x in files if not x . endswith ( '<STR_LIT>' ) ] <EOL> return files <EOL> pattern = '<STR_LIT>' <EOL> regex = re . compile ( pattern , re . IGNORECASE ) <EOL> output = [ ] <EOL> for d in dirs : <EOL> for f in listfiles ( app , d ) : <EOL> matches = [ ] <EOL> filename = apath ( os . path . join ( app , d , f ) , r = request ) <EOL> with open ( filename , '<STR_LIT:r>' ) as f_s : <EOL> src = f_s . read ( ) <EOL> for m in regex . finditer ( src ) : <EOL> start = m . start ( ) <EOL> lineno = src . count ( '<STR_LIT:\n>' , <NUM_LIT:0> , start ) + <NUM_LIT:1> <EOL> matches . append ( { '<STR_LIT:text>' : m . group ( <NUM_LIT:0> ) , '<STR_LIT>' : lineno } ) <EOL> if len ( matches ) != <NUM_LIT:0> : <EOL> output . append ( { '<STR_LIT:filename>' : f , '<STR_LIT>' : matches , '<STR_LIT>' : d } ) <EOL> return { '<STR_LIT>' : output , '<STR_LIT>' : app } <EOL> def editor_sessions ( ) : <EOL> config = Config ( os . path . join ( request . folder , '<STR_LIT>' ) , <EOL> section = '<STR_LIT>' , default_values = { } ) <EOL> preferences = config . read ( ) <EOL> if request . vars . session_name and request . vars . files : <EOL> session_name = request . vars . session_name <EOL> files = request . vars . files <EOL> preferences . update ( { session_name : '<STR_LIT:U+002C>' . join ( files ) } ) <EOL> if config . save ( preferences . items ( ) ) : <EOL> response . headers [ "<STR_LIT>" ] = T ( '<STR_LIT>' ) <EOL> else : <EOL> response . headers [ "<STR_LIT>" ] = T ( '<STR_LIT>' ) <EOL> return response . render ( '<STR_LIT>' , { '<STR_LIT>' : preferences } ) <EOL> def resolve ( ) : <EOL> """<STR_LIT:U+0020>""" <EOL> filename = '<STR_LIT:/>' . join ( request . args ) <EOL> path = apath ( filename , r = request ) <EOL> a = safe_read ( path ) . split ( '<STR_LIT:\n>' ) <EOL> try : <EOL> b = safe_read ( path + '<STR_LIT>' ) . split ( '<STR_LIT:\n>' ) <EOL> except IOError : <EOL> session . flash = '<STR_LIT>' <EOL> redirect ( URL ( '<STR_LIT>' , args = request . args ) ) <EOL> d = difflib . ndiff ( a , b ) <EOL> def leading ( line ) : <EOL> """<STR_LIT:U+0020>""" <EOL> z = '<STR_LIT>' <EOL> for ( k , c ) in enumerate ( line ) : <EOL> if c == '<STR_LIT:U+0020>' : <EOL> z += '<STR_LIT>' <EOL> elif c == '<STR_LIT>' : <EOL> z += '<STR_LIT>' <EOL> elif k == <NUM_LIT:0> and c == '<STR_LIT:?>' : <EOL> pass <EOL> else : <EOL> break <EOL> return XML ( z ) <EOL> def getclass ( item ) : <EOL> """<STR_LIT>""" <EOL> if item [ <NUM_LIT:0> ] == '<STR_LIT:U+0020>' : <EOL> return '<STR_LIT>' <EOL> if item [ <NUM_LIT:0> ] == '<STR_LIT:+>' : <EOL> return '<STR_LIT>' <EOL> if item [ <NUM_LIT:0> ] == '<STR_LIT:->' : <EOL> return '<STR_LIT>' <EOL> if request . vars : <EOL> c = '<STR_LIT:\n>' . join ( [ item [ <NUM_LIT:2> : ] . rstrip ( ) for ( i , item ) in enumerate ( d ) if item [ <NUM_LIT:0> ] <EOL> == '<STR_LIT:U+0020>' or '<STR_LIT>' % i in request . vars ] ) <EOL> safe_write ( path , c ) <EOL> session . flash = '<STR_LIT>' <EOL> redirect ( URL ( '<STR_LIT>' , args = request . args ) ) <EOL> else : <EOL> gen_data = lambda index , item : not item [ : <NUM_LIT:1> ] in [ '<STR_LIT:+>' , '<STR_LIT:->' ] and "<STR_LIT>" or INPUT ( _type = '<STR_LIT>' , <EOL> _name = '<STR_LIT>' % index , <EOL> value = item [ <NUM_LIT:0> ] == '<STR_LIT:+>' ) <EOL> diff = TABLE ( * [ TR ( TD ( gen_data ( i , item ) ) , <EOL> TD ( item [ <NUM_LIT:0> ] ) , <EOL> TD ( leading ( item [ <NUM_LIT:2> : ] ) , <EOL> TT ( item [ <NUM_LIT:2> : ] . rstrip ( ) ) ) , <EOL> _class = getclass ( item ) ) <EOL> for ( i , item ) in enumerate ( d ) if item [ <NUM_LIT:0> ] != '<STR_LIT:?>' ] ) <EOL> return dict ( diff = diff , filename = filename ) <EOL> def edit_language ( ) : <EOL> """<STR_LIT>""" <EOL> app = get_app ( ) <EOL> filename = '<STR_LIT:/>' . join ( request . args ) <EOL> response . title = request . args [ - <NUM_LIT:1> ] <EOL> strings = read_dict ( apath ( filename , r = request ) ) <EOL> if '<STR_LIT>' in strings : <EOL> form = SPAN ( strings [ '<STR_LIT>' ] , _class = '<STR_LIT:error>' ) <EOL> return dict ( filename = filename , form = form ) <EOL> keys = sorted ( strings . keys ( ) , lambda x , y : cmp ( <EOL> unicode ( x , '<STR_LIT:utf-8>' ) . lower ( ) , unicode ( y , '<STR_LIT:utf-8>' ) . lower ( ) ) ) <EOL> rows = [ ] <EOL> rows . append ( H2 ( T ( '<STR_LIT>' ) ) ) <EOL> for key in keys : <EOL> name = md5_hash ( key ) <EOL> s = strings [ key ] <EOL> ( prefix , sep , key ) = key . partition ( '<STR_LIT>' ) <EOL> if sep : <EOL> prefix = SPAN ( prefix + '<STR_LIT>' , _class = '<STR_LIT>' ) <EOL> k = key <EOL> else : <EOL> ( k , prefix ) = ( prefix , '<STR_LIT>' ) <EOL> _class = '<STR_LIT>' if k == s else '<STR_LIT>' <EOL> if len ( s ) <= <NUM_LIT> : <EOL> elem = INPUT ( _type = '<STR_LIT:text>' , _name = name , value = s , <EOL> _size = <NUM_LIT> , _class = _class ) <EOL> else : <EOL> elem = TEXTAREA ( _name = name , value = s , _cols = <NUM_LIT> , <EOL> _rows = <NUM_LIT:5> , _class = _class ) <EOL> k = ( s != k ) and k or B ( k ) <EOL> new_row = DIV ( LABEL ( prefix , k , _style = "<STR_LIT>" ) , <EOL> CAT ( elem , '<STR_LIT:\n>' , TAG . BUTTON ( <EOL> T ( '<STR_LIT>' ) , <EOL> _onclick = '<STR_LIT>' % name , <EOL> _class = '<STR_LIT>' ) ) , _id = name , _class = '<STR_LIT>' ) <EOL> rows . append ( DIV ( new_row , _class = "<STR_LIT>" ) ) <EOL> rows . append ( DIV ( INPUT ( _type = '<STR_LIT>' , _value = T ( '<STR_LIT>' ) , _class = "<STR_LIT>" ) , _class = '<STR_LIT>' ) ) <EOL> form = FORM ( * rows ) <EOL> if form . accepts ( request . vars , keepvalues = True ) : <EOL> strs = dict ( ) <EOL> for key in keys : <EOL> name = md5_hash ( key ) <EOL> if form . vars [ name ] == chr ( <NUM_LIT> ) : <EOL> continue <EOL> strs [ key ] = form . vars [ name ] <EOL> write_dict ( apath ( filename , r = request ) , strs ) <EOL> session . flash = T ( '<STR_LIT>' , dict ( time = time . ctime ( ) ) ) <EOL> redirect ( URL ( r = request , args = request . args ) ) <EOL> return dict ( app = request . args [ <NUM_LIT:0> ] , filename = filename , form = form ) <EOL> def edit_plurals ( ) : <EOL> """<STR_LIT>""" <EOL> app = get_app ( ) <EOL> filename = '<STR_LIT:/>' . join ( request . args ) <EOL> plurals = read_plural_dict ( <EOL> apath ( filename , r = request ) ) <EOL> nplurals = int ( request . vars . nplurals ) - <NUM_LIT:1> <EOL> xnplurals = xrange ( nplurals ) <EOL> if '<STR_LIT>' in plurals : <EOL> form = SPAN ( plurals [ '<STR_LIT>' ] , _class = '<STR_LIT:error>' ) <EOL> return dict ( filename = filename , form = form ) <EOL> keys = sorted ( plurals . keys ( ) , lambda x , y : cmp ( <EOL> unicode ( x , '<STR_LIT:utf-8>' ) . lower ( ) , unicode ( y , '<STR_LIT:utf-8>' ) . lower ( ) ) ) <EOL> tab_rows = [ ] <EOL> for key in keys : <EOL> name = md5_hash ( key ) <EOL> forms = plurals [ key ] <EOL> if len ( forms ) < nplurals : <EOL> forms . extend ( None for i in xrange ( nplurals - len ( forms ) ) ) <EOL> tab_col1 = DIV ( CAT ( LABEL ( T ( "<STR_LIT>" ) ) , B ( key , <EOL> _class = '<STR_LIT>' ) ) ) <EOL> tab_inputs = [ SPAN ( LABEL ( T ( "<STR_LIT>" , n + <NUM_LIT:1> ) ) , INPUT ( _type = '<STR_LIT:text>' , _name = name + '<STR_LIT:_>' + str ( n ) , value = forms [ n ] , _size = <NUM_LIT:20> ) , _class = '<STR_LIT>' ) for n in xnplurals ] <EOL> tab_col2 = DIV ( CAT ( * tab_inputs ) ) <EOL> tab_col3 = DIV ( CAT ( LABEL ( XML ( '<STR_LIT>' ) ) , TAG . BUTTON ( T ( '<STR_LIT>' ) , _onclick = '<STR_LIT>' % name , _class = '<STR_LIT>' ) , _class = '<STR_LIT>' ) ) <EOL> tab_row = DIV ( DIV ( tab_col1 , '<STR_LIT:\n>' , tab_col2 , '<STR_LIT:\n>' , tab_col3 , _class = '<STR_LIT>' ) , _id = name , _class = '<STR_LIT>' ) <EOL> tab_rows . append ( tab_row ) <EOL> tab_rows . append ( DIV ( TAG [ '<STR_LIT>' ] ( T ( '<STR_LIT>' ) , _type = '<STR_LIT>' , <EOL> _class = '<STR_LIT>' ) , <EOL> _class = '<STR_LIT>' ) ) <EOL> tab_container = DIV ( * tab_rows , ** dict ( _class = "<STR_LIT>" ) ) <EOL> form = FORM ( tab_container ) <EOL> if form . accepts ( request . vars , keepvalues = True ) : <EOL> new_plurals = dict ( ) <EOL> for key in keys : <EOL> name = md5_hash ( key ) <EOL> if form . vars [ name + '<STR_LIT>' ] == chr ( <NUM_LIT> ) : <EOL> continue <EOL> new_plurals [ key ] = [ form . vars [ name + '<STR_LIT:_>' + str ( n ) ] <EOL> for n in xnplurals ] <EOL> write_plural_dict ( apath ( filename , r = request ) , new_plurals ) <EOL> session . flash = T ( '<STR_LIT>' , dict ( time = time . ctime ( ) ) ) <EOL> redirect ( URL ( r = request , args = request . args , vars = dict ( <EOL> nplurals = request . vars . nplurals ) ) ) <EOL> return dict ( app = request . args [ <NUM_LIT:0> ] , filename = filename , form = form ) <EOL> def about ( ) : <EOL> """<STR_LIT>""" <EOL> app = get_app ( ) <EOL> about = safe_read ( apath ( '<STR_LIT>' % app , r = request ) ) <EOL> license = safe_read ( apath ( '<STR_LIT>' % app , r = request ) ) <EOL> return dict ( app = app , about = MARKMIN ( about ) , license = MARKMIN ( license ) , progress = report_progress ( app ) ) <EOL> def design ( ) : <EOL> """<STR_LIT>""" <EOL> app = get_app ( ) <EOL> if not response . flash and app == request . application : <EOL> msg = T ( '<STR_LIT>' ) <EOL> response . flash = msg <EOL> if request . vars and not request . vars . token == session . token : <EOL> redirect ( URL ( '<STR_LIT>' ) ) <EOL> if request . vars . pluginfile is not None and not isinstance ( request . vars . pluginfile , str ) : <EOL> filename = os . path . basename ( request . vars . pluginfile . filename ) <EOL> if plugin_install ( app , request . vars . pluginfile . file , <EOL> request , filename ) : <EOL> session . flash = T ( '<STR_LIT>' ) <EOL> redirect ( URL ( '<STR_LIT>' , args = app ) ) <EOL> else : <EOL> session . flash = T ( '<STR_LIT>' , request . vars . filename ) <EOL> redirect ( URL ( r = request ) ) <EOL> elif isinstance ( request . vars . pluginfile , str ) : <EOL> session . flash = T ( '<STR_LIT>' ) <EOL> redirect ( URL ( r = request ) ) <EOL> if os . path . exists ( apath ( '<STR_LIT>' % app , r = request ) ) : <EOL> session . flash = T ( '<STR_LIT>' ) <EOL> redirect ( URL ( '<STR_LIT>' ) ) <EOL> models = listdir ( apath ( '<STR_LIT>' % app , r = request ) , '<STR_LIT>' ) <EOL> models = [ x . replace ( '<STR_LIT:\\>' , '<STR_LIT:/>' ) for x in models ] <EOL> defines = { } <EOL> for m in models : <EOL> data = safe_read ( apath ( '<STR_LIT>' % ( app , m ) , r = request ) ) <EOL> defines [ m ] = regex_tables . findall ( data ) <EOL> defines [ m ] . sort ( ) <EOL> controllers = sorted ( <EOL> listdir ( apath ( '<STR_LIT>' % app , r = request ) , '<STR_LIT>' ) ) <EOL> controllers = [ x . replace ( '<STR_LIT:\\>' , '<STR_LIT:/>' ) for x in controllers ] <EOL> functions = { } <EOL> for c in controllers : <EOL> data = safe_read ( apath ( '<STR_LIT>' % ( app , c ) , r = request ) ) <EOL> items = find_exposed_functions ( data ) <EOL> functions [ c ] = items <EOL> views = sorted ( <EOL> listdir ( apath ( '<STR_LIT>' % app , r = request ) , '<STR_LIT>' ) ) <EOL> views = [ x . replace ( '<STR_LIT:\\>' , '<STR_LIT:/>' ) for x in views if not x . endswith ( '<STR_LIT>' ) ] <EOL> extend = { } <EOL> include = { } <EOL> for c in views : <EOL> data = safe_read ( apath ( '<STR_LIT>' % ( app , c ) , r = request ) ) <EOL> items = regex_extend . findall ( data ) <EOL> if items : <EOL> extend [ c ] = items [ <NUM_LIT:0> ] [ <NUM_LIT:1> ] <EOL> items = regex_include . findall ( data ) <EOL> include [ c ] = [ i [ <NUM_LIT:1> ] for i in items ] <EOL> modules = listdir ( apath ( '<STR_LIT>' % app , r = request ) , '<STR_LIT>' ) <EOL> modules = modules = [ x . replace ( '<STR_LIT:\\>' , '<STR_LIT:/>' ) for x in modules ] <EOL> modules . sort ( ) <EOL> privates = listdir ( apath ( '<STR_LIT>' % app , r = request ) , '<STR_LIT>' ) <EOL> privates = [ x . replace ( '<STR_LIT:\\>' , '<STR_LIT:/>' ) for x in privates ] <EOL> privates . sort ( ) <EOL> statics = listdir ( apath ( '<STR_LIT>' % app , r = request ) , '<STR_LIT>' , <EOL> maxnum = MAXNFILES ) <EOL> statics = [ x . replace ( os . path . sep , '<STR_LIT:/>' ) for x in statics ] <EOL> statics . sort ( ) <EOL> langpath = os . path . join ( apath ( app , r = request ) , '<STR_LIT>' ) <EOL> languages = dict ( [ ( lang , info ) for lang , info <EOL> in read_possible_languages ( langpath ) . iteritems ( ) <EOL> if info [ <NUM_LIT:2> ] != <NUM_LIT:0> ] ) <EOL> cronfolder = apath ( '<STR_LIT>' % app , r = request ) <EOL> crontab = apath ( '<STR_LIT>' % app , r = request ) <EOL> if not is_gae : <EOL> if not os . path . exists ( cronfolder ) : <EOL> os . mkdir ( cronfolder ) <EOL> if not os . path . exists ( crontab ) : <EOL> safe_write ( crontab , '<STR_LIT>' ) <EOL> plugins = [ ] <EOL> def filter_plugins ( items , plugins ) : <EOL> plugins += [ item [ <NUM_LIT:7> : ] . split ( '<STR_LIT:/>' ) [ <NUM_LIT:0> ] . split ( <EOL> '<STR_LIT:.>' ) [ <NUM_LIT:0> ] for item in items if item . startswith ( '<STR_LIT>' ) ] <EOL> plugins [ : ] = list ( set ( plugins ) ) <EOL> plugins . sort ( ) <EOL> return [ item for item in items if not item . startswith ( '<STR_LIT>' ) ] <EOL> return dict ( app = app , <EOL> models = filter_plugins ( models , plugins ) , <EOL> defines = defines , <EOL> controllers = filter_plugins ( controllers , plugins ) , <EOL> functions = functions , <EOL> views = filter_plugins ( views , plugins ) , <EOL> modules = filter_plugins ( modules , plugins ) , <EOL> extend = extend , <EOL> include = include , <EOL> privates = filter_plugins ( privates , plugins ) , <EOL> statics = filter_plugins ( statics , plugins ) , <EOL> languages = languages , <EOL> crontab = crontab , <EOL> plugins = plugins ) <EOL> def delete_plugin ( ) : <EOL> """<STR_LIT>""" <EOL> app = request . args ( <NUM_LIT:0> ) <EOL> plugin = request . args ( <NUM_LIT:1> ) <EOL> plugin_name = '<STR_LIT>' + plugin <EOL> dialog = FORM . confirm ( <EOL> T ( '<STR_LIT>' ) , <EOL> { T ( '<STR_LIT>' ) : URL ( '<STR_LIT>' , args = app ) } ) <EOL> if dialog . accepted : <EOL> try : <EOL> for folder in [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] : <EOL> path = os . path . join ( apath ( app , r = request ) , folder ) <EOL> for item in os . listdir ( path ) : <EOL> if item . rsplit ( '<STR_LIT:.>' , <NUM_LIT:1> ) [ <NUM_LIT:0> ] == plugin_name : <EOL> filename = os . path . join ( path , item ) <EOL> if os . path . isdir ( filename ) : <EOL> shutil . rmtree ( filename ) <EOL> else : <EOL> os . unlink ( filename ) <EOL> session . flash = T ( '<STR_LIT>' , <EOL> dict ( plugin = plugin ) ) <EOL> except Exception : <EOL> session . flash = T ( '<STR_LIT>' , <EOL> dict ( plugin = plugin ) ) <EOL> redirect ( URL ( '<STR_LIT>' , args = request . args ( <NUM_LIT:0> ) , anchor = request . vars . id2 ) ) <EOL> return dict ( dialog = dialog , plugin = plugin ) <EOL> def plugin ( ) : <EOL> """<STR_LIT>""" <EOL> app = get_app ( ) <EOL> plugin = request . args ( <NUM_LIT:1> ) <EOL> if not response . flash and app == request . application : <EOL> msg = T ( '<STR_LIT>' ) <EOL> response . flash = msg <EOL> if os . path . exists ( apath ( '<STR_LIT>' % app , r = request ) ) : <EOL> session . flash = T ( '<STR_LIT>' ) <EOL> redirect ( URL ( '<STR_LIT>' ) ) <EOL> models = listdir ( apath ( '<STR_LIT>' % app , r = request ) , '<STR_LIT>' ) <EOL> models = [ x . replace ( '<STR_LIT:\\>' , '<STR_LIT:/>' ) for x in models ] <EOL> defines = { } <EOL> for m in models : <EOL> data = safe_read ( apath ( '<STR_LIT>' % ( app , m ) , r = request ) ) <EOL> defines [ m ] = regex_tables . findall ( data ) <EOL> defines [ m ] . sort ( ) <EOL> controllers = sorted ( <EOL> listdir ( apath ( '<STR_LIT>' % app , r = request ) , '<STR_LIT>' ) ) <EOL> controllers = [ x . replace ( '<STR_LIT:\\>' , '<STR_LIT:/>' ) for x in controllers ] <EOL> functions = { } <EOL> for c in controllers : <EOL> data = safe_read ( apath ( '<STR_LIT>' % ( app , c ) , r = request ) ) <EOL> items = find_exposed_functions ( data ) <EOL> functions [ c ] = items <EOL> views = sorted ( <EOL> listdir ( apath ( '<STR_LIT>' % app , r = request ) , '<STR_LIT>' ) ) <EOL> views = [ x . replace ( '<STR_LIT:\\>' , '<STR_LIT:/>' ) for x in views ] <EOL> extend = { } <EOL> include = { } <EOL> for c in views : <EOL> data = safe_read ( apath ( '<STR_LIT>' % ( app , c ) , r = request ) ) <EOL> items = regex_extend . findall ( data ) <EOL> if items : <EOL> extend [ c ] = items [ <NUM_LIT:0> ] [ <NUM_LIT:1> ] <EOL> items = regex_include . findall ( data ) <EOL> include [ c ] = [ i [ <NUM_LIT:1> ] for i in items ] <EOL> modules = listdir ( apath ( '<STR_LIT>' % app , r = request ) , '<STR_LIT>' ) <EOL> modules = modules = [ x . replace ( '<STR_LIT:\\>' , '<STR_LIT:/>' ) for x in modules ] <EOL> modules . sort ( ) <EOL> privates = listdir ( apath ( '<STR_LIT>' % app , r = request ) , '<STR_LIT>' ) <EOL> privates = [ x . replace ( '<STR_LIT:\\>' , '<STR_LIT:/>' ) for x in privates ] <EOL> privates . sort ( ) <EOL> statics = listdir ( apath ( '<STR_LIT>' % app , r = request ) , '<STR_LIT>' , <EOL> maxnum = MAXNFILES ) <EOL> statics = [ x . replace ( os . path . sep , '<STR_LIT:/>' ) for x in statics ] <EOL> statics . sort ( ) <EOL> languages = sorted ( [ lang + '<STR_LIT>' for lang , info in <EOL> T . get_possible_languages_info ( ) . iteritems ( ) <EOL> if info [ <NUM_LIT:2> ] != <NUM_LIT:0> ] ) <EOL> crontab = apath ( '<STR_LIT>' % app , r = request ) <EOL> if not os . path . exists ( crontab ) : <EOL> safe_write ( crontab , '<STR_LIT>' ) <EOL> def filter_plugins ( items ) : <EOL> regex = re . compile ( '<STR_LIT>' + plugin + '<STR_LIT>' ) <EOL> return [ item for item in items if item and regex . match ( item ) ] <EOL> return dict ( app = app , <EOL> models = filter_plugins ( models ) , <EOL> defines = defines , <EOL> controllers = filter_plugins ( controllers ) , <EOL> functions = functions , <EOL> views = filter_plugins ( views ) , <EOL> modules = filter_plugins ( modules ) , <EOL> extend = extend , <EOL> include = include , <EOL> privates = filter_plugins ( privates ) , <EOL> statics = filter_plugins ( statics ) , <EOL> languages = languages , <EOL> crontab = crontab ) <EOL> def create_file ( ) : <EOL> """<STR_LIT>""" <EOL> if request . vars and not request . vars . token == session . token : <EOL> redirect ( URL ( '<STR_LIT>' ) ) <EOL> try : <EOL> anchor = '<STR_LIT:#>' + request . vars . id if request . vars . id else '<STR_LIT>' <EOL> if request . vars . app : <EOL> app = get_app ( request . vars . app ) <EOL> path = abspath ( request . vars . location ) <EOL> else : <EOL> if request . vars . dir : <EOL> request . vars . location += request . vars . dir + '<STR_LIT:/>' <EOL> app = get_app ( name = request . vars . location . split ( '<STR_LIT:/>' ) [ <NUM_LIT:0> ] ) <EOL> path = apath ( request . vars . location , r = request ) <EOL> filename = re . sub ( '<STR_LIT>' , '<STR_LIT:_>' , request . vars . filename ) <EOL> if path [ - <NUM_LIT:7> : ] == '<STR_LIT>' : <EOL> if len ( filename ) == <NUM_LIT:0> : <EOL> raise SyntaxError <EOL> if not filename [ - <NUM_LIT:3> : ] == '<STR_LIT>' : <EOL> filename += '<STR_LIT>' <EOL> lang = re . match ( '<STR_LIT>' , filename ) . group ( <NUM_LIT:1> ) <EOL> langinfo = read_possible_languages ( apath ( app , r = request ) ) [ lang ] <EOL> text = dedent ( """<STR_LIT>""" ) [ <NUM_LIT:1> : ] % dict ( lang = langinfo [ <NUM_LIT:0> ] , langname = langinfo [ <NUM_LIT:1> ] ) <EOL> elif path [ - <NUM_LIT:11> : ] == '<STR_LIT>' : <EOL> if len ( filename ) == <NUM_LIT:0> : <EOL> raise SyntaxError <EOL> if not filename [ - <NUM_LIT:3> : ] == '<STR_LIT>' : <EOL> filename += '<STR_LIT>' <EOL> path = os . path . join ( apath ( app , r = request ) , '<STR_LIT>' , filename ) <EOL> if not os . path . exists ( path ) : <EOL> safe_write ( path , '<STR_LIT>' ) <EOL> findT ( apath ( app , r = request ) , filename [ : - <NUM_LIT:3> ] ) <EOL> session . flash = T ( '<STR_LIT>' , <EOL> dict ( filename = filename ) ) <EOL> redirect ( request . vars . sender + anchor ) <EOL> elif path [ - <NUM_LIT:8> : ] == '<STR_LIT>' : <EOL> if not filename [ - <NUM_LIT:3> : ] == '<STR_LIT>' : <EOL> filename += '<STR_LIT>' <EOL> if len ( filename ) == <NUM_LIT:3> : <EOL> raise SyntaxError <EOL> text = '<STR_LIT>' <EOL> elif path [ - <NUM_LIT> : ] == '<STR_LIT>' : <EOL> if not filename [ - <NUM_LIT:3> : ] == '<STR_LIT>' : <EOL> filename += '<STR_LIT>' <EOL> if len ( filename ) == <NUM_LIT:3> : <EOL> raise SyntaxError <EOL> text = '<STR_LIT>' <EOL> text = text % ( T ( '<STR_LIT>' ) , filename ) <EOL> elif path [ - <NUM_LIT:7> : ] == '<STR_LIT>' : <EOL> if request . vars . plugin and not filename . startswith ( '<STR_LIT>' % request . vars . plugin ) : <EOL> filename = '<STR_LIT>' % ( request . vars . plugin , filename ) <EOL> if filename . find ( '<STR_LIT:.>' ) < <NUM_LIT:0> : <EOL> filename += '<STR_LIT>' <EOL> extension = filename . split ( '<STR_LIT:.>' ) [ - <NUM_LIT:1> ] . lower ( ) <EOL> if len ( filename ) == <NUM_LIT:5> : <EOL> raise SyntaxError <EOL> msg = T ( <EOL> '<STR_LIT>' , dict ( filename = filename ) ) <EOL> if extension == '<STR_LIT:html>' : <EOL> text = dedent ( """<STR_LIT>""" % msg ) [ <NUM_LIT:1> : ] <EOL> else : <EOL> generic = os . path . join ( path , '<STR_LIT>' + extension ) <EOL> if os . path . exists ( generic ) : <EOL> text = read_file ( generic ) <EOL> else : <EOL> text = '<STR_LIT>' <EOL> elif path [ - <NUM_LIT:9> : ] == '<STR_LIT>' : <EOL> if request . vars . plugin and not filename . startswith ( '<STR_LIT>' % request . vars . plugin ) : <EOL> filename = '<STR_LIT>' % ( request . vars . plugin , filename ) <EOL> if not filename [ - <NUM_LIT:3> : ] == '<STR_LIT>' : <EOL> filename += '<STR_LIT>' <EOL> if len ( filename ) == <NUM_LIT:3> : <EOL> raise SyntaxError <EOL> text = dedent ( """<STR_LIT>""" ) [ <NUM_LIT:1> : ] <EOL> elif ( path [ - <NUM_LIT:8> : ] == '<STR_LIT>' ) or ( path [ - <NUM_LIT:9> : ] == '<STR_LIT>' ) : <EOL> if ( request . vars . plugin and <EOL> not filename . startswith ( '<STR_LIT>' % request . vars . plugin ) ) : <EOL> filename = '<STR_LIT>' % ( request . vars . plugin , filename ) <EOL> text = '<STR_LIT>' <EOL> else : <EOL> redirect ( request . vars . sender + anchor ) <EOL> full_filename = os . path . join ( path , filename ) <EOL> dirpath = os . path . dirname ( full_filename ) <EOL> if not os . path . exists ( dirpath ) : <EOL> os . makedirs ( dirpath ) <EOL> if os . path . exists ( full_filename ) : <EOL> raise SyntaxError <EOL> safe_write ( full_filename , text ) <EOL> log_progress ( app , '<STR_LIT>' , filename ) <EOL> if request . vars . dir : <EOL> result = T ( '<STR_LIT>' , <EOL> dict ( filename = full_filename [ len ( path ) : ] ) ) <EOL> else : <EOL> session . flash = T ( '<STR_LIT>' , <EOL> dict ( filename = full_filename [ len ( path ) : ] ) ) <EOL> vars = { } <EOL> if request . vars . id : <EOL> vars [ '<STR_LIT:id>' ] = request . vars . id <EOL> if request . vars . app : <EOL> vars [ '<STR_LIT>' ] = request . vars . app <EOL> redirect ( URL ( '<STR_LIT>' , <EOL> args = [ os . path . join ( request . vars . location , filename ) ] , vars = vars ) ) <EOL> except Exception , e : <EOL> if not isinstance ( e , HTTP ) : <EOL> session . flash = T ( '<STR_LIT>' ) <EOL> if request . vars . dir : <EOL> response . flash = result <EOL> response . headers [ '<STR_LIT>' ] = '<STR_LIT>' <EOL> response . headers [ '<STR_LIT>' ] = """<STR_LIT>""" % URL ( '<STR_LIT>' , args = [ app , request . vars . dir , filename ] ) <EOL> return '<STR_LIT>' <EOL> else : <EOL> redirect ( request . vars . sender + anchor ) <EOL> def listfiles ( app , dir , regexp = '<STR_LIT>' ) : <EOL> files = sorted ( <EOL> listdir ( apath ( '<STR_LIT>' % { '<STR_LIT>' : app , '<STR_LIT>' : dir } , r = request ) , regexp ) ) <EOL> files = [ x . replace ( '<STR_LIT:\\>' , '<STR_LIT:/>' ) for x in files if not x . endswith ( '<STR_LIT>' ) ] <EOL> return files <EOL> def editfile ( path , file , vars = { } , app = None ) : <EOL> args = ( path , file ) if '<STR_LIT>' in vars else ( app , path , file ) <EOL> url = URL ( '<STR_LIT>' , args = args , vars = vars ) <EOL> return A ( file , _class = '<STR_LIT>' , _href = url , _style = '<STR_LIT>' ) <EOL> def files_menu ( ) : <EOL> app = request . vars . app or '<STR_LIT>' <EOL> dirs = [ { '<STR_LIT:name>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT>' } , <EOL> { '<STR_LIT:name>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT>' } , <EOL> { '<STR_LIT:name>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT>' } , <EOL> { '<STR_LIT:name>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT>' } , <EOL> { '<STR_LIT:name>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT>' } ] <EOL> result_files = [ ] <EOL> for dir in dirs : <EOL> result_files . append ( TAG [ '<STR_LIT>' ] ( LI ( dir [ '<STR_LIT:name>' ] , _class = "<STR_LIT>" , _onclick = "<STR_LIT>" + dir [ '<STR_LIT:name>' ] + "<STR_LIT>" ) , <EOL> LI ( UL ( * [ LI ( editfile ( dir [ '<STR_LIT:name>' ] , f , dict ( id = dir [ '<STR_LIT:name>' ] + f . replace ( '<STR_LIT:.>' , '<STR_LIT>' ) ) , app ) , _style = "<STR_LIT>" , _id = dir [ '<STR_LIT:name>' ] + "<STR_LIT>" + f . replace ( '<STR_LIT:.>' , '<STR_LIT>' ) ) <EOL> for f in listfiles ( app , dir [ '<STR_LIT:name>' ] , regexp = dir [ '<STR_LIT>' ] ) ] , <EOL> _class = "<STR_LIT>" ) , <EOL> _id = dir [ '<STR_LIT:name>' ] + '<STR_LIT>' , _style = "<STR_LIT>" ) ) ) <EOL> return dict ( result_files = result_files ) <EOL> def upload_file ( ) : <EOL> """<STR_LIT>""" <EOL> if request . vars and not request . vars . token == session . token : <EOL> redirect ( URL ( '<STR_LIT>' ) ) <EOL> try : <EOL> filename = None <EOL> app = get_app ( name = request . vars . location . split ( '<STR_LIT:/>' ) [ <NUM_LIT:0> ] ) <EOL> path = apath ( request . vars . location , r = request ) <EOL> if request . vars . filename : <EOL> filename = re . sub ( '<STR_LIT>' , '<STR_LIT:_>' , request . vars . filename ) <EOL> else : <EOL> filename = os . path . split ( request . vars . file . filename ) [ - <NUM_LIT:1> ] <EOL> if path [ - <NUM_LIT:8> : ] == '<STR_LIT>' and not filename [ - <NUM_LIT:3> : ] == '<STR_LIT>' : <EOL> filename += '<STR_LIT>' <EOL> if path [ - <NUM_LIT:9> : ] == '<STR_LIT>' and not filename [ - <NUM_LIT:3> : ] == '<STR_LIT>' : <EOL> filename += '<STR_LIT>' <EOL> if path [ - <NUM_LIT> : ] == '<STR_LIT>' and not filename [ - <NUM_LIT:3> : ] == '<STR_LIT>' : <EOL> filename += '<STR_LIT>' <EOL> if path [ - <NUM_LIT:7> : ] == '<STR_LIT>' and not filename [ - <NUM_LIT:5> : ] == '<STR_LIT>' : <EOL> filename += '<STR_LIT>' <EOL> if path [ - <NUM_LIT:11> : ] == '<STR_LIT>' and not filename [ - <NUM_LIT:3> : ] == '<STR_LIT>' : <EOL> filename += '<STR_LIT>' <EOL> filename = os . path . join ( path , filename ) <EOL> dirpath = os . path . dirname ( filename ) <EOL> if not os . path . exists ( dirpath ) : <EOL> os . makedirs ( dirpath ) <EOL> data = request . vars . file . file . read ( ) <EOL> lineno = count_lines ( data ) <EOL> safe_write ( filename , data , '<STR_LIT:wb>' ) <EOL> log_progress ( app , '<STR_LIT>' , filename , lineno ) <EOL> session . flash = T ( '<STR_LIT>' , <EOL> dict ( filename = filename [ len ( path ) : ] ) ) <EOL> except Exception : <EOL> if filename : <EOL> d = dict ( filename = filename [ len ( path ) : ] ) <EOL> else : <EOL> d = dict ( filename = '<STR_LIT>' ) <EOL> session . flash = T ( '<STR_LIT>' , d ) <EOL> redirect ( request . vars . sender ) <EOL> def errors ( ) : <EOL> """<STR_LIT>""" <EOL> import operator <EOL> import os <EOL> import pickle <EOL> import hashlib <EOL> app = get_app ( ) <EOL> if is_gae : <EOL> method = '<STR_LIT>' if ( '<STR_LIT>' in <EOL> ( request . args ( <NUM_LIT:1> ) or '<STR_LIT>' ) ) else '<STR_LIT>' <EOL> else : <EOL> method = request . args ( <NUM_LIT:1> ) or '<STR_LIT>' <EOL> db_ready = { } <EOL> db_ready [ '<STR_LIT:status>' ] = get_ticket_storage ( app ) <EOL> db_ready [ '<STR_LIT>' ] = T ( <EOL> "<STR_LIT>" ) <EOL> db_ready [ '<STR_LIT>' ] = "<STR_LIT>" <EOL> if method == '<STR_LIT>' : <EOL> errors_path = apath ( '<STR_LIT>' % app , r = request ) <EOL> delete_hashes = [ ] <EOL> for item in request . vars : <EOL> if item [ : <NUM_LIT:7> ] == '<STR_LIT>' : <EOL> delete_hashes . append ( item [ <NUM_LIT:7> : ] ) <EOL> hash2error = dict ( ) <EOL> for fn in listdir ( errors_path , '<STR_LIT>' ) : <EOL> fullpath = os . path . join ( errors_path , fn ) <EOL> if not os . path . isfile ( fullpath ) : <EOL> continue <EOL> try : <EOL> fullpath_file = open ( fullpath , '<STR_LIT:r>' ) <EOL> try : <EOL> error = pickle . load ( fullpath_file ) <EOL> finally : <EOL> fullpath_file . close ( ) <EOL> except IOError : <EOL> continue <EOL> except EOFError : <EOL> continue <EOL> hash = hashlib . md5 ( error [ '<STR_LIT>' ] ) . hexdigest ( ) <EOL> if hash in delete_hashes : <EOL> os . unlink ( fullpath ) <EOL> else : <EOL> try : <EOL> hash2error [ hash ] [ '<STR_LIT:count>' ] += <NUM_LIT:1> <EOL> except KeyError : <EOL> error_lines = error [ '<STR_LIT>' ] . split ( "<STR_LIT:\n>" ) <EOL> last_line = error_lines [ - <NUM_LIT:2> ] if len ( error_lines ) > <NUM_LIT:1> else '<STR_LIT>' <EOL> error_causer = os . path . split ( error [ '<STR_LIT>' ] ) [ <NUM_LIT:1> ] <EOL> hash2error [ hash ] = dict ( count = <NUM_LIT:1> , pickel = error , <EOL> causer = error_causer , <EOL> last_line = last_line , <EOL> hash = hash , ticket = fn ) <EOL> decorated = [ ( x [ '<STR_LIT:count>' ] , x ) for x in hash2error . values ( ) ] <EOL> decorated . sort ( key = operator . itemgetter ( <NUM_LIT:0> ) , reverse = True ) <EOL> return dict ( errors = [ x [ <NUM_LIT:1> ] for x in decorated ] , app = app , method = method , db_ready = db_ready ) <EOL> elif method == '<STR_LIT>' : <EOL> errors_path = apath ( '<STR_LIT>' % app , r = request ) <EOL> tk_db , tk_table = get_ticket_storage ( app ) <EOL> delete_hashes = [ ] <EOL> for item in request . vars : <EOL> if item [ : <NUM_LIT:7> ] == '<STR_LIT>' : <EOL> delete_hashes . append ( item [ <NUM_LIT:7> : ] ) <EOL> hash2error = dict ( ) <EOL> for fn in tk_db ( tk_table . id > <NUM_LIT:0> ) . select ( ) : <EOL> try : <EOL> error = pickle . loads ( fn . ticket_data ) <EOL> hash = hashlib . md5 ( error [ '<STR_LIT>' ] ) . hexdigest ( ) <EOL> if hash in delete_hashes : <EOL> tk_db ( tk_table . id == fn . id ) . delete ( ) <EOL> tk_db . commit ( ) <EOL> else : <EOL> try : <EOL> hash2error [ hash ] [ '<STR_LIT:count>' ] += <NUM_LIT:1> <EOL> except KeyError : <EOL> error_lines = error [ '<STR_LIT>' ] . split ( "<STR_LIT:\n>" ) <EOL> last_line = error_lines [ - <NUM_LIT:2> ] <EOL> error_causer = os . path . split ( error [ '<STR_LIT>' ] ) [ <NUM_LIT:1> ] <EOL> hash2error [ hash ] = dict ( count = <NUM_LIT:1> , <EOL> pickel = error , causer = error_causer , <EOL> last_line = last_line , hash = hash , <EOL> ticket = fn . ticket_id ) <EOL> except AttributeError , e : <EOL> tk_db ( tk_table . id == fn . id ) . delete ( ) <EOL> tk_db . commit ( ) <EOL> decorated = [ ( x [ '<STR_LIT:count>' ] , x ) for x in hash2error . values ( ) ] <EOL> decorated . sort ( key = operator . itemgetter ( <NUM_LIT:0> ) , reverse = True ) <EOL> return dict ( errors = [ x [ <NUM_LIT:1> ] for x in decorated ] , app = app , <EOL> method = method , db_ready = db_ready ) <EOL> elif method == '<STR_LIT>' : <EOL> tk_db , tk_table = get_ticket_storage ( app ) <EOL> for item in request . vars : <EOL> if item [ : <NUM_LIT:7> ] == '<STR_LIT>' : <EOL> tk_db ( tk_table . ticket_id == item [ <NUM_LIT:7> : ] ) . delete ( ) <EOL> tk_db . commit ( ) <EOL> tickets_ = tk_db ( tk_table . id > <NUM_LIT:0> ) . select ( tk_table . ticket_id , <EOL> tk_table . created_datetime , <EOL> orderby = ~ tk_table . created_datetime ) <EOL> tickets = [ row . ticket_id for row in tickets_ ] <EOL> times = dict ( [ ( row . ticket_id , row . created_datetime ) for <EOL> row in tickets_ ] ) <EOL> return dict ( app = app , tickets = tickets , method = method , <EOL> times = times , db_ready = db_ready ) <EOL> else : <EOL> for item in request . vars : <EOL> if item [ : <NUM_LIT:7> ] == '<STR_LIT>' and ( not item == "<STR_LIT>" ) : <EOL> os . unlink ( apath ( '<STR_LIT>' % ( app , item [ <NUM_LIT:7> : ] ) , r = request ) ) <EOL> func = lambda p : os . stat ( apath ( '<STR_LIT>' % <EOL> ( app , p ) , r = request ) ) . st_mtime <EOL> tickets = sorted ( <EOL> listdir ( apath ( '<STR_LIT>' % app , r = request ) , '<STR_LIT>' ) , <EOL> key = func , <EOL> reverse = True ) <EOL> return dict ( app = app , tickets = tickets , method = method , db_ready = db_ready ) <EOL> def get_ticket_storage ( app ) : <EOL> private_folder = apath ( '<STR_LIT>' % app , r = request ) <EOL> ticket_file = os . path . join ( private_folder , '<STR_LIT>' ) <EOL> if os . path . exists ( ticket_file ) : <EOL> db_string = open ( ticket_file ) . read ( ) <EOL> db_string = db_string . strip ( ) . replace ( '<STR_LIT:\r>' , '<STR_LIT>' ) . replace ( '<STR_LIT:\n>' , '<STR_LIT>' ) <EOL> elif is_gae : <EOL> db_string = "<STR_LIT>" <EOL> else : <EOL> return False <EOL> tickets_table = '<STR_LIT>' <EOL> tablename = tickets_table + '<STR_LIT:_>' + app <EOL> db_path = apath ( '<STR_LIT>' % app , r = request ) <EOL> ticketsdb = DAL ( db_string , folder = db_path , auto_import = True ) <EOL> if not ticketsdb . get ( tablename ) : <EOL> table = ticketsdb . define_table ( <EOL> tablename , <EOL> Field ( '<STR_LIT>' , length = <NUM_LIT:100> ) , <EOL> Field ( '<STR_LIT>' , '<STR_LIT:text>' ) , <EOL> Field ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ) <EOL> return ticketsdb , ticketsdb . get ( tablename ) <EOL> def make_link ( path ) : <EOL> """<STR_LIT>""" <EOL> tryFile = path . replace ( '<STR_LIT:\\>' , '<STR_LIT:/>' ) <EOL> if os . path . isabs ( tryFile ) and os . path . isfile ( tryFile ) : <EOL> ( folder , filename ) = os . path . split ( tryFile ) <EOL> ( base , ext ) = os . path . splitext ( filename ) <EOL> app = get_app ( ) <EOL> editable = { '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT>' } <EOL> for key in editable . keys ( ) : <EOL> check_extension = folder . endswith ( "<STR_LIT>" % ( app , key ) ) <EOL> if ext . lower ( ) == editable [ key ] and check_extension : <EOL> return A ( '<STR_LIT:">' + tryFile + '<STR_LIT:">' , <EOL> _href = URL ( r = request , <EOL> f = '<STR_LIT>' % ( app , key , filename ) ) ) . xml ( ) <EOL> return '<STR_LIT>' <EOL> def make_links ( traceback ) : <EOL> """<STR_LIT>""" <EOL> lwords = traceback . split ( '<STR_LIT:">' ) <EOL> result = ( len ( lwords ) != <NUM_LIT:0> ) and lwords [ <NUM_LIT:0> ] or '<STR_LIT>' <EOL> i = <NUM_LIT:1> <EOL> while i < len ( lwords ) : <EOL> link = make_link ( lwords [ i ] ) <EOL> if link == '<STR_LIT>' : <EOL> result += '<STR_LIT:">' + lwords [ i ] <EOL> else : <EOL> result += link <EOL> if i + <NUM_LIT:1> < len ( lwords ) : <EOL> result += lwords [ i + <NUM_LIT:1> ] <EOL> i = i + <NUM_LIT:1> <EOL> i = i + <NUM_LIT:1> <EOL> return result <EOL> class TRACEBACK ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , text ) : <EOL> """<STR_LIT>""" <EOL> self . s = make_links ( CODE ( text ) . xml ( ) ) <EOL> def xml ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . s <EOL> def ticket ( ) : <EOL> """<STR_LIT>""" <EOL> if len ( request . args ) != <NUM_LIT:2> : <EOL> session . flash = T ( '<STR_LIT>' ) <EOL> redirect ( URL ( '<STR_LIT>' ) ) <EOL> app = get_app ( ) <EOL> myversion = request . env . web2py_version <EOL> ticket = request . args [ <NUM_LIT:1> ] <EOL> e = RestrictedError ( ) <EOL> e . load ( request , app , ticket ) <EOL> return dict ( app = app , <EOL> ticket = ticket , <EOL> output = e . output , <EOL> traceback = ( e . traceback and TRACEBACK ( e . traceback ) ) , <EOL> snapshot = e . snapshot , <EOL> code = e . code , <EOL> layer = e . layer , <EOL> myversion = myversion ) <EOL> def ticketdb ( ) : <EOL> """<STR_LIT>""" <EOL> if len ( request . args ) != <NUM_LIT:2> : <EOL> session . flash = T ( '<STR_LIT>' ) <EOL> redirect ( URL ( '<STR_LIT>' ) ) <EOL> app = get_app ( ) <EOL> myversion = request . env . web2py_version <EOL> ticket = request . args [ <NUM_LIT:1> ] <EOL> e = RestrictedError ( ) <EOL> request . tickets_db = get_ticket_storage ( app ) [ <NUM_LIT:0> ] <EOL> e . load ( request , app , ticket ) <EOL> response . view = '<STR_LIT>' <EOL> return dict ( app = app , <EOL> ticket = ticket , <EOL> output = e . output , <EOL> traceback = ( e . traceback and TRACEBACK ( e . traceback ) ) , <EOL> snapshot = e . snapshot , <EOL> code = e . code , <EOL> layer = e . layer , <EOL> myversion = myversion ) <EOL> def error ( ) : <EOL> """<STR_LIT>""" <EOL> raise RuntimeError ( '<STR_LIT>' ) <EOL> def update_languages ( ) : <EOL> """<STR_LIT>""" <EOL> app = get_app ( ) <EOL> update_all_languages ( apath ( app , r = request ) ) <EOL> session . flash = T ( '<STR_LIT>' ) <EOL> redirect ( URL ( '<STR_LIT>' , args = app , anchor = '<STR_LIT>' ) ) <EOL> def user ( ) : <EOL> if MULTI_USER_MODE : <EOL> if not db ( db . auth_user ) . count ( ) : <EOL> auth . settings . registration_requires_approval = False <EOL> return dict ( form = auth ( ) ) <EOL> else : <EOL> return dict ( form = T ( "<STR_LIT>" ) ) <EOL> def reload_routes ( ) : <EOL> """<STR_LIT>""" <EOL> import gluon . rewrite <EOL> gluon . rewrite . load ( ) <EOL> redirect ( URL ( '<STR_LIT>' ) ) <EOL> def manage_students ( ) : <EOL> if not ( MULTI_USER_MODE and is_manager ( ) ) : <EOL> session . flash = T ( '<STR_LIT>' ) <EOL> redirect ( URL ( '<STR_LIT>' ) ) <EOL> db . auth_user . registration_key . writable = True <EOL> grid = SQLFORM . grid ( db . auth_user ) <EOL> return locals ( ) <EOL> def bulk_register ( ) : <EOL> if not ( MULTI_USER_MODE and is_manager ( ) ) : <EOL> session . flash = T ( '<STR_LIT>' ) <EOL> redirect ( URL ( '<STR_LIT>' ) ) <EOL> form = SQLFORM . factory ( Field ( '<STR_LIT>' , '<STR_LIT:text>' ) ) <EOL> if form . process ( ) . accepted : <EOL> emails = [ x . strip ( ) for x in form . vars . emails . split ( '<STR_LIT:\n>' ) if x . strip ( ) ] <EOL> n = <NUM_LIT:0> <EOL> for email in emails : <EOL> if not db . auth_user ( email = email ) : <EOL> n += db . auth_user . insert ( email = email ) and <NUM_LIT:1> or <NUM_LIT:0> <EOL> session . flash = T ( '<STR_LIT>' , n ) <EOL> redirect ( URL ( '<STR_LIT>' ) ) <EOL> return locals ( ) <EOL> def git_pull ( ) : <EOL> """<STR_LIT>""" <EOL> app = get_app ( ) <EOL> if not have_git : <EOL> session . flash = GIT_MISSING <EOL> redirect ( URL ( '<STR_LIT>' ) ) <EOL> dialog = FORM . confirm ( T ( '<STR_LIT>' ) , <EOL> { T ( '<STR_LIT>' ) : URL ( '<STR_LIT>' ) } ) <EOL> if dialog . accepted : <EOL> try : <EOL> repo = git . Repo ( os . path . join ( apath ( r = request ) , app ) ) <EOL> origin = repo . remotes . origin <EOL> origin . fetch ( ) <EOL> origin . pull ( ) <EOL> session . flash = T ( "<STR_LIT>" ) <EOL> redirect ( URL ( '<STR_LIT>' ) ) <EOL> except git . CheckoutError : <EOL> session . flash = T ( "<STR_LIT>" ) <EOL> redirect ( URL ( '<STR_LIT>' ) ) <EOL> except git . UnmergedEntriesError : <EOL> session . flash = T ( "<STR_LIT>" ) <EOL> redirect ( URL ( '<STR_LIT>' ) ) <EOL> except git . GitCommandError : <EOL> session . flash = T ( <EOL> "<STR_LIT>" ) <EOL> redirect ( URL ( '<STR_LIT>' ) ) <EOL> except AssertionError : <EOL> session . flash = T ( "<STR_LIT>" ) <EOL> redirect ( URL ( '<STR_LIT>' ) ) <EOL> elif '<STR_LIT>' in request . vars : <EOL> redirect ( URL ( '<STR_LIT>' ) ) <EOL> return dict ( app = app , dialog = dialog ) <EOL> def git_push ( ) : <EOL> """<STR_LIT>""" <EOL> app = get_app ( ) <EOL> if not have_git : <EOL> session . flash = GIT_MISSING <EOL> redirect ( URL ( '<STR_LIT>' ) ) <EOL> form = SQLFORM . factory ( Field ( '<STR_LIT>' , requires = IS_NOT_EMPTY ( ) ) ) <EOL> form . element ( '<STR_LIT>' ) [ '<STR_LIT>' ] = T ( '<STR_LIT>' ) <EOL> form . add_button ( T ( '<STR_LIT>' ) , URL ( '<STR_LIT>' ) ) <EOL> form . process ( ) <EOL> if form . accepted : <EOL> try : <EOL> repo = git . Repo ( os . path . join ( apath ( r = request ) , app ) ) <EOL> index = repo . index <EOL> index . add ( [ apath ( r = request ) + app + '<STR_LIT>' ] ) <EOL> new_commit = index . commit ( form . vars . changelog ) <EOL> origin = repo . remotes . origin <EOL> origin . push ( ) <EOL> session . flash = T ( <EOL> "<STR_LIT>" ) <EOL> redirect ( URL ( '<STR_LIT>' ) ) <EOL> except git . UnmergedEntriesError : <EOL> session . flash = T ( "<STR_LIT>" ) <EOL> redirect ( URL ( '<STR_LIT>' ) ) <EOL> return dict ( app = app , form = form ) <EOL> def plugins ( ) : <EOL> app = request . args ( <NUM_LIT:0> ) <EOL> from serializers import loads_json <EOL> if not session . plugins : <EOL> try : <EOL> rawlist = urllib . urlopen ( "<STR_LIT>" + <EOL> "<STR_LIT>" + <EOL> "<STR_LIT>" ) . read ( ) <EOL> session . plugins = loads_json ( rawlist ) <EOL> except : <EOL> response . flash = T ( '<STR_LIT>' ) <EOL> session . plugins = [ ] <EOL> return dict ( plugins = session . plugins [ "<STR_LIT>" ] , app = request . args ( <NUM_LIT:0> ) ) <EOL> def install_plugin ( ) : <EOL> app = request . args ( <NUM_LIT:0> ) <EOL> source = request . vars . source <EOL> plugin = request . vars . plugin <EOL> if not ( source and app ) : <EOL> raise HTTP ( <NUM_LIT> , T ( "<STR_LIT>" ) ) <EOL> form = SQLFORM . factory ( ) <EOL> result = None <EOL> if form . process ( ) . accepted : <EOL> if "<STR_LIT>" in source : <EOL> filename = "<STR_LIT>" % source . split ( "<STR_LIT>" ) [ - <NUM_LIT:1> ] . split ( "<STR_LIT>" ) [ <NUM_LIT:0> ] <EOL> else : <EOL> filename = "<STR_LIT>" % cleanpath ( plugin ) <EOL> if plugin_install ( app , urllib . urlopen ( source ) , <EOL> request , filename ) : <EOL> session . flash = T ( '<STR_LIT>' , filename ) <EOL> else : <EOL> session . flash = T ( '<STR_LIT>' , filename ) <EOL> redirect ( URL ( f = "<STR_LIT>" , args = [ app , ] ) ) <EOL> return dict ( form = form , app = app , plugin = plugin , source = source ) </s>
