浏览代码

install fresh frameworks and build 'core' now works

version-14
Rushabh Mehta 13 年前
父节点
当前提交
af599ac36a
共有 5 个文件被更改,包括 109 次插入151 次删除
  1. +18
    -4
      py/core/__init__.py
  2. +7
    -3
      py/webnotes/boot.py
  3. +70
    -139
      py/webnotes/install_lib/install.py
  4. +9
    -4
      py/webnotes/model/db_schema.py
  5. +5
    -1
      py/webnotes/utils/cache.py

+ 18
- 4
py/core/__init__.py 查看文件

@@ -21,8 +21,22 @@
#

install_docs = [
{'doctype':'Module Def', 'name': 'Core'},
{'doctype':'Role', 'name': 'Administrator'},
{'doctype':'Role', 'name': 'All'},
{'doctype':'Role', 'name': 'Guest'}
{'doctype':'Module Def', 'name': 'Core', 'module_name':'Core'},

# roles
{'doctype':'Role', 'role_name': 'Administrator'},
{'doctype':'Role', 'role_name': 'All'},
{'doctype':'Role', 'role_name': 'Guest'},
# profiles
{'doctype':'Profile', 'name':'Administrator', 'first_name':'Administrator',
'email':'updatethis@localhost', 'enabled':1},
{'doctype':'Profile', 'name':'Guest', 'first_name':'Guest',
'email':'doesnotmatter@localhost', 'enabled':1},
# userroles
{'doctype':'UserRole', 'parent': 'Administrator', 'role': 'Administrator',
'parenttype':'Profile', 'parentfield':'userroles'},
{'doctype':'UserRole', 'parent': 'Guest', 'role': 'Guest',
'parenttype':'Profile', 'parentfield':'userroles'}
]

+ 7
- 3
py/webnotes/boot.py 查看文件

@@ -63,9 +63,13 @@ def get_bootinfo():
bootinfo['docs'] = doclist
# plugins
import startup.event_handlers
if getattr(startup.event_handlers, 'boot_session'):
startup.event_handlers.boot_session(bootinfo)
try:
import startup.event_handlers
if getattr(startup.event_handlers, 'boot_session'):
startup.event_handlers.boot_session(bootinfo)

except ImportError:
pass

webnotes.conn.commit()


+ 70
- 139
py/webnotes/install_lib/install.py 查看文件

@@ -20,11 +20,11 @@
# OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#

# called from wnf.py
# lib/wnf.py --install [rootpassword] [dbname] [source]

import os,sys

#
# Main Installer Class
#
class Installer:
def __init__(self, root_login, root_password):

@@ -39,11 +39,59 @@ class Installer:
webnotes.session= {'user':'Administrator'}
self.dbman = DbManager(self.conn)

#
# run framework related cleanups
#
def framework_cleanups(self, target):
def import_from_db(self, target, source_path='', password = 'admin', verbose=0):
"""
a very simplified version, just for the time being..will eventually be deprecated once the framework stabilizes.
"""
import conf
# delete user (if exists)
self.dbman.delete_user(target)

# create user and db
self.dbman.create_user(target, conf.db_password)
if verbose: print "Created user %s" % target
# create a database
self.dbman.create_database(target)
if verbose: print "Created database %s" % target
# grant privileges to user
self.dbman.grant_all_privileges(target,target)
if verbose: print "Granted privileges to user %s and database %s" % (target, target)

# flush user privileges
self.dbman.flush_privileges()

self.conn.use(target)
# import in target
if verbose: print "Starting database import..."

# get the path of the sql file to import
source_given = True
if not source_path:
source_given = False
source_path = os.path.join(os.path.sep.join(os.path.abspath(webnotes.__file__).split(os.path.sep)[:-3]), 'data', 'Framework.sql')

self.dbman.restore_database(target, source_path, self.root_password)
if verbose: print "Imported from database %s" % source_path

# fresh app
if 'Framework.sql' in source_path:
from webnotes.model.sync import sync_core_doctypes
print "Building tables from core module..."
sync_core_doctypes()
self.install_core()

# framework cleanups
self.framework_cleanups(target)
if verbose: print "Ran framework startups on %s" % target
return target

def framework_cleanups(self, target):
"""create framework internal tables"""
import webnotes
self.create_sessions_table()
self.create_scheduler_log()
@@ -95,143 +143,26 @@ class Installer:
user VARCHAR(120),
country VARCHAR(120),
cache LONGTEXT)""")
def import_core_module(self):
"""
Imports the "Core" module from .txt file and creates
Creates profile Administrator
"""
import webnotes
from webnotes.modules import Module
core = Module('core')

core.reload('doctype','doctype')
core.reload('doctype','docfield')
core.reload('doctype','docperm')
core.sync_all(verbose=1)
def create_users(self):
"""
Create Administrator / Guest
"""
webnotes.conn.begin()
def install_core(self):
"""create install docs"""
import webnotes
from core import install_docs
from webnotes.model.doc import Document
p = Document('Profile')
p.name = p.first_name = 'Administrator'
p.email = 'admin@localhost'
p.save(new = 1)
ur = Document('UserRole')
ur.parent = 'Administrator'
ur.role = 'Administrator'
ur.parenttype = 'Profile'
ur.parentfield = 'userroles'
p.enabled = 1
ur.save(1)

p = Document('Profile')
p.name = p.first_name = 'Guest'
p.email = 'guest@localhost'
p.enabled = 1
p.save(new = 1)
ur = Document('UserRole')
ur.parent = 'Guest'
ur.role = 'Guest'
ur.parenttype = 'Profile'
ur.parentfield = 'userroles'
ur.save(1)
from webnotes.modules import reload_doc

webnotes.conn.commit()

def get_db_password(self, db_name):
"""
Get the db_password by method
"""
import conf
return conf.db_password

def import_from_db(self, target, source_path='', password = 'admin', verbose=0):
"""
a very simplified version, just for the time being..will eventually be deprecated once the framework stabilizes.
"""
webnotes.conn.begin()
# delete user (if exists)
self.dbman.delete_user(target)

# create user and db
self.dbman.create_user(target,self.get_db_password(target))
if verbose: print "Created user %s" % target
for data in install_docs:
d = Document(data['doctype'])
d.fields.update(data)
d.save()
print 'Created %(doctype)s %(name)s' % d.fields
# create a database
self.dbman.create_database(target)
if verbose: print "Created database %s" % target
# grant privileges to user
self.dbman.grant_all_privileges(target,target)
if verbose: print "Granted privileges to user %s and database %s" % (target, target)

# flush user privileges
self.dbman.flush_privileges()

self.conn.use(target)
# login page
reload_doc('core', 'page', 'login_page')
print 'Loaded Login Page'
# import in target
if verbose: print "Starting database import..."

# get the path of the sql file to import
source_given = True
if not source_path:
source_given = False
source_path = os.path.join(os.path.sep.join(os.path.abspath(webnotes.__file__).split(os.path.sep)[:-3]), 'data', 'Framework.sql')

self.dbman.restore_database(target, source_path, self.root_password)
if verbose: print "Imported from database %s" % source_path

if not source_given:
if verbose: print "Importing core module..."
self.import_core_module()
self.create_users()

# framework cleanups
self.framework_cleanups(target)
if verbose: print "Ran framework startups on %s" % target
return target

#
# load the options
#
def get_parser():
from optparse import OptionParser

parser = OptionParser(usage="usage: %prog [options] ROOT_LOGIN ROOT_PASSWORD DBNAME")
parser.add_option("-x", "--database-password", dest="password", default="admin", help="Optional: New password for the Framework Administrator, default 'admin'")
parser.add_option("-s", "--source", dest="source_path", default=None, help="Optional: Path of the sql file from which you want to import the instance, default 'data/Framework.sql'")
return parser


#
# execution here
#
if __name__=='__main__':

parser = get_parser()
(options, args) = parser.parse_args()
import webnotes
import webnotes.db

if len(args)==3:
root_login, root_password, db_name = args[0], args[1], args[2]
inst = Installer(root_login, root_password)
inst.import_from_db(db_name, source_path=options.source_path, \
password = options.password, verbose = 1)

webnotes.conn.commit()

print "Database created, please edit conf.py to get started"
else:
parser.print_help()

+ 9
- 4
py/webnotes/model/db_schema.py 查看文件

@@ -110,10 +110,15 @@ class DbTable:
get columns from docfields and custom fields
"""
fl = webnotes.conn.sql("SELECT * FROM tabDocField WHERE parent = '%s'" % self.doctype, as_dict = 1)
custom_fl = webnotes.conn.sql("""\
SELECT * FROM `tabCustom Field`
WHERE dt = %s AND docstatus < 2""", self.doctype, as_dict=1)
if custom_fl: fl += custom_fl
try:
custom_fl = webnotes.conn.sql("""\
SELECT * FROM `tabCustom Field`
WHERE dt = %s AND docstatus < 2""", self.doctype, as_dict=1)
if custom_fl: fl += custom_fl
except Exception, e:
if e.args[0]!=1146: # ignore no custom field
raise e

for f in fl:
self.columns[f['fieldname']] = DbColumn(self, f['fieldname'],


+ 5
- 1
py/webnotes/utils/cache.py 查看文件

@@ -62,7 +62,11 @@ class CacheItem:
def clear(self):
"""clear the item"""
webnotes.conn.sql("delete from __CacheItem where `key`=%s", self.key)
try:
webnotes.conn.sql("delete from __CacheItem where `key`=%s", self.key)
except Exception, e:
if e.args[0]!=1146: # ignore table not existing
raise e

def setup():
webnotes.conn.commit()


正在加载...
取消
保存