| 1 |
/* |
| 2 |
* Copyright (C) 2017 Red Hat, Inc. |
| 3 |
* SPDX-License-Identifier: LGPL-2.1-or-later |
| 4 |
*/ |
| 5 |
|
| 6 |
import cockpit from "cockpit"; |
| 7 |
import * as python from "python.js"; |
| 8 |
import inotify_py from "inotify.py"; |
| 9 |
|
| 10 |
import { debug } from "./utils"; |
| 11 |
import watch_appstream_py from "./watch-appstream.py"; |
| 12 |
|
| 13 |
let metainfo_db = null; |
| 14 |
|
| 15 |
export function get_metainfo_db() { |
| 16 |
if (!metainfo_db) { |
| 17 |
metainfo_db = cockpit.event_target({ |
| 18 |
ready: false, |
| 19 |
components: [], |
| 20 |
origin_files: [] |
| 21 |
}); |
| 22 |
|
| 23 |
let buf = ""; |
| 24 |
python.spawn([inotify_py, watch_appstream_py], [], |
| 25 |
{ environ: ["LANGUAGE=" + (cockpit.language || "en")] }) |
| 26 |
.stream(function (data) { |
| 27 |
buf += data; |
| 28 |
const lines = buf.split("\n"); |
| 29 |
buf = lines[lines.length - 1]; |
| 30 |
if (lines.length >= 2) { |
| 31 |
const metadata = JSON.parse(lines[lines.length - 2]); |
| 32 |
metainfo_db.components = metadata.components; |
| 33 |
metainfo_db.origin_files = metadata.origin_files; |
| 34 |
metainfo_db.ready = true; |
| 35 |
metainfo_db.dispatchEvent("changed"); |
| 36 |
debug("read metainfo_db:", metainfo_db); |
| 37 |
} |
| 38 |
}) |
| 39 |
.catch(error => console.warn("watch-appstream.py failed:", error)); |
| 40 |
} |
| 41 |
|
| 42 |
return metainfo_db; |
| 43 |
} |