fixes to install and importing modules
This commit is contained in:
parent
ccbb17684b
commit
6b1f5a422a
5 changed files with 44 additions and 20 deletions
|
|
@ -55,14 +55,13 @@ class Installer:
|
|||
Creates profile Administrator
|
||||
"""
|
||||
import webnotes
|
||||
from webnotes.modules.import_module import import_module
|
||||
from webnotes.modules.module_manager import reload_doc
|
||||
from webnotes.modules import Module
|
||||
core = Module('core')
|
||||
|
||||
reload_doc('core','doctype','doctype')
|
||||
reload_doc('core','doctype','docfield')
|
||||
reload_doc('core','doctype','docperm')
|
||||
|
||||
import_module('core')
|
||||
core.reload('doctype','doctype')
|
||||
core.reload('doctype','docfield')
|
||||
core.reload('doctype','docperm')
|
||||
core.sync_all(verbose=1)
|
||||
|
||||
def create_users(self):
|
||||
"""
|
||||
|
|
|
|||
|
|
@ -206,6 +206,10 @@ class Document:
|
|||
# default name for table
|
||||
elif istable:
|
||||
self.name = make_autoname('#########', self.doctype)
|
||||
|
||||
# unable to determine a name, use a serial number!
|
||||
if not self.name:
|
||||
self.name = make_autoname('#########', self.doctype)
|
||||
|
||||
# Validate Name
|
||||
# ---------------------------------------------------------------------------
|
||||
|
|
@ -397,6 +401,10 @@ class Document:
|
|||
def check_perm(self, verbose=0):
|
||||
import webnotes
|
||||
|
||||
# Admin has all permissions
|
||||
if webnotes.session['user']=='Administrator':
|
||||
return 1
|
||||
|
||||
# find roles with read access for this record at 0
|
||||
self._get_perms()
|
||||
self._get_roles()
|
||||
|
|
|
|||
|
|
@ -142,16 +142,28 @@ class Module:
|
|||
dt, dn = scrub_dt_dn(dt, dn)
|
||||
self.get_file(dt, dn, dn + '.txt').sync()
|
||||
|
||||
def sync_all(self):
|
||||
def sync_all_of_type(self, extn, verbose=0):
|
||||
"""
|
||||
Walk through all the files in the modules and sync all files
|
||||
Walk through all the files in the modules and sync all files of
|
||||
a particular type
|
||||
"""
|
||||
import os
|
||||
ret = []
|
||||
for walk_tuple in os.walk(self.get_path()):
|
||||
for f in walk_tuple[2]:
|
||||
if f.split('.')[-1] in self.sync_types:
|
||||
self.get_file(os.path.join(walk_tuple[0], f)).sync()
|
||||
if f.split('.')[-1] == extn:
|
||||
path = os.path.relpath(os.path.join(walk_tuple[0], f), self.get_path())
|
||||
self.get_file(path).sync()
|
||||
if verbose:
|
||||
print 'complete: ' + path
|
||||
|
||||
def sync_all(self, verbose=0):
|
||||
"""
|
||||
Walk through all the files in the modules and sync all files
|
||||
"""
|
||||
import os
|
||||
self.sync_all_of_type('txt', verbose)
|
||||
self.sync_all_of_type('sql', verbose)
|
||||
|
||||
class ModuleFile:
|
||||
"""
|
||||
|
|
@ -187,7 +199,7 @@ class ModuleFile:
|
|||
webnotes.conn.sql("""
|
||||
create table __file_timestamp (
|
||||
file_name varchar(180) primary key,
|
||||
tstamp varchar(40))""")
|
||||
tstamp varchar(40)) engine=InnoDB""")
|
||||
webnotes.conn.begin()
|
||||
else:
|
||||
raise e
|
||||
|
|
@ -241,7 +253,6 @@ class TxtModuleFile(ModuleFile):
|
|||
import the doclist if new
|
||||
"""
|
||||
if self.is_new():
|
||||
|
||||
from webnotes.model.utils import peval_doclist
|
||||
doclist = peval_doclist(self.read())
|
||||
if doclist:
|
||||
|
|
@ -262,13 +273,21 @@ class SqlModuleFile(ModuleFile):
|
|||
def sync(self):
|
||||
"""
|
||||
execute the sql if new
|
||||
The caller must either commit or rollback an open transaction
|
||||
"""
|
||||
if self.is_new():
|
||||
content = self.read()
|
||||
|
||||
# execute everything but selects
|
||||
# theses are ddl statements, should either earlier
|
||||
# changes must be committed or rollbacked
|
||||
# by the caller
|
||||
if content.strip().split()[0].lower() in ('insert','update','delete','create','alter','drop'):
|
||||
webnotes.conn.sql(self.read())
|
||||
|
||||
|
||||
# start a new transaction, as we have to update
|
||||
# the timestamp table
|
||||
webnotes.conn.begin()
|
||||
self.update()
|
||||
|
||||
class JsModuleFile(ModuleFile):
|
||||
|
|
|
|||
|
|
@ -71,6 +71,7 @@ class ModuleTest(unittest.TestCase):
|
|||
"""
|
||||
Test sync all (rerun the sql file test calling sync_all)
|
||||
"""
|
||||
|
||||
webnotes.conn.rollback()
|
||||
webnotes.conn.sql("drop trigger if exists sandbox_trigger")
|
||||
self.update_timestamp('doctype/sandbox/my_trigger.sql')
|
||||
|
|
|
|||
|
|
@ -85,7 +85,7 @@ class UpdateDocument:
|
|||
# delete existing
|
||||
def delete_existing(self):
|
||||
from webnotes.model import delete_doc
|
||||
delete_doc(self.doc.doctype, self.doc.namem, force=1)
|
||||
delete_doc(self.doc.doctype, self.doc.name, force=1)
|
||||
|
||||
# update modified timestamp
|
||||
def update_modified(self):
|
||||
|
|
@ -293,11 +293,8 @@ class UpdateModuleDef(UpdateDocumentMerge):
|
|||
return webnotes.conn.sql("select module_seq, disabled, is_hidden from `tabModule Def` where name=%s", d.name, as_dict = 1)[0]
|
||||
|
||||
def run_on_update(self):
|
||||
from webnotes.model.code import get_server_obj
|
||||
so = get_server_obj(self.doc, self.doclist)
|
||||
print str(dir(so))
|
||||
if hasattr(so, 'on_update'):
|
||||
so.on_update(from_update=1)
|
||||
# no scripts for Module Def
|
||||
pass
|
||||
|
||||
|
||||
class UpdateDocTypeMapper(UpdateDocumentMerge):
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue