Parcourir la source

[minor] fixes in installer, call init in connect, added destroy in webnotes

version-14
Anand Doshi il y a 11 ans
Parent
révision
128ddff24e
3 fichiers modifiés avec 26 ajouts et 7 suppressions
  1. +14
    -2
      webnotes/__init__.py
  2. +4
    -1
      webnotes/app.py
  3. +8
    -4
      webnotes/install_lib/install.py

+ 14
- 2
webnotes/__init__.py Voir le fichier

@@ -33,7 +33,7 @@ class _dict(dict):
return _dict(super(_dict, self).copy())

def __getattr__(self, key):
return webnotes.local.get("key", None)
return local.get("key", None)
def _(msg):
"""translate object in current lang, if exists"""
@@ -74,6 +74,9 @@ message_log = local("message_log")
lang = local("lang")

def init(site=None):
if getattr(local, "initialised", None):
return
local.error_log = []
local.message_log = []
local.debug_log = []
@@ -81,6 +84,14 @@ def init(site=None):
local.lang = "en"
local.request_method = request.method if request else None
local.conf = get_conf(site)
local.initialised = True
def destroy():
"""closes connection and releases werkzeug local"""
webnotes.conn.close()
from werkzeug.local import release_local
release_local(local)

_memc = None
mute_emails = False
@@ -184,8 +195,9 @@ def remove_file(path):
if e.args[0]!=2:
raise e
def connect(db_name=None, password=None):
def connect(db_name=None, password=None, site=None):
import webnotes.db
init(site=site)
local.conn = webnotes.db.Database(user=db_name, password=password)
local.session = _dict({'user':'Administrator'})
local.response = _dict()


+ 4
- 1
webnotes/app.py Voir le fichier

@@ -39,7 +39,10 @@ def application(request):
webnotes.handler.handle()
else:
webnotes.webutils.render(webnotes.request.path[1:])
if webnotes.conn:
webnotes.conn.close()
return webnotes._response

application = local_manager.make_middleware(application)


+ 8
- 4
webnotes/install_lib/install.py Voir le fichier

@@ -7,7 +7,8 @@
from __future__ import unicode_literals

import os, sys, json
import webnotes, conf
import webnotes
from webnotes import conf
import webnotes.db
import getpass
from webnotes.model.db_schema import DbManager
@@ -22,10 +23,11 @@ class Installer:
root_password = getpass.getpass("MySQL root password: ")
self.root_password = root_password
self.conn = webnotes.db.Database(user=root_login, password=root_password)
webnotes.conn=self.conn
webnotes.session= webnotes._dict({'user':'Administrator'})
webnotes.local.conn = self.conn
webnotes.local.session = webnotes._dict({'user':'Administrator'})
self.dbman = DbManager(self.conn)

def import_from_db(self, target, source_path='', password = 'admin', verbose=0):
@@ -73,6 +75,8 @@ class Installer:
# update admin password
self.create_auth_table()
self.update_admin_password(password)
self.conn.close()

return target


Chargement…
Annuler
Enregistrer