def pack(target, sources, no_compress): from cStringIO import StringIO outtype, outtxt = target.split(".")[-1], '' jsm = JavascriptMinify() for f in sources: suffix = None if ':' in f: f, suffix = f.split(':') if not os.path.exists(f) or os.path.isdir(f): continue timestamps[f] = os.path.getmtime(f) try: with open(f, 'r') as sourcefile: data = unicode(sourcefile.read(), 'utf-8', errors='ignore') if outtype=="js" and (not no_compress) and suffix!="concat" and (".min." not in f): tmpin, tmpout = StringIO(data.encode('utf-8')), StringIO() jsm.minify(tmpin, tmpout) outtxt += unicode(tmpout.getvalue() or '', 'utf-8').strip('\n') + ';' else: outtxt += ('\n/*\n *\t%s\n */' % f) outtxt += '\n' + data + '\n' except Exception, e: print "--Error in:" + f + "--" print webnotes.get_traceback()
def execute_patch(patchmodule, method=None, methodargs=None): """execute the patch""" success = False block_user(True) webnotes.conn.begin() try: log("Executing %s in %s" % (patchmodule or str(methodargs), webnotes.conn.cur_db_name)) if patchmodule: if patchmodule.startswith("execute:"): exec patchmodule.split("execute:")[1] in globals() else: webnotes.get_attr(patchmodule + ".execute")() update_patch_log(patchmodule) elif method: method(**methodargs) webnotes.conn.commit() success = True except Exception, e: webnotes.conn.rollback() tb = webnotes.get_traceback() log(tb) import os if webnotes.request: add_to_patch_log(tb)
def validate_parent(parent_list, parenttype, ret, error): if parent_list: parent_list = list(set(parent_list)) for p in parent_list: try: obj = webnotes.bean(parenttype, p) obj.run_method("validate") obj.run_method("on_update") except Exception, e: error = True ret.append('Validation Error for %s %s: %s' % (parenttype, p, cstr(e))) webnotes.errprint(webnotes.get_traceback())
def trigger(method): """trigger method in startup.schedule_handler""" traceback = "" for scheduler_event in webnotes.get_hooks().scheduler_event: event_name, handler = scheduler_event.split(":") if method == event_name: try: webnotes.get_attr(handler)() webnotes.conn.commit() except Exception: traceback += log("Method: {method}, Handler: {handler}".format(method=method, handler=handler)) traceback += log(webnotes.get_traceback()) webnotes.conn.rollback() return traceback or "ok"
def delete_items(): """delete selected items""" import json from webnotes.model.code import get_obj il = json.loads(webnotes.form_dict.get('items')) doctype = webnotes.form_dict.get('doctype') for d in il: try: dt_obj = get_obj(doctype, d) if hasattr(dt_obj, 'on_trash'): dt_obj.on_trash() webnotes.delete_doc(doctype, d) except Exception, e: webnotes.errprint(webnotes.get_traceback()) pass
def log(method, message=None): """log error in patch_log""" message = webnotes.utils.cstr(message) + "\n" if message else "" message += webnotes.get_traceback() if not (webnotes.conn and webnotes.conn._conn): webnotes.connect() webnotes.conn.rollback() webnotes.conn.begin() d = webnotes.doc("Scheduler Log") d.method = method d.error = message d.save() webnotes.conn.commit() return message
doc.parentfield = parentfield doc.save() ret.append('Inserted row for %s at #%s' % (getlink(parenttype, doc.parent), unicode(doc.idx))) parent_list.append(doc.parent) else: ret.append(import_doc(doclist[0], doctype, overwrite, row_idx, submit_after_import, ignore_links)) except Exception, e: error = True if bean: webnotes.errprint(bean.doclist) err_msg = webnotes.local.message_log and "<br>".join(webnotes.local.message_log) or cstr(e) ret.append('Error for row (#%d) %s : %s' % (row_idx + 1, len(row)>1 and row[1] or "", err_msg)) webnotes.errprint(webnotes.get_traceback()) ret, error = validate_parent(parent_list, parenttype, ret, error) if error: webnotes.conn.rollback() else: webnotes.conn.commit() webnotes.flags.mute_emails = False return {"messages": ret, "error": error} def validate_parent(parent_list, parenttype, ret, error): if parent_list: parent_list = list(set(parent_list))
def get_context(context): error_context = {"error": webnotes.get_traceback()} error_context.update(context) return render_blocks(error_context)