Não pode escolher mais do que 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.
 
 
 
 
 
 

125 linhas
3.5 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. touch_file(os.path.join(hooks.app_name, hooks.app_name, "__init__.py"))
  24. touch_file(os.path.join(hooks.app_name, hooks.app_name, hooks.app_name, "__init__.py"))
  25. touch_file(os.path.join(hooks.app_name, hooks.app_name, "templates", "__init__.py"))
  26. with open(os.path.join(hooks.app_name, "MANIFEST.in"), "w") as f:
  27. f.write(manifest_template.format(**hooks))
  28. with open(os.path.join(hooks.app_name, ".gitignore"), "w") as f:
  29. f.write(gitignore_template)
  30. with open(os.path.join(hooks.app_name, "setup.py"), "w") as f:
  31. f.write(setup_template.format(**hooks))
  32. with open(os.path.join(hooks.app_name, "requirements.txt"), "w") as f:
  33. f.write("webnotes")
  34. touch_file(os.path.join(hooks.app_name, "README.md"))
  35. with open(os.path.join(hooks.app_name, "license.txt"), "w") as f:
  36. f.write("License: " + hooks.app_license)
  37. with open(os.path.join(hooks.app_name, hooks.app_name, "modules.txt"), "w") as f:
  38. f.write(hooks.app_name)
  39. with open(os.path.join(hooks.app_name, hooks.app_name, "hooks.txt"), "w") as f:
  40. f.write(hooks_template.format(**hooks))
  41. touch_file(os.path.join(hooks.app_name, hooks.app_name, "patches.txt"))
  42. with open(os.path.join(hooks.app_name, hooks.app_name, "desktop.json"), "w") as f:
  43. f.write(desktop_template.format(**hooks))
  44. manifest_template = """include MANIFEST.in
  45. include requirements.txt
  46. include *.json
  47. include *.md
  48. include *.py
  49. include *.txt
  50. recursive-include {app_name} *.css
  51. recursive-include {app_name} *.csv
  52. recursive-include {app_name} *.html
  53. recursive-include {app_name} *.ico
  54. recursive-include {app_name} *.js
  55. recursive-include {app_name} *.json
  56. recursive-include {app_name} *.md
  57. recursive-include {app_name} *.png
  58. recursive-include {app_name} *.py
  59. recursive-include {app_name} *.svg
  60. recursive-include {app_name} *.txt
  61. recursive-exclude {app_name} *.pyc"""
  62. hooks_template = """app_name = {app_name}
  63. app_title = {app_title}
  64. app_publisher = {app_publisher}
  65. app_description = {app_description}
  66. app_icon = {app_icon}
  67. app_color = {app_color}
  68. app_email = {app_email}
  69. app_url = {app_url}
  70. app_version = 0.0.1
  71. """
  72. desktop_template = """{{
  73. "{app_title}": {{
  74. "color": "{app_color}",
  75. "icon": "{app_icon}",
  76. "label": "{app_title}"
  77. }}
  78. }}
  79. """
  80. setup_template = """from setuptools import setup, find_packages
  81. import os
  82. version = '0.0.1'
  83. setup(
  84. name='{app_name}',
  85. version=version,
  86. description='{app_description}',
  87. author='{app_publisher}',
  88. author_email='{app_email}',
  89. packages=find_packages(),
  90. zip_safe=False,
  91. include_package_data=True,
  92. install_requires=("webnotes",),
  93. )
  94. """
  95. gitignore_template = """.DS_Store
  96. *.pyc
  97. *.egg-info
  98. *.swp
  99. tags"""