Code Duplication    Length = 34-35 lines in 2 locations

opcua/tools.py 2 locations

@@ 259-293 (lines=35) @@
256
        client.disconnect()
257
    sys.exit(0)
258
    print(args)
259
260
261
def uals():
262
    parser = argparse.ArgumentParser(description="Browse OPC-UA node and print result")
263
    add_common_args(parser)
264
    parser.add_argument("-l",
265
                        dest="long_format",
266
                        const=3,
267
                        nargs="?",
268
                        type=int,
269
                        help="use a long listing format")
270
    parser.add_argument("-d",
271
                        "--depth",
272
                        default=1,
273
                        type=int,
274
                        help="Browse depth")
275
276
    args = parse_args(parser)
277
    if args.long_format is None:
278
        args.long_format = 1
279
280
    client = Client(args.url, timeout=args.timeout)
281
    client.set_security_string(args.security)
282
    client.connect()
283
    try:
284
        node = get_node(client, args)
285
        print("Browsing node {0} at {1}\n".format(node, args.url))
286
        if args.long_format == 0:
287
            _lsprint_0(node, args.depth - 1)
288
        elif args.long_format == 1:
289
            _lsprint_1(node, args.depth - 1)
290
        else:
291
            _lsprint_long(node, args.depth - 1)
292
    finally:
293
        client.disconnect()
294
    sys.exit(0)
295
    print(args)
296
@@ 95-128 (lines=34) @@
92
            path = path[1:]
93
        node = node.get_child(path)
94
    return node
95
96
97
def uaread():
98
    parser = argparse.ArgumentParser(description="Read attribute of a node, per default reads value of a node")
99
    add_common_args(parser)
100
    parser.add_argument("-a",
101
                        "--attribute",
102
                        dest="attribute",
103
                        type=int,
104
                        default=ua.AttributeIds.Value,
105
                        help="Set attribute to read")
106
    parser.add_argument("-t",
107
                        "--datatype",
108
                        dest="datatype",
109
                        default="python",
110
                        choices=['python', 'variant', 'datavalue'],
111
                        help="Data type to return")
112
113
    args = parse_args(parser, requirenodeid=True)
114
115
    client = Client(args.url, timeout=args.timeout)
116
    client.set_security_string(args.security)
117
    client.connect()
118
    try:
119
        node = get_node(client, args)
120
        attr = node.get_attribute(args.attribute)
121
        if args.datatype == "python":
122
            print(attr.Value.Value)
123
        elif args.datatype == "variant":
124
            print(attr.Value)
125
        else:
126
            print(attr)
127
    finally:
128
        client.disconnect()
129
    sys.exit(0)
130
    print(args)
131