示例#1
0
def write_file(fid, content):
    import os, webnotes.defs

    # test size
    max_file_size = 1000000
    if hasattr(webnotes.defs, 'max_file_size'):
        max_file_size = webnotes.defs.max_file_size

    if len(content) > max_file_size:
        raise Exception, 'Maximum File Limit (%s MB) Crossed' % (int(
            max_file_size / 1000000))

    # no slashes
    fid = fid.replace('/', '-')

    # save to a folder (not accessible to public)
    folder = webnotes.get_files_path()

    # create account folder (if not exists)
    webnotes.create_folder(folder)

    # write the file
    file = open(os.path.join(folder, fid), 'w+')
    file.write(content)
    file.close()
示例#2
0
def write_document_file(doclist, record_module=None):
	import os
	import webnotes
	import webnotes.defs

	global updated_modules

	# module name
	if doclist[0]['doctype'] == 'Module Def':
		module = doclist[0]['name']
	elif doclist[0]['doctype']=='Control Panel':
		module = 'System'
	elif record_module:
		module = record_module
	else:
		module = doclist[0]['module']

	updated_modules.append(module)

	# create the folder
	folder = os.path.join(webnotes.defs.modules_path, module, doclist[0]['doctype'], doclist[0]['name'].replace('/', '-'))
	
	webnotes.create_folder(folder)

	# separate code files
	separate_code_files(doclist, folder)
		
	# write the data file
	txtfile = open(os.path.join(folder, doclist[0]['name'].replace('/', '-')+'.txt'),'w+')
	txtfile.write(str(doclist))
	txtfile.close()
def write_file(content, files_path):
    """write file to disk with a random name (to compare)"""
    # create account folder (if not exists)
    webnotes.create_folder(files_path)
    fname = os.path.join(files_path, webnotes.generate_hash())

    # write the file
    with open(fname, 'w+') as f:
        f.write(content)

    return fname
def write_file(content):
	"""write file to disk with a random name (to compare)"""
	# create account folder (if not exists)
	webnotes.create_folder(get_files_path())
	fname = os.path.join(get_files_path(), webnotes.generate_hash())

	# write the file
	with open(fname, 'w+') as f:
		f.write(content)

	return fname	
示例#5
0
def make_demo_on_login_script():
	import shutil
	import webnotes.plugins
	custom_script_path = webnotes.plugins.get_path("Core", "DocType", "Control Panel")
	webnotes.create_folder(os.path.dirname(custom_script_path))
	
	shutil.copyfile(os.path.join(os.path.dirname(__file__), "demo_control_panel.py"), custom_script_path)
	
	cp = webnotes.bean("Control Panel")
	cp.doc.custom_startup_code = """wn.ui.toolbar.show_banner('You are using ERPNino Demo. To start your own ERPNino Trial, <a href="https://erpnext.com/pricing-and-signup" target="_blank">click here</a>')"""
	cp.save()

	webnotes.conn.commit()
示例#6
0
def create_folder(module, dt, dn, create_init):
	module_path = get_module_path(module)

	dt, dn = scrub_dt_dn(dt, dn)
	
	# create folder
	folder = os.path.join(module_path, dt, dn)
	
	webnotes.create_folder(folder)
	
	# create init_py_files
	if create_init:
		create_init_py(module_path, dt, dn)
	
	return folder
def create_folder(module, dt, dn, code_type):
    # get module path by importing the module
    module_path = get_module_path(module)

    dt, dn = scrub_dt_dn(dt, dn)

    # create folder
    folder = os.path.join(module_path, dt, dn)

    webnotes.create_folder(folder)

    # create init_py_files
    if code_type:
        create_init_py(module_path, dt, dn)

    return folder
示例#8
0
def make_demo_on_login_script():
    import shutil
    import webnotes.plugins
    custom_script_path = webnotes.plugins.get_path("Core", "DocType",
                                                   "Control Panel")
    webnotes.create_folder(os.path.dirname(custom_script_path))

    shutil.copyfile(
        os.path.join(os.path.dirname(__file__), "demo_control_panel.py"),
        custom_script_path)

    cp = webnotes.bean("Control Panel")
    cp.doc.custom_startup_code = """wn.ui.toolbar.show_banner('You are using ERPNext Demo. To start your own ERPNext Trial, <a href="https://erpnext.com/pricing-and-signup" target="_blank">click here</a>')"""
    cp.save()

    webnotes.conn.commit()
示例#9
0
def create_folder(module, dt, dn, code_type):
	# get module path by importing the module
	module_path = get_module_path(module)

	dt, dn = scrub_dt_dn(dt, dn)
	
	# create folder
	folder = os.path.join(module_path, dt, dn)
	
	webnotes.create_folder(folder)
	
	# create init_py_files
	if code_type:
		create_init_py(module_path, dt, dn)
	
	return folder
示例#10
0
def create_folder(module, dt, dn):
	import webnotes, os
	
	# get module path by importing the module
	modules_path = get_module_path(module)
			
	code_type = dt in ['DocType', 'Page', 'Search Criteria']
	
	# create folder
	folder = os.path.join(modules_path, code_type and scrub(dt) or dt, code_type and scrub(dn) or dn)
	
	webnotes.create_folder(folder)
	
	# create init_py_files
	if code_type:
		create_init_py(modules_path, scrub(dt), scrub(dn))
	
	return folder
示例#11
0
def create_folder(module, dt, dn, code_type, plugin=None):
	if plugin:
		module_path = os.path.join(get_plugin_path(plugin), scrub(module))
	else:
		module_path = get_module_path(module)

	dt, dn = scrub_dt_dn(dt, dn)
	
	# create folder
	folder = os.path.join(module_path, dt, dn)
	
	webnotes.create_folder(folder)
	
	# create init_py_files
	if code_type:
		create_init_py(module_path, dt, dn)
	
	return folder
示例#12
0
def create_folder(module, dt, dn, code_type, plugin=None):
    if plugin:
        module_path = os.path.join(get_plugin_path(plugin), scrub(module))
    else:
        module_path = get_module_path(module)

    dt, dn = scrub_dt_dn(dt, dn)

    # create folder
    folder = os.path.join(module_path, dt, dn)

    webnotes.create_folder(folder)

    # create init_py_files
    if code_type:
        create_init_py(module_path, dt, dn)

    return folder
示例#13
0
def create_folder(module, dt, dn):
    """
		Creates directories for module and their __init__.py
	"""
    import webnotes, os

    # get module path by importing the module
    modules_path = get_module_path(module)

    code_type = dt in ['DocType', 'Page', 'Search Criteria']

    # create folder
    folder = os.path.join(modules_path, code_type and scrub(dt) or dt,
                          code_type and scrub(dn) or dn)

    webnotes.create_folder(folder)

    # create init_py_files
    if code_type:
        create_init_py(modules_path, scrub(dt), scrub(dn))

    return folder
示例#14
0
def make_custom_server_script_file(doctype, script=None):
	import os

	file_path = get_custom_server_script_path(doctype)
	if os.path.exists(file_path):
		raise IOError(file_path + " already exists")
		
	# create folder if not exists
	webnotes.create_folder(os.path.dirname(file_path))
	
	# create file
	custom_script = """from __future__ import unicode_literals
import webnotes
from webnotes.utils import cint, cstr, flt
from webnotes.model.doc import Document
from webnotes.model.code import get_obj
from webnotes import msgprint, _

class CustomDocType(DocType):
{script}""".format(script=script or "\tpass")

	with open(file_path, "w") as f:
		f.write(custom_script)
示例#15
0
def write_file(fid, content):
	import os, conf

	# test size
	max_file_size = 1000000
	if hasattr(conf, 'max_file_size'):
		max_file_size = conf.max_file_size

	if len(content) > max_file_size:
		raise Exception, 'Maximum File Limit (%s MB) Crossed' % (int(max_file_size / 1000000))

	# no slashes
	fid = fid.replace('/','-')

	# save to a folder (not accessible to public)
	folder = webnotes.get_files_path()
		
	# create account folder (if not exists)
	webnotes.create_folder(folder)

	# write the file
	file = open(os.path.join(folder, fid),'w+')
	file.write(content)
	file.close()
示例#16
0
def write_file(fid, content):
    import os, webnotes.defs

    # test size
    max_file_size = 1000000
    if hasattr(webnotes.defs, "max_file_size"):
        max_file_size = webnotes.defs.max_file_size

    if len(content) > max_file_size:
        raise Exception, "Maximum File Limit (%s MB) Crossed" % (int(max_file_size / 1000000))

        # no slashes
    fid = fid.replace("/", "-")

    # save to a folder (not accessible to public)
    folder = webnotes.get_files_path()

    # create account folder (if not exists)
    webnotes.create_folder(folder)

    # write the file
    file = open(os.path.join(folder, fid), "w+")
    file.write(content)
    file.close()
示例#17
0
def make_boilerplate():
	if not os.path.exists("sites"):
		print "Run from bench! (sites folder must exist)"
		return
	
	hooks = webnotes._dict()
	for key in ("App Name", "App Title", "App Description", "App Publisher", 
		"App Icon", "App Color", "App Email", "App URL", "App License"):
		hook_key = key.lower().replace(" ", "_")
		hook_val = None
		while not hook_val:
			hook_val = raw_input(key + ": ")
			if hook_key=="app_name" and hook_val.lower().replace(" ", "_") != hook_val:
				print "App Name must be all lowercase and without spaces"
				hook_val = ""
		
		hooks[hook_key] = hook_val
		
	webnotes.create_folder(os.path.join(hooks.app_name, hooks.app_name, hooks.app_name))
	webnotes.create_folder(os.path.join(hooks.app_name, hooks.app_name, "templates"))
	webnotes.create_folder(os.path.join(hooks.app_name, hooks.app_name, "config"))
	touch_file(os.path.join(hooks.app_name, hooks.app_name, "__init__.py"))
	touch_file(os.path.join(hooks.app_name, hooks.app_name, hooks.app_name, "__init__.py"))
	touch_file(os.path.join(hooks.app_name, hooks.app_name, "templates", "__init__.py"))
	touch_file(os.path.join(hooks.app_name, hooks.app_name, "config", "__init__.py"))
	
	with open(os.path.join(hooks.app_name, "MANIFEST.in"), "w") as f:
		f.write(manifest_template.format(**hooks))

	with open(os.path.join(hooks.app_name, ".gitignore"), "w") as f:
		f.write(gitignore_template)

	with open(os.path.join(hooks.app_name, "setup.py"), "w") as f:
		f.write(setup_template.format(**hooks))

	with open(os.path.join(hooks.app_name, "requirements.txt"), "w") as f:
		f.write("webnotes")

	touch_file(os.path.join(hooks.app_name, "README.md"))

	with open(os.path.join(hooks.app_name, "license.txt"), "w") as f:
		f.write("License: " + hooks.app_license)

	with open(os.path.join(hooks.app_name, hooks.app_name, "modules.txt"), "w") as f:
		f.write(hooks.app_name)

	with open(os.path.join(hooks.app_name, hooks.app_name, "hooks.txt"), "w") as f:
		f.write(hooks_template.format(**hooks))

	touch_file(os.path.join(hooks.app_name, hooks.app_name, "patches.txt"))

	with open(os.path.join(hooks.app_name, hooks.app_name, "config", "desktop.py"), "w") as f:
		f.write(desktop_template.format(**hooks))
示例#18
0
def write_attachments(m):
	import webnotes, os
	from webnotes.utils.file_manager import get_file

	try:
		fl = webnotes.conn.sql("select name from `tabFile Data` where module=%s", m)
	except Exception, e:
		if e.args[0]==1054: # no field called module
			return
		else:
			raise e
	
	# write the files	
	if fl:
		folder = os.path.join(webnotes.defs.modules_path, m, 'files')
		webnotes.create_folder(folder)
		for f in fl:
			file_det = get_file(f)
			file = open(os.path.join(folder, file_det[0]), 'w+')
			file.write(file_det[1])
			file.close()		
		
	
# ==============================================================================
# write module.info file with last updated timestamp
# ==============================================================================

def write_module_info(mod):
	import webnotes.utils, os

	file = open(os.path.join(get_module_path(mod), 'module.info'), 'w')
示例#19
0
def write_translations_file(app, lang, full_dict=None):
	tpath = webnotes.get_pymodule_path(app, "translations")
	webnotes.create_folder(tpath)
	write_csv_file(os.path.join(tpath, lang + ".csv"),
		get_messages_for_app(app), full_dict or get_full_dict(lang))