| 1 |
# Use the command-line tools |
| 2 |
|
| 3 |
`prov` installs two console scripts: `prov-convert` (format/graphics conversion) and |
| 4 |
`prov-compare` (equivalence checking). Both wrap the same {py:class}`~prov.model.ProvDocument` |
| 5 |
API described in the other how-to pages. |
| 6 |
|
| 7 |
## `prov-convert` |
| 8 |
|
| 9 |
Convert a PROV-JSON document to PROV-N, PROV-XML, PROV-O/RDF, or any image format |
| 10 |
supported by Graphviz. |
| 11 |
|
| 12 |
### Synopsis |
| 13 |
|
| 14 |
```bash |
| 15 |
prov-convert [-h] [-f FORMAT] [-V] [infile] [outfile] |
| 16 |
``` |
| 17 |
|
| 18 |
### Options |
| 19 |
|
| 20 |
| Flag | Argument | Default | Meaning | |
| 21 |
| --- | --- | --- | --- | |
| 22 |
| `-f`, `--format` | `FORMAT` | `json` | Output format: `json`, `xml`, `provn`, or any format name GraphViz's `dot` accepts (e.g. `svg`, `pdf`, `png`) | |
| 23 |
| `-V`, `--version` | — | — | Print the version and exit | |
| 24 |
| `-h`, `--help` | — | — | Print usage and exit | |
| 25 |
| `infile` (positional) | — | stdin | Input file — **always read as PROV-JSON**, there is no input-format flag | |
| 26 |
| `outfile` (positional) | — | stdout | Output file, written in `--format` | |
| 27 |
|
| 28 |
`prov-convert` has no flag to choose the *input* format — the input is always |
| 29 |
deserialized as PROV-JSON (`ProvDocument.deserialize(infile)`, which defaults to |
| 30 |
`format="json"`). To convert from PROV-XML or RDF, load and re-serialize the document as |
| 31 |
PROV-JSON first (or write a two-line Python script using |
| 32 |
{py:meth}`~prov.model.ProvDocument.deserialize`/{py:meth}`~prov.model.ProvDocument.serialize` |
| 33 |
directly — see the format-specific how-to pages). |
| 34 |
|
| 35 |
### Examples |
| 36 |
|
| 37 |
Convert a PROV-JSON file to PROV-N: |
| 38 |
|
| 39 |
```bash |
| 40 |
prov-convert -f provn document.json document.provn |
| 41 |
``` |
| 42 |
|
| 43 |
Convert a PROV-JSON file to an SVG diagram (needs a local Graphviz install, see |
| 44 |
{doc}`graphics`): |
| 45 |
|
| 46 |
```bash |
| 47 |
prov-convert -f svg document.json document.svg |
| 48 |
``` |
| 49 |
|
| 50 |
Read from stdin, write PROV-JSON (the default) to stdout: |
| 51 |
|
| 52 |
```bash |
| 53 |
cat document.json | prov-convert > copy.json |
| 54 |
``` |
| 55 |
|
| 56 |
### Exit behaviour |
| 57 |
|
| 58 |
- Success: exit code `0`; the converted document is written to `outfile`. |
| 59 |
- Unsupported `--format` value, or any other error (bad input, missing file): the error is |
| 60 |
printed to stderr prefixed with the program name, and the process exits with code `2`. |
| 61 |
|
| 62 |
```bash |
| 63 |
prov-convert -f bogus document.json out.bogus |
| 64 |
# prov-convert: E: Output format "bogus" is not supported. |
| 65 |
# for help use --help |
| 66 |
echo $? # 2 |
| 67 |
``` |
| 68 |
|
| 69 |
## `prov-compare` |
| 70 |
|
| 71 |
Compare two PROV documents for equivalence (after |
| 72 |
{py:meth}`~prov.model.ProvBundle.unified`-style equality — the same `==` used throughout |
| 73 |
`prov`), each independently loadable as PROV-JSON or PROV-XML. |
| 74 |
|
| 75 |
### Synopsis |
| 76 |
|
| 77 |
```bash |
| 78 |
prov-compare [-h] [-f FORMAT1] [-F FORMAT2] [-V] [file1] [file2] |
| 79 |
``` |
| 80 |
|
| 81 |
### Options |
| 82 |
|
| 83 |
| Flag | Argument | Default | Meaning | |
| 84 |
| --- | --- | --- | --- | |
| 85 |
| `-f`, `--format1` | `FORMAT1` | `json` | File 1's format: `json` or `xml` | |
| 86 |
| `-F`, `--format2` | `FORMAT2` | `json` | File 2's format: `json` or `xml` | |
| 87 |
| `-V`, `--version` | — | — | Print the version and exit | |
| 88 |
| `-h`, `--help` | — | — | Print usage and exit | |
| 89 |
| `file1`, `file2` (positional) | — | — | The two files to compare | |
| 90 |
|
| 91 |
Although the help text says "`json` or `xml`", any format name registered with |
| 92 |
{py:class}`prov.serializers.Registry` is actually accepted (e.g. `rdf`), because the flag |
| 93 |
value is passed straight through to |
| 94 |
{py:meth}`~prov.model.ProvDocument.deserialize`(format=...). |
| 95 |
|
| 96 |
### Examples |
| 97 |
|
| 98 |
Compare two PROV-JSON files: |
| 99 |
|
| 100 |
```bash |
| 101 |
prov-compare document.json copy.json |
| 102 |
``` |
| 103 |
|
| 104 |
Compare a PROV-JSON file against a PROV-XML file: |
| 105 |
|
| 106 |
```bash |
| 107 |
prov-compare -f json -F xml document.json document.xml |
| 108 |
``` |
| 109 |
|
| 110 |
### Exit behaviour |
| 111 |
|
| 112 |
`prov-compare` has no textual "equal"/"different" output on success — it communicates the |
| 113 |
result purely through the exit code: |
| 114 |
|
| 115 |
- Exit code `0`: the two documents are equivalent (`doc1 == doc2`). |
| 116 |
- Exit code `1`: the two documents differ (`doc1 != doc2`). |
| 117 |
- Exit code `2`: an error occurred (e.g. a file could not be parsed); a message is printed |
| 118 |
to stderr. |
| 119 |
|
| 120 |
```bash |
| 121 |
prov-compare document.json document.json; echo $? # 0 (identical) |
| 122 |
prov-compare document.json copy2.json; echo $? # 1 (different) |
| 123 |
``` |