您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
 
 
 
 
 
 

238 行
6.2 KiB

  1. # Copyright (c) 2013, Web Notes Technologies Pvt. Ltd. and Contributors
  2. # MIT License. See license.txt
  3. from __future__ import unicode_literals
  4. import frappe, os
  5. from frappe.utils import touch_file
  6. def make_boilerplate(dest, app_name):
  7. if not os.path.exists(dest):
  8. print "Destination directory does not exist"
  9. return
  10. hooks = frappe._dict()
  11. hooks.app_name = app_name
  12. app_title = hooks.app_name.replace("_", " ").title()
  13. for key in ("App Title (defaut: {0})".format(app_title), "App Description", "App Publisher",
  14. "App Icon (e.g. 'octicon octicon-zap')", "App Color", "App Email", "App License"):
  15. hook_key = key.split(" (")[0].lower().replace(" ", "_")
  16. hook_val = None
  17. while not hook_val:
  18. hook_val = raw_input(key + ": ")
  19. if hook_key=="app_name" and hook_val.lower().replace(" ", "_") != hook_val:
  20. print "App Name must be all lowercase and without spaces"
  21. hook_val = ""
  22. elif hook_key=="app_title" and not hook_val:
  23. hook_val = app_title
  24. hooks[hook_key] = hook_val
  25. frappe.create_folder(os.path.join(dest, hooks.app_name, hooks.app_name, hooks.app_title),
  26. with_init=True)
  27. frappe.create_folder(os.path.join(dest, hooks.app_name, hooks.app_name, "templates"), with_init=True)
  28. frappe.create_folder(os.path.join(dest, hooks.app_name, hooks.app_name, "templates",
  29. "statics"))
  30. frappe.create_folder(os.path.join(dest, hooks.app_name, hooks.app_name, "templates",
  31. "pages"), with_init=True)
  32. frappe.create_folder(os.path.join(dest, hooks.app_name, hooks.app_name, "templates",
  33. "generators"), with_init=True)
  34. frappe.create_folder(os.path.join(dest, hooks.app_name, hooks.app_name, "config"), with_init=True)
  35. touch_file(os.path.join(dest, hooks.app_name, hooks.app_name, "__init__.py"))
  36. with open(os.path.join(dest, hooks.app_name, "MANIFEST.in"), "w") as f:
  37. f.write(manifest_template.format(**hooks))
  38. with open(os.path.join(dest, hooks.app_name, ".gitignore"), "w") as f:
  39. f.write(gitignore_template)
  40. with open(os.path.join(dest, hooks.app_name, "setup.py"), "w") as f:
  41. f.write(setup_template.format(**hooks))
  42. with open(os.path.join(dest, hooks.app_name, "requirements.txt"), "w") as f:
  43. f.write("frappe")
  44. touch_file(os.path.join(dest, hooks.app_name, "README.md"))
  45. with open(os.path.join(dest, hooks.app_name, "license.txt"), "w") as f:
  46. f.write("License: " + hooks.app_license)
  47. with open(os.path.join(dest, hooks.app_name, hooks.app_name, "modules.txt"), "w") as f:
  48. f.write(hooks.app_title)
  49. with open(os.path.join(dest, hooks.app_name, hooks.app_name, "hooks.py"), "w") as f:
  50. f.write(hooks_template.format(**hooks))
  51. touch_file(os.path.join(dest, hooks.app_name, hooks.app_name, "patches.txt"))
  52. with open(os.path.join(dest, hooks.app_name, hooks.app_name, "config", "desktop.py"), "w") as f:
  53. f.write(desktop_template.format(**hooks))
  54. manifest_template = """include MANIFEST.in
  55. include requirements.txt
  56. include *.json
  57. include *.md
  58. include *.py
  59. include *.txt
  60. recursive-include {app_name} *.css
  61. recursive-include {app_name} *.csv
  62. recursive-include {app_name} *.html
  63. recursive-include {app_name} *.ico
  64. recursive-include {app_name} *.js
  65. recursive-include {app_name} *.json
  66. recursive-include {app_name} *.md
  67. recursive-include {app_name} *.png
  68. recursive-include {app_name} *.py
  69. recursive-include {app_name} *.svg
  70. recursive-include {app_name} *.txt
  71. recursive-exclude {app_name} *.pyc"""
  72. hooks_template = """app_name = "{app_name}"
  73. app_title = "{app_title}"
  74. app_publisher = "{app_publisher}"
  75. app_description = "{app_description}"
  76. app_icon = "{app_icon}"
  77. app_color = "{app_color}"
  78. app_email = "{app_email}"
  79. app_version = "0.0.1"
  80. # Includes in <head>
  81. # ------------------
  82. # include js, css files in header of desk.html
  83. # app_include_css = "/assets/{app_name}/css/{app_name}.css"
  84. # app_include_js = "/assets/{app_name}/js/{app_name}.js"
  85. # include js, css files in header of web template
  86. # web_include_css = "/assets/{app_name}/css/{app_name}.css"
  87. # web_include_js = "/assets/{app_name}/js/{app_name}.js"
  88. # Home Pages
  89. # ----------
  90. # application home page (will override Website Settings)
  91. # home_page = "login"
  92. # website user home page (by Role)
  93. # role_home_page = {{
  94. # "Role": "home_page"
  95. # }}
  96. # Generators
  97. # ----------
  98. # automatically create page for each record of this doctype
  99. # website_generators = ["Web Page"]
  100. # Installation
  101. # ------------
  102. # before_install = "{app_name}.install.before_install"
  103. # after_install = "{app_name}.install.after_install"
  104. # Desk Notifications
  105. # ------------------
  106. # See frappe.core.notifications.get_notification_config
  107. # notification_config = "{app_name}.notifications.get_notification_config"
  108. # Permissions
  109. # -----------
  110. # Permissions evaluated in scripted ways
  111. # permission_query_conditions = {{
  112. # "Event": "frappe.core.doctype.event.event.get_permission_query_conditions",
  113. # }}
  114. #
  115. # has_permission = {{
  116. # "Event": "frappe.core.doctype.event.event.has_permission",
  117. # }}
  118. # Document Events
  119. # ---------------
  120. # Hook on document methods and events
  121. # doc_events = {{
  122. # "*": {{
  123. # "on_update": "method",
  124. # "on_cancel": "method",
  125. # "on_trash": "method"
  126. # }}
  127. # }}
  128. # Scheduled Tasks
  129. # ---------------
  130. # scheduler_events = {{
  131. # "all": [
  132. # "{app_name}.tasks.all"
  133. # ],
  134. # "daily": [
  135. # "{app_name}.tasks.daily"
  136. # ],
  137. # "hourly": [
  138. # "{app_name}.tasks.hourly"
  139. # ],
  140. # "weekly": [
  141. # "{app_name}.tasks.weekly"
  142. # ]
  143. # "monthly": [
  144. # "{app_name}.tasks.monthly"
  145. # ]
  146. # }}
  147. # Testing
  148. # -------
  149. # before_tests = "{app_name}.install.before_tests"
  150. # Overriding Whitelisted Methods
  151. # ------------------------------
  152. #
  153. # override_whitelisted_methods = {{
  154. # "frappe.core.doctype.event.event.get_events": "{app_name}.event.get_events"
  155. # }}
  156. """
  157. desktop_template = """from frappe import _
  158. def get_data():
  159. return {{
  160. "{app_title}": {{
  161. "color": "{app_color}",
  162. "icon": "{app_icon}",
  163. "type": "module",
  164. "label": _("{app_title}")
  165. }}
  166. }}
  167. """
  168. setup_template = """from setuptools import setup, find_packages
  169. import os
  170. version = '0.0.1'
  171. setup(
  172. name='{app_name}',
  173. version=version,
  174. description='{app_description}',
  175. author='{app_publisher}',
  176. author_email='{app_email}',
  177. packages=find_packages(),
  178. zip_safe=False,
  179. include_package_data=True,
  180. install_requires=("frappe",),
  181. )
  182. """
  183. gitignore_template = """.DS_Store
  184. *.pyc
  185. *.egg-info
  186. *.swp
  187. tags"""