summaryrefslogtreecommitdiff
path: root/examples/demo.js
blob: 28cf80577ab823af1b2017b0b9c5236be7b5e61f (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
#!/usr/bin/seed

const osinfo = imports.gi.Libosinfo;

var loader = new osinfo.Loader()
loader.process_path("./")

var db = loader.get_db()

var devs = db.get_device_list()

print ("All device IDs")
for (idx in devs.get_elements()) {
    var dev = devs.get_nth(idx)
    print ("  Device " + dev.get_id())
}

var names = db.unique_values_for_property_in_device("name")

print ("All device names")
for (idx in names) {
    var name = names[idx]
    print ("  Name " + name)
}

var osnames = db.unique_values_for_property_in_os("short-id")

print ("All OS short ids")
for (idx in osnames) {
    var name = osnames[idx]

    print ("  OS short id " + name)
}

var osid = "http://fedoraproject.org/fedora-11"
var hvid = "http://qemu.org/qemu-kvm-0.11.0"
var drvclass = "net"
//var drvclass = "audio"

var os = db.get_os(osid)
var hv = db.get_platform(hvid)

var dep = db.find_deployment(os, hv)

var filter = new osinfo.Filter()
filter.add_constraint("class", drvclass)
var link = dep.get_preferred_device_link(new osinfo.DeviceLinkFilter({target_filter: filter}))
var dev = link.get_target()
var drv = link.get_param_value("driver")
print ("For OS '" + os.get_name() + "' " +
       "fruit '" + os.get_param_value("x-fruit") + "' " +
       "zoo '" + os.get_param_values("x-animal") + "' " +
       "with HV '" + hv.get_name() + "' " +
       "for class '" + drvclass + "' " +
       "use device '" + dev.get_name() + "' " +
       "with HV driver '" + link.get_driver() + "'")