forked from SAP-archive/PyRFC
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclientPrintDescription.py
102 lines (88 loc) · 3.67 KB
/
clientPrintDescription.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
# SPDX-FileCopyrightText: 2013 SAP SE Srdjan Boskovic <[email protected]>
#
# SPDX-License-Identifier: Apache-2.0
# -*- coding: utf-8 -*-
from configparser import ConfigParser
import sys
from pyrfc import Connection, ABAPApplicationError, ABAPRuntimeError, LogonError, CommunicationError
def parameter_key_function(parameter):
""" returns a key for sorting parameters """
value = {"RFC_IMPORT": 1, "RFC_CHANGING": 2, "RFC_TABLES": 3, "RFC_EXPORT": 4}
return value[parameter["direction"]]
def main(function_name):
config = ConfigParser()
config.read("sapnwrfc.cfg")
params_connection = config._sections["connection"]
try:
connection = Connection(**params_connection)
func_desc = connection.get_function_description(function_name)
print("Parameters of function: {0}".format(function_name))
parameter_keys = [
"name",
"parameter_type",
"direction",
"nuc_length",
"uc_length",
"decimals",
"default_value",
"optional",
"type_description",
"parameter_text",
]
parameter_widths = [20, 17, 11, 10, 9, 9, 15, 10, 15, 20]
for key, width in zip(parameter_keys, parameter_widths):
sys.stdout.write("{0}".format(key).ljust(width).upper() + " ")
sys.stdout.write("\n")
for parameter in sorted(func_desc.parameters, key=parameter_key_function):
for key, width in zip(parameter_keys, parameter_widths):
if key == "type_description" and parameter[key] is not None:
sys.stdout.write("{0}".format(parameter[key].name).ljust(width) + " ")
else:
sys.stdout.write("{0}".format(parameter[key]).ljust(width) + " ")
sys.stdout.write("\n")
type_desc = parameter["type_description"]
if type_desc is not None:
# type_desc of class TypeDescription
field_keys = [
"name",
"field_type",
"nuc_length",
"nuc_offset",
"uc_length",
"uc_offset",
"decimals",
"type_description",
]
field_widths = [20, 17, 10, 10, 9, 9, 10, 15]
sys.stdout.write(
" " * 4
+ "-----------( Structure of {0.name} (n/uc_length={0.nuc_length}/{0.uc_length})--\n".format(
type_desc
)
)
for key, width in zip(field_keys, field_widths):
sys.stdout.write("{0}".format(key).ljust(width).upper() + " ")
sys.stdout.write("\n")
for field_description in type_desc.fields:
for key, width in zip(field_keys, field_widths):
sys.stdout.write("{0}".format(field_description[key]).ljust(width) + " ")
sys.stdout.write("\n")
sys.stdout.write(
" " * 4 + "-----------( Structure of {0.name} )-----------\n".format(type_desc)
)
sys.stdout.write("-" * sum(parameter_widths) + "\n")
connection.close()
except CommunicationError:
print("Could not connect to server.")
raise
except LogonError:
print("Could not log in. Wrong credentials?")
raise
except (ABAPApplicationError, ABAPRuntimeError):
print("An error occurred.")
raise
if __name__ == "__main__":
if len(sys.argv) < 2:
print("No function name provided.")
sys.exit()
main(sys.argv[1])