Imported Upstream version 1.3.0
[platform/upstream/augeas.git] / lenses / aptconf.aug
1 (*
2 Module: AptConf
3  Parses /etc/apt/apt.conf and /etc/apt/apt.conf.d/*
4
5 Author: Raphael Pinson <raphink@gmail.com>
6
7 About: Reference
8  This lens tries to keep as close as possible to `man 5 apt.conf`
9 where possible.
10
11 About: License
12   This file is licenced under the LGPL v2+, like the rest of Augeas.
13
14 About: Lens Usage
15   To be documented
16
17 About: Configuration files
18   This lens applies to /etc/apt/apt.conf and /etc/apt/apt.conf.d/*.
19 See <filter>.
20 *)
21
22
23 module AptConf =
24  autoload xfm
25
26 (************************************************************************
27  * Group:                 USEFUL PRIMITIVES
28  *************************************************************************)
29
30 (* View: eol
31    And <Util.eol> end of line *)
32 let eol = Util.eol
33
34 (* View: empty
35    A C-style empty line *)
36 let empty = Util.empty_c_style
37
38 (* View: indent
39    An indentation *)
40 let indent = Util.indent
41
42 (* View: comment_simple
43    A one-line comment, C-style *)
44 let comment_simple = Util.comment_c_style
45
46 (* View: comment_multi
47    A multiline comment, C-style *)
48 let comment_multi = Util.comment_multiline
49
50 (* View: comment
51    A comment, either <comment_simple> or <comment_multi> *)
52 let comment = comment_simple | comment_multi
53
54
55 (************************************************************************
56  * Group:                 ENTRIES
57  *************************************************************************)
58
59 (* View: name_re
60    Regex for entry names *)
61 let name_re = /[A-Za-z][A-Za-z-]*/
62
63 (* View: name_re_colons
64    Regex for entry names with colons *)
65 let name_re_colons = /[A-Za-z][A-Za-z:-]*/
66
67
68 (* View: entry
69    An apt.conf entry, recursive
70
71    WARNING:
72      This lens exploits a put ambiguity
73      since apt.conf allows for both
74      APT { Clean-Installed { "true" } }
75      and APT::Clean-Installed "true";
76      but we're chosing to map them the same way
77
78      The recursive lens doesn't seem
79      to care and defaults to the first
80      item in the union.
81
82      This is why the APT { Clean-Installed { "true"; } }
83      form is listed first, since it supports
84      all subnodes (which Dpkg::Conf) doesn't.
85
86      Exchanging these two expressions in the union
87      makes tests fails since the tree cannot
88      be mapped back.
89
90      This situation results in existing
91      configuration being modified when the
92      associated tree is modified. For example,
93      changing the value of
94      APT::Clean-Installed "true"; to "false"
95      results in
96      APT { Clean-Installed "false"; }
97      (see unit tests)
98  *)
99 let rec entry_noeol =
100  let value =
101     Util.del_str "\"" . store /[^"\n]+/
102                       . del /";?/ "\";" in
103  let opt_eol = del /[ \t\n]*/ "\n" in
104  let long_eol = del /[ \t]*\n+/ "\n" in
105  let list_elem = [ opt_eol . label "@elem" . value ] in
106  let eol_comment = del /([ \t\n]*\n)?/ "" . comment in
107      [ key name_re . Sep.space . value ]
108    | [ key name_re . del /[ \t\n]*\{/ " {" .
109          ( (opt_eol . entry_noeol) |
110            list_elem |
111            eol_comment
112            )* .
113          del /[ \t\n]*\};?/ "\n};" ]
114    | [ key name_re . Util.del_str "::" . entry_noeol ]
115
116 let entry = indent . entry_noeol . eol
117
118
119 (* View: include
120    A file inclusion
121    /!\ The manpage is not clear on the syntax *)
122 let include =
123  [ indent . key "#include" . Sep.space
124           . store Rx.fspath . eol ]
125
126
127 (* View: clear
128    A list of variables to clear
129    /!\ The manpage is not clear on the syntax *)
130 let clear =
131  let name = [ label "name" . store name_re_colons ] in
132  [ indent . key "#clear" . Sep.space
133           . Build.opt_list name Sep.space
134           . eol ]
135
136
137 (************************************************************************
138  * Group:                 LENS AND FILTER
139  *************************************************************************)
140
141 (* View: lns
142     The apt.conf lens *)
143 let lns = (empty|comment|entry|include|clear)*
144
145
146 (* View: filter *)
147 let filter = incl "/etc/apt/apt.conf"
148    . incl "/etc/apt/apt.conf.d/*"
149    . Util.stdexcl
150
151 let xfm = transform lns filter