ruby-augeas 0.5.0 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/COPYING +38 -46
- data/NEWS +7 -1
- data/README.md +86 -0
- data/Rakefile +5 -4
- data/ext/augeas/_augeas.c +128 -29
- data/lib/augeas/facade.rb +326 -0
- data/lib/augeas.rb +71 -0
- data/tests/tc_augeas.rb +3 -1
- data/tests/tc_facade.rb +554 -0
- metadata +16 -16
- data/README.rdoc +0 -34
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 516d7f0b53e2ef92757c400168ab4fd4ac8f1fe121ba3378f89293d181d1a8ad
|
4
|
+
data.tar.gz: 7e2511ae0787aa55a441a311218caf78fe954e02f863b73cc00a6f2419834cb0
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: a390e7d3add28bfdc4624ebcb6b6e4887b8f613751c1507fb30f72ce2b04e36e5c2b33a51712c72a0200c9218528ab9bb02b5d15761116a8e6375d7e7d8afe01
|
7
|
+
data.tar.gz: c7700610c5447a52673685a4a414fb2cef0ea3bc6214a8e9ac751812e23cdd39088b80bbc62765ade52a48d7cc7aece836dcc6a9412cd3e5f8542ed9b5d8663f
|
data/COPYING
CHANGED
@@ -1,9 +1,8 @@
|
|
1
|
-
|
2
1
|
GNU LESSER GENERAL PUBLIC LICENSE
|
3
2
|
Version 2.1, February 1999
|
4
3
|
|
5
4
|
Copyright (C) 1991, 1999 Free Software Foundation, Inc.
|
6
|
-
|
5
|
+
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
7
6
|
Everyone is permitted to copy and distribute verbatim copies
|
8
7
|
of this license document, but changing it is not allowed.
|
9
8
|
|
@@ -23,8 +22,7 @@ specially designated software packages--typically libraries--of the
|
|
23
22
|
Free Software Foundation and other authors who decide to use it. You
|
24
23
|
can use it too, but we suggest you first think carefully about whether
|
25
24
|
this license or the ordinary General Public License is the better
|
26
|
-
strategy to use in any particular case, based on the explanations
|
27
|
-
below.
|
25
|
+
strategy to use in any particular case, based on the explanations below.
|
28
26
|
|
29
27
|
When we speak of free software, we are referring to freedom of use,
|
30
28
|
not price. Our General Public Licenses are designed to make sure that
|
@@ -57,7 +55,7 @@ modified by someone else and passed on, the recipients should know
|
|
57
55
|
that what they have is not the original version, so that the original
|
58
56
|
author's reputation will not be affected by problems that might be
|
59
57
|
introduced by others.
|
60
|
-
|
58
|
+
|
61
59
|
Finally, software patents pose a constant threat to the existence of
|
62
60
|
any free program. We wish to make sure that a company cannot
|
63
61
|
effectively restrict the users of a free program by obtaining a
|
@@ -89,9 +87,9 @@ libraries. However, the Lesser license provides advantages in certain
|
|
89
87
|
special circumstances.
|
90
88
|
|
91
89
|
For example, on rare occasions, there may be a special need to
|
92
|
-
encourage the widest possible use of a certain library, so that it
|
93
|
-
|
94
|
-
|
90
|
+
encourage the widest possible use of a certain library, so that it becomes
|
91
|
+
a de-facto standard. To achieve this, non-free programs must be
|
92
|
+
allowed to use the library. A more frequent case is that a free
|
95
93
|
library does the same job as widely used non-free libraries. In this
|
96
94
|
case, there is little to gain by limiting the free library to free
|
97
95
|
software only, so we use the Lesser General Public License.
|
@@ -113,7 +111,7 @@ modification follow. Pay close attention to the difference between a
|
|
113
111
|
"work based on the library" and a "work that uses the library". The
|
114
112
|
former contains code derived from the library, whereas the latter must
|
115
113
|
be combined with the library in order to run.
|
116
|
-
|
114
|
+
|
117
115
|
GNU LESSER GENERAL PUBLIC LICENSE
|
118
116
|
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
|
119
117
|
|
@@ -138,8 +136,8 @@ included without limitation in the term "modification".)
|
|
138
136
|
"Source code" for a work means the preferred form of the work for
|
139
137
|
making modifications to it. For a library, complete source code means
|
140
138
|
all the source code for all modules it contains, plus any associated
|
141
|
-
interface definition files, plus the scripts used to control
|
142
|
-
|
139
|
+
interface definition files, plus the scripts used to control compilation
|
140
|
+
and installation of the library.
|
143
141
|
|
144
142
|
Activities other than copying, distribution and modification are not
|
145
143
|
covered by this License; they are outside its scope. The act of
|
@@ -218,7 +216,7 @@ instead of to this License. (If a newer version than version 2 of the
|
|
218
216
|
ordinary GNU General Public License has appeared, then you can specify
|
219
217
|
that version instead if you wish.) Do not make any other change in
|
220
218
|
these notices.
|
221
|
-
|
219
|
+
|
222
220
|
Once this change is made in a given copy, it is irreversible for
|
223
221
|
that copy, so the ordinary GNU General Public License applies to all
|
224
222
|
subsequent copies and derivative works made from that copy.
|
@@ -269,7 +267,7 @@ Library will still fall under Section 6.)
|
|
269
267
|
distribute the object code for the work under the terms of Section 6.
|
270
268
|
Any executables containing that work also fall under Section 6,
|
271
269
|
whether or not they are linked directly with the Library itself.
|
272
|
-
|
270
|
+
|
273
271
|
6. As an exception to the Sections above, you may also combine or
|
274
272
|
link a "work that uses the Library" with the Library to produce a
|
275
273
|
work containing portions of the Library, and distribute that work
|
@@ -305,10 +303,10 @@ of these things:
|
|
305
303
|
the user installs one, as long as the modified version is
|
306
304
|
interface-compatible with the version that the work was made with.
|
307
305
|
|
308
|
-
c) Accompany the work with a written offer, valid for at
|
309
|
-
three years, to give the same user the materials
|
310
|
-
Subsection 6a, above, for a charge no more
|
311
|
-
performing this distribution.
|
306
|
+
c) Accompany the work with a written offer, valid for at
|
307
|
+
least three years, to give the same user the materials
|
308
|
+
specified in Subsection 6a, above, for a charge no more
|
309
|
+
than the cost of performing this distribution.
|
312
310
|
|
313
311
|
d) If distribution of the work is made by offering access to copy
|
314
312
|
from a designated place, offer equivalent access to copy the above
|
@@ -331,7 +329,7 @@ restrictions of other proprietary libraries that do not normally
|
|
331
329
|
accompany the operating system. Such a contradiction means you cannot
|
332
330
|
use both them and the Library together in an executable that you
|
333
331
|
distribute.
|
334
|
-
|
332
|
+
|
335
333
|
7. You may place library facilities that are a work based on the
|
336
334
|
Library side-by-side in a single library together with other library
|
337
335
|
facilities not covered by this License, and distribute such a combined
|
@@ -372,7 +370,7 @@ subject to these terms and conditions. You may not impose any further
|
|
372
370
|
restrictions on the recipients' exercise of the rights granted herein.
|
373
371
|
You are not responsible for enforcing compliance by third parties with
|
374
372
|
this License.
|
375
|
-
|
373
|
+
|
376
374
|
11. If, as a consequence of a court judgment or allegation of patent
|
377
375
|
infringement or for any other reason (not limited to patent issues),
|
378
376
|
conditions are imposed on you (whether by court order, agreement or
|
@@ -386,10 +384,9 @@ all those who receive copies directly or indirectly through you, then
|
|
386
384
|
the only way you could satisfy both it and this License would be to
|
387
385
|
refrain entirely from distribution of the Library.
|
388
386
|
|
389
|
-
If any portion of this section is held invalid or unenforceable under
|
390
|
-
|
391
|
-
|
392
|
-
circumstances.
|
387
|
+
If any portion of this section is held invalid or unenforceable under any
|
388
|
+
particular circumstance, the balance of the section is intended to apply,
|
389
|
+
and the section as a whole is intended to apply in other circumstances.
|
393
390
|
|
394
391
|
It is not the purpose of this section to induce you to infringe any
|
395
392
|
patents or other property right claims or to contest validity of any
|
@@ -407,11 +404,11 @@ be a consequence of the rest of this License.
|
|
407
404
|
|
408
405
|
12. If the distribution and/or use of the Library is restricted in
|
409
406
|
certain countries either by patents or by copyrighted interfaces, the
|
410
|
-
original copyright holder who places the Library under this License
|
411
|
-
|
412
|
-
|
413
|
-
|
414
|
-
|
407
|
+
original copyright holder who places the Library under this License may add
|
408
|
+
an explicit geographical distribution limitation excluding those countries,
|
409
|
+
so that distribution is permitted only in or among countries not thus
|
410
|
+
excluded. In such case, this License incorporates the limitation as if
|
411
|
+
written in the body of this License.
|
415
412
|
|
416
413
|
13. The Free Software Foundation may publish revised and/or new
|
417
414
|
versions of the Lesser General Public License from time to time.
|
@@ -425,7 +422,7 @@ conditions either of that version or of any later version published by
|
|
425
422
|
the Free Software Foundation. If the Library does not specify a
|
426
423
|
license version number, you may choose any version ever published by
|
427
424
|
the Free Software Foundation.
|
428
|
-
|
425
|
+
|
429
426
|
14. If you wish to incorporate parts of the Library into other free
|
430
427
|
programs whose distribution conditions are incompatible with these,
|
431
428
|
write to the author to ask for permission. For software which is
|
@@ -459,21 +456,19 @@ SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
|
|
459
456
|
DAMAGES.
|
460
457
|
|
461
458
|
END OF TERMS AND CONDITIONS
|
462
|
-
|
459
|
+
|
463
460
|
How to Apply These Terms to Your New Libraries
|
464
461
|
|
465
462
|
If you develop a new library, and you want it to be of the greatest
|
466
463
|
possible use to the public, we recommend making it free software that
|
467
464
|
everyone can redistribute and change. You can do so by permitting
|
468
|
-
redistribution under these terms (or, alternatively, under the terms
|
469
|
-
|
470
|
-
|
471
|
-
To apply these terms, attach the following notices to the library.
|
472
|
-
It is safest to attach them to the start of each source file to most
|
473
|
-
effectively convey the exclusion of warranty; and each file should
|
474
|
-
have at least the "copyright" line and a pointer to where the full
|
475
|
-
notice is found.
|
465
|
+
redistribution under these terms (or, alternatively, under the terms of the
|
466
|
+
ordinary General Public License).
|
476
467
|
|
468
|
+
To apply these terms, attach the following notices to the library. It is
|
469
|
+
safest to attach them to the start of each source file to most effectively
|
470
|
+
convey the exclusion of warranty; and each file should have at least the
|
471
|
+
"copyright" line and a pointer to where the full notice is found.
|
477
472
|
|
478
473
|
<one line to give the library's name and a brief idea of what it does.>
|
479
474
|
Copyright (C) <year> <name of author>
|
@@ -490,21 +485,18 @@ notice is found.
|
|
490
485
|
|
491
486
|
You should have received a copy of the GNU Lesser General Public
|
492
487
|
License along with this library; if not, write to the Free Software
|
493
|
-
Foundation, Inc.,
|
488
|
+
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
494
489
|
|
495
490
|
Also add information on how to contact you by electronic and paper mail.
|
496
491
|
|
497
|
-
You should also get your employer (if you work as a programmer) or
|
498
|
-
|
499
|
-
|
492
|
+
You should also get your employer (if you work as a programmer) or your
|
493
|
+
school, if any, to sign a "copyright disclaimer" for the library, if
|
494
|
+
necessary. Here is a sample; alter the names:
|
500
495
|
|
501
496
|
Yoyodyne, Inc., hereby disclaims all copyright interest in the
|
502
|
-
library `Frob' (a library for tweaking knobs) written by James
|
503
|
-
Random Hacker.
|
497
|
+
library `Frob' (a library for tweaking knobs) written by James Random Hacker.
|
504
498
|
|
505
499
|
<signature of Ty Coon>, 1 April 1990
|
506
500
|
Ty Coon, President of Vice
|
507
501
|
|
508
502
|
That's all there is to it!
|
509
|
-
|
510
|
-
|
data/NEWS
CHANGED
@@ -1,4 +1,10 @@
|
|
1
|
-
0.
|
1
|
+
0.6.0 - 2024-08-07
|
2
|
+
- Updated ruby bindings that behave more Ruby-ish
|
3
|
+
- Fix errors and warnings during build process
|
4
|
+
- Minor updates to README.md
|
5
|
+
- Update ruby-augeas.spec from current Fedora 39 spec file
|
6
|
+
|
7
|
+
0.5.0 - 2013-03-12
|
2
8
|
- add libxml2 headers and library to Makefile
|
3
9
|
- add libxml2-devel build req to rpm spec
|
4
10
|
- split out header, add memstream utils from Augeas
|
data/README.md
ADDED
@@ -0,0 +1,86 @@
|
|
1
|
+
![ruby-augeas ci build status](../../actions/workflows/ci.yml/badge.svg)
|
2
|
+
|
3
|
+
# Ruby bindings for augeas
|
4
|
+
|
5
|
+
The class Augeas provides bindings to [Augeas](https://augeas.net) library.
|
6
|
+
|
7
|
+
|
8
|
+
## Building
|
9
|
+
|
10
|
+
To build the bindings, which unfortunately includes installing them from a
|
11
|
+
gem, you need to have Augeas and its header file installed as well as
|
12
|
+
`pkg-config`.
|
13
|
+
|
14
|
+
On Fedora, you can do that simply by running
|
15
|
+
```
|
16
|
+
dnf install augeas-devel pkgconfig
|
17
|
+
```
|
18
|
+
|
19
|
+
On MacOS (OSX), you need to set up [Homebrew](https://brew.sh/) and then run
|
20
|
+
```
|
21
|
+
brew install augeas pkg-config
|
22
|
+
```
|
23
|
+
|
24
|
+
Build the ruby gem by running
|
25
|
+
```
|
26
|
+
rake build
|
27
|
+
rake test
|
28
|
+
rake gem
|
29
|
+
```
|
30
|
+
The output is pkg/ruby-augeas-VERSION.gem
|
31
|
+
|
32
|
+
Build the rpm package (optional) in the pkg/ subdirectory
|
33
|
+
```
|
34
|
+
rake rpm
|
35
|
+
```
|
36
|
+
The output is pkg/ruby-augeas-VERSION-1.DIST.src.rpm with binary packages in pkg/$(uname -m)
|
37
|
+
|
38
|
+
Create html documentation using rdoc
|
39
|
+
|
40
|
+
```
|
41
|
+
rake rdoc
|
42
|
+
```
|
43
|
+
|
44
|
+
The output is in doc/site/api/
|
45
|
+
The starting document is doc/site/api/index.html
|
46
|
+
|
47
|
+
## Usage
|
48
|
+
|
49
|
+
### Setting Data
|
50
|
+
```ruby
|
51
|
+
Augeas::open do |aug|
|
52
|
+
aug.set("/files/etc/sysconfig/firstboot/RUN_FIRSTBOOT", "YES")
|
53
|
+
unless aug.save
|
54
|
+
raise IOError, "Failed to save changes"
|
55
|
+
end
|
56
|
+
end
|
57
|
+
```
|
58
|
+
|
59
|
+
### Accessing Data
|
60
|
+
```ruby
|
61
|
+
firstboot = Augeas::open { |aug| aug.get("/files/etc/sysconfig/firstboot/RUN_FIRSTBOOT") }
|
62
|
+
```
|
63
|
+
|
64
|
+
### Removing Data
|
65
|
+
```ruby
|
66
|
+
Augeas::open do |aug|
|
67
|
+
aug.rm("/files/etc/sysconfig/firstboot/RUN_FIRSTBOOT")
|
68
|
+
unless aug.save
|
69
|
+
raise IOError, "Failed to save changes"
|
70
|
+
end
|
71
|
+
end
|
72
|
+
```
|
73
|
+
|
74
|
+
### Minimal Setup with a Custom Root
|
75
|
+
|
76
|
+
By passing `NO_MODL_AUTOLOAD`, no files are read on startup; that allows
|
77
|
+
setting up a custom transform.
|
78
|
+
|
79
|
+
```ruby
|
80
|
+
Augeas::open("/var/tmp/augeas-root", "/usr/local/share/mylenses",
|
81
|
+
Augeas::NO_MODL_AUTOLOAD) do |aug|
|
82
|
+
aug.transform(:lens => "Aliases.lns", :incl => "/etc/aliases")
|
83
|
+
aug.load
|
84
|
+
aug.get("/files/etc/aliases/*[name = 'postmaster']/value")
|
85
|
+
end
|
86
|
+
```
|
data/Rakefile
CHANGED
@@ -15,7 +15,7 @@ require 'rubygems/package_task'
|
|
15
15
|
|
16
16
|
PKG_NAME='ruby-augeas'
|
17
17
|
GEM_NAME=PKG_NAME # we'd like 'augeas' but that makes RPM fail
|
18
|
-
PKG_VERSION='0.
|
18
|
+
PKG_VERSION='0.6.0'
|
19
19
|
EXT_CONF='ext/augeas/extconf.rb'
|
20
20
|
MAKEFILE="ext/augeas/Makefile"
|
21
21
|
AUGEAS_MODULE="ext/augeas/_augeas.so"
|
@@ -66,16 +66,16 @@ task :test => :build
|
|
66
66
|
# Generate the documentation
|
67
67
|
#
|
68
68
|
RDoc::Task.new do |rd|
|
69
|
-
rd.main = "README.
|
69
|
+
rd.main = "README.md"
|
70
70
|
rd.rdoc_dir = "doc/site/api"
|
71
|
-
rd.rdoc_files.include("README.
|
71
|
+
rd.rdoc_files.include("README.md", "ext/**/*.[ch]","lib/**/*.rb")
|
72
72
|
end
|
73
73
|
|
74
74
|
#
|
75
75
|
# Packaging
|
76
76
|
#
|
77
77
|
PKG_FILES = FileList[
|
78
|
-
"Rakefile", "COPYING","README.
|
78
|
+
"Rakefile", "COPYING","README.md", "NEWS",
|
79
79
|
"ext/**/*.[ch]", "lib/**/*.rb", "ext/**/MANIFEST", "ext/**/extconf.rb",
|
80
80
|
"tests/**/*",
|
81
81
|
"spec/**/*"
|
@@ -93,6 +93,7 @@ SPEC = Gem::Specification.new do |s|
|
|
93
93
|
s.summary = "Ruby bindings for augeas"
|
94
94
|
s.authors = [ "Bryan Kearney", "David Lutterkort" ]
|
95
95
|
s.files = PKG_FILES
|
96
|
+
s.licenses = ['LGPL-2.1+']
|
96
97
|
s.autorequire = "augeas"
|
97
98
|
s.required_ruby_version = '>= 1.8.1'
|
98
99
|
s.extensions = "ext/augeas/extconf.rb"
|
data/ext/augeas/_augeas.c
CHANGED
@@ -25,6 +25,7 @@
|
|
25
25
|
#include <augeas.h>
|
26
26
|
|
27
27
|
static VALUE c_augeas;
|
28
|
+
static VALUE c_facade;
|
28
29
|
|
29
30
|
static augeas *aug_handle(VALUE s) {
|
30
31
|
augeas *aug;
|
@@ -50,16 +51,39 @@ static void augeas_free(augeas *aug) {
|
|
50
51
|
VALUE augeas_get(VALUE s, VALUE path) {
|
51
52
|
augeas *aug = aug_handle(s);
|
52
53
|
const char *cpath = StringValueCStr(path);
|
53
|
-
const char *value;
|
54
|
+
const char *value = NULL;
|
54
55
|
|
55
|
-
aug_get(aug, cpath, &value);
|
56
|
-
|
56
|
+
int r = aug_get(aug, cpath, &value);
|
57
|
+
/* There used to be a bug in Augeas that would make it not properly set
|
58
|
+
* VALUE to NULL when PATH was invalid. We check RETVAL, too, to avoid
|
59
|
+
* running into that */
|
60
|
+
if (r == 1 && value != NULL) {
|
57
61
|
return rb_str_new(value, strlen(value)) ;
|
58
62
|
} else {
|
59
63
|
return Qnil;
|
60
64
|
}
|
61
65
|
}
|
62
66
|
|
67
|
+
/*
|
68
|
+
* call-seq:
|
69
|
+
* get(PATH) -> String
|
70
|
+
*
|
71
|
+
* Lookup the value associated with PATH
|
72
|
+
*/
|
73
|
+
VALUE facade_get(VALUE s, VALUE path) {
|
74
|
+
augeas *aug = aug_handle(s);
|
75
|
+
const char *cpath = StringValueCStr(path);
|
76
|
+
const char *value = NULL;
|
77
|
+
|
78
|
+
int retval = aug_get(aug, cpath, &value);
|
79
|
+
|
80
|
+
if (retval == 1 && value != NULL) {
|
81
|
+
return rb_str_new(value, strlen(value));
|
82
|
+
} else {
|
83
|
+
return Qnil;
|
84
|
+
}
|
85
|
+
}
|
86
|
+
|
63
87
|
/*
|
64
88
|
* call-seq:
|
65
89
|
* exists(PATH) -> boolean
|
@@ -74,28 +98,30 @@ VALUE augeas_exists(VALUE s, VALUE path) {
|
|
74
98
|
return (ret == 1) ? Qtrue : Qfalse;
|
75
99
|
}
|
76
100
|
|
101
|
+
static int set(VALUE s, VALUE path, VALUE value) {
|
102
|
+
augeas *aug = aug_handle(s);
|
103
|
+
const char *cpath = StringValueCStr(path) ;
|
104
|
+
const char *cvalue = StringValueCStrOrNull(value) ;
|
105
|
+
|
106
|
+
return aug_set(aug, cpath, cvalue) ;
|
107
|
+
}
|
108
|
+
|
77
109
|
/*
|
78
110
|
* call-seq:
|
79
|
-
* set(PATH, VALUE) ->
|
111
|
+
* set(PATH, VALUE) -> int
|
80
112
|
*
|
81
113
|
* Set the value associated with PATH to VALUE. VALUE is copied into the
|
82
114
|
* internal data structure. Intermediate entries are created if they don't
|
83
115
|
* exist.
|
84
116
|
*/
|
85
117
|
VALUE augeas_set(VALUE s, VALUE path, VALUE value) {
|
86
|
-
|
87
|
-
const char *cpath = StringValueCStr(path) ;
|
88
|
-
const char *cvalue = StringValueCStrOrNull(value) ;
|
89
|
-
|
90
|
-
int callValue = aug_set(aug, cpath, cvalue) ;
|
91
|
-
VALUE returnValue ;
|
118
|
+
int callValue = set(s, path, value);
|
92
119
|
|
93
|
-
|
94
|
-
|
95
|
-
else
|
96
|
-
returnValue = Qfalse ;
|
120
|
+
return (callValue == 0) ? Qtrue : Qfalse;
|
121
|
+
}
|
97
122
|
|
98
|
-
|
123
|
+
VALUE facade_set(VALUE s, VALUE path, VALUE value) {
|
124
|
+
return INT2FIX(set(s, path, value));
|
99
125
|
}
|
100
126
|
|
101
127
|
/*
|
@@ -158,7 +184,7 @@ VALUE augeas_mv(VALUE s, VALUE src, VALUE dst) {
|
|
158
184
|
*
|
159
185
|
* Remove path and all its children. Returns the number of entries removed
|
160
186
|
*/
|
161
|
-
VALUE augeas_rm(VALUE s, VALUE path
|
187
|
+
VALUE augeas_rm(VALUE s, VALUE path) {
|
162
188
|
augeas *aug = aug_handle(s);
|
163
189
|
const char *cpath = StringValueCStr(path) ;
|
164
190
|
|
@@ -176,6 +202,7 @@ VALUE augeas_rm(VALUE s, VALUE path, VALUE sibling) {
|
|
176
202
|
VALUE augeas_match(VALUE s, VALUE p) {
|
177
203
|
augeas *aug = aug_handle(s);
|
178
204
|
const char *path = StringValueCStr(p);
|
205
|
+
VALUE result;
|
179
206
|
char **matches = NULL;
|
180
207
|
int cnt, i;
|
181
208
|
|
@@ -184,7 +211,36 @@ VALUE augeas_match(VALUE s, VALUE p) {
|
|
184
211
|
rb_raise(rb_eSystemCallError, "Matching path expression '%s' failed",
|
185
212
|
path);
|
186
213
|
|
187
|
-
|
214
|
+
result = rb_ary_new();
|
215
|
+
for (i = 0; i < cnt; i++) {
|
216
|
+
rb_ary_push(result, rb_str_new(matches[i], strlen(matches[i])));
|
217
|
+
free(matches[i]) ;
|
218
|
+
}
|
219
|
+
free (matches) ;
|
220
|
+
|
221
|
+
return result ;
|
222
|
+
}
|
223
|
+
|
224
|
+
/*
|
225
|
+
* call-seq:
|
226
|
+
* match(PATH) -> an_array
|
227
|
+
*
|
228
|
+
* Return all the paths that match the path expression PATH as an aray of
|
229
|
+
* strings.
|
230
|
+
* Returns an empty array if no paths were found.
|
231
|
+
*/
|
232
|
+
VALUE facade_match(VALUE s, VALUE p) {
|
233
|
+
augeas *aug = aug_handle(s);
|
234
|
+
const char *path = StringValueCStr(p);
|
235
|
+
char **matches = NULL;
|
236
|
+
int cnt, i;
|
237
|
+
VALUE result;
|
238
|
+
|
239
|
+
cnt = aug_match(aug, path, &matches) ;
|
240
|
+
if (cnt < 0)
|
241
|
+
return -1;
|
242
|
+
|
243
|
+
result = rb_ary_new();
|
188
244
|
for (i = 0; i < cnt; i++) {
|
189
245
|
rb_ary_push(result, rb_str_new(matches[i], strlen(matches[i])));
|
190
246
|
free(matches[i]) ;
|
@@ -202,15 +258,19 @@ VALUE augeas_match(VALUE s, VALUE p) {
|
|
202
258
|
*/
|
203
259
|
VALUE augeas_save(VALUE s) {
|
204
260
|
augeas *aug = aug_handle(s);
|
205
|
-
int callValue = aug_save(aug) ;
|
206
|
-
VALUE returnValue ;
|
207
261
|
|
208
|
-
|
209
|
-
|
210
|
-
else
|
211
|
-
returnValue = Qfalse ;
|
262
|
+
return (aug_save(aug) == 0) ? Qtrue : Qfalse;
|
263
|
+
}
|
212
264
|
|
213
|
-
|
265
|
+
/*
|
266
|
+
* call-seq:
|
267
|
+
* save() -> int
|
268
|
+
*
|
269
|
+
* Write all pending changes to disk
|
270
|
+
*/
|
271
|
+
VALUE facade_save(VALUE s) {
|
272
|
+
augeas *aug = aug_handle(s);
|
273
|
+
return INT2FIX(aug_save(aug));
|
214
274
|
}
|
215
275
|
|
216
276
|
/*
|
@@ -282,7 +342,7 @@ VALUE augeas_defnode(VALUE s, VALUE name, VALUE expr, VALUE value) {
|
|
282
342
|
return (r < 0) ? Qfalse : INT2NUM(r);
|
283
343
|
}
|
284
344
|
|
285
|
-
VALUE
|
345
|
+
static VALUE init(VALUE class, VALUE m, VALUE r, VALUE l, VALUE f) {
|
286
346
|
unsigned int flags = NUM2UINT(f);
|
287
347
|
const char *root = StringValueCStrOrNull(r);
|
288
348
|
const char *loadpath = StringValueCStrOrNull(l);
|
@@ -292,7 +352,15 @@ VALUE augeas_init(VALUE m, VALUE r, VALUE l, VALUE f) {
|
|
292
352
|
if (aug == NULL) {
|
293
353
|
rb_raise(rb_eSystemCallError, "Failed to initialize Augeas");
|
294
354
|
}
|
295
|
-
return Data_Wrap_Struct(
|
355
|
+
return Data_Wrap_Struct(class, NULL, augeas_free, aug);
|
356
|
+
}
|
357
|
+
|
358
|
+
VALUE augeas_init(VALUE m, VALUE r, VALUE l, VALUE f) {
|
359
|
+
return init(c_augeas, m, r, l, f);
|
360
|
+
}
|
361
|
+
|
362
|
+
VALUE facade_init(VALUE m, VALUE r, VALUE l, VALUE f) {
|
363
|
+
return init(c_facade, m, r, l, f);
|
296
364
|
}
|
297
365
|
|
298
366
|
VALUE augeas_close (VALUE s) {
|
@@ -396,14 +464,15 @@ VALUE augeas_span(VALUE s, VALUE path) {
|
|
396
464
|
VALUE augeas_srun(VALUE s, VALUE text) {
|
397
465
|
augeas *aug = aug_handle(s);
|
398
466
|
const char *ctext = StringValueCStr(text);
|
399
|
-
|
467
|
+
int r;
|
468
|
+
VALUE result;
|
400
469
|
struct memstream ms;
|
401
470
|
__aug_init_memstream(&ms);
|
402
471
|
|
403
|
-
|
472
|
+
r = aug_srun(aug, ms.stream, ctext);
|
404
473
|
__aug_close_memstream(&ms);
|
405
474
|
|
406
|
-
|
475
|
+
result = rb_ary_new();
|
407
476
|
rb_ary_push(result, INT2NUM(r));
|
408
477
|
rb_ary_push(result, rb_str_new2(ms.buf));
|
409
478
|
|
@@ -489,6 +558,9 @@ void Init__augeas() {
|
|
489
558
|
|
490
559
|
/* Define the ruby class */
|
491
560
|
c_augeas = rb_define_class("Augeas", rb_cObject) ;
|
561
|
+
rb_undef_alloc_func(c_augeas);
|
562
|
+
c_facade = rb_define_class_under(c_augeas, "Facade", rb_cObject);
|
563
|
+
rb_undef_alloc_func(c_facade);
|
492
564
|
|
493
565
|
/* Constants for enum aug_flags */
|
494
566
|
#define DEF_AUG_FLAG(name) \
|
@@ -517,7 +589,10 @@ void Init__augeas() {
|
|
517
589
|
DEF_AUG_ERR(ENOLENS);
|
518
590
|
DEF_AUG_ERR(EMXFM);
|
519
591
|
DEF_AUG_ERR(ENOSPAN);
|
592
|
+
DEF_AUG_ERR(EMVDESC);
|
520
593
|
DEF_AUG_ERR(ECMDRUN);
|
594
|
+
DEF_AUG_ERR(EBADARG);
|
595
|
+
DEF_AUG_ERR(ELABEL);
|
521
596
|
#undef DEF_AUG_ERR
|
522
597
|
|
523
598
|
/* Define the methods */
|
@@ -542,6 +617,30 @@ void Init__augeas() {
|
|
542
617
|
rb_define_method(c_augeas, "rename", augeas_rename, 2);
|
543
618
|
rb_define_method(c_augeas, "text_store", augeas_text_store, 3);
|
544
619
|
rb_define_method(c_augeas, "text_retrieve", augeas_text_retrieve, 4);
|
620
|
+
|
621
|
+
/* Define methods to support the 'new' API in Augeas::Facade */
|
622
|
+
rb_define_singleton_method(c_facade, "open3", facade_init, 3);
|
623
|
+
/* The `close` and `error` methods as used unchanged in the ruby bindings */
|
624
|
+
rb_define_method(c_facade, "close", augeas_close, 0);
|
625
|
+
rb_define_method(c_facade, "error", augeas_error, 0);
|
626
|
+
rb_define_method(c_facade, "augeas_defvar", augeas_defvar, 2);
|
627
|
+
rb_define_method(c_facade, "augeas_defnode", augeas_defnode, 3);
|
628
|
+
rb_define_method(c_facade, "augeas_get", augeas_get, 1);
|
629
|
+
rb_define_method(c_facade, "augeas_exists", augeas_exists, 1);
|
630
|
+
rb_define_method(c_facade, "augeas_insert", augeas_insert, 3);
|
631
|
+
rb_define_method(c_facade, "augeas_mv", augeas_mv, 2);
|
632
|
+
rb_define_method(c_facade, "augeas_rm", augeas_rm, 1);
|
633
|
+
rb_define_method(c_facade, "augeas_match", facade_match, 1);
|
634
|
+
rb_define_method(c_facade, "augeas_save", facade_save, 0);
|
635
|
+
rb_define_method(c_facade, "augeas_load", augeas_load, 0);
|
636
|
+
rb_define_method(c_facade, "augeas_set", facade_set, 2);
|
637
|
+
rb_define_method(c_facade, "augeas_setm", augeas_setm, 3);
|
638
|
+
rb_define_method(c_facade, "augeas_span", augeas_span, 1);
|
639
|
+
rb_define_method(c_facade, "augeas_srun", augeas_srun, 1);
|
640
|
+
rb_define_method(c_facade, "augeas_label", augeas_label, 1);
|
641
|
+
rb_define_method(c_facade, "augeas_rename", augeas_rename, 2);
|
642
|
+
rb_define_method(c_facade, "augeas_text_store", augeas_text_store, 3);
|
643
|
+
rb_define_method(c_facade, "augeas_text_retrieve", augeas_text_retrieve, 4);
|
545
644
|
}
|
546
645
|
|
547
646
|
/*
|