conf migration part 1

This commit is contained in:
Pratik Vyas 2013-09-21 15:13:18 +05:30
parent 63b370865e
commit 927a697ef6
16 changed files with 53 additions and 23 deletions

View file

@ -76,7 +76,7 @@ class DocType:
self.change_modified_of_parent()
make_module_and_roles(self.doclist)
import conf
from webnotes import conf
if (not webnotes.in_import) and getattr(conf, 'developer_mode', 0):
self.export_doc()
self.make_controller_template()

View file

@ -33,7 +33,7 @@ class DocType:
Writes the .txt for this page and if write_content is checked,
it will write out a .html file
"""
import conf
from webnotes import conf
from core.doctype.doctype.doctype import make_module_and_roles
make_module_and_roles(self.doclist, "Page Role")

View file

@ -52,7 +52,7 @@ class DocType:
def validate_max_users(self):
"""don't allow more than max users if set in conf"""
import conf
from webnotes import conf
# check only when enabling a user
if hasattr(conf, 'max_users') and self.doc.enabled and \
self.doc.name not in ["Administrator", "Guest"] and \

View file

@ -9,7 +9,7 @@ from webnotes import _
@webnotes.whitelist(allow_roles=["System Manager", "Administrator"])
def update_this_app():
import conf
from webnotes import conf
if hasattr(conf, "expires_on"):
return _("This feature is only applicable to self hosted instances")

View file

@ -9,6 +9,9 @@ from __future__ import unicode_literals
from werkzeug.local import Local
import os
import json
local = Local()
class _dict(dict):
@ -54,6 +57,7 @@ def load_translations(module, doctype, name):
# local-globals
conn = local("conn")
conf = local("conf")
form = form_dict = local("form_dict")
request = local("request")
request_method = local("request_method")
@ -68,13 +72,14 @@ message_log = local("message_log")
lang = local("lang")
def init():
def init(site=None):
local.error_log = []
local.message_log = []
local.debug_log = []
local.response = _dict({})
local.lang = "en"
local.request_method = request.method if request else None
local.conf = get_conf(site)
_memc = None
mute_emails = False
@ -515,4 +520,15 @@ def get_config():
update_config(webnotes.utils.get_path("app", "config.json"))
return _config
def get_conf(site):
import conf
from webnotes.utils import get_storage_base_path
conf = _dict(conf.__dict__)
if conf.sites_dir and site:
with open(os.path.join(get_storage_base_path(conf.sites_dir, site), 'site_config.json'), 'r') as f:
site_config = json.load(f)
site_config.update(conf.__dict__)
return _dict(site_config)
else:
return conf

View file

@ -1,4 +1,5 @@
import sys, os
import json
sys.path.insert(0, '.')
sys.path.insert(0, 'app')
@ -7,6 +8,7 @@ sys.path.insert(0, 'lib')
from werkzeug.wrappers import Request, Response
from werkzeug.local import LocalManager
from werkzeug.wsgi import SharedDataMiddleware
from webnotes import get_config
import mimetypes
import webnotes
@ -20,8 +22,8 @@ local_manager = LocalManager([webnotes.local])
def application(request):
webnotes.local.request = request
webnotes.init()
webnotes.init(site=request.host)
webnotes.local.form_dict = webnotes._dict({ k:v[0] if isinstance(v, (list, tuple)) else v \
for k, v in (request.form or request.args).iteritems() })
@ -54,6 +56,6 @@ if __name__ == '__main__':
if len(sys.argv) > 1:
port = sys.argv[1]
run_simple('localhost', int(port), application, use_reloader=True,
run_simple('0.0.0.0', int(port), application, use_reloader=True,
use_debugger=True, use_evalex=True)

View file

@ -6,7 +6,7 @@ import webnotes
import webnotes.db
import webnotes.utils
import webnotes.profile
import conf
from webnotes import conf
from webnotes.sessions import Session
@ -251,4 +251,4 @@ def _update_password(user, password):
@webnotes.whitelist()
def get_logged_user():
return webnotes.session.user
return webnotes.session.user

View file

@ -69,7 +69,7 @@ def get_bootinfo():
return bootinfo
def load_conf_settings(bootinfo):
import conf
from webnotes import conf
for key in ['developer_mode']:
if hasattr(conf, key): bootinfo[key] = getattr(conf, key)

View file

@ -7,7 +7,7 @@
from __future__ import unicode_literals
import MySQLdb
import webnotes
import conf
from webnotes import conf
import datetime
class Database:

View file

@ -2,7 +2,8 @@
# MIT License. See license.txt
from __future__ import unicode_literals
import memcache, conf
import memcache
from webnotes import conf
class MClient(memcache.Client):
"""memcache client that will automatically prefix conf.db_name"""
@ -23,4 +24,4 @@ class MClient(memcache.Client):
return val
def delete_value(self, key):
self.delete(self.n(key))
self.delete(self.n(key))

View file

@ -31,7 +31,7 @@ def reload_doc(args):
run_single(method = webnotes.modules.reload_doc, methodargs = args)
def run_single(patchmodule=None, method=None, methodargs=None, force=False):
import conf
from webnotes import conf
# don't write txt files
conf.developer_mode = 0
@ -77,6 +77,7 @@ def execute_patch(patchmodule, method=None, methodargs=None):
def add_to_patch_log(tb):
"""add error log to patches/patch.log"""
import conf, os
# TODO use get_storage_base_path
with open(os.path.join(os.path.dirname(conf.__file__), 'app', 'patches','patch.log'),'a') as patchlog:
patchlog.write('\n\n' + tb)

View file

@ -4,8 +4,11 @@
# util __init__.py
from __future__ import unicode_literals
from webnotes import conf
import webnotes
user_time_zone = None
user_format = None
current_date = None
@ -65,11 +68,11 @@ def validate_email_add(email_str):
def get_request_site_address(full_address=False):
"""get app url from request"""
import os, conf
import os
if hasattr(conf, "host_name"):
host_name = conf.host_name
else:
host_name = conf.host_name
if not host_name:
if webnotes.request:
protocol = 'HTTPS' in webnotes.get_request_header('SERVER_PROTOCOL', "") and 'https://' or 'http://'
host_name = protocol + webnotes.request.host
@ -815,6 +818,10 @@ def get_base_path():
import conf
import os
return os.path.dirname(os.path.abspath(conf.__file__))
def get_storage_base_path(sites_dir, hostname):
import os
return os.path.join(sites_dir, hostname)
def get_url(uri=None):
url = get_request_site_address()

View file

@ -70,6 +70,7 @@ class BackupGenerator:
self.backup_path_db = this_file_path
def zip_files(self):
# TODO use get_storage_base_path
files_path = os.path.join(os.path.dirname(os.path.abspath(conf.__file__)), 'public', 'files')
cmd_string = """tar -cf %s %s""" % (self.backup_path_files, files_path)
err, out = webnotes.utils.execute_in_shell(cmd_string)
@ -185,6 +186,7 @@ def get_backup_path():
global backup_path
if not backup_path:
import os, conf
# TODO Use get_storage_base_path
backup_path = os.path.join(os.path.dirname(os.path.abspath(conf.__file__)),
'public', 'backups')
return backup_path

View file

@ -18,7 +18,8 @@ def send(recipients=None, sender=None, doctype='Profile', email_field='email',
return cint(rdata.unsubscribed)
def check_bulk_limit(new_mails):
import conf, startup
import startup
from webnotes import conf
from webnotes.utils import nowdate
this_month = webnotes.conn.sql("""select count(*) from `tabBulk Email` where
month(creation)=month(%s)""" % nowdate())[0][0]

View file

@ -8,7 +8,7 @@ Allows easy adding of Attachments of "File" objects
"""
import webnotes
import conf
from webnotes import conf
from webnotes import msgprint
from webnotes.utils import cint

View file

@ -3,7 +3,7 @@
from __future__ import unicode_literals
import conf
from webnotes import conf
import webnotes
from webnotes import _
import webnotes.utils