Cleaned up export_module

This commit is contained in:
Pratik Vyas 2011-06-29 15:33:38 +05:30
parent 5315c1c0c8
commit 6b763ebb41
3 changed files with 30 additions and 8 deletions

View file

@ -85,5 +85,3 @@ def switch_module(dt, dn, to, frm=None, export=None):
for ext in ('py','js','html','css'):
os.system('cp %s %s')

View file

@ -1,18 +1,23 @@
from webnotes.modules import scrub, get_module_path
def export_to_files(record_list=[], record_module=None, verbose=0):
"""
Export record_list to files. record_list is a list of lists ([doctype],[docname] ) ,
"""
import webnotes.model.doc
module_doclist =[]
if record_list:
for record in record_list:
doclist = [d.fields for d in webnotes.model.doc.get(record[0], record[1])]
write_document_file(doclist, record_module)
return out
def create_init_py(modules_path, module, dt, dn):
"""
Creates __init__.py in the module directory structure
"""
import os
from webnotes.modules import scrub
def create_if_not_exists(path):
initpy = os.path.join(path, '__init__.py')
if not os.path.exists(initpy):
@ -23,6 +28,9 @@ def create_init_py(modules_path, module, dt, dn):
create_if_not_exists(os.path.join(modules_path, module, dt, dn))
def create_folder(module, dt, dn):
"""
Creates directories for module and their __init__.py
"""
import webnotes, os
# get module path by importing the module
@ -42,6 +50,9 @@ def create_folder(module, dt, dn):
return folder
def get_module_name(doclist, record_module=None):
"""
Returns the module-name of a doclist
"""
# module name
if doclist[0]['doctype'] == 'Module Def':
module = doclist[0]['name']
@ -55,10 +66,13 @@ def get_module_name(doclist, record_module=None):
return module
def write_document_file(doclist, record_module=None):
"""
Write a doclist to file, can optionally specify module name
"""
import os
from webnotes.utils import pprint_dict
module = get_module_name()
module = get_module_name(doclist, record_module)
# create the folder
code_type = doclist[0]['doctype'] in ['DocType','Page','Search Criteria']
@ -78,6 +92,9 @@ def write_document_file(doclist, record_module=None):
txtfile.close()
def clear_code_fields(doclist, folder, code_type):
"""
Removes code from the doc
"""
import os
import webnotes
@ -88,4 +105,3 @@ def clear_code_fields(doclist, folder, code_type):
if doclist[0].get(code_field[0]):
doclist[0][code_field[0]] = None

View file

@ -535,7 +535,15 @@ def send_error_report():
# pretty print a dict
# ==============================================================================
def pprint_dict(d, level=1):
def pprint_dict(d, level=1, no_blanks=True):
if no_blanks:
empty_keys = []
for key in d:
if d[key]=='' or d[key]==None:
# del d[key] raises runtime exception, using a workaround
empty_keys.append(key)
for key in empty_keys:
del d[key]
indent = ''
for i in range(0,level):
indent += '\t'