2013-10-14 10:18:57 +00:00
|
|
|
# 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
|
|
|
|
"""
|
2013-10-14 13:29:16 +00:00
|
|
|
import os
|
|
|
|
from webnotes.utils import get_site_base_path
|
2013-10-14 10:18:57 +00:00
|
|
|
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'"""):
|
2013-11-11 12:31:37 +00:00
|
|
|
if script and script.strip():
|
2013-10-31 13:35:38 +00:00
|
|
|
try:
|
|
|
|
script = indent_using_tabs(script)
|
|
|
|
make_custom_server_script_file(dt, script)
|
|
|
|
except IOError, e:
|
|
|
|
if "already exists" not in repr(e):
|
|
|
|
raise
|
2013-10-14 10:18:57 +00:00
|
|
|
|
|
|
|
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
|