def state(): form = FORM( P( TAG.BUTTON("Switch to production ?", _type="submit", _name="prod", _value="prod")), P( TAG.BUTTON("Switch to development ?", _type="submit", _name="dev", _value="dev"))) if form.accepts(request.vars, session): if request.vars.prod: os.environ['PRODUCTION'] = 'True' global css_files global js_files compress = local_import('pack', reload=True) compress.process_css(css_files, request.folder, 'min.css') compress.process_js(js_files, request.folder, 'min.js') c = app_compile(request.application, request) if request.vars.dev: os.environ['PRODUCTION'] = '' remove_compiled_application(apath(request.application, r=request)) redirect(URL(r=request)) return dict(form=form)
def remove_compiled_app(): """ Remove the compiled application """ app = request.args[0] remove_compiled_application(apath(app)) session.flash = T('compiled application removed') redirect(URL(r=request, f='site'))
def test_compile(self): cwd = os.getcwd() app_path = os.path.join(cwd, 'applications', test_app_name) self.assertIsNone(compile_application(app_path)) remove_compiled_application(app_path) test_pack = os.path.join(cwd, "%s.w2p" % test_app_name) w2p_pack(test_pack, app_path, compiled=True, filenames=None) w2p_pack(test_pack, app_path, compiled=False, filenames=None) global test_unpack_dir test_unpack_dir = tempfile.mkdtemp() w2p_unpack(test_pack, test_unpack_dir)
def test_compile(self): #apps = ['welcome', 'admin', 'examples'] apps = ['welcome'] for appname in apps: appname_path = os.path.join(os.getcwd(), 'applications', appname) compile_application(appname_path) remove_compiled_application(appname_path) test_path = os.path.join(os.getcwd(), "%s.w2p" % appname) unpack_path = os.path.join(os.getcwd(), 'unpack', appname) w2p_pack(test_path, appname_path, compiled=True, filenames=None) w2p_pack(test_path, appname_path, compiled=False, filenames=None) w2p_unpack(test_path, unpack_path) return
def compile_app(): """ Compile the application """ app = request.args[0] folder = apath(app) try: compile_application(folder) session.flash = T('application compiled') except (Exception, RestrictedError), e: remove_compiled_application(folder) msg = 'cannot compile. there are errors in your app. run it to debug it' msg = T(msg) session.flash = msg
def app_compile(app, request, skip_failed_views=False): """Compiles the application Args: app(str): application name request: the global request object Returns: None if everything went ok, traceback text if errors are found """ from gluon.compileapp import compile_application, remove_compiled_application folder = apath(app, request) try: failed_views = compile_application(folder, skip_failed_views) return failed_views except (Exception, RestrictedError): tb = traceback.format_exc() remove_compiled_application(folder) return tb
def state(): form = FORM( P(TAG.BUTTON("Switch to production ?", _type="submit", _name="prod", _value="prod")), P(TAG.BUTTON("Switch to development ?", _type="submit", _name="dev", _value="dev")) ) if form.accepts(request.vars, session): if request.vars.prod: os.environ['PRODUCTION'] = 'True' global css_files global js_files compress = local_import('pack', reload=True) compress.process_css(css_files, request.folder, 'min.css') compress.process_js(js_files, request.folder, 'min.js') c = app_compile(request.application, request) if request.vars.dev: os.environ['PRODUCTION'] = '' remove_compiled_application(apath(request.application, r=request)) redirect(URL(r=request)) return dict(form=form)
def pull(self, version=None): """ Update the Eden code """ #if GITPYTHON: #else: #import s3log #s3log.S3Log.setup() #current.log.warning("GitPython not installed, will need to call out to Git via CLI") # Copy the current working directory to revert back to later cwd = os.getcwd() # Change to the Eden folder folder = current.request.folder os.chdir(os.path.join(cwd, folder)) # Remove old compiled code remove_compiled_application(folder) # Reset to remove any hotfixes subprocess.call(["git", "reset", "--hard", "HEAD"]) # Store the current version old_version = subprocess.check_output( ["git", "describe", "--always", "HEAD"]) self.old_version = old_version.strip() # Pull subprocess.call(["git", "pull"]) if version: # Checkout this version subprocess.call(["git", "checkout", version]) # Change back os.chdir(cwd)
def pull(self, version=None): """ Update the Eden code """ #if GITPYTHON: #else: #import s3log #s3log.S3Log.setup() #current.log.warning("GitPython not installed, will need to call out to Git via CLI") # Copy the current working directory to revert back to later cwd = os.getcwd() # Change to the Eden folder folder = current.request.folder os.chdir(os.path.join(cwd, folder)) # Remove old compiled code remove_compiled_application(folder) # Reset to remove any hotfixes subprocess.call(["git", "reset", "--hard", "HEAD"]) # Store the current version old_version = subprocess.check_output(["git", "describe", "--always", "HEAD"]) self.old_version = old_version.strip() # Pull subprocess.call(["git", "pull"]) if version: # Checkout this version subprocess.call(["git", "checkout", version]) # Change back os.chdir(cwd)
def widget(self): request=self.environment.request response=self.environment.response T=self.environment.T form=SQLFORM(self.db.innoinfo,1,showid=False,col3={ 'InnoCompiler':'The full path of your Inno compiler. e.g. C:\Program Files\Inno Setup 5\Compil32.exe', 'AppName':'e.g. My App', 'AppVerName':'e.g. My App 1.0', 'DefaultDirName':'No space allowed. E.g. {sd}\MY_COMPANY\MY_APP', 'DisableDirPage':'You might not want users to choose a directory that might break your app.',}) if form.accepts(request,keepvalues=True): try: compile_application(request.folder) except (Exception, RestrictedError), e: response.flash = T('cannot compile. there are errors in your app. run it to debug it') else: codecs.open(os.path.join(request.folder,'cache','license.inno'),'w',self.InnoEncoding).write( codecs.open(os.path.join(request.folder,'license'),'r','utf8').read()) codecs.open(os.path.join(request.folder,'cache','about.inno'),'w',self.InnoEncoding).write( codecs.open(os.path.join(request.folder,'about'),'r','utf8').read()) open(os.path.join(request.folder,'cache','default.py'),'w').write(''' def index(): redirect(URL(a='%s',c='default',f='index')) # Use this file to override the webcome/controllers/default.py '''.strip()%request.application) data={'application':request.application} data.update(request.vars) open(os.path.join(request.folder,'cache','setup.iss'),'wb').write(self.template%data) ret=os.system('"%s"/cc applications\%s\cache\setup.iss' %(request.vars.InnoCompiler,request.application)) if ret: response.flash=T('Inno Compile Error: %d'%ret) else: response.flash = T('application compiled') response.headers['Content-disposition']="attachment;filename=%s_setup.exe"%request.application return response.stream(open(os.path.join(request.env.web2py_path, 'Output','setup.exe'),'rb'),chunk_size=4096) finally: remove_compiled_application(request.folder)
'wb').write(self.template % data) ret = os.system( '"%s"/cc applications\%s\cache\setup.iss' % (request.vars.InnoCompiler, request.application)) if ret: response.flash = T('Inno Compile Error: %d' % ret) else: response.flash = T('application compiled') response.headers[ 'Content-disposition'] = "attachment;filename=%s_setup.exe" % request.application return response.stream(open( os.path.join(request.env.web2py_path, 'Output', 'setup.exe'), 'rb'), chunk_size=4096) finally: remove_compiled_application(request.folder) return form class InnoAndHstart(Inno): def __init__(self, environment, **kwargs): logging.warn( 'This installer is partially based on hstart.exe (http://www.ntwind.com/software/utilities/hstart.html). You need to make sure you have the permission to redistribute it.' ) self.TEMPLATE += '\r%s\r' % 'Source: "applications\inno\static\hstart.exe"; DestDir: "{app}"; Flags: ignoreversion' self.TEMPLATE_RUN = r''' [Icons] Name: "{group}\%(AppName)s (with Console)"; Filename: "{app}\web2py.exe"; Parameters: "-i 0.0.0.0 -a ""<recycle>"""; WorkingDir: "{app}"; IconFilename: "{app}\applications\%(application)s\static\logo.ico" Name: "{group}\%(AppName)s"; Filename: "{app}\hstart.exe"; Parameters: "%(param)s"; WorkingDir: "{app}"; IconFilename: "{app}\applications\%(application)s\static\logo.ico" Name: "{commondesktop}\%(AppName)s"; Filename: "{app}\hstart.exe"; Parameters: "%(param)s"; Tasks: desktopicon; WorkingDir: "{app}"; IconFilename: "{app}\applications\%(application)s\static\logo.ico" Name: "{group}\Uninstall %(AppName)s"; Filename: "{uninstallexe}"
def test_index_compiled(self): appname_path = os.path.join(os.getcwd(), 'applications', 'welcome') compile_application(appname_path) self._test_index() remove_compiled_application(appname_path)
old_scheduler = os.path.join(w2p_folder, 'gluon', 'scheduler.py') olddb = os.path.join(w2p_folder, 'applications', 'w2p_tvseries', 'databases', 'storage_scheduler.db') tablefiles = os.path.join(w2p_folder, 'applications', 'w2p_tvseries', 'databases', '*scheduler_*.table') todelete = glob.glob(tablefiles) + [olddb] for todel in todelete: if os.path.isfile(todel): try: os.unlink(todel) except: pass shutil.copy(new_scheduler, old_scheduler) print ' INFO: new scheduler in place' if raw_input("Q: Let's create/migrate our database.... ([Y]/n)?").lower() in ['y', 'yes']: remove_compiled_application(os.path.join(w2p_folder, 'applications', 'w2p_tvseries')) model_file = os.path.join(w2p_folder, 'applications', 'w2p_tvseries', 'models', 'db.py') print ' INFO: setting migrate to True, just to be sure' with open(model_file) as g: content = g.read() content = content.replace("MIGRATE = False", "MIGRATE = True") content = content.replace("LAZY_TABLES = True", "LAZY_TABLES = False") with open(model_file, 'w') as g: g.write(content) run('w2p_tvseries/manage/stop_operations') print ' INFO: migration occurred, setting migrate to False' with open(model_file) as g: content = g.read().replace("MIGRATE = True", "MIGRATE = False") content = content.replace("LAZY_TABLES = False", "LAZY_TABLES = True")