Browse Source

Module name based on app title and make init while creating folder

version-14
Nabin Hait 11 years ago
parent
commit
25f83d8f32
2 changed files with 14 additions and 16 deletions
  1. +7
    -2
      frappe/__init__.py
  2. +7
    -14
      frappe/utils/boilerplate.py

+ 7
- 2
frappe/__init__.py View File

@@ -204,8 +204,13 @@ def msgprint(msg, small=0, raise_exception=0, as_table=False):
def throw(msg, exc=ValidationError): def throw(msg, exc=ValidationError):
msgprint(msg, raise_exception=exc) msgprint(msg, raise_exception=exc)


def create_folder(path):
if not os.path.exists(path): os.makedirs(path)
def create_folder(path, with_init=False):
from frappe.utils import touch_file
if not os.path.exists(path):
os.makedirs(path)

if with_init:
touch_file(os.path.join(path, "__init__.py"))


def set_user(username): def set_user(username):
from frappe.utils.user import User from frappe.utils.user import User


+ 7
- 14
frappe/utils/boilerplate.py View File

@@ -24,25 +24,18 @@ def make_boilerplate(dest):


hooks[hook_key] = hook_val hooks[hook_key] = hook_val


frappe.create_folder(os.path.join(dest, hooks.app_name, hooks.app_name, hooks.app_name))
frappe.create_folder(os.path.join(dest, hooks.app_name, hooks.app_name, "templates"))
frappe.create_folder(os.path.join(dest, hooks.app_name, hooks.app_name, frappe.scrub(hooks.app_title)),
with_init=True)
frappe.create_folder(os.path.join(dest, hooks.app_name, hooks.app_name, "templates"), with_init=True)
frappe.create_folder(os.path.join(dest, hooks.app_name, hooks.app_name, "templates", frappe.create_folder(os.path.join(dest, hooks.app_name, hooks.app_name, "templates",
"statics")) "statics"))
frappe.create_folder(os.path.join(dest, hooks.app_name, hooks.app_name, "templates", frappe.create_folder(os.path.join(dest, hooks.app_name, hooks.app_name, "templates",
"pages"))
"pages"), with_init=True)
frappe.create_folder(os.path.join(dest, hooks.app_name, hooks.app_name, "templates", frappe.create_folder(os.path.join(dest, hooks.app_name, hooks.app_name, "templates",
"generators"))
frappe.create_folder(os.path.join(dest, hooks.app_name, hooks.app_name, "config"))
"generators"), with_init=True)
frappe.create_folder(os.path.join(dest, hooks.app_name, hooks.app_name, "config"), with_init=True)


# init files
touch_file(os.path.join(dest, hooks.app_name, hooks.app_name, "__init__.py")) touch_file(os.path.join(dest, hooks.app_name, hooks.app_name, "__init__.py"))
touch_file(os.path.join(dest, hooks.app_name, hooks.app_name, hooks.app_name, "__init__.py"))
touch_file(os.path.join(dest, hooks.app_name, hooks.app_name, "templates", "__init__.py"))
touch_file(os.path.join(dest, hooks.app_name, hooks.app_name, "templates",
"pages", "__init__.py"))
touch_file(os.path.join(dest, hooks.app_name, hooks.app_name, "templates",
"generators", "__init__.py"))
touch_file(os.path.join(dest, hooks.app_name, hooks.app_name, "config", "__init__.py"))


with open(os.path.join(dest, hooks.app_name, "MANIFEST.in"), "w") as f: with open(os.path.join(dest, hooks.app_name, "MANIFEST.in"), "w") as f:
f.write(manifest_template.format(**hooks)) f.write(manifest_template.format(**hooks))
@@ -62,7 +55,7 @@ def make_boilerplate(dest):
f.write("License: " + hooks.app_license) f.write("License: " + hooks.app_license)


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


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


Loading…
Cancel
Save