| author | Radek Brich <brich.radek@ifortuna.cz> | 
| Tue, 06 May 2014 18:37:43 +0200 | |
| changeset 101 | 2a2d0d5df03b | 
| parent 100 | d6088dba8fea | 
| child 102 | fda45bdfd68d | 
| permissions | -rwxr-xr-x | 
| 
100
 
d6088dba8fea
Add pgtool wrapper for all tools. Only this script will be installed into system bin.
 
Radek Brich <brich.radek@ifortuna.cz> 
parents:  
diff
changeset
 | 
1  | 
#!/usr/bin/env python3  | 
| 
 
d6088dba8fea
Add pgtool wrapper for all tools. Only this script will be installed into system bin.
 
Radek Brich <brich.radek@ifortuna.cz> 
parents:  
diff
changeset
 | 
2  | 
|
| 
 
d6088dba8fea
Add pgtool wrapper for all tools. Only this script will be installed into system bin.
 
Radek Brich <brich.radek@ifortuna.cz> 
parents:  
diff
changeset
 | 
3  | 
"""  | 
| 
 
d6088dba8fea
Add pgtool wrapper for all tools. Only this script will be installed into system bin.
 
Radek Brich <brich.radek@ifortuna.cz> 
parents:  
diff
changeset
 | 
4  | 
Wrapper script for pgtoolkit tools.  | 
| 
 
d6088dba8fea
Add pgtool wrapper for all tools. Only this script will be installed into system bin.
 
Radek Brich <brich.radek@ifortuna.cz> 
parents:  
diff
changeset
 | 
5  | 
|
| 
 
d6088dba8fea
Add pgtool wrapper for all tools. Only this script will be installed into system bin.
 
Radek Brich <brich.radek@ifortuna.cz> 
parents:  
diff
changeset
 | 
6  | 
Usage:  | 
| 
 
d6088dba8fea
Add pgtool wrapper for all tools. Only this script will be installed into system bin.
 
Radek Brich <brich.radek@ifortuna.cz> 
parents:  
diff
changeset
 | 
7  | 
|
| 
 
d6088dba8fea
Add pgtool wrapper for all tools. Only this script will be installed into system bin.
 
Radek Brich <brich.radek@ifortuna.cz> 
parents:  
diff
changeset
 | 
8  | 
pgtool --list  | 
| 
 
d6088dba8fea
Add pgtool wrapper for all tools. Only this script will be installed into system bin.
 
Radek Brich <brich.radek@ifortuna.cz> 
parents:  
diff
changeset
 | 
9  | 
List all available tools.  | 
| 
 
d6088dba8fea
Add pgtool wrapper for all tools. Only this script will be installed into system bin.
 
Radek Brich <brich.radek@ifortuna.cz> 
parents:  
diff
changeset
 | 
10  | 
|
| 
 
d6088dba8fea
Add pgtool wrapper for all tools. Only this script will be installed into system bin.
 
Radek Brich <brich.radek@ifortuna.cz> 
parents:  
diff
changeset
 | 
11  | 
pgtool <tool_name> <arg_1> <arg_2> ...  | 
| 
 
d6088dba8fea
Add pgtool wrapper for all tools. Only this script will be installed into system bin.
 
Radek Brich <brich.radek@ifortuna.cz> 
parents:  
diff
changeset
 | 
12  | 
Run tool. All args except first one are forwarded to the tool.  | 
| 
 
d6088dba8fea
Add pgtool wrapper for all tools. Only this script will be installed into system bin.
 
Radek Brich <brich.radek@ifortuna.cz> 
parents:  
diff
changeset
 | 
13  | 
|
| 
 
d6088dba8fea
Add pgtool wrapper for all tools. Only this script will be installed into system bin.
 
Radek Brich <brich.radek@ifortuna.cz> 
parents:  
diff
changeset
 | 
14  | 
pgtool schemadiff db1 db2  | 
| 
 
d6088dba8fea
Add pgtool wrapper for all tools. Only this script will be installed into system bin.
 
Radek Brich <brich.radek@ifortuna.cz> 
parents:  
diff
changeset
 | 
15  | 
E.g. run schemadiff between db1 and db2.  | 
| 
 
d6088dba8fea
Add pgtool wrapper for all tools. Only this script will be installed into system bin.
 
Radek Brich <brich.radek@ifortuna.cz> 
parents:  
diff
changeset
 | 
16  | 
|
| 
 
d6088dba8fea
Add pgtool wrapper for all tools. Only this script will be installed into system bin.
 
Radek Brich <brich.radek@ifortuna.cz> 
parents:  
diff
changeset
 | 
17  | 
pgtool schemadiff --help  | 
| 
 
d6088dba8fea
Add pgtool wrapper for all tools. Only this script will be installed into system bin.
 
Radek Brich <brich.radek@ifortuna.cz> 
parents:  
diff
changeset
 | 
18  | 
Get help for tool parameters.  | 
| 
 
d6088dba8fea
Add pgtool wrapper for all tools. Only this script will be installed into system bin.
 
Radek Brich <brich.radek@ifortuna.cz> 
parents:  
diff
changeset
 | 
19  | 
|
| 
 
d6088dba8fea
Add pgtool wrapper for all tools. Only this script will be installed into system bin.
 
Radek Brich <brich.radek@ifortuna.cz> 
parents:  
diff
changeset
 | 
20  | 
"""  | 
| 
 
d6088dba8fea
Add pgtool wrapper for all tools. Only this script will be installed into system bin.
 
Radek Brich <brich.radek@ifortuna.cz> 
parents:  
diff
changeset
 | 
21  | 
|
| 
 
d6088dba8fea
Add pgtool wrapper for all tools. Only this script will be installed into system bin.
 
Radek Brich <brich.radek@ifortuna.cz> 
parents:  
diff
changeset
 | 
22  | 
import pgtoolkit.tools  | 
| 
 
d6088dba8fea
Add pgtool wrapper for all tools. Only this script will be installed into system bin.
 
Radek Brich <brich.radek@ifortuna.cz> 
parents:  
diff
changeset
 | 
23  | 
import sys  | 
| 
 
d6088dba8fea
Add pgtool wrapper for all tools. Only this script will be installed into system bin.
 
Radek Brich <brich.radek@ifortuna.cz> 
parents:  
diff
changeset
 | 
24  | 
from importlib import import_module  | 
| 
 
d6088dba8fea
Add pgtool wrapper for all tools. Only this script will be installed into system bin.
 
Radek Brich <brich.radek@ifortuna.cz> 
parents:  
diff
changeset
 | 
25  | 
|
| 
 
d6088dba8fea
Add pgtool wrapper for all tools. Only this script will be installed into system bin.
 
Radek Brich <brich.radek@ifortuna.cz> 
parents:  
diff
changeset
 | 
26  | 
|
| 
101
 
2a2d0d5df03b
Refactor ToolBase to allow tool composition. Add TableSync tool (composited). Move more tools under pgtool.
 
Radek Brich <brich.radek@ifortuna.cz> 
parents: 
100 
diff
changeset
 | 
27  | 
def print_tool_with_short_desc(name):  | 
| 
 
2a2d0d5df03b
Refactor ToolBase to allow tool composition. Add TableSync tool (composited). Move more tools under pgtool.
 
Radek Brich <brich.radek@ifortuna.cz> 
parents: 
100 
diff
changeset
 | 
28  | 
    module = import_module('pgtoolkit.tools.' + tool)
 | 
| 
 
2a2d0d5df03b
Refactor ToolBase to allow tool composition. Add TableSync tool (composited). Move more tools under pgtool.
 
Radek Brich <brich.radek@ifortuna.cz> 
parents: 
100 
diff
changeset
 | 
29  | 
short_desc = module.cls.__doc__.lstrip().splitlines()[0]  | 
| 
 
2a2d0d5df03b
Refactor ToolBase to allow tool composition. Add TableSync tool (composited). Move more tools under pgtool.
 
Radek Brich <brich.radek@ifortuna.cz> 
parents: 
100 
diff
changeset
 | 
30  | 
print(name.ljust(15), '-', short_desc)  | 
| 
100
 
d6088dba8fea
Add pgtool wrapper for all tools. Only this script will be installed into system bin.
 
Radek Brich <brich.radek@ifortuna.cz> 
parents:  
diff
changeset
 | 
31  | 
|
| 
101
 
2a2d0d5df03b
Refactor ToolBase to allow tool composition. Add TableSync tool (composited). Move more tools under pgtool.
 
Radek Brich <brich.radek@ifortuna.cz> 
parents: 
100 
diff
changeset
 | 
32  | 
|
| 
 
2a2d0d5df03b
Refactor ToolBase to allow tool composition. Add TableSync tool (composited). Move more tools under pgtool.
 
Radek Brich <brich.radek@ifortuna.cz> 
parents: 
100 
diff
changeset
 | 
33  | 
if __name__ == '__main__':  | 
| 
 
2a2d0d5df03b
Refactor ToolBase to allow tool composition. Add TableSync tool (composited). Move more tools under pgtool.
 
Radek Brich <brich.radek@ifortuna.cz> 
parents: 
100 
diff
changeset
 | 
34  | 
if len(sys.argv) < 2:  | 
| 
 
2a2d0d5df03b
Refactor ToolBase to allow tool composition. Add TableSync tool (composited). Move more tools under pgtool.
 
Radek Brich <brich.radek@ifortuna.cz> 
parents: 
100 
diff
changeset
 | 
35  | 
print(__doc__, end='')  | 
| 
 
2a2d0d5df03b
Refactor ToolBase to allow tool composition. Add TableSync tool (composited). Move more tools under pgtool.
 
Radek Brich <brich.radek@ifortuna.cz> 
parents: 
100 
diff
changeset
 | 
36  | 
sys.exit()  | 
| 
100
 
d6088dba8fea
Add pgtool wrapper for all tools. Only this script will be installed into system bin.
 
Radek Brich <brich.radek@ifortuna.cz> 
parents:  
diff
changeset
 | 
37  | 
|
| 
101
 
2a2d0d5df03b
Refactor ToolBase to allow tool composition. Add TableSync tool (composited). Move more tools under pgtool.
 
Radek Brich <brich.radek@ifortuna.cz> 
parents: 
100 
diff
changeset
 | 
38  | 
    if sys.argv[1].startswith('--'):
 | 
| 
 
2a2d0d5df03b
Refactor ToolBase to allow tool composition. Add TableSync tool (composited). Move more tools under pgtool.
 
Radek Brich <brich.radek@ifortuna.cz> 
parents: 
100 
diff
changeset
 | 
39  | 
if sys.argv[1] == '--list':  | 
| 
 
2a2d0d5df03b
Refactor ToolBase to allow tool composition. Add TableSync tool (composited). Move more tools under pgtool.
 
Radek Brich <brich.radek@ifortuna.cz> 
parents: 
100 
diff
changeset
 | 
40  | 
for tool in pgtoolkit.tools.__all__:  | 
| 
 
2a2d0d5df03b
Refactor ToolBase to allow tool composition. Add TableSync tool (composited). Move more tools under pgtool.
 
Radek Brich <brich.radek@ifortuna.cz> 
parents: 
100 
diff
changeset
 | 
41  | 
print_tool_with_short_desc(tool)  | 
| 
 
2a2d0d5df03b
Refactor ToolBase to allow tool composition. Add TableSync tool (composited). Move more tools under pgtool.
 
Radek Brich <brich.radek@ifortuna.cz> 
parents: 
100 
diff
changeset
 | 
42  | 
else:  | 
| 
 
2a2d0d5df03b
Refactor ToolBase to allow tool composition. Add TableSync tool (composited). Move more tools under pgtool.
 
Radek Brich <brich.radek@ifortuna.cz> 
parents: 
100 
diff
changeset
 | 
43  | 
print(__doc__, end='')  | 
| 
 
2a2d0d5df03b
Refactor ToolBase to allow tool composition. Add TableSync tool (composited). Move more tools under pgtool.
 
Radek Brich <brich.radek@ifortuna.cz> 
parents: 
100 
diff
changeset
 | 
44  | 
sys.exit()  | 
| 
100
 
d6088dba8fea
Add pgtool wrapper for all tools. Only this script will be installed into system bin.
 
Radek Brich <brich.radek@ifortuna.cz> 
parents:  
diff
changeset
 | 
45  | 
|
| 
101
 
2a2d0d5df03b
Refactor ToolBase to allow tool composition. Add TableSync tool (composited). Move more tools under pgtool.
 
Radek Brich <brich.radek@ifortuna.cz> 
parents: 
100 
diff
changeset
 | 
46  | 
tool = sys.argv[1]  | 
| 
 
2a2d0d5df03b
Refactor ToolBase to allow tool composition. Add TableSync tool (composited). Move more tools under pgtool.
 
Radek Brich <brich.radek@ifortuna.cz> 
parents: 
100 
diff
changeset
 | 
47  | 
tool_args = sys.argv[2:]  | 
| 
100
 
d6088dba8fea
Add pgtool wrapper for all tools. Only this script will be installed into system bin.
 
Radek Brich <brich.radek@ifortuna.cz> 
parents:  
diff
changeset
 | 
48  | 
|
| 
101
 
2a2d0d5df03b
Refactor ToolBase to allow tool composition. Add TableSync tool (composited). Move more tools under pgtool.
 
Radek Brich <brich.radek@ifortuna.cz> 
parents: 
100 
diff
changeset
 | 
49  | 
if tool not in pgtoolkit.tools.__all__:  | 
| 
 
2a2d0d5df03b
Refactor ToolBase to allow tool composition. Add TableSync tool (composited). Move more tools under pgtool.
 
Radek Brich <brich.radek@ifortuna.cz> 
parents: 
100 
diff
changeset
 | 
50  | 
        print('Unknown tool "%s".\n\nCall "pgtool --list" to get list of all available tools.' % tool)
 | 
| 
 
2a2d0d5df03b
Refactor ToolBase to allow tool composition. Add TableSync tool (composited). Move more tools under pgtool.
 
Radek Brich <brich.radek@ifortuna.cz> 
parents: 
100 
diff
changeset
 | 
51  | 
sys.exit()  | 
| 
100
 
d6088dba8fea
Add pgtool wrapper for all tools. Only this script will be installed into system bin.
 
Radek Brich <brich.radek@ifortuna.cz> 
parents:  
diff
changeset
 | 
52  | 
|
| 
101
 
2a2d0d5df03b
Refactor ToolBase to allow tool composition. Add TableSync tool (composited). Move more tools under pgtool.
 
Radek Brich <brich.radek@ifortuna.cz> 
parents: 
100 
diff
changeset
 | 
53  | 
    module = import_module('pgtoolkit.tools.' + tool)
 | 
| 
 
2a2d0d5df03b
Refactor ToolBase to allow tool composition. Add TableSync tool (composited). Move more tools under pgtool.
 
Radek Brich <brich.radek@ifortuna.cz> 
parents: 
100 
diff
changeset
 | 
54  | 
|
| 
 
2a2d0d5df03b
Refactor ToolBase to allow tool composition. Add TableSync tool (composited). Move more tools under pgtool.
 
Radek Brich <brich.radek@ifortuna.cz> 
parents: 
100 
diff
changeset
 | 
55  | 
tool = module.cls()  | 
| 
 
2a2d0d5df03b
Refactor ToolBase to allow tool composition. Add TableSync tool (composited). Move more tools under pgtool.
 
Radek Brich <brich.radek@ifortuna.cz> 
parents: 
100 
diff
changeset
 | 
56  | 
tool.setup(tool_args)  | 
| 
 
2a2d0d5df03b
Refactor ToolBase to allow tool composition. Add TableSync tool (composited). Move more tools under pgtool.
 
Radek Brich <brich.radek@ifortuna.cz> 
parents: 
100 
diff
changeset
 | 
57  | 
tool.main()  | 
| 
 
2a2d0d5df03b
Refactor ToolBase to allow tool composition. Add TableSync tool (composited). Move more tools under pgtool.
 
Radek Brich <brich.radek@ifortuna.cz> 
parents: 
100 
diff
changeset
 | 
58  |