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

48 statements  

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

1#!/usr/bin/env python3 

2 

3import os 

4import io 

5import contextlib 

6import argparse 

7import sys 

8from mfplugin.utils import inside_a_plugin_env 

9from mfplugin.manager import PluginsManager 

10from mfplugin.utils import NotInstalledPlugin 

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

12 

13DESCRIPTION = "repacke and installed plugin" 

14MFMODULE_LOWERCASE = os.environ.get('MFMODULE_LOWERCASE', 'mfext') 

15 

16 

17def main(): 

18 arg_parser = argparse.ArgumentParser(description=DESCRIPTION) 

19 arg_parser.add_argument("name", type=str, 

20 help="plugin name") 

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

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

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

24 "MFMODULE_PLUGINS_BASE_DIR env var is used (or a " 

25 "hardcoded standard value).") 

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

27 help="add some debug informations in " 

28 "case of problems") 

29 args = arg_parser.parse_args() 

30 name = args.name 

31 if inside_a_plugin_env(): 

32 print("ERROR: Don't use plugins.install/uninstall inside a plugin_env") 

33 sys.exit(1) 

34 manager = PluginsManager(plugins_base_dir=args.plugins_base_dir) 

35 echo_running("- Repackaging plugin %s..." % name) 

36 try: 

37 f = io.StringIO() 

38 with contextlib.redirect_stderr(f): 

39 path = manager.repackage_plugin(name) 

40 except NotInstalledPlugin: 

41 echo_nok() 

42 echo_bold(" => not installed plugin") 

43 sys.exit(1) 

44 except Exception as e: 

45 echo_nok() 

46 stderr = f.getvalue() 

47 if stderr != '': 

48 print(stderr) 

49 print(e) 

50 if args.debug: 

51 print("details of the problem:") 

52 raise e 

53 else: 

54 print("note: use --debug option for more details") 

55 else: 

56 echo_ok() 

57 stderr = f.getvalue() 

58 if stderr != '': 

59 print(stderr) 

60 echo_bold("plugin file is ready at %s" % path) 

61 

62 

63if __name__ == '__main__': 

64 main()