relpipe-data/examples-apt.xml
author František Kučera <franta-hg@frantovo.cz>
Tue, 09 Apr 2019 22:53:40 +0200
branchv_0
changeset 257 a39066264509
child 326 ab7f333f1225
permissions -rw-r--r--
examples: Reading apt (Debian package system) results
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
257
a39066264509 examples: Reading apt (Debian package system) results
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     1
<stránka
a39066264509 examples: Reading apt (Debian package system) results
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     2
	xmlns="https://trac.frantovo.cz/xml-web-generator/wiki/xmlns/strana"
a39066264509 examples: Reading apt (Debian package system) results
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     3
	xmlns:m="https://trac.frantovo.cz/xml-web-generator/wiki/xmlns/makro">
a39066264509 examples: Reading apt (Debian package system) results
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     4
	
a39066264509 examples: Reading apt (Debian package system) results
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     5
	<nadpis>Reading apt (Debian package system) results</nadpis>
a39066264509 examples: Reading apt (Debian package system) results
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     6
	<perex>using Recutils and/or Relational pipes</perex>
a39066264509 examples: Reading apt (Debian package system) results
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     7
	<m:pořadí-příkladu>02000</m:pořadí-příkladu>
a39066264509 examples: Reading apt (Debian package system) results
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     8
a39066264509 examples: Reading apt (Debian package system) results
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     9
	<text xmlns="http://www.w3.org/1999/xhtml">
a39066264509 examples: Reading apt (Debian package system) results
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    10
		
a39066264509 examples: Reading apt (Debian package system) results
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    11
		<p>
a39066264509 examples: Reading apt (Debian package system) results
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    12
			Debian, Ubuntu and other derived GNU/Linux distributions have their package system based on the <code>.deb</code> packages and tools like <code>apt</code> (or formerly <code>aptitude</code> and <code>apt-get</code>).
a39066264509 examples: Reading apt (Debian package system) results
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    13
			This is a command line tool for installing packages and also for searching, showing metadata and other related tasks.
a39066264509 examples: Reading apt (Debian package system) results
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    14
			We can show a metadata for a package this way:
a39066264509 examples: Reading apt (Debian package system) results
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    15
		</p>
a39066264509 examples: Reading apt (Debian package system) results
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    16
		
a39066264509 examples: Reading apt (Debian package system) results
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    17
		<m:pre jazyk="text"><![CDATA[$ apt show emacs
a39066264509 examples: Reading apt (Debian package system) results
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    18
Package: emacs
a39066264509 examples: Reading apt (Debian package system) results
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    19
Version: 47.0
a39066264509 examples: Reading apt (Debian package system) results
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    20
Priority: optional
a39066264509 examples: Reading apt (Debian package system) results
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    21
Section: editors
a39066264509 examples: Reading apt (Debian package system) results
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    22
Source: emacs-defaults
a39066264509 examples: Reading apt (Debian package system) results
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    23
Installed-Size: 8 192 B
a39066264509 examples: Reading apt (Debian package system) results
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    24
Supported: 5y
a39066264509 examples: Reading apt (Debian package system) results
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    25
Download-Size: 1 748 B
a39066264509 examples: Reading apt (Debian package system) results
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    26
Description: GNU Emacs editor (metapackage)
a39066264509 examples: Reading apt (Debian package system) results
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    27
 GNU Emacs is the extensible self-documenting text editor.
a39066264509 examples: Reading apt (Debian package system) results
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    28
 This is a metapackage that will always depend on the latest
a39066264509 examples: Reading apt (Debian package system) results
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    29
 recommended Emacs release.
a39066264509 examples: Reading apt (Debian package system) results
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    30
 …]]></m:pre>
a39066264509 examples: Reading apt (Debian package system) results
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    31
a39066264509 examples: Reading apt (Debian package system) results
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    32
		<p>
a39066264509 examples: Reading apt (Debian package system) results
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    33
			This is some kind of ordinary human-readable listing.
a39066264509 examples: Reading apt (Debian package system) results
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    34
			But, it seems familiar, like we have met somewhere before… Yes, it is almost the same format as recfile from <a href="https://www.gnu.org/software/recutils/">GNU Recutils</a>!
a39066264509 examples: Reading apt (Debian package system) results
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    35
			There are field names, colons and values. Each pair on a separate line.
a39066264509 examples: Reading apt (Debian package system) results
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    36
			And there is also a convention for multi-line text – just with a little difference: indentation instead of <code>+</code>.
a39066264509 examples: Reading apt (Debian package system) results
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    37
			But we can tune it with just a little <code>sed</code> transformation
a39066264509 examples: Reading apt (Debian package system) results
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    38
			and then read it like a recfile:
a39066264509 examples: Reading apt (Debian package system) results
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    39
		</p>
a39066264509 examples: Reading apt (Debian package system) results
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    40
		
a39066264509 examples: Reading apt (Debian package system) results
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    41
		<m:pre jazyk="bash"><![CDATA[apt show emacs25* \
a39066264509 examples: Reading apt (Debian package system) results
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    42
	| sed 's/^ /+/g' \
a39066264509 examples: Reading apt (Debian package system) results
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    43
	| relpipe-in-recfile \
a39066264509 examples: Reading apt (Debian package system) results
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    44
	| relpipe-tr-cut '.*' 'Package|Version|Section|Installed-Size|Homepage|Supported' \
a39066264509 examples: Reading apt (Debian package system) results
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    45
	| relpipe-out-tabular]]></m:pre>
a39066264509 examples: Reading apt (Debian package system) results
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    46
	
a39066264509 examples: Reading apt (Debian package system) results
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    47
		<p>And print results in a pretty table:</p>
a39066264509 examples: Reading apt (Debian package system) results
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    48
		
a39066264509 examples: Reading apt (Debian package system) results
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    49
		<pre><![CDATA[recfile:
a39066264509 examples: Reading apt (Debian package system) results
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    50
 ╭─────────────────────────┬──────────────────┬────────────────────┬─────────────────────────┬────────────────────────────────────┬────────────────────╮
a39066264509 examples: Reading apt (Debian package system) results
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    51
 │ Package        (string) │ Version (string) │ Section   (string) │ Installed-Size (string) │ Homepage                  (string) │ Supported (string) │
a39066264509 examples: Reading apt (Debian package system) results
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    52
 ├─────────────────────────┼──────────────────┼────────────────────┼─────────────────────────┼────────────────────────────────────┼────────────────────┤
a39066264509 examples: Reading apt (Debian package system) results
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    53
 │ emacs25                 │ 25.2+1-6         │ editors            │ 19,7 MB                 │ http://www.gnu.org/software/emacs/ │ 5y                 │
a39066264509 examples: Reading apt (Debian package system) results
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    54
 │ emacs25-nox             │ 25.2+1-6         │ editors            │ 17,9 MB                 │ http://www.gnu.org/software/emacs/ │ 5y                 │
a39066264509 examples: Reading apt (Debian package system) results
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    55
 │ emacs25-bin-common      │ 25.2+1-6         │ editors            │ 473 kB                  │ http://www.gnu.org/software/emacs/ │ 5y                 │
a39066264509 examples: Reading apt (Debian package system) results
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    56
 │ emacs25-common-non-dfsg │ 25.2+1-1         │ multiverse/editors │ 4 685 kB                │                                    │                    │
a39066264509 examples: Reading apt (Debian package system) results
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    57
 │ emacs25-common          │ 25.2+1-6         │ editors            │ 66,9 MB                 │ http://www.gnu.org/software/emacs/ │ 5y                 │
a39066264509 examples: Reading apt (Debian package system) results
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    58
 │ emacs25-el              │ 25.2+1-6         │ editors            │ 16,3 MB                 │ http://www.gnu.org/software/emacs/ │ 5y                 │
a39066264509 examples: Reading apt (Debian package system) results
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    59
 │ emacs25-dbg             │ 25.2+1-6         │ debug              │ 5 604 kB                │ http://www.gnu.org/software/emacs/ │ 5y                 │
a39066264509 examples: Reading apt (Debian package system) results
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    60
 │ emacs25-nox-dbg         │ 25.2+1-6         │ debug              │ 3 996 kB                │ http://www.gnu.org/software/emacs/ │ 5y                 │
a39066264509 examples: Reading apt (Debian package system) results
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    61
 ╰─────────────────────────┴──────────────────┴────────────────────┴─────────────────────────┴────────────────────────────────────┴────────────────────╯
a39066264509 examples: Reading apt (Debian package system) results
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    62
Record count: 8]]></pre>
a39066264509 examples: Reading apt (Debian package system) results
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    63
a39066264509 examples: Reading apt (Debian package system) results
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    64
		<p>
a39066264509 examples: Reading apt (Debian package system) results
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    65
			We can use also GNU Recutils, but we have to rename some fields like <code>Installed-Size</code> because the <code>-</code> hyphen does not seem to be edible.
a39066264509 examples: Reading apt (Debian package system) results
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    66
			This can be fixed this way:
a39066264509 examples: Reading apt (Debian package system) results
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    67
		</p>
a39066264509 examples: Reading apt (Debian package system) results
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    68
		
a39066264509 examples: Reading apt (Debian package system) results
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    69
		<m:pre jazyk="bash"><![CDATA[apt show emacs* \
a39066264509 examples: Reading apt (Debian package system) results
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    70
	| sed -E \
a39066264509 examples: Reading apt (Debian package system) results
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    71
		-e 's/^([^-]+)-([^-]+)-([^:]+)/\1_\2_\3/g' \
a39066264509 examples: Reading apt (Debian package system) results
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    72
		-e 's/^([^-]+)-([^:]+)/\1_\2/g' \
a39066264509 examples: Reading apt (Debian package system) results
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    73
		-e 's/^ /+/g' \
a39066264509 examples: Reading apt (Debian package system) results
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    74
	| recsel -p Package,Version,Homepage]]></m:pre>
a39066264509 examples: Reading apt (Debian package system) results
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    75
a39066264509 examples: Reading apt (Debian package system) results
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    76
		<p>However, it is still quite dirty, because <code>apt</code> complains about:</p>
a39066264509 examples: Reading apt (Debian package system) results
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    77
		
a39066264509 examples: Reading apt (Debian package system) results
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    78
		<pre>WARNING: apt does not have a stable CLI interface. Use with caution in scripts.</pre>
a39066264509 examples: Reading apt (Debian package system) results
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    79
		
a39066264509 examples: Reading apt (Debian package system) results
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    80
		<p>
a39066264509 examples: Reading apt (Debian package system) results
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    81
			So it would be better to introduce some machine-readable output in the <code>apt</code> tool.
a39066264509 examples: Reading apt (Debian package system) results
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    82
			But until that: <em>Happy hacking!</em>
a39066264509 examples: Reading apt (Debian package system) results
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    83
			For some ad-hoc operations it is usable and we can e.g. convert the results to a CSV or a LibreOffice Calc file (ODS).
a39066264509 examples: Reading apt (Debian package system) results
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    84
		</p>
a39066264509 examples: Reading apt (Debian package system) results
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    85
		
a39066264509 examples: Reading apt (Debian package system) results
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    86
		<m:pre jazyk="bash"><![CDATA[apt show emacs25* \
a39066264509 examples: Reading apt (Debian package system) results
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    87
	| sed 's/^ /+/g' \
a39066264509 examples: Reading apt (Debian package system) results
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    88
	| relpipe-in-recfile \
a39066264509 examples: Reading apt (Debian package system) results
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    89
	| relpipe-tr-cut '.*' 'Package|Version|Section|Installed-Size|Homepage|Supported' \
a39066264509 examples: Reading apt (Debian package system) results
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    90
	| relpipe-out-ods \
a39066264509 examples: Reading apt (Debian package system) results
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    91
	> apt-packages.fods]]></m:pre>
a39066264509 examples: Reading apt (Debian package system) results
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    92
	
a39066264509 examples: Reading apt (Debian package system) results
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    93
		<p>The machine-readable format should also carry the sizes in bytes instead of human-friendly units.</p>
a39066264509 examples: Reading apt (Debian package system) results
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    94
		
a39066264509 examples: Reading apt (Debian package system) results
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    95
		<p>Good news are that the <a href="https://www.gnu.org/software/guix/manual/en/html_node/Invoking-guix-package.html">Guix SD</a> package system already prints results in regular recfile format.</p>
a39066264509 examples: Reading apt (Debian package system) results
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    96
		
a39066264509 examples: Reading apt (Debian package system) results
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    97
	</text>
a39066264509 examples: Reading apt (Debian package system) results
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    98
a39066264509 examples: Reading apt (Debian package system) results
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    99
</stránka>