Você não pode selecionar mais de 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.
 
 
 
 
 
 

79 linhas
1.9 KiB

  1. from __future__ import unicode_literals
  2. import click
  3. import frappe
  4. import os
  5. import json
  6. import importlib
  7. import frappe.utils
  8. def main():
  9. commands = get_app_groups()
  10. commands.update({'get-frappe-commands': get_frappe_commands,
  11. 'get-frappe-help': get_frappe_help
  12. })
  13. click.Group(commands=commands)(prog_name='bench')
  14. def get_app_groups():
  15. ret = {}
  16. for app in get_apps():
  17. app_group = get_app_group(app)
  18. if app_group:
  19. ret[app] = app_group
  20. return ret
  21. def get_app_group(app):
  22. app_commands = get_app_commands(app)
  23. if app_commands:
  24. return click.group(name=app, commands=app_commands)(app_group)
  25. @click.option('--site')
  26. @click.option('--profile', is_flag=True, default=False, help='Profile')
  27. @click.option('--verbose', is_flag=True, default=False, help='Verbose')
  28. @click.option('--force', is_flag=True, default=False, help='Force')
  29. @click.pass_context
  30. def app_group(ctx, site=False, force=False, verbose=False, profile=False):
  31. ctx.obj = {
  32. 'sites': get_sites(site),
  33. 'force': force,
  34. 'verbose': verbose,
  35. 'profile': profile
  36. }
  37. if ctx.info_name == 'frappe':
  38. ctx.info_name = ''
  39. def get_sites(site_arg):
  40. if site_arg and site_arg == 'all':
  41. return frappe.utils.get_sites()
  42. else:
  43. if site_arg:
  44. return [site_arg]
  45. if os.path.exists('currentsite.txt'):
  46. with open('currentsite.txt') as f:
  47. return [f.read().strip()]
  48. def get_app_commands(app):
  49. try:
  50. app_command_module = importlib.import_module(app + '.commands')
  51. except ImportError:
  52. return []
  53. ret = {}
  54. for command in getattr(app_command_module, 'commands', []):
  55. ret[command.name] = command
  56. return ret
  57. @click.command('get-frappe-commands')
  58. def get_frappe_commands():
  59. print json.dumps(get_app_commands('frappe').keys())
  60. @click.command('get-frappe-help')
  61. def get_frappe_help():
  62. print click.Context(get_app_group('frappe')).get_help()
  63. def get_apps():
  64. return frappe.get_all_apps(with_internal_apps=False, sites_path='.')
  65. if __name__ == "__main__":
  66. main()