augeas 0.6.0 → 0.6.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.rdoc +2 -0
- data/Rakefile +8 -2
- data/ext/augeas/_augeas.c +11 -109
- data/lib/augeas.rb +33 -23
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ba9ebbb3fbea59d2f722866713c6ff12fc52d9ea
|
4
|
+
data.tar.gz: 6e09cb5ef788772f2cde0dbf896092f7055cb644
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2171c37b81a34c693adda647b3cc4fdd6342c091cd8ce04078bda5edd672148990b7f2555a48ba007b6904da6019c570c826e251ddfd71b38729df9f127391b9
|
7
|
+
data.tar.gz: aa62e622d2456f7813d34dfbcf23a1b8610d826af9dae105cb301192338052480c449d1f605d764027f9a195a80c79749fa51d3adb3ae101b7c03406c0dc890b
|
data/README.rdoc
CHANGED
data/Rakefile
CHANGED
@@ -1,4 +1,10 @@
|
|
1
1
|
# -*- ruby -*-
|
2
|
+
# Rakefile: build ruby augeas bindings
|
3
|
+
#
|
4
|
+
# See AUTHORS for the list of authors
|
5
|
+
#
|
6
|
+
# Distributed under the GNU Lesser General Public License v2.1 or later.
|
7
|
+
# See COPYING for details
|
2
8
|
|
3
9
|
require 'rake/clean'
|
4
10
|
require 'rdoc/task'
|
@@ -6,7 +12,7 @@ require 'rake/testtask'
|
|
6
12
|
require 'rubygems/package_task'
|
7
13
|
|
8
14
|
GEM_NAME='augeas'
|
9
|
-
GEM_VERSION='0.6.
|
15
|
+
GEM_VERSION='0.6.1'
|
10
16
|
EXT_CONF='ext/augeas/extconf.rb'
|
11
17
|
MAKEFILE="ext/augeas/Makefile"
|
12
18
|
AUGEAS_MODULE="ext/augeas/_augeas.so"
|
@@ -80,7 +86,7 @@ SPEC = Gem::Specification.new do |s|
|
|
80
86
|
s.summary = "Ruby bindings for augeas"
|
81
87
|
s.authors = [ "Bryan Kearney", "David Lutterkort", "Ionut Artarisi", "Artem Sheremet" ]
|
82
88
|
s.files = PKG_FILES
|
83
|
-
|
89
|
+
s.licenses = ['LGPLv2']
|
84
90
|
s.required_ruby_version = '>= 1.8.7'
|
85
91
|
s.extensions = "ext/augeas/extconf.rb"
|
86
92
|
s.description = "Provides bindings for augeas."
|
data/ext/augeas/_augeas.c
CHANGED
@@ -25,6 +25,7 @@
|
|
25
25
|
|
26
26
|
#include <ruby.h>
|
27
27
|
#include <augeas.h>
|
28
|
+
#include <errno.h>
|
28
29
|
|
29
30
|
static VALUE c_augeas;
|
30
31
|
|
@@ -54,12 +55,12 @@ VALUE augeas_get(VALUE s, VALUE path) {
|
|
54
55
|
const char *cpath = StringValueCStr(path);
|
55
56
|
const char *value = NULL;
|
56
57
|
|
57
|
-
|
58
|
+
int retval = aug_get(aug, cpath, &value);
|
58
59
|
|
59
60
|
if (retval == 1 && value != NULL) {
|
60
|
-
|
61
|
+
return rb_str_new(value, strlen(value));
|
61
62
|
} else {
|
62
|
-
|
63
|
+
return Qnil;
|
63
64
|
}
|
64
65
|
}
|
65
66
|
|
@@ -94,30 +95,6 @@ VALUE augeas_set(VALUE s, VALUE path, VALUE value) {
|
|
94
95
|
return INT2FIX(callValue);
|
95
96
|
}
|
96
97
|
|
97
|
-
/*
|
98
|
-
* call-seq:
|
99
|
-
* set(PATH, VALUE) -> boolean
|
100
|
-
*
|
101
|
-
* Set the value associated with PATH to VALUE. VALUE is copied into the
|
102
|
-
* internal data structure. Intermediate entries are created if they don't
|
103
|
-
* exist.
|
104
|
-
*/
|
105
|
-
VALUE augeas_set_old(VALUE s, VALUE path, VALUE value) {
|
106
|
-
augeas *aug = aug_handle(s);
|
107
|
-
const char *cpath = StringValueCStr(path) ;
|
108
|
-
const char *cvalue = StringValueCStrOrNull(value) ;
|
109
|
-
|
110
|
-
int callValue = aug_set(aug, cpath, cvalue) ;
|
111
|
-
VALUE returnValue ;
|
112
|
-
|
113
|
-
if (callValue == 0)
|
114
|
-
returnValue = Qtrue ;
|
115
|
-
else
|
116
|
-
returnValue = Qfalse ;
|
117
|
-
|
118
|
-
return returnValue ;
|
119
|
-
}
|
120
|
-
|
121
98
|
/*
|
122
99
|
* call-seq:
|
123
100
|
* setm(BASE, SUB, VALUE) -> boolean
|
@@ -214,35 +191,6 @@ VALUE augeas_match(VALUE s, VALUE p) {
|
|
214
191
|
return result ;
|
215
192
|
}
|
216
193
|
|
217
|
-
/*
|
218
|
-
* call-seq:
|
219
|
-
* match(PATH) -> an_array
|
220
|
-
*
|
221
|
-
* Return all the paths that match the path expression PATH as an aray of
|
222
|
-
* strings.
|
223
|
-
* Raises an error if no paths were found.
|
224
|
-
*/
|
225
|
-
VALUE augeas_match_old(VALUE s, VALUE p) {
|
226
|
-
augeas *aug = aug_handle(s);
|
227
|
-
const char *path = StringValueCStr(p);
|
228
|
-
char **matches = NULL;
|
229
|
-
int cnt, i;
|
230
|
-
|
231
|
-
cnt = aug_match(aug, path, &matches) ;
|
232
|
-
if (cnt < 0)
|
233
|
-
rb_raise(rb_eSystemCallError, "Matching path expression '%s' failed",
|
234
|
-
path);
|
235
|
-
|
236
|
-
VALUE result = rb_ary_new();
|
237
|
-
for (i = 0; i < cnt; i++) {
|
238
|
-
rb_ary_push(result, rb_str_new(matches[i], strlen(matches[i])));
|
239
|
-
free(matches[i]) ;
|
240
|
-
}
|
241
|
-
free (matches) ;
|
242
|
-
|
243
|
-
return result ;
|
244
|
-
}
|
245
|
-
|
246
194
|
/*
|
247
195
|
* call-seq:
|
248
196
|
* save() -> int
|
@@ -255,25 +203,6 @@ VALUE augeas_save(VALUE s) {
|
|
255
203
|
return INT2FIX(callValue);
|
256
204
|
}
|
257
205
|
|
258
|
-
/*
|
259
|
-
* call-seq:
|
260
|
-
* save() -> boolean
|
261
|
-
*
|
262
|
-
* Write all pending changes to disk
|
263
|
-
*/
|
264
|
-
VALUE augeas_save_old(VALUE s) {
|
265
|
-
augeas *aug = aug_handle(s);
|
266
|
-
int callValue = aug_save(aug) ;
|
267
|
-
VALUE returnValue ;
|
268
|
-
|
269
|
-
if (callValue == 0)
|
270
|
-
returnValue = Qtrue ;
|
271
|
-
else
|
272
|
-
returnValue = Qfalse ;
|
273
|
-
|
274
|
-
return returnValue ;
|
275
|
-
}
|
276
|
-
|
277
206
|
/*
|
278
207
|
* call-seq:
|
279
208
|
* load() -> int
|
@@ -286,25 +215,6 @@ VALUE augeas_load(VALUE s) {
|
|
286
215
|
return INT2FIX(callValue);
|
287
216
|
}
|
288
217
|
|
289
|
-
/*
|
290
|
-
* call-seq:
|
291
|
-
* load() -> boolean
|
292
|
-
*
|
293
|
-
* Load files from disk according to the transforms under +/augeas/load+
|
294
|
-
*/
|
295
|
-
VALUE augeas_load_old(VALUE s) {
|
296
|
-
augeas *aug = aug_handle(s);
|
297
|
-
int callValue = aug_load(aug);
|
298
|
-
VALUE returnValue ;
|
299
|
-
|
300
|
-
if (callValue == 0)
|
301
|
-
returnValue = Qtrue ;
|
302
|
-
else
|
303
|
-
returnValue = Qfalse ;
|
304
|
-
|
305
|
-
return returnValue ;
|
306
|
-
}
|
307
|
-
|
308
218
|
/*
|
309
219
|
* call-seq:
|
310
220
|
* defvar(NAME, EXPR) -> boolean
|
@@ -355,10 +265,7 @@ VALUE augeas_defnode(VALUE s, VALUE name, VALUE expr, VALUE value) {
|
|
355
265
|
return (r < 0) ? Qfalse : INT2NUM(r);
|
356
266
|
}
|
357
267
|
|
358
|
-
|
359
|
-
/* version specified in the +version+ argument. See augeas_init_old and */
|
360
|
-
/* augeas_init. */
|
361
|
-
VALUE augeas_init_split(VALUE m, VALUE r, VALUE l, VALUE f, char version) {
|
268
|
+
VALUE augeas_init(VALUE m, VALUE r, VALUE l, VALUE f) {
|
362
269
|
unsigned int flags = NUM2UINT(f);
|
363
270
|
const char *root = StringValueCStrOrNull(r);
|
364
271
|
const char *loadpath = StringValueCStrOrNull(l);
|
@@ -366,19 +273,11 @@ VALUE augeas_init_split(VALUE m, VALUE r, VALUE l, VALUE f, char version) {
|
|
366
273
|
|
367
274
|
aug = aug_init(root, loadpath, flags);
|
368
275
|
if (aug == NULL) {
|
369
|
-
rb_raise(rb_eSystemCallError, "Failed to initialize Augeas");
|
276
|
+
rb_raise(rb_eSystemCallError, "Failed to initialize Augeas (%d)", errno);
|
370
277
|
}
|
371
278
|
return Data_Wrap_Struct(c_augeas, NULL, augeas_free, aug);
|
372
279
|
}
|
373
280
|
|
374
|
-
VALUE augeas_init_old(VALUE m, VALUE r, VALUE l, VALUE f) {
|
375
|
-
return augeas_init_split(m, r, l, f, 0);
|
376
|
-
}
|
377
|
-
VALUE augeas_init(VALUE m, VALUE r, VALUE l, VALUE f) {
|
378
|
-
return augeas_init_split(m, r, l, f, 1);
|
379
|
-
}
|
380
|
-
|
381
|
-
|
382
281
|
VALUE augeas_close (VALUE s) {
|
383
282
|
augeas *aug = aug_handle(s);
|
384
283
|
|
@@ -590,6 +489,7 @@ void Init__augeas() {
|
|
590
489
|
DEF_AUG_FLAG(NO_LOAD);
|
591
490
|
DEF_AUG_FLAG(NO_MODL_AUTOLOAD);
|
592
491
|
DEF_AUG_FLAG(ENABLE_SPAN);
|
492
|
+
DEF_AUG_FLAG(NO_ERR_CLOSE);
|
593
493
|
#undef DEF_AUG_FLAG
|
594
494
|
|
595
495
|
/* Constants for enum aug_errcode_t */
|
@@ -607,8 +507,10 @@ void Init__augeas() {
|
|
607
507
|
DEF_AUG_ERR(ENOSPAN);
|
608
508
|
DEF_AUG_ERR(EMVDESC);
|
609
509
|
DEF_AUG_ERR(ECMDRUN);
|
610
|
-
|
611
|
-
|
510
|
+
DEF_AUG_ERR(EBADARG);
|
511
|
+
#ifdef AUG_ELABEL
|
512
|
+
DEF_AUG_ERR(ELABEL);
|
513
|
+
#endif
|
612
514
|
#undef DEF_AUG_ERR
|
613
515
|
|
614
516
|
/* Define the methods */
|
data/lib/augeas.rb
CHANGED
@@ -43,23 +43,23 @@ class Augeas
|
|
43
43
|
class CommandExecutionError < Error; end
|
44
44
|
class InvalidArgumentError < Error; end
|
45
45
|
class InvalidLabelError < Error; end
|
46
|
-
|
46
|
+
ERRORS_HASH = Hash[{
|
47
47
|
# the cryptic error names come from the C library, we just make
|
48
48
|
# them more ruby and more human
|
49
|
-
ENOMEM => NoMemoryError,
|
50
|
-
EINTERNAL => InternalError,
|
51
|
-
EPATHX => InvalidPathError,
|
52
|
-
ENOMATCH => NoMatchError,
|
53
|
-
EMMATCH => MultipleMatchesError,
|
54
|
-
ESYNTAX => LensSyntaxError,
|
55
|
-
ENOLENS => LensNotFoundError,
|
56
|
-
EMXFM => MultipleTransformsError,
|
57
|
-
ENOSPAN => NoSpanInfoError,
|
58
|
-
EMVDESC => DescendantError,
|
59
|
-
ECMDRUN => CommandExecutionError,
|
60
|
-
EBADARG => InvalidArgumentError,
|
61
|
-
ELABEL => InvalidLabelError,
|
62
|
-
}
|
49
|
+
:ENOMEM => NoMemoryError,
|
50
|
+
:EINTERNAL => InternalError,
|
51
|
+
:EPATHX => InvalidPathError,
|
52
|
+
:ENOMATCH => NoMatchError,
|
53
|
+
:EMMATCH => MultipleMatchesError,
|
54
|
+
:ESYNTAX => LensSyntaxError,
|
55
|
+
:ENOLENS => LensNotFoundError,
|
56
|
+
:EMXFM => MultipleTransformsError,
|
57
|
+
:ENOSPAN => NoSpanInfoError,
|
58
|
+
:EMVDESC => DescendantError,
|
59
|
+
:ECMDRUN => CommandExecutionError,
|
60
|
+
:EBADARG => InvalidArgumentError,
|
61
|
+
:ELABEL => InvalidLabelError,
|
62
|
+
}.map { |k, v| [(const_get(k) rescue nil), v] }].freeze
|
63
63
|
|
64
64
|
# Create a new Augeas instance and return it.
|
65
65
|
#
|
@@ -101,7 +101,7 @@ class Augeas
|
|
101
101
|
# aug_flags is a bitmask in the underlying library, we add all the
|
102
102
|
# values of the flags which were set to true to the default value
|
103
103
|
# Augeas::NONE (which is 0)
|
104
|
-
aug_flags = Augeas::NONE
|
104
|
+
aug_flags = defined?(Augeas::NO_ERR_CLOSE) ? Augeas::NO_ERR_CLOSE : Augeas::NONE
|
105
105
|
|
106
106
|
flags = {
|
107
107
|
:type_check => Augeas::TYPE_CHECK,
|
@@ -117,10 +117,10 @@ class Augeas
|
|
117
117
|
}
|
118
118
|
opts.each_key do |key|
|
119
119
|
if flags.key? key
|
120
|
-
aug_flags
|
120
|
+
aug_flags |= flags[key]
|
121
121
|
elsif key == :save_mode
|
122
122
|
if save_modes[opts[:save_mode]]
|
123
|
-
aug_flags
|
123
|
+
aug_flags |= save_modes[opts[:save_mode]]
|
124
124
|
else
|
125
125
|
raise ArgumentError, "Invalid save mode #{opts[:save_mode]}."
|
126
126
|
end
|
@@ -131,6 +131,13 @@ class Augeas
|
|
131
131
|
|
132
132
|
aug = Augeas::open3(opts[:root], opts[:loadpath], aug_flags)
|
133
133
|
|
134
|
+
begin
|
135
|
+
aug.send(:raise_last_error)
|
136
|
+
rescue
|
137
|
+
aug.close
|
138
|
+
raise
|
139
|
+
end
|
140
|
+
|
134
141
|
if block_given?
|
135
142
|
begin
|
136
143
|
yield aug
|
@@ -366,11 +373,7 @@ class Augeas
|
|
366
373
|
def run_command(cmd, *params)
|
367
374
|
result = self.send cmd, *params
|
368
375
|
|
369
|
-
|
370
|
-
unless errcode.zero?
|
371
|
-
raise @@error_hash[errcode],
|
372
|
-
"#{error[:message]} #{error[:details]}"
|
373
|
-
end
|
376
|
+
raise_last_error
|
374
377
|
|
375
378
|
if result.kind_of? Fixnum and result < 0
|
376
379
|
# we raise CommandExecutionError here, because this is the error that
|
@@ -380,4 +383,11 @@ class Augeas
|
|
380
383
|
|
381
384
|
return result
|
382
385
|
end
|
386
|
+
|
387
|
+
def raise_last_error
|
388
|
+
error_cache = error
|
389
|
+
unless error_cache[:code].zero?
|
390
|
+
raise ERRORS_HASH[error_cache[:code]], "#{error_cache[:message]} #{error_cache[:details]}"
|
391
|
+
end
|
392
|
+
end
|
383
393
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: augeas
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.6.
|
4
|
+
version: 0.6.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Bryan Kearney
|
@@ -11,7 +11,7 @@ authors:
|
|
11
11
|
autorequire:
|
12
12
|
bindir: bin
|
13
13
|
cert_chain: []
|
14
|
-
date: 2014-01-
|
14
|
+
date: 2014-01-19 00:00:00.000000000 Z
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
17
17
|
name: rake
|