Coverage for mfplugin/cli_tools/plugins_check.py: 0%

30 statements  

« prev     ^ index     » next       coverage.py v7.6.1, created at 2024-11-13 15:57 +0000

1#!/usr/bin/env python3 

2 

3import argparse 

4import sys 

5from mfplugin.manager import PluginsManager 

6from mfplugin.utils import get_nice_dump 

7from mfutil.cli import echo_ok, echo_running, echo_nok, echo_bold 

8 

9DESCRIPTION = "make a plugin from the current directory" 

10 

11 

12def main(): 

13 arg_parser = argparse.ArgumentParser(description=DESCRIPTION) 

14 arg_parser.add_argument("PLUGIN_PATH", default=".", 

15 help="plugin directory path to check") 

16 arg_parser.add_argument("--debug", action="store_true", 

17 help="add some debug informations in " 

18 "case of problems") 

19 arg_parser.add_argument("--plugins-base-dir", type=str, default=None, 

20 help="can be use to set an alternate " 

21 "plugins-base-dir, if not set the value of " 

22 "MFMODULE_PLUGINS_BASE_DIR env var is used (or a " 

23 "hardcoded standard value).") 

24 args = arg_parser.parse_args() 

25 echo_running("- Checking plugin...") 

26 manager = PluginsManager(args.plugins_base_dir) 

27 try: 

28 plugin = manager.make_plugin(args.PLUGIN_PATH) 

29 plugin.load_full() 

30 if args.debug: 

31 print(get_nice_dump(plugin._get_debug())) 

32 except Exception as e: 

33 echo_nok() 

34 echo_bold(str(e)) 

35 if args.debug: 

36 print("details of the problem:") 

37 raise e 

38 else: 

39 print("(note: use 'plugins.check --debug /plugin/path' " 

40 "for more details)") 

41 sys.exit(1) 

42 echo_ok() 

43 

44 

45if __name__ == '__main__': 

46 main()