def run(project=None, urlbase=None): path = project or '.' if not os.path.exists(path): raise IOError("%r does not exist" % path) urlbase = urlbase or 'http://example.com' # load project from luban.scaffolding.project import loadProject conf = os.path.join(path, 'conf.py') if not os.path.exists(conf): raise IOError("luban project configuration file %s does not exist" % conf) project = loadProject(conf) # add project pytree to python path pytree_container = os.path.join(path, project.pytree_container) import sys if pytree_container not in sys.path: sys.path.insert(0, pytree_container) # get sitemap name = project.name mod = __import__("%s.sitemap" % name, fromlist=['']) # create sitemap.xml urls = mod.urls xmlout = os.path.join(path, project.web_static, 'sitemap.xml') from luban.utils.sitemap import create create(urlbase, urls, xmlout) print("created sitemap at %s" % xmlout) return
def run(project=None): print("creating db...") # load the project path = project or '.' from luban.scaffolding.project import loadProject project = loadProject(path) # change into deployment directory dep_path = project.getDeploymentPath() os.chdir(dep_path) # pythonpath project.setPythonPath() # loadModels(project) # XXX: this is fixed to sqlalchemy for now from luban.db.sqlalchemy import createSession session = createSession() session.commit() import luban dburi = luban.app_config.db.uri print("create db at %s. cwd: %s" % (dburi, os.path.abspath('.'))) return
def run(workflow, project=None): # check if the workflow exists mod = 'luban.workflows.%s' % workflow try: __import__(mod, locals=locals(), globals=globals()) except ImportError: print("*** workflow %r does not exist.\n" % workflow) print_available_workflows() return project = project or '.' project = os.path.abspath(project) print("adding workflow %r to luban project %r" % (workflow, project)) # load the project from luban.scaffolding.project import loadProject path = project conf = os.path.join(path, 'conf.py') project = loadProject(conf) # update conf.py if necessary if 'luban.workflows' not in project.extensions: open(conf, 'a').write("\nextensions.append('luban.workflows')\n") # see if files already exist actor_file = os.path.join(path, project.pytree_container, project.actors_pkg.replace('.', '/'), workflow + '.py') workflow_file = os.path.join(path, project.pytree_container, project.workflows_pkg.replace('.', '/'), workflow + '.py') if os.path.exists(actor_file) or os.path.exists(workflow_file): print( "*** Cannot create workflow template because %s and/or %s already exist" % (actor_file, workflow_file)) return # actor import aokuang.workflows as awpkg awpkgpath = os.path.dirname(awpkg.__file__) actorsrc = os.path.join(awpkgpath, 'actors', workflow + '.py') workflowsrc = os.path.join(awpkgpath, 'workflows', workflow + '.py') if not os.path.exists(actorsrc) or not os.path.exists(workflowsrc): print("*** workflow template was not installed correctly.") print("*** missing %s or %s" % (actorsrc, workflowsrc)) return # patch the project directory. new version of luban may need # more files in the project directory. from luban.scaffolding.project.CreateProjectInFS import Renderer Renderer().render(project, project.root, onconflict='skip') shutil.copy(actorsrc, actor_file) print("created %s" % actor_file) shutil.copy(workflowsrc, workflow_file) print("created %s" % workflow_file) update_app_config(workflow, project) return
def run(project=None): path = project or '.' from luban.scaffolding.project import loadProject project = loadProject(path) pytreeroot = project.getPyTreeRoot() s = [] s.append('export PYTHONPATH="%s":${PYTHONPATH}' % pytreeroot) print('\n'.join(s)) return
def run(path, **kwds): if not os.path.exists(path): raise IOError("%r does not exist" % path) # sanity check for k in kwds: assert k in options continue # load project from luban.scaffolding.project import loadProject conf = os.path.join(path, 'conf.py') if not os.path.exists(conf): raise IOError("luban project configuration file %s does not exist" % conf) project = loadProject(conf) # update project if necessary updateProjectConfiguration(project, **kwds) # check if the port is avilable checkPort(project.port) # create a deployment deployment = project.deployment or 'cherrypy' from luban.scaffolding.project.deployment import createDeployment deployments_path = os.path.join(path, 'deployments') deployment_path = createDeployment(deployment, project, deployments_path) # wait a bit time.sleep(1) # start server class StartServer(threading.Thread): def run(self): os.chdir(deployment_path) optstr = ' '.join('--%s=%s' % (k, getattr(project, k)) for k in server_options) os.system('%s start %s' % (sys.executable, optstr)) # print ("\nYour interface could be running. use\n\n $ luban stop <project>\n\nif you need to stop it") return StartServer().start() # XXX: need better implementation # wait a second and start the browser port = project.port url = "http://localhost:%s" % port time.sleep(2) import webbrowser webbrowser.open(url) return
def run(project=None, **kwds): path = project or '.' if not os.path.exists(path): raise IOError("%r does not exist" % path) # load project from luban.scaffolding.project import loadProject conf = os.path.join(path, 'conf.py') if not os.path.exists(conf): raise IOError("luban project configuration file %s does not exist" % conf) project = loadProject(conf) print(project) return
def run(project=None, urlbase=None): path = project or '.' if not os.path.exists(path): raise IOError("%r does not exist" % path) urlbase = urlbase or 'http://example.com' # load project from luban.scaffolding.project import loadProject conf = os.path.join(path, 'conf.py') if not os.path.exists(conf): raise IOError("luban project configuration file %s does not exist" % conf) project = loadProject(conf) # add project pytree to python path pytree_container = os.path.join(path, project.pytree_container) import sys if pytree_container not in sys.path: sys.path.insert(0, pytree_container) # get sitemap module name = project.name mod = __import__("%s.sitemap" % name, fromlist=['']) # create snapshots from luban.controller.utils import getSnapshot urls = mod.urls # .. data store outdir = os.path.join(path, project.web_static, 'snapshots') if not os.path.exists(outdir): os.makedirs(outdir) for url in urls: html = getSnapshot(urlbase + '/' + url.location) html = html.decode() out = os.path.join(outdir, url.getFragmentHash()) open(out, 'w').write(html) print("created %s" % out) continue return
def test1(self): """luban.scaffolding.project.deployment.cherrypy""" outdir = 'deployments' import os os.chdir('testproj') # filename = "conf.py" from luban.scaffolding.project import loadProject project = loadProject(filename) # from luban.scaffolding.project.deployment import createDeployment createDeployment('cherrypy', project, outdir) return
def run(path, **kwds): if not os.path.exists(path): raise IOError("%r does not exist" % path) # load project info from luban.scaffolding.project import loadProject conf = os.path.join(path, 'conf.py') if not os.path.exists(conf): raise IOError("luban project configuration file %s does not exist" % conf) project = loadProject(conf) # deployment deployment = project.deployment or 'cherrypy' deployment_path = os.path.join(path, 'deployments', deployment) # stop server os.chdir(deployment_path) os.system('%s stop' % sys.executable) return
def run(path, **kwds): if not os.path.exists(path): raise IOError("%r does not exist" % path) # load project from luban.scaffolding.project import loadProject conf = os.path.join(path, 'conf.py') if not os.path.exists(conf): raise IOError("luban project configuration file %s does not exist" % conf) project = loadProject(conf) # update project if necessary updateProjectConfiguration(project, **kwds) # create a deployment deployment = project.deployment or 'cherrypy' from luban.scaffolding.project.deployment import createDeployment deployments_path = os.path.join(path, 'deployments') deployment_path = createDeployment(deployment, project, deployments_path) return