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.
 
 
 
 
 
 

60 rader
1.4 KiB

  1. # Copyright (c) 2015, Web Notes Technologies Pvt. Ltd. and Contributors
  2. # MIT License. See license.txt
  3. from __future__ import unicode_literals, absolute_import, print_function
  4. import sys
  5. import click
  6. import cProfile
  7. import StringIO
  8. import pstats
  9. import frappe
  10. import frappe.utils
  11. from functools import wraps
  12. click.disable_unicode_literals_warning = True
  13. def pass_context(f):
  14. @wraps(f)
  15. def _func(ctx, *args, **kwargs):
  16. profile = ctx.obj['profile']
  17. if profile:
  18. pr = cProfile.Profile()
  19. pr.enable()
  20. ret = f(frappe._dict(ctx.obj), *args, **kwargs)
  21. if profile:
  22. pr.disable()
  23. s = StringIO.StringIO()
  24. ps = pstats.Stats(pr, stream=s)\
  25. .sort_stats('cumtime', 'tottime', 'ncalls')
  26. ps.print_stats()
  27. print(s.getvalue())
  28. return ret
  29. return click.pass_context(_func)
  30. def get_site(context):
  31. try:
  32. site = context.sites[0]
  33. return site
  34. except (IndexError, TypeError):
  35. print('Please specify --site sitename')
  36. sys.exit(1)
  37. def call_command(cmd, context):
  38. return click.Context(cmd, obj=context).forward(cmd)
  39. def get_commands():
  40. # prevent circular imports
  41. from .docs import commands as doc_commands
  42. from .scheduler import commands as scheduler_commands
  43. from .site import commands as site_commands
  44. from .translate import commands as translate_commands
  45. from .utils import commands as utils_commands
  46. return list(set(doc_commands + scheduler_commands + site_commands + translate_commands + utils_commands))
  47. commands = get_commands()