25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

129 lines
3.7 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 webnotes, os
  5. from webnotes.utils import touch_file
  6. def make_boilerplate():
  7. if not os.path.exists("sites"):
  8. print "Run from bench! (sites folder must exist)"
  9. return
  10. hooks = webnotes._dict()
  11. for key in ("App Name", "App Title", "App Description", "App Publisher",
  12. "App Icon", "App Color", "App Email", "App URL", "App License"):
  13. hook_key = key.lower().replace(" ", "_")
  14. hook_val = None
  15. while not hook_val:
  16. hook_val = raw_input(key + ": ")
  17. if hook_key=="app_name" and hook_val.lower().replace(" ", "_") != hook_val:
  18. print "App Name must be all lowercase and without spaces"
  19. hook_val = ""
  20. hooks[hook_key] = hook_val
  21. webnotes.create_folder(os.path.join(hooks.app_name, hooks.app_name, hooks.app_name))
  22. webnotes.create_folder(os.path.join(hooks.app_name, hooks.app_name, "templates"))
  23. webnotes.create_folder(os.path.join(hooks.app_name, hooks.app_name, "config"))
  24. touch_file(os.path.join(hooks.app_name, hooks.app_name, "__init__.py"))
  25. touch_file(os.path.join(hooks.app_name, hooks.app_name, hooks.app_name, "__init__.py"))
  26. touch_file(os.path.join(hooks.app_name, hooks.app_name, "templates", "__init__.py"))
  27. touch_file(os.path.join(hooks.app_name, hooks.app_name, "config", "__init__.py"))
  28. with open(os.path.join(hooks.app_name, "MANIFEST.in"), "w") as f:
  29. f.write(manifest_template.format(**hooks))
  30. with open(os.path.join(hooks.app_name, ".gitignore"), "w") as f:
  31. f.write(gitignore_template)
  32. with open(os.path.join(hooks.app_name, "setup.py"), "w") as f:
  33. f.write(setup_template.format(**hooks))
  34. with open(os.path.join(hooks.app_name, "requirements.txt"), "w") as f:
  35. f.write("webnotes")
  36. touch_file(os.path.join(hooks.app_name, "README.md"))
  37. with open(os.path.join(hooks.app_name, "license.txt"), "w") as f:
  38. f.write("License: " + hooks.app_license)
  39. with open(os.path.join(hooks.app_name, hooks.app_name, "modules.txt"), "w") as f:
  40. f.write(hooks.app_name)
  41. with open(os.path.join(hooks.app_name, hooks.app_name, "hooks.txt"), "w") as f:
  42. f.write(hooks_template.format(**hooks))
  43. touch_file(os.path.join(hooks.app_name, hooks.app_name, "patches.txt"))
  44. with open(os.path.join(hooks.app_name, hooks.app_name, "config", "desktop.py"), "w") as f:
  45. f.write(desktop_template.format(**hooks))
  46. manifest_template = """include MANIFEST.in
  47. include requirements.txt
  48. include *.json
  49. include *.md
  50. include *.py
  51. include *.txt
  52. recursive-include {app_name} *.css
  53. recursive-include {app_name} *.csv
  54. recursive-include {app_name} *.html
  55. recursive-include {app_name} *.ico
  56. recursive-include {app_name} *.js
  57. recursive-include {app_name} *.json
  58. recursive-include {app_name} *.md
  59. recursive-include {app_name} *.png
  60. recursive-include {app_name} *.py
  61. recursive-include {app_name} *.svg
  62. recursive-include {app_name} *.txt
  63. recursive-exclude {app_name} *.pyc"""
  64. hooks_template = """app_name = {app_name}
  65. app_title = {app_title}
  66. app_publisher = {app_publisher}
  67. app_description = {app_description}
  68. app_icon = {app_icon}
  69. app_color = {app_color}
  70. app_email = {app_email}
  71. app_url = {app_url}
  72. app_version = 0.0.1
  73. """
  74. desktop_template = """from webnotes import _
  75. data = {{
  76. "{app_title}": {{
  77. "color": "{app_color}",
  78. "icon": "{app_icon}",
  79. "label": _("{app_title}")
  80. }}
  81. }}
  82. """
  83. setup_template = """from setuptools import setup, find_packages
  84. import os
  85. version = '0.0.1'
  86. setup(
  87. name='{app_name}',
  88. version=version,
  89. description='{app_description}',
  90. author='{app_publisher}',
  91. author_email='{app_email}',
  92. packages=find_packages(),
  93. zip_safe=False,
  94. include_package_data=True,
  95. install_requires=("webnotes",),
  96. )
  97. """
  98. gitignore_template = """.DS_Store
  99. *.pyc
  100. *.egg-info
  101. *.swp
  102. tags"""