You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

152 lines
3.9KB

  1. # Copyright (C) 2019 - Today: GRAP (http://www.grap.coop)
  2. # @author: Sylvain LE GAL (https://twitter.com/legalsylvain)
  3. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
  4. import argparse
  5. import argcomplete
  6. import sys
  7. from . import tools
  8. from .log import setup_logger
  9. from .migration import Migration
  10. def get_parser():
  11. main_parser = argparse.ArgumentParser(
  12. formatter_class=argparse.RawTextHelpFormatter
  13. )
  14. main_parser.add_argument(
  15. "-d",
  16. "--directory",
  17. dest="directory",
  18. default="./",
  19. type=str,
  20. help="Target Modules directory. Set here a folder path"
  21. " that contains Odoo modules you want to migrate from a version"
  22. " to another.",
  23. )
  24. main_parser.add_argument(
  25. "-m",
  26. "--modules",
  27. dest="modules",
  28. type=str,
  29. help="Targer Modules to migrate."
  30. " If not set, all the modules present in the directory will be"
  31. " migrated.",
  32. )
  33. main_parser.add_argument(
  34. "-i",
  35. "--init-version-name",
  36. choices=tools._get_available_init_version_names(),
  37. dest="init_version_name",
  38. required=True,
  39. type=str,
  40. )
  41. main_parser.add_argument(
  42. "-t",
  43. "--target-version-name",
  44. dest="target_version_name",
  45. type=str,
  46. choices=tools._get_available_target_version_names(),
  47. default=tools._get_latest_version_name(),
  48. help="Target version of the Odoo module you want to migrate."
  49. " If 'latest' is set, the tool will try to migrate to the latest"
  50. " Odoo version.",
  51. )
  52. main_parser.add_argument(
  53. "-fp",
  54. "--format-patch",
  55. action='store_true',
  56. help="Enable this option, if you want to get the code from the"
  57. " previous branch."
  58. )
  59. main_parser.add_argument(
  60. "-rn",
  61. "--remote-name",
  62. dest="remote_name",
  63. default='origin',
  64. type=str,
  65. )
  66. main_parser.add_argument(
  67. "-ll",
  68. "--log-level",
  69. choices=["DEBUG", "INFO", "WARNING", "ERROR", "CRITICAL"],
  70. dest="log_level",
  71. default="INFO",
  72. type=str,
  73. )
  74. main_parser.add_argument(
  75. "-lp",
  76. "--log-path",
  77. dest="log_path",
  78. default=False,
  79. type=str,
  80. )
  81. main_parser.add_argument(
  82. "-nc",
  83. "--no-commit",
  84. action='store_true',
  85. default=False,
  86. help="Enable this option, if you don't want that the library commits"
  87. " the changes. (using git add and git commit command)"
  88. )
  89. # TODO: Move to `argparse.BooleanOptionalAction` once in Python 3.9+
  90. main_parser.add_argument(
  91. "-npc", "--no-pre-commit", dest="pre_commit", action="store_false",
  92. help="Skip pre-commit execution",
  93. )
  94. # TODO: Move to `argparse.BooleanOptionalAction` once in Python 3.9+
  95. main_parser.add_argument(
  96. "-nrmf", "--no-remove-migration-folder",
  97. dest="remove_migration_folder", action="store_false",
  98. help="Skip removing migration folder",
  99. )
  100. return main_parser
  101. def main(args=False):
  102. # Parse Arguments
  103. parser = get_parser()
  104. argcomplete.autocomplete(parser, always_complete_options=False)
  105. if args:
  106. args = parser.parse_args(args)
  107. else:
  108. args = parser.parse_args()
  109. # Set log level
  110. setup_logger(args.log_level, args.log_path)
  111. try:
  112. # Create a new Migration Object
  113. module_names = args.modules\
  114. and [x.strip() for x in args.modules.split(",") if x.strip()] or []
  115. migration = Migration(
  116. args.directory, args.init_version_name, args.target_version_name,
  117. module_names, args.format_patch, args.remote_name,
  118. not args.no_commit, args.pre_commit, args.remove_migration_folder,
  119. )
  120. # run Migration
  121. migration.run()
  122. except KeyboardInterrupt:
  123. pass
  124. if __name__ == "__main__":
  125. main(sys.argv[1:])
上海开阖软件有限公司 沪ICP备12045867号-1