Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.
 
 
 
 
 
 

257 rader
6.9 KiB

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