fixes to install and importing modules

This commit is contained in:
Rushabh Mehta 2011-07-22 18:50:34 +05:30
parent ccbb17684b
commit 6b1f5a422a
5 changed files with 44 additions and 20 deletions

View file

@ -55,14 +55,13 @@ class Installer:
Creates profile Administrator Creates profile Administrator
""" """
import webnotes import webnotes
from webnotes.modules.import_module import import_module from webnotes.modules import Module
from webnotes.modules.module_manager import reload_doc core = Module('core')
reload_doc('core','doctype','doctype') core.reload('doctype','doctype')
reload_doc('core','doctype','docfield') core.reload('doctype','docfield')
reload_doc('core','doctype','docperm') core.reload('doctype','docperm')
core.sync_all(verbose=1)
import_module('core')
def create_users(self): def create_users(self):
""" """

View file

@ -206,6 +206,10 @@ class Document:
# default name for table # default name for table
elif istable: elif istable:
self.name = make_autoname('#########', self.doctype) 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 # Validate Name
# --------------------------------------------------------------------------- # ---------------------------------------------------------------------------
@ -397,6 +401,10 @@ class Document:
def check_perm(self, verbose=0): def check_perm(self, verbose=0):
import webnotes import webnotes
# Admin has all permissions
if webnotes.session['user']=='Administrator':
return 1
# find roles with read access for this record at 0 # find roles with read access for this record at 0
self._get_perms() self._get_perms()
self._get_roles() self._get_roles()

View file

@ -142,16 +142,28 @@ class Module:
dt, dn = scrub_dt_dn(dt, dn) dt, dn = scrub_dt_dn(dt, dn)
self.get_file(dt, dn, dn + '.txt').sync() 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 import os
ret = [] ret = []
for walk_tuple in os.walk(self.get_path()): for walk_tuple in os.walk(self.get_path()):
for f in walk_tuple[2]: for f in walk_tuple[2]:
if f.split('.')[-1] in self.sync_types: if f.split('.')[-1] == extn:
self.get_file(os.path.join(walk_tuple[0], f)).sync() 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: class ModuleFile:
""" """
@ -187,7 +199,7 @@ class ModuleFile:
webnotes.conn.sql(""" webnotes.conn.sql("""
create table __file_timestamp ( create table __file_timestamp (
file_name varchar(180) primary key, file_name varchar(180) primary key,
tstamp varchar(40))""") tstamp varchar(40)) engine=InnoDB""")
webnotes.conn.begin() webnotes.conn.begin()
else: else:
raise e raise e
@ -241,7 +253,6 @@ class TxtModuleFile(ModuleFile):
import the doclist if new import the doclist if new
""" """
if self.is_new(): if self.is_new():
from webnotes.model.utils import peval_doclist from webnotes.model.utils import peval_doclist
doclist = peval_doclist(self.read()) doclist = peval_doclist(self.read())
if doclist: if doclist:
@ -262,13 +273,21 @@ class SqlModuleFile(ModuleFile):
def sync(self): def sync(self):
""" """
execute the sql if new execute the sql if new
The caller must either commit or rollback an open transaction
""" """
if self.is_new(): if self.is_new():
content = self.read() content = self.read()
# execute everything but selects # 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'): if content.strip().split()[0].lower() in ('insert','update','delete','create','alter','drop'):
webnotes.conn.sql(self.read()) webnotes.conn.sql(self.read())
# start a new transaction, as we have to update
# the timestamp table
webnotes.conn.begin()
self.update() self.update()
class JsModuleFile(ModuleFile): class JsModuleFile(ModuleFile):

View file

@ -71,6 +71,7 @@ class ModuleTest(unittest.TestCase):
""" """
Test sync all (rerun the sql file test calling sync_all) Test sync all (rerun the sql file test calling sync_all)
""" """
webnotes.conn.rollback() webnotes.conn.rollback()
webnotes.conn.sql("drop trigger if exists sandbox_trigger") webnotes.conn.sql("drop trigger if exists sandbox_trigger")
self.update_timestamp('doctype/sandbox/my_trigger.sql') self.update_timestamp('doctype/sandbox/my_trigger.sql')

View file

@ -85,7 +85,7 @@ class UpdateDocument:
# delete existing # delete existing
def delete_existing(self): def delete_existing(self):
from webnotes.model import delete_doc 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 # update modified timestamp
def update_modified(self): 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] 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): def run_on_update(self):
from webnotes.model.code import get_server_obj # no scripts for Module Def
so = get_server_obj(self.doc, self.doclist) pass
print str(dir(so))
if hasattr(so, 'on_update'):
so.on_update(from_update=1)
class UpdateDocTypeMapper(UpdateDocumentMerge): class UpdateDocTypeMapper(UpdateDocumentMerge):