forked from exosite-archive/exoline
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path_example.py
More file actions
61 lines (51 loc) · 2.08 KB
/
_example.py
File metadata and controls
61 lines (51 loc) · 2.08 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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# -*- coding: utf-8 -*-
'''Print a greeting and the latest value of a dataport.
This is an example Exoline plugin.
Usage:
exo [options] hello <auth> <rid>
Command Options:
--greeting=<greeting> Custom greeting, in case "hello" is not good
enough for you. [default: hello]
--extra-exclamations Add three exclamation points to the greeting.
{{ helpoption }}
'''
class Plugin():
# Return command(s) this plugin supports
# This should match the Usage information
# in the docstring at the top of this file.
def command(self):
return 'hello'
# Do a command
# cmd - the string name of the command
# args - dictionary of docopt arguments - for custom arguments
def run(self, cmd, args, options):
# Common arguments
# ----------------
# exo.ExoRPC instance configured with host, port, other options
rpc = options['rpc']
# auth is the RPC auth, either a 40 character CIK
# or auth dictionary, like this {"cik": <cik> ...}
# For more: http://docs.exosite.com/rpc/#authentication
auth = options['auth']
# rids is either a 40 character RID or an alias
# dict, like {"alias": "temperature}. If <rid> is not
# in the usage docs, then options['rids'] is an empty
# list.
rid = options['rids'][0]
# Custom arguments
# ----------------
# Defined in the docstring at the top
# of this file. For details of docopt syntax:
# https://github.com/docopt/docopt
greeting = args['--greeting']
# this is True or False depending on whether it
# was passed in.
exclamations = args['--extra-exclamations']
# if docopt format/arguments get confusing, uncomment this
print(args)
# ExoRPC methods will raise an exception if something goes wrong
points = rpc.read(auth, rid, 1)
if len(points) == 0:
print('No value in that dataport')
else:
print('{0}, {1}{2}'.format(greeting, points[0][1], '!!!' if exclamations else ''))