From 6bc48070a1c4bcda34ada8f9f262bfd3a2bced0c Mon Sep 17 00:00:00 2001 From: Anand Doshi Date: Mon, 14 Oct 2013 15:48:57 +0530 Subject: [PATCH] Moved Custom Server Scripts to custom_scripts/doctype_name.py --- .../p05_server_custom_script_to_file.py | 35 +++++++++++++++++++ patches/patch_list.py | 1 + 2 files changed, 36 insertions(+) create mode 100644 patches/october_2013/p05_server_custom_script_to_file.py diff --git a/patches/october_2013/p05_server_custom_script_to_file.py b/patches/october_2013/p05_server_custom_script_to_file.py new file mode 100644 index 0000000000..93cfa346ef --- /dev/null +++ b/patches/october_2013/p05_server_custom_script_to_file.py @@ -0,0 +1,35 @@ +# Copyright (c) 2013, Web Notes Technologies Pvt. Ltd. +# License: GNU General Public License v3. See license.txt + +from __future__ import unicode_literals +import webnotes + +def execute(): + """ + Assuming that some kind of indentation exists: + - Find indentation of server custom script + - replace indentation with tabs + - Add line: + class CustomDocType(DocType): + - Add tab indented code after this line + - Write to file + - Delete custom script record + """ + from core.doctype.custom_script.custom_script import make_custom_server_script_file + for name, dt, script in webnotes.conn.sql("""select name, dt, script from `tabCustom Script` + where script_type='Server'"""): + if script.strip(): + script = indent_using_tabs(script) + make_custom_server_script_file(dt, script) + webnotes.delete_doc("Custom Script", name) + +def indent_using_tabs(script): + for line in script.split("\n"): + try: + indentation_used = line[:line.index("def ")] + script = script.replace(indentation_used, "\t") + break + except ValueError: + pass + + return script \ No newline at end of file diff --git a/patches/patch_list.py b/patches/patch_list.py index 92dd52742c..8a79155a51 100644 --- a/patches/patch_list.py +++ b/patches/patch_list.py @@ -225,4 +225,5 @@ patch_list = [ "patches.october_2013.p03_crm_update_status", "execute:webnotes.delete_doc('DocType', 'Setup Control')", "patches.october_2013.p04_wsgi_migration", + "patches.october_2013.p05_server_custom_script_to_file", ] \ No newline at end of file