File: ceres-node-write

package info (click to toggle)
python-ceres 0.10.0~git20130913-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 200 kB
  • ctags: 232
  • sloc: python: 1,156; makefile: 126
file content (62 lines) | stat: -rwxr-xr-x 1,247 bytes parent folder | download
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
#!/usr/bin/env python

import sys
import time
from optparse import OptionParser
from ceres import CeresTree, getTree


parser = OptionParser(usage='''%prog [options] <path> <datapoint> [datapoint]+
  If --tree is specified, <path> is taken as a node path
  Otherwise <path> is taken as a filesystem path

Each datapoint is of the form <timestamp>:<value> where <timestamp> may
be a UNIX epoch time or the character 'N' to indicate 'now'.
''')
parser.add_option('--tree', default=None)

options, args = parser.parse_args()

if not args:
  parser.print_usage()
  sys.exit(1)


if options.tree:
  nodePath = args[0]
  tree = CeresTree(options.tree)

else:
  fsPath = args[0]
  tree = getTree(fsPath)

  if not tree:
    print "error: %s is not in a ceres tree" % fsPath
    sys.exit(1)

  nodePath = tree.getNodePath(fsPath)


datapoints = []
now = time.time()
for datapoint in args[1:]:
  timestamp, value = datapoint.split(':', 1)

  if timestamp == 'N':
    timestamp = now
  else:
    timestamp = float(timestamp)

  value = float(value)
  datapoints.append( (timestamp, value) )

datapoints.sort()

if not args:
  print "error: no datapoints specified"
  parser.print_usage()
  sys.exit(1)


node = tree.getNode(nodePath)
node.write(datapoints)