equal
  deleted
  inserted
  replaced
  
    
    
|      1 #!/usr/bin/env python3 |      1 #!/usr/bin/env python3 | 
|      2  |      2  | 
|      3 """ |      3 """ | 
|      4 Wrapper script for pgtoolkit tools. |      4 Wrapper script for pydbkit tools. | 
|      5  |      5  | 
|      6 Usage |      6 Usage | 
|      7 ----- |      7 ----- | 
|      8  |      8  | 
|      9     pgtool --list |      9     pgtool --list | 
|     19         Get help for tool parameters. |     19         Get help for tool parameters. | 
|     20  |     20  | 
|     21 Configuration |     21 Configuration | 
|     22 ------------- |     22 ------------- | 
|     23  |     23  | 
|     24 Global pgtoolkit configuration: |     24 Global pydbkit configuration: | 
|     25     /etc/pgtoolkit.conf |     25     /etc/pydbkit.conf | 
|     26  |     26  | 
|     27 Local configuration: |     27 Local configuration: | 
|     28     ./pgtoolkit.conf |     28     ./pydbkit.conf | 
|     29  |     29  | 
|     30 Additional config file can be loaded using -c parameter (after tool name). |     30 Additional config file can be loaded using -c parameter (after tool name). | 
|     31  |     31  | 
|     32 Configuration from all present files is loaded in above order, |     32 Configuration from all present files is loaded in above order, | 
|     33 later value overrides previous value. Resulting config file priority is: |     33 later value overrides previous value. Resulting config file priority is: | 
|     36    2) local |     36    2) local | 
|     37    3) global |     37    3) global | 
|     38  |     38  | 
|     39 """ |     39 """ | 
|     40  |     40  | 
|     41 import pgtoolkit.tools |     41 import pydbkit.tools | 
|     42 import sys |     42 import sys | 
|     43 from importlib import import_module |     43 from importlib import import_module | 
|     44  |     44  | 
|     45  |     45  | 
|     46 def print_tool_with_short_desc(name): |     46 def print_tool_with_short_desc(name): | 
|     47     module = import_module('pgtoolkit.tools.' + tool) |     47     module = import_module('pydbkit.tools.' + tool) | 
|     48     short_desc = module.cls.__doc__.lstrip().splitlines()[0] |     48     short_desc = module.cls.__doc__.lstrip().splitlines()[0] | 
|     49     print(name.ljust(15), '-', short_desc) |     49     print(name.ljust(15), '-', short_desc) | 
|     50  |     50  | 
|     51  |     51  | 
|     52 if __name__ == '__main__': |     52 if __name__ == '__main__': | 
|     54         print(__doc__, end='') |     54         print(__doc__, end='') | 
|     55         sys.exit() |     55         sys.exit() | 
|     56  |     56  | 
|     57     if sys.argv[1].startswith('--'): |     57     if sys.argv[1].startswith('--'): | 
|     58         if sys.argv[1] == '--list': |     58         if sys.argv[1] == '--list': | 
|     59             for tool in pgtoolkit.tools.__all__: |     59             for tool in pydbkit.tools.__all__: | 
|     60                 print_tool_with_short_desc(tool) |     60                 print_tool_with_short_desc(tool) | 
|     61         else: |     61         else: | 
|     62             print(__doc__, end='') |     62             print(__doc__, end='') | 
|     63         sys.exit() |     63         sys.exit() | 
|     64  |     64  | 
|     65     tool = sys.argv[1] |     65     tool = sys.argv[1] | 
|     66     tool_args = sys.argv[2:] |     66     tool_args = sys.argv[2:] | 
|     67  |     67  | 
|     68     if tool not in pgtoolkit.tools.__all__: |     68     if tool not in pydbkit.tools.__all__: | 
|     69         print('Unknown tool "%s".\n\nCall "pgtool --list" to get list of all available tools.' % tool) |     69         print('Unknown tool "%s".\n\nCall "pgtool --list" to get list of all available tools.' % tool) | 
|     70         sys.exit() |     70         sys.exit() | 
|     71  |     71  | 
|     72     module = import_module('pgtoolkit.tools.' + tool) |     72     module = import_module('pydbkit.tools.' + tool) | 
|     73  |     73  | 
|     74     tool = module.cls() |     74     tool = module.cls() | 
|     75     tool.setup(tool_args) |     75     tool.setup(tool_args) | 
|     76     tool.main() |     76     tool.main() | 
|     77  |     77  |