forked from Azure/azure-iot-sdk-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathiothub_service_client_args.py
More file actions
40 lines (31 loc) · 1.11 KB
/
iothub_service_client_args.py
File metadata and controls
40 lines (31 loc) · 1.11 KB
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
# Copyright (c) Microsoft. All rights reserved.
# Licensed under the MIT license. See LICENSE file in the project root for
# full license information.
import getopt
class OptionError(Exception):
def __init__(self, value):
self.value = value
def __str__(self):
return repr(self.value)
def get_iothub_opt(
argv,
connection_string,
device_id):
if len(argv) > 0:
try:
opts, args = getopt.getopt(
argv, "hd:c:", [
"connectionstring=", "deviceid="])
except getopt.GetoptError as get_opt_error:
raise OptionError("Error: %s" % get_opt_error.msg)
for opt, arg in opts:
if opt == '-h':
raise OptionError("Help:")
elif opt in ("-c", "--connectionstring"):
connection_string = arg
elif opt in ("-d", "--deviceid"):
device_id = arg
if connection_string.find("HostName") < 0:
raise OptionError(
"Error: Hostname not found, not a valid connection string")
return connection_string, device_id