From 6b763ebb416a2c5241b941f0ccb168bdf14f8c58 Mon Sep 17 00:00:00 2001 From: Pratik Vyas Date: Wed, 29 Jun 2011 15:33:38 +0530 Subject: [PATCH] Cleaned up export_module --- cgi-bin/webnotes/modules/__init__.py | 2 -- cgi-bin/webnotes/modules/export_module.py | 26 ++++++++++++++++++----- cgi-bin/webnotes/utils/__init__.py | 10 ++++++++- 3 files changed, 30 insertions(+), 8 deletions(-) diff --git a/cgi-bin/webnotes/modules/__init__.py b/cgi-bin/webnotes/modules/__init__.py index 62efefc36a..cbe182e97e 100644 --- a/cgi-bin/webnotes/modules/__init__.py +++ b/cgi-bin/webnotes/modules/__init__.py @@ -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') - - diff --git a/cgi-bin/webnotes/modules/export_module.py b/cgi-bin/webnotes/modules/export_module.py index 9465a2d036..696229830c 100644 --- a/cgi-bin/webnotes/modules/export_module.py +++ b/cgi-bin/webnotes/modules/export_module.py @@ -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 - diff --git a/cgi-bin/webnotes/utils/__init__.py b/cgi-bin/webnotes/utils/__init__.py index c40b9cab24..ff9b89cbd8 100644 --- a/cgi-bin/webnotes/utils/__init__.py +++ b/cgi-bin/webnotes/utils/__init__.py @@ -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'