def read(self, do_execute=None): """ Return the file content, if dynamic, execute it """ self.load_content() if do_execute and self.content.startswith('#!python'): from webnotes.model.code import execute self.content = execute(self.content) return self.content
def read(self, do_execute = None): """ Return the file content, if dynamic, execute it """ self.load_content() if do_execute and self.content.startswith('#!python'): from webnotes.model.code import execute self.content = execute(self.content) return self.content
def process_content(self, doc): """ Put in template and generate dynamic if starts with #!python """ template = self.get_template(doc.template) content = '' # eval content if doc.content and doc.content.startswith('#!python'): from webnotes.model.code import execute content = template % {'content': execute(doc.content).get('content')} else: content = template % {'content': doc.content or ''} doc.__content = content
def run_script(self, script): try: self.connect(ac_name = self.ac_name) webnotes.conn = self.conn from webnotes.model import code self.conn.sql("start transaction") sc = code.execute(script) self.conn.sql("commit") print sc self.close() except Exception, e: print webnotes.utils.getTraceback() self.conn.sql("rollback") self.close() raise e
def process_content(self, doc): """ Put in template and generate dynamic if starts with #!python """ template = self.get_template(doc.template) content = '' # eval content if doc.content and doc.content.startswith('#!python'): from webnotes.model.code import execute content = template % { 'content': execute(doc.content).get('content') } else: content = template % {'content': doc.content or ''} doc.__content = content
ret = {} try: patch_list, ret = get_patch_list(modules, record_list, ret) except Exception, e: if e.args[0]==1146: return 'No table Patch' else: raise e for d in patch_list: try: if not webnotes.conn.in_transaction: webnotes.conn.sql("START TRANSACTION") #print 'Patch: ' + d[0] ret_msg = code.execute(d[1]) webnotes.conn.sql("update tabPatch set status = 'Executed' where name = %s", d[0]) webnotes.conn.sql("COMMIT") except Exception, e: ret_msg = e #finally: #Only works on python 2.5+ ret[d[0]] = ret_msg return ret # ============================================================================= # Get patch list # ============================================================================= def get_patch_list(modules, record_list, ret): import webnotes
def test_execute(self): code.execute("import sys;sys.path.append('/home/')") assert ('/home/' in sys.path)