Exemple #1
0
 def save(path, reload_app=True):
     """Saves a file"""
     app_name = path.split("/")[0]
     path = safe_join(FOLDER, path) or abort()
     with open(path, "wb") as myfile:
         myfile.write(request.body.read())
     if reload_app:
         Reloader.import_app(app_name)
     return {"status": "success"}
Exemple #2
0
 def new_app():
     form = request.json
     # Directory for zipped assets
     assets_dir = os.path.join(os.path.dirname(py4web.__file__), "assets")
     app_name = form["name"]
     target_dir = safe_join(FOLDER, app_name)
     if form["type"] == "minimal":
         source = os.path.join(assets_dir, "py4web.app._minimal.zip")
         source_dir = safe_join(FOLDER, "_minimal")
         prepare_target_dir(form, target_dir)
         install_by_unzip_or_treecopy(source, source_dir, target_dir)
     elif form["type"] == "scaffold":
         source = os.path.join(assets_dir, "py4web.app._scaffold.zip")
         source_dir = safe_join(FOLDER, "_scaffold")
         prepare_target_dir(form, target_dir)
         install_by_unzip_or_treecopy(source, source_dir, target_dir)
     elif form["type"] == "web":
         prepare_target_dir(form, target_dir)
         source = form["source"]
         if source.endswith(".zip"):  # install from the web (zip file)
             res = requests.get(source)
             mem_zip = io.BytesIO(res.content)
             zfile = zipfile.ZipFile(mem_zip, "r")
             zfile.extractall(target_dir)
             zfile.close()
         elif source.endswith(".git"):  # clone from a git repo
             process = subprocess.Popen(
                 ["git", "clone", source, form["name"]], cwd=FOLDER
             )
             process.communicate()
             if process.returncode != 0:
                 abort(500)
     elif form["type"] == "upload":
         print(request.files.keys())
         prepare_target_dir(form, target_dir)
         source_stream = io.BytesIO(base64.b64decode(form["file"]))
         zfile = zipfile.ZipFile(source_stream, "r")
         zfile.extractall(target_dir)
         zfile.close()
     else:
         abort(500)
     settings = os.path.join(target_dir, "settings.py")
     if os.path.exists(settings):
         with open(settings) as fp:
             data = fp.read()
         data = data.replace("<session-secret-key>", str(uuid.uuid4()))
         with open(settings, "w") as fp:
             fp.write(data)
     Reloader.import_app(app_name)
     return {"status": "success"}
import os
import site
site.addsitedir(os.path.join(os.path.dirname(__file__), 'lib'))
from py4web.core import Reloader, bottle
os.environ['PY4WEB_DASHBOARD_MODE'] = 'demo'
os.environ['PY4WEB_SERVICE_DB_URI'] = 'sqlite:memory'
os.environ['PY4WEB_APPS_FOLDER'] = os.path.join(os.path.dirname(__file__),
                                                'apps')
os.environ['PY4WEB_SERVICE_FOLDER'] = os.path.join(os.path.dirname(__file__),
                                                   'apps/.service')
Reloader.import_apps()
app = bottle.default_app()
Exemple #4
0
 def checkout(project, commit):
     if not is_git_repo(project):
         raise HTTP(400)
     run("git stash", project)
     run("git checkout " + commit, project)
     Reloader.import_app(project)
Exemple #5
0
 def reload(name=None):
     """Reloads installed apps"""
     Reloader.import_app(name) if name else Reloader.import_apps()
     return "ok"
Exemple #6
0
 def reload():
     """Reloads installed apps"""
     Reloader.import_apps()
     return 'ok'
Exemple #7
0
def reload(name = None):
    """reloads installed apps"""
    Reloader.import_app(name) if name else Reloader.import_apps()
    return dict(flash = 'Done!')
Exemple #8
0
def reload():
    """reloads installed apps"""
    Reloader.import_apps()
    return dict(flash='Done!')