summaryrefslogtreecommitdiffstats
path: root/tests/roof.py
blob: a8590695930e93bc41be7fb539a9f9bd46962a20 (plain)
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
import gi
import sys
import json
import argparse

gi.require_version('Ufo', '0.0') 
from gi.repository import Ufo
from gi.repository import GObject

class RoofConfig:
    def __init__(self, config="roof.json"):
        self.streams = 1
        
        with open(config) as json_file:
            cfg = json.load(json_file)
            if cfg.get("network", {}).get("streams") != None:
                self.streams = cfg["network"]["streams"]
            elif cfg.get("setup", {}).get("modules") != None:
                self.streams = cfg["setup"]["modules"]


config = "roof.json"
output = None

parser = argparse.ArgumentParser()
parser.add_argument('-c', '--config', dest="config", default="roof.json", help="ROOF configuration (JSON)")
parser.add_argument('-o', '--output', dest="output", default=None, help="Output file")
parser.add_argument('-n', '--number', dest="number", default=None, help="Specify number of frames to capture")
args = parser.parse_args()


cfg = RoofConfig(args.config)

pm  = Ufo.PluginManager()
graph = Ufo.TaskGraph()
scheduler = Ufo.Scheduler()

if args.output is None:
    print ("Starting ROOF using NULL writter")
    write = pm.get_task('null')
    if args.number is None: args.number = 0
else:
    print ("Starting ROOF streaming to {}".format(args.output))
    write = pm.get_task('write')
    write.set_properties(filename=args.output)
    if args.number is None: args.number = 5

build = pm.get_task('roof-build')
build.set_properties(config=args.config, number=args.number)

for id in range(cfg.streams):
    read = pm.get_task('roof-read') 
    read.set_properties(config=args.config, id=id)
    graph.connect_nodes(read, build)
    build.bind_property('stop', read, 'stop', GObject.BindingFlags.DEFAULT)

#read_task.set_properties(path='/home/data/*.tif', start=10, number=100)
#graph.connect_nodes_full(read, write, 0)
graph.connect_nodes(build, write)



scheduler.run(graph)