From 6b1f5a422a3cc58f876bc8338fce45a622ba6aae Mon Sep 17 00:00:00 2001 From: Rushabh Mehta Date: Fri, 22 Jul 2011 18:50:34 +0530 Subject: [PATCH] fixes to install and importing modules --- cgi-bin/webnotes/install_lib/install.py | 13 +++++----- cgi-bin/webnotes/model/doc.py | 8 ++++++ cgi-bin/webnotes/modules/__init__.py | 33 +++++++++++++++++++------ cgi-bin/webnotes/tests/modules.py | 1 + cgi-bin/webnotes/utils/transfer.py | 9 +++---- 5 files changed, 44 insertions(+), 20 deletions(-) diff --git a/cgi-bin/webnotes/install_lib/install.py b/cgi-bin/webnotes/install_lib/install.py index 2c74a88577..c270b2059c 100755 --- a/cgi-bin/webnotes/install_lib/install.py +++ b/cgi-bin/webnotes/install_lib/install.py @@ -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): """ diff --git a/cgi-bin/webnotes/model/doc.py b/cgi-bin/webnotes/model/doc.py index 117337f421..38e4896227 100755 --- a/cgi-bin/webnotes/model/doc.py +++ b/cgi-bin/webnotes/model/doc.py @@ -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() diff --git a/cgi-bin/webnotes/modules/__init__.py b/cgi-bin/webnotes/modules/__init__.py index 29c7371d7d..a3b151f66a 100644 --- a/cgi-bin/webnotes/modules/__init__.py +++ b/cgi-bin/webnotes/modules/__init__.py @@ -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): diff --git a/cgi-bin/webnotes/tests/modules.py b/cgi-bin/webnotes/tests/modules.py index 356912b6be..49a32e3312 100644 --- a/cgi-bin/webnotes/tests/modules.py +++ b/cgi-bin/webnotes/tests/modules.py @@ -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') diff --git a/cgi-bin/webnotes/utils/transfer.py b/cgi-bin/webnotes/utils/transfer.py index 18f0199bc7..d46eb87106 100644 --- a/cgi-bin/webnotes/utils/transfer.py +++ b/cgi-bin/webnotes/utils/transfer.py @@ -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):