From cf23b335ca947a533ad8d53c16bd43c8b4cc5bd4 Mon Sep 17 00:00:00 2001 From: Pratik Vyas Date: Tue, 8 Oct 2013 16:58:59 +0530 Subject: [PATCH] add mysql and runserver utilites --- webnotes/app.py | 18 +++++++++++------- wnf.py | 16 ++++++++++++++++ 2 files changed, 27 insertions(+), 7 deletions(-) diff --git a/webnotes/app.py b/webnotes/app.py index 43bddf9dd9..1dc58d85ed 100644 --- a/webnotes/app.py +++ b/webnotes/app.py @@ -57,14 +57,18 @@ application = StaticDataMiddleware(application, { '/': 'public', }) -if __name__ == '__main__': - import sys +def serve(port=8000): from werkzeug.serving import run_simple - - port = 8000 - if len(sys.argv) > 1: - port = sys.argv[1] - run_simple('0.0.0.0', int(port), application, use_reloader=True, use_debugger=True, use_evalex=True) +if __name__ == '__main__': + import sys + + port = None + if len(sys.argv) > 1: + port = sys.argv[1] + + serve(port) + + diff --git a/wnf.py b/wnf.py index 62a439174c..0a62340a50 100755 --- a/wnf.py +++ b/wnf.py @@ -131,6 +131,9 @@ def setup_utilities(parser): help="Create new conf.py file") parser.add_argument("--set_admin_password", metavar='ADMIN-PASSWORD', nargs=1, help="Set administrator password") + parser.add_argument("--mysql", action="store_true", help="get mysql shell for a site") + parser.add_argument("--serve", action="store_true", help="Run development server") + parser.add_argument("--port", default=8000, type=int, help="port for development server") # clear parser.add_argument("--clear_web", default=False, action="store_true", @@ -519,6 +522,19 @@ def set_admin_password(admin_password, site=None): webnotes.conn.commit() webnotes.destroy() +@cmd +def mysql(site=None): + import webnotes + import commands, os + msq = commands.getoutput('which mysql') + webnotes.init(site=site) + os.execv(msq, [msq, '-u', webnotes.conf.db_name, '-p'+webnotes.conf.db_password, webnotes.conf.db_name]) + +@cmd +def serve(port=8000): + import webnotes.app + webnotes.app.serve(port=port) + def replace_code(start, txt1, txt2, extn, search=None, force=False): """replace all txt1 by txt2 in files with extension (extn)""" import webnotes.utils