lodestone 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENCE.txt +202 -0
- data/README.md +61 -0
- data/bin/lodestone +28 -0
- data/lib/grammars/lodestone.rb +480 -0
- data/lib/lodestone.rb +39 -0
- metadata +68 -0
data/LICENCE.txt
ADDED
@@ -0,0 +1,202 @@
|
|
1
|
+
|
2
|
+
Apache License
|
3
|
+
Version 2.0, January 2004
|
4
|
+
http://www.apache.org/licenses/
|
5
|
+
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
7
|
+
|
8
|
+
1. Definitions.
|
9
|
+
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
12
|
+
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
14
|
+
the copyright owner that is granting the License.
|
15
|
+
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
17
|
+
other entities that control, are controlled by, or are under common
|
18
|
+
control with that entity. For the purposes of this definition,
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
20
|
+
direction or management of such entity, whether by contract or
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
23
|
+
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
25
|
+
exercising permissions granted by this License.
|
26
|
+
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
28
|
+
including but not limited to software source code, documentation
|
29
|
+
source, and configuration files.
|
30
|
+
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
32
|
+
transformation or translation of a Source form, including but
|
33
|
+
not limited to compiled object code, generated documentation,
|
34
|
+
and conversions to other media types.
|
35
|
+
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
37
|
+
Object form, made available under the License, as indicated by a
|
38
|
+
copyright notice that is included in or attached to the work
|
39
|
+
(an example is provided in the Appendix below).
|
40
|
+
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
47
|
+
the Work and Derivative Works thereof.
|
48
|
+
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
50
|
+
the original version of the Work and any modifications or additions
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
62
|
+
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
65
|
+
subsequently incorporated within the Work.
|
66
|
+
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
73
|
+
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
79
|
+
where such license applies only to those patent claims licensable
|
80
|
+
by such Contributor that are necessarily infringed by their
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
83
|
+
institute patent litigation against any entity (including a
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
86
|
+
or contributory patent infringement, then any patent licenses
|
87
|
+
granted to You under this License for that Work shall terminate
|
88
|
+
as of the date such litigation is filed.
|
89
|
+
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
92
|
+
modifications, and in Source or Object form, provided that You
|
93
|
+
meet the following conditions:
|
94
|
+
|
95
|
+
(a) You must give any other recipients of the Work or
|
96
|
+
Derivative Works a copy of this License; and
|
97
|
+
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
99
|
+
stating that You changed the files; and
|
100
|
+
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
103
|
+
attribution notices from the Source form of the Work,
|
104
|
+
excluding those notices that do not pertain to any part of
|
105
|
+
the Derivative Works; and
|
106
|
+
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
109
|
+
include a readable copy of the attribution notices contained
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
112
|
+
of the following places: within a NOTICE text file distributed
|
113
|
+
as part of the Derivative Works; within the Source form or
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
115
|
+
within a display generated by the Derivative Works, if and
|
116
|
+
wherever such third-party notices normally appear. The contents
|
117
|
+
of the NOTICE file are for informational purposes only and
|
118
|
+
do not modify the License. You may add Your own attribution
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
121
|
+
that such additional attribution notices cannot be construed
|
122
|
+
as modifying the License.
|
123
|
+
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
125
|
+
may provide additional or different license terms and conditions
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
129
|
+
the conditions stated in this License.
|
130
|
+
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
134
|
+
this License, without any additional terms or conditions.
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
136
|
+
the terms of any separate license agreement you may have executed
|
137
|
+
with Licensor regarding such Contributions.
|
138
|
+
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
141
|
+
except as required for reasonable and customary use in describing the
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
143
|
+
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
153
|
+
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
159
|
+
incidental, or consequential damages of any character arising as a
|
160
|
+
result of this License or out of the use or inability to use the
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
163
|
+
other commercial damages or losses), even if such Contributor
|
164
|
+
has been advised of the possibility of such damages.
|
165
|
+
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
169
|
+
or other liability obligations and/or rights consistent with this
|
170
|
+
License. However, in accepting such obligations, You may act only
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
175
|
+
of your accepting any such warranty or additional liability.
|
176
|
+
|
177
|
+
END OF TERMS AND CONDITIONS
|
178
|
+
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
180
|
+
|
181
|
+
To apply the Apache License to your work, attach the following
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
183
|
+
replaced with your own identifying information. (Don't include
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
185
|
+
comment syntax for the file format. We also recommend that a
|
186
|
+
file or class name and description of purpose be included on the
|
187
|
+
same "printed page" as the copyright notice for easier
|
188
|
+
identification within third-party archives.
|
189
|
+
|
190
|
+
Copyright [yyyy] [name of copyright owner]
|
191
|
+
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
193
|
+
you may not use this file except in compliance with the License.
|
194
|
+
You may obtain a copy of the License at
|
195
|
+
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
197
|
+
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
201
|
+
See the License for the specific language governing permissions and
|
202
|
+
limitations under the License.
|
data/README.md
ADDED
@@ -0,0 +1,61 @@
|
|
1
|
+
Lodestone
|
2
|
+
==
|
3
|
+
|
4
|
+
Rationale
|
5
|
+
--
|
6
|
+
|
7
|
+
Directories and filesystems on File Servers (especially but not exclusively) require specific directory permissions; both for traversal and for security.
|
8
|
+
|
9
|
+
We can use scripts, setgid, etc., etc. to configure these but they're a pain.
|
10
|
+
|
11
|
+
We can also use puppet but this is overkill and more complex to setup.
|
12
|
+
|
13
|
+
|
14
|
+
Usage
|
15
|
+
--
|
16
|
+
|
17
|
+
A valid definition **must** start with the word 'define'. It takes the verbs:
|
18
|
+
|
19
|
+
`file`
|
20
|
+
`directory`
|
21
|
+
`user`
|
22
|
+
`group`
|
23
|
+
`perms`
|
24
|
+
|
25
|
+
It also has the helper /make me prettier/ verbs:
|
26
|
+
|
27
|
+
`should be`
|
28
|
+
`and`
|
29
|
+
`with`
|
30
|
+
`it`
|
31
|
+
|
32
|
+
Which means we can be can build definitions such as:
|
33
|
+
|
34
|
+
`"define directory /sss perms 777 user jspc group jspc"`
|
35
|
+
|
36
|
+
Or:
|
37
|
+
|
38
|
+
` "define directory /sss with perms 777 it should be user jspc and should be group jspc"`
|
39
|
+
|
40
|
+
Of course all options are optional.
|
41
|
+
|
42
|
+
Licence
|
43
|
+
--
|
44
|
+
|
45
|
+
Apache License, Version 2.0.
|
46
|
+
|
47
|
+
See `./LICENCE.txt`
|
48
|
+
|
49
|
+
Copyright 2013 James Condron
|
50
|
+
|
51
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
52
|
+
you may not use this file except in compliance with the License.
|
53
|
+
You may obtain a copy of the License at
|
54
|
+
|
55
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
56
|
+
|
57
|
+
Unless required by applicable law or agreed to in writing, software
|
58
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
59
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
60
|
+
See the License for the specific language governing permissions and
|
61
|
+
limitations under the License.
|
data/bin/lodestone
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
#
|
3
|
+
|
4
|
+
$LOAD_PATH.unshift File.join(File.dirname(__FILE__), '..', 'lib')
|
5
|
+
|
6
|
+
require 'lodestone'
|
7
|
+
require 'optparse'
|
8
|
+
require 'pathname'
|
9
|
+
|
10
|
+
opt_path = "/etc/lodestone.conf"
|
11
|
+
verbose = false
|
12
|
+
|
13
|
+
OptionParser.new do |opts|
|
14
|
+
opts.banner = "Usage: lodestone [options]"
|
15
|
+
|
16
|
+
opts.on("-c", "--config [CONFIG FILE]", "Path to config file") { |c| opt_path = c }
|
17
|
+
opts.on("-v", "--verbose", "See extra debug") { |v| verbose = true }
|
18
|
+
end.parse!
|
19
|
+
|
20
|
+
if not File.exists? opt_path
|
21
|
+
raise "#{opt_path} :: No such file"
|
22
|
+
end
|
23
|
+
|
24
|
+
IO.readlines( opt_path ).each do |definition|
|
25
|
+
res = Lodestone.apply definition.strip
|
26
|
+
puts res[1] unless res[0]
|
27
|
+
puts res[1] if res[0] and verbose
|
28
|
+
end
|
@@ -0,0 +1,480 @@
|
|
1
|
+
# Autogenerated from a Treetop grammar. Edits may be lost.
|
2
|
+
|
3
|
+
|
4
|
+
module Lodestone
|
5
|
+
include Treetop::Runtime
|
6
|
+
|
7
|
+
def root
|
8
|
+
@root ||= :document
|
9
|
+
end
|
10
|
+
|
11
|
+
module Document0
|
12
|
+
def content
|
13
|
+
elements.map{ |e| e.content unless e.content.nil? }
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def _nt_document
|
18
|
+
start_index = index
|
19
|
+
if node_cache[:document].has_key?(index)
|
20
|
+
cached = node_cache[:document][index]
|
21
|
+
if cached
|
22
|
+
cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
|
23
|
+
@index = cached.interval.end
|
24
|
+
end
|
25
|
+
return cached
|
26
|
+
end
|
27
|
+
|
28
|
+
s0, i0 = [], index
|
29
|
+
loop do
|
30
|
+
i1 = index
|
31
|
+
r2 = _nt_define
|
32
|
+
if r2
|
33
|
+
r1 = r2
|
34
|
+
else
|
35
|
+
r3 = _nt_path
|
36
|
+
if r3
|
37
|
+
r1 = r3
|
38
|
+
else
|
39
|
+
r4 = _nt_user
|
40
|
+
if r4
|
41
|
+
r1 = r4
|
42
|
+
else
|
43
|
+
r5 = _nt_group
|
44
|
+
if r5
|
45
|
+
r1 = r5
|
46
|
+
else
|
47
|
+
r6 = _nt_perms
|
48
|
+
if r6
|
49
|
+
r1 = r6
|
50
|
+
else
|
51
|
+
@index = i1
|
52
|
+
r1 = nil
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
if r1
|
59
|
+
s0 << r1
|
60
|
+
else
|
61
|
+
break
|
62
|
+
end
|
63
|
+
end
|
64
|
+
r0 = instantiate_node(SyntaxNode,input, i0...index, s0)
|
65
|
+
r0.extend(Document0)
|
66
|
+
|
67
|
+
node_cache[:document][start_index] = r0
|
68
|
+
|
69
|
+
r0
|
70
|
+
end
|
71
|
+
|
72
|
+
module Define0
|
73
|
+
def content
|
74
|
+
nil
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
def _nt_define
|
79
|
+
start_index = index
|
80
|
+
if node_cache[:define].has_key?(index)
|
81
|
+
cached = node_cache[:define][index]
|
82
|
+
if cached
|
83
|
+
cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
|
84
|
+
@index = cached.interval.end
|
85
|
+
end
|
86
|
+
return cached
|
87
|
+
end
|
88
|
+
|
89
|
+
i0 = index
|
90
|
+
if has_terminal?("define", false, index)
|
91
|
+
r1 = instantiate_node(SyntaxNode,input, index...(index + 6))
|
92
|
+
@index += 6
|
93
|
+
else
|
94
|
+
terminal_parse_failure("define")
|
95
|
+
r1 = nil
|
96
|
+
end
|
97
|
+
if r1
|
98
|
+
r0 = r1
|
99
|
+
r0.extend(Define0)
|
100
|
+
else
|
101
|
+
if has_terminal?(" and", false, index)
|
102
|
+
r2 = instantiate_node(SyntaxNode,input, index...(index + 4))
|
103
|
+
@index += 4
|
104
|
+
else
|
105
|
+
terminal_parse_failure(" and")
|
106
|
+
r2 = nil
|
107
|
+
end
|
108
|
+
if r2
|
109
|
+
r0 = r2
|
110
|
+
r0.extend(Define0)
|
111
|
+
else
|
112
|
+
if has_terminal?(" with", false, index)
|
113
|
+
r3 = instantiate_node(SyntaxNode,input, index...(index + 5))
|
114
|
+
@index += 5
|
115
|
+
else
|
116
|
+
terminal_parse_failure(" with")
|
117
|
+
r3 = nil
|
118
|
+
end
|
119
|
+
if r3
|
120
|
+
r0 = r3
|
121
|
+
r0.extend(Define0)
|
122
|
+
else
|
123
|
+
if has_terminal?(" it", false, index)
|
124
|
+
r4 = instantiate_node(SyntaxNode,input, index...(index + 3))
|
125
|
+
@index += 3
|
126
|
+
else
|
127
|
+
terminal_parse_failure(" it")
|
128
|
+
r4 = nil
|
129
|
+
end
|
130
|
+
if r4
|
131
|
+
r0 = r4
|
132
|
+
r0.extend(Define0)
|
133
|
+
else
|
134
|
+
if has_terminal?(" should be", false, index)
|
135
|
+
r5 = instantiate_node(SyntaxNode,input, index...(index + 10))
|
136
|
+
@index += 10
|
137
|
+
else
|
138
|
+
terminal_parse_failure(" should be")
|
139
|
+
r5 = nil
|
140
|
+
end
|
141
|
+
if r5
|
142
|
+
r0 = r5
|
143
|
+
r0.extend(Define0)
|
144
|
+
else
|
145
|
+
@index = i0
|
146
|
+
r0 = nil
|
147
|
+
end
|
148
|
+
end
|
149
|
+
end
|
150
|
+
end
|
151
|
+
end
|
152
|
+
|
153
|
+
node_cache[:define][start_index] = r0
|
154
|
+
|
155
|
+
r0
|
156
|
+
end
|
157
|
+
|
158
|
+
module Path0
|
159
|
+
end
|
160
|
+
|
161
|
+
module Path1
|
162
|
+
end
|
163
|
+
|
164
|
+
module Path2
|
165
|
+
def content
|
166
|
+
["path", text_value.split[-1]]
|
167
|
+
end
|
168
|
+
end
|
169
|
+
|
170
|
+
def _nt_path
|
171
|
+
start_index = index
|
172
|
+
if node_cache[:path].has_key?(index)
|
173
|
+
cached = node_cache[:path][index]
|
174
|
+
if cached
|
175
|
+
cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
|
176
|
+
@index = cached.interval.end
|
177
|
+
end
|
178
|
+
return cached
|
179
|
+
end
|
180
|
+
|
181
|
+
i0 = index
|
182
|
+
i1, s1 = index, []
|
183
|
+
if has_terminal?(" file ", false, index)
|
184
|
+
r2 = instantiate_node(SyntaxNode,input, index...(index + 6))
|
185
|
+
@index += 6
|
186
|
+
else
|
187
|
+
terminal_parse_failure(" file ")
|
188
|
+
r2 = nil
|
189
|
+
end
|
190
|
+
s1 << r2
|
191
|
+
if r2
|
192
|
+
s3, i3 = [], index
|
193
|
+
loop do
|
194
|
+
if has_terminal?('\G[A-Za-z\\/^]', true, index)
|
195
|
+
r4 = true
|
196
|
+
@index += 1
|
197
|
+
else
|
198
|
+
r4 = nil
|
199
|
+
end
|
200
|
+
if r4
|
201
|
+
s3 << r4
|
202
|
+
else
|
203
|
+
break
|
204
|
+
end
|
205
|
+
end
|
206
|
+
if s3.empty?
|
207
|
+
@index = i3
|
208
|
+
r3 = nil
|
209
|
+
else
|
210
|
+
r3 = instantiate_node(SyntaxNode,input, i3...index, s3)
|
211
|
+
end
|
212
|
+
s1 << r3
|
213
|
+
end
|
214
|
+
if s1.last
|
215
|
+
r1 = instantiate_node(SyntaxNode,input, i1...index, s1)
|
216
|
+
r1.extend(Path0)
|
217
|
+
else
|
218
|
+
@index = i1
|
219
|
+
r1 = nil
|
220
|
+
end
|
221
|
+
if r1
|
222
|
+
r0 = r1
|
223
|
+
r0.extend(Path2)
|
224
|
+
else
|
225
|
+
i5, s5 = index, []
|
226
|
+
if has_terminal?(" directory ", false, index)
|
227
|
+
r6 = instantiate_node(SyntaxNode,input, index...(index + 11))
|
228
|
+
@index += 11
|
229
|
+
else
|
230
|
+
terminal_parse_failure(" directory ")
|
231
|
+
r6 = nil
|
232
|
+
end
|
233
|
+
s5 << r6
|
234
|
+
if r6
|
235
|
+
s7, i7 = [], index
|
236
|
+
loop do
|
237
|
+
if has_terminal?('\G[A-Za-z\\/^]', true, index)
|
238
|
+
r8 = true
|
239
|
+
@index += 1
|
240
|
+
else
|
241
|
+
r8 = nil
|
242
|
+
end
|
243
|
+
if r8
|
244
|
+
s7 << r8
|
245
|
+
else
|
246
|
+
break
|
247
|
+
end
|
248
|
+
end
|
249
|
+
if s7.empty?
|
250
|
+
@index = i7
|
251
|
+
r7 = nil
|
252
|
+
else
|
253
|
+
r7 = instantiate_node(SyntaxNode,input, i7...index, s7)
|
254
|
+
end
|
255
|
+
s5 << r7
|
256
|
+
end
|
257
|
+
if s5.last
|
258
|
+
r5 = instantiate_node(SyntaxNode,input, i5...index, s5)
|
259
|
+
r5.extend(Path1)
|
260
|
+
else
|
261
|
+
@index = i5
|
262
|
+
r5 = nil
|
263
|
+
end
|
264
|
+
if r5
|
265
|
+
r0 = r5
|
266
|
+
r0.extend(Path2)
|
267
|
+
else
|
268
|
+
@index = i0
|
269
|
+
r0 = nil
|
270
|
+
end
|
271
|
+
end
|
272
|
+
|
273
|
+
node_cache[:path][start_index] = r0
|
274
|
+
|
275
|
+
r0
|
276
|
+
end
|
277
|
+
|
278
|
+
module User0
|
279
|
+
end
|
280
|
+
|
281
|
+
module User1
|
282
|
+
def content
|
283
|
+
["user", text_value.split[-1]]
|
284
|
+
end
|
285
|
+
end
|
286
|
+
|
287
|
+
def _nt_user
|
288
|
+
start_index = index
|
289
|
+
if node_cache[:user].has_key?(index)
|
290
|
+
cached = node_cache[:user][index]
|
291
|
+
if cached
|
292
|
+
cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
|
293
|
+
@index = cached.interval.end
|
294
|
+
end
|
295
|
+
return cached
|
296
|
+
end
|
297
|
+
|
298
|
+
i0, s0 = index, []
|
299
|
+
if has_terminal?(" user ", false, index)
|
300
|
+
r1 = instantiate_node(SyntaxNode,input, index...(index + 6))
|
301
|
+
@index += 6
|
302
|
+
else
|
303
|
+
terminal_parse_failure(" user ")
|
304
|
+
r1 = nil
|
305
|
+
end
|
306
|
+
s0 << r1
|
307
|
+
if r1
|
308
|
+
s2, i2 = [], index
|
309
|
+
loop do
|
310
|
+
if has_terminal?('\G[A-Za-z^]', true, index)
|
311
|
+
r3 = true
|
312
|
+
@index += 1
|
313
|
+
else
|
314
|
+
r3 = nil
|
315
|
+
end
|
316
|
+
if r3
|
317
|
+
s2 << r3
|
318
|
+
else
|
319
|
+
break
|
320
|
+
end
|
321
|
+
end
|
322
|
+
if s2.empty?
|
323
|
+
@index = i2
|
324
|
+
r2 = nil
|
325
|
+
else
|
326
|
+
r2 = instantiate_node(SyntaxNode,input, i2...index, s2)
|
327
|
+
end
|
328
|
+
s0 << r2
|
329
|
+
end
|
330
|
+
if s0.last
|
331
|
+
r0 = instantiate_node(SyntaxNode,input, i0...index, s0)
|
332
|
+
r0.extend(User0)
|
333
|
+
r0.extend(User1)
|
334
|
+
else
|
335
|
+
@index = i0
|
336
|
+
r0 = nil
|
337
|
+
end
|
338
|
+
|
339
|
+
node_cache[:user][start_index] = r0
|
340
|
+
|
341
|
+
r0
|
342
|
+
end
|
343
|
+
|
344
|
+
module Group0
|
345
|
+
end
|
346
|
+
|
347
|
+
module Group1
|
348
|
+
def content
|
349
|
+
["group", text_value.split[-1]]
|
350
|
+
end
|
351
|
+
end
|
352
|
+
|
353
|
+
def _nt_group
|
354
|
+
start_index = index
|
355
|
+
if node_cache[:group].has_key?(index)
|
356
|
+
cached = node_cache[:group][index]
|
357
|
+
if cached
|
358
|
+
cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
|
359
|
+
@index = cached.interval.end
|
360
|
+
end
|
361
|
+
return cached
|
362
|
+
end
|
363
|
+
|
364
|
+
i0, s0 = index, []
|
365
|
+
if has_terminal?(" group ", false, index)
|
366
|
+
r1 = instantiate_node(SyntaxNode,input, index...(index + 7))
|
367
|
+
@index += 7
|
368
|
+
else
|
369
|
+
terminal_parse_failure(" group ")
|
370
|
+
r1 = nil
|
371
|
+
end
|
372
|
+
s0 << r1
|
373
|
+
if r1
|
374
|
+
s2, i2 = [], index
|
375
|
+
loop do
|
376
|
+
if has_terminal?('\G[A-Za-z^]', true, index)
|
377
|
+
r3 = true
|
378
|
+
@index += 1
|
379
|
+
else
|
380
|
+
r3 = nil
|
381
|
+
end
|
382
|
+
if r3
|
383
|
+
s2 << r3
|
384
|
+
else
|
385
|
+
break
|
386
|
+
end
|
387
|
+
end
|
388
|
+
if s2.empty?
|
389
|
+
@index = i2
|
390
|
+
r2 = nil
|
391
|
+
else
|
392
|
+
r2 = instantiate_node(SyntaxNode,input, i2...index, s2)
|
393
|
+
end
|
394
|
+
s0 << r2
|
395
|
+
end
|
396
|
+
if s0.last
|
397
|
+
r0 = instantiate_node(SyntaxNode,input, i0...index, s0)
|
398
|
+
r0.extend(Group0)
|
399
|
+
r0.extend(Group1)
|
400
|
+
else
|
401
|
+
@index = i0
|
402
|
+
r0 = nil
|
403
|
+
end
|
404
|
+
|
405
|
+
node_cache[:group][start_index] = r0
|
406
|
+
|
407
|
+
r0
|
408
|
+
end
|
409
|
+
|
410
|
+
module Perms0
|
411
|
+
end
|
412
|
+
|
413
|
+
module Perms1
|
414
|
+
def content
|
415
|
+
["perms", text_value.split[-1]]
|
416
|
+
end
|
417
|
+
end
|
418
|
+
|
419
|
+
def _nt_perms
|
420
|
+
start_index = index
|
421
|
+
if node_cache[:perms].has_key?(index)
|
422
|
+
cached = node_cache[:perms][index]
|
423
|
+
if cached
|
424
|
+
cached = SyntaxNode.new(input, index...(index + 1)) if cached == true
|
425
|
+
@index = cached.interval.end
|
426
|
+
end
|
427
|
+
return cached
|
428
|
+
end
|
429
|
+
|
430
|
+
i0, s0 = index, []
|
431
|
+
if has_terminal?(" perms ", false, index)
|
432
|
+
r1 = instantiate_node(SyntaxNode,input, index...(index + 7))
|
433
|
+
@index += 7
|
434
|
+
else
|
435
|
+
terminal_parse_failure(" perms ")
|
436
|
+
r1 = nil
|
437
|
+
end
|
438
|
+
s0 << r1
|
439
|
+
if r1
|
440
|
+
s2, i2 = [], index
|
441
|
+
loop do
|
442
|
+
if has_terminal?('\G[0-9^]', true, index)
|
443
|
+
r3 = true
|
444
|
+
@index += 1
|
445
|
+
else
|
446
|
+
r3 = nil
|
447
|
+
end
|
448
|
+
if r3
|
449
|
+
s2 << r3
|
450
|
+
else
|
451
|
+
break
|
452
|
+
end
|
453
|
+
end
|
454
|
+
if s2.empty?
|
455
|
+
@index = i2
|
456
|
+
r2 = nil
|
457
|
+
else
|
458
|
+
r2 = instantiate_node(SyntaxNode,input, i2...index, s2)
|
459
|
+
end
|
460
|
+
s0 << r2
|
461
|
+
end
|
462
|
+
if s0.last
|
463
|
+
r0 = instantiate_node(SyntaxNode,input, i0...index, s0)
|
464
|
+
r0.extend(Perms0)
|
465
|
+
r0.extend(Perms1)
|
466
|
+
else
|
467
|
+
@index = i0
|
468
|
+
r0 = nil
|
469
|
+
end
|
470
|
+
|
471
|
+
node_cache[:perms][start_index] = r0
|
472
|
+
|
473
|
+
r0
|
474
|
+
end
|
475
|
+
|
476
|
+
end
|
477
|
+
|
478
|
+
class LodestoneParser < Treetop::Runtime::CompiledParser
|
479
|
+
include Lodestone
|
480
|
+
end
|
data/lib/lodestone.rb
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
$LOAD_PATH.unshift File.join(File.dirname(__FILE__), 'grammars')
|
4
|
+
|
5
|
+
require "treetop"
|
6
|
+
require "polyglot"
|
7
|
+
require "lodestone"
|
8
|
+
require "fileutils"
|
9
|
+
|
10
|
+
module Lodestone
|
11
|
+
@ls = LodestoneParser.new
|
12
|
+
@opts = Hash.new
|
13
|
+
|
14
|
+
def self.__parse definition
|
15
|
+
@ls.parse( definition.to_s ).content.each do |thing|
|
16
|
+
next if thing.nil?
|
17
|
+
@opts.merge!( thing[0].to_sym => thing[1] )
|
18
|
+
end
|
19
|
+
@opts
|
20
|
+
end
|
21
|
+
|
22
|
+
def self.apply definition
|
23
|
+
definition_hash = self.__parse definition
|
24
|
+
|
25
|
+
unless File.exists? definition_hash[:path]
|
26
|
+
return false, "#{definition_hash[:path]} does not exist"
|
27
|
+
end
|
28
|
+
|
29
|
+
begin
|
30
|
+
FileUtils.chown definition_hash[:user], definition_hash[:group], definition_hash[:path]
|
31
|
+
FileUtils.chmod definition_hash[:perms].to_i(8), definition_hash[:path]
|
32
|
+
rescue Exception => e
|
33
|
+
return false, "Failed to set the perms on #{definition_hash[:path]} - #{e}"
|
34
|
+
end
|
35
|
+
|
36
|
+
return true, "Succesfully applied definition to #{definition_hash[:path]}"
|
37
|
+
|
38
|
+
end
|
39
|
+
end
|
metadata
ADDED
@@ -0,0 +1,68 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: lodestone
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- jspc
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-02-02 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: treetop
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - '='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: 1.4.12
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - '='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: 1.4.12
|
30
|
+
description: A DSL to set perms on a dir in a sane way
|
31
|
+
email: james@zero-internet.org.uk
|
32
|
+
executables:
|
33
|
+
- lodestone
|
34
|
+
extensions: []
|
35
|
+
extra_rdoc_files:
|
36
|
+
- LICENCE.txt
|
37
|
+
- README.md
|
38
|
+
files:
|
39
|
+
- LICENCE.txt
|
40
|
+
- README.md
|
41
|
+
- bin/lodestone
|
42
|
+
- lib/lodestone.rb
|
43
|
+
- lib/grammars/lodestone.rb
|
44
|
+
homepage: https://github.com/jspc/lodestone
|
45
|
+
licenses: []
|
46
|
+
post_install_message:
|
47
|
+
rdoc_options: []
|
48
|
+
require_paths:
|
49
|
+
- lib
|
50
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
51
|
+
none: false
|
52
|
+
requirements:
|
53
|
+
- - ! '>='
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: '0'
|
56
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
requirements: []
|
63
|
+
rubyforge_project:
|
64
|
+
rubygems_version: 1.8.21
|
65
|
+
signing_key:
|
66
|
+
specification_version: 3
|
67
|
+
summary: A DSL to set perms on a dir in a sane way
|
68
|
+
test_files: []
|