def app_create(app, request, force=False, key=None, info=False): """Create a copy of welcome.w2p (scaffolding) app Args: app(str): application name request: the global request object """ path = apath(app, request) if not os.path.exists(path): try: os.mkdir(path) except: if info: return False, traceback.format_exc(sys.exc_info) else: return False elif not force: if info: return False, "Application exists" else: return False try: w2p_unpack("welcome.w2p", path) for subfolder in [ "models", "views", "controllers", "databases", "modules", "cron", "errors", "sessions", "cache", "languages", "static", "private", "uploads", ]: subpath = os.path.join(path, subfolder) if not os.path.exists(subpath): os.mkdir(subpath) db = os.path.join(path, "models", "db.py") if os.path.exists(db): data = read_file(db) data = data.replace("<your secret key>", "sha512:" + (key or web2py_uuid())) write_file(db, data) if info: return True, None else: return True except: rmtree(path) if info: return False, traceback.format_exc(sys.exc_info) else: return False
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 app_create(app, request, force=False, key=None, info=False): """ Create a copy of welcome.w2p (scaffolding) app Parameters ---------- app: application name request: the global request object """ path = apath(app, request) if not os.path.exists(path): try: os.mkdir(path) except: if info: return False, traceback.format_exc(sys.exc_info) else: return False elif not force: if info: return False, "Application exists" else: return False try: w2p_unpack('welcome.w2p', path) for subfolder in [ 'models', 'views', 'controllers', 'databases', 'modules', 'cron', 'errors', 'sessions', 'cache', 'languages', 'static', 'private', 'uploads' ]: subpath = os.path.join(path, subfolder) if not os.path.exists(subpath): os.mkdir(subpath) db = os.path.join(path, 'models', 'db.py') if os.path.exists(db): data = read_file(db) data = data.replace('<your secret key>', 'sha512:' + (key or web2py_uuid())) write_file(db, data) if info: return True, None else: return True except: rmtree(path) if info: return False, traceback.format_exc(sys.exc_info) else: return False
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 app_create(app, request, force=False, key=None, info=False): """ Create a copy of welcome.w2p (scaffolding) app Parameters ---------- app: application name request: the global request object """ path = apath(app, request) if not os.path.exists(path): try: os.mkdir(path) except: if info: return False, traceback.format_exc(sys.exc_info) else: return False elif not force: if info: return False, "Application exists" else: return False try: w2p_unpack('welcome.w2p', path) for subfolder in [ 'models', 'views', 'controllers', 'databases', 'modules', 'cron', 'errors', 'sessions', 'cache', 'languages', 'static', 'private', 'uploads']: subpath = os.path.join(path, subfolder) if not os.path.exists(subpath): os.mkdir(subpath) db = os.path.join(path, 'models', 'db.py') if os.path.exists(db): data = read_file(db) data = data.replace('<your secret key>', 'sha512:' + (key or web2py_uuid())) write_file(db, data) if info: return True, None else: return True except: rmtree(path) if info: return False, traceback.format_exc(sys.exc_info) else: return False
def app_install(app, fobj, request, filename, overwrite=None): """ Installs an application: - Identifies file type by filename - Writes `fobj` contents to the `../deposit/` folder - Calls `w2p_unpack()` to do the job. Parameters ---------- app: new application name fobj: file object containing the application to be installed request: the global request object filename: original filename of the `fobj`, required to determine extension Returns ------- upname: name of the file where app is temporarily stored or `None` on failure """ did_mkdir = False if filename[-4:] == '.w2p': extension = 'w2p' elif filename[-7:] == '.tar.gz': extension = 'tar.gz' else: extension = 'tar' upname = apath('../deposit/%s.%s' % (app, extension), request) try: write_file(upname, fobj.read(), 'wb') path = apath(app, request) if not overwrite: os.mkdir(path) did_mkdir = True w2p_unpack(upname, path) if extension != 'tar': os.unlink(upname) fix_newlines(path) return upname except Exception: if did_mkdir: rmtree(path) return False
def app_install(app, fobj, request, filename, overwrite=None): """Installs an application: - Identifies file type by filename - Writes `fobj` contents to the `../deposit/` folder - Calls `w2p_unpack()` to do the job. Args: app(str): new application name fobj(obj): file object containing the application to be installed request: the global request object filename(str): original filename of the `fobj`, required to determine extension overwrite(bool): force overwrite of existing application Returns: name of the file where app is temporarily stored or `None` on failure """ did_mkdir = False if filename[-4:] == '.w2p': extension = 'w2p' elif filename[-7:] == '.tar.gz': extension = 'tar.gz' else: extension = 'tar' upname = apath('../deposit/%s.%s' % (app, extension), request) try: with open(upname, 'wb') as appfp: copyfileobj(fobj, appfp, 4194304) # 4 MB buffer path = apath(app, request) if not overwrite: os.mkdir(path) did_mkdir = True w2p_unpack(upname, path) if extension != 'tar': os.unlink(upname) fix_newlines(path) return upname except Exception: if did_mkdir: rmtree(path) return False
def app_install(app, fobj, request, filename, overwrite=None): """Installs an application: - Identifies file type by filename - Writes `fobj` contents to the `../deposit/` folder - Calls `w2p_unpack()` to do the job. Args: app(str): new application name fobj(obj): file object containing the application to be installed request: the global request object filename(str): original filename of the `fobj`, required to determine extension overwrite(bool): force overwrite of existing application Returns: name of the file where app is temporarily stored or `None` on failure """ did_mkdir = False if filename[-4:] == ".w2p": extension = "w2p" elif filename[-7:] == ".tar.gz": extension = "tar.gz" else: extension = "tar" upname = apath("../deposit/%s.%s" % (app, extension), request) try: write_file(upname, fobj.read(), "wb") path = apath(app, request) if not overwrite: os.mkdir(path) did_mkdir = True w2p_unpack(upname, path) if extension != "tar": os.unlink(upname) fix_newlines(path) return upname except Exception: if did_mkdir: rmtree(path) return False