gooderp18绿色标准版
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

49 行
1.6KB

  1. # Part of Odoo. See LICENSE file for full copyright and licensing details.
  2. import argparse
  3. import os
  4. import sys
  5. import textwrap
  6. from pathlib import Path
  7. from odoo.tools import cloc, config
  8. from . import Command
  9. class Cloc(Command):
  10. """ Count lines of code per modules """
  11. def run(self, args):
  12. parser = argparse.ArgumentParser(
  13. prog=f'{Path(sys.argv[0]).name} {self.name}',
  14. description="""\
  15. Odoo cloc is a tool to count the number of relevant lines written in
  16. Python, Javascript or XML. This can be used as rough metric for pricing
  17. maintenance of customizations.
  18. It has two modes of operation, either by providing a path:
  19. odoo-bin cloc -p module_path
  20. Or by providing the name of a database:
  21. odoo-bin cloc --addons-path=dirs -d database
  22. In the latter mode, only the custom code is accounted for.
  23. """,
  24. formatter_class=argparse.RawDescriptionHelpFormatter
  25. )
  26. parser.add_argument('--database', '-d', dest="database", help="Database name")
  27. parser.add_argument('--path', '-p', action='append', help="File or directory path")
  28. parser.add_argument('--verbose', '-v', action='count', default=0)
  29. opt, unknown = parser.parse_known_args(args)
  30. if not opt.database and not opt.path:
  31. parser.print_help()
  32. sys.exit()
  33. c = cloc.Cloc()
  34. if opt.database:
  35. config.parse_config(['-d', opt.database] + unknown)
  36. c.count_database(opt.database)
  37. if opt.path:
  38. for i in opt.path:
  39. c.count_path(i)
  40. c.report(opt.verbose)
上海开阖软件有限公司 沪ICP备12045867号-1