chef 0.9.18 → 0.10.0.beta.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +0 -3
- data/distro/arch/etc/rc.d/chef-server +0 -4
- data/distro/arch/etc/rc.d/chef-server-webui +0 -4
- data/distro/arch/etc/rc.d/chef-solr +0 -4
- data/distro/arch/etc/rc.d/chef-solr-indexer +0 -4
- data/lib/chef.rb +3 -3
- data/lib/chef/api_client.rb +1 -1
- data/lib/chef/application.rb +11 -1
- data/lib/chef/application/client.rb +18 -22
- data/lib/chef/application/knife.rb +28 -29
- data/lib/chef/application/solo.rb +14 -12
- data/lib/chef/client.rb +112 -54
- data/lib/chef/config.rb +4 -0
- data/lib/chef/cookbook/chefignore.rb +66 -0
- data/lib/chef/cookbook/cookbook_collection.rb +6 -5
- data/lib/chef/cookbook/cookbook_version_loader.rb +151 -0
- data/lib/chef/cookbook/file_system_file_vendor.rb +10 -8
- data/lib/chef/cookbook/metadata.rb +200 -108
- data/lib/chef/cookbook_loader.rb +39 -163
- data/lib/chef/cookbook_uploader.rb +100 -78
- data/lib/chef/cookbook_version.rb +92 -47
- data/lib/chef/cookbook_version_selector.rb +163 -0
- data/lib/chef/couchdb.rb +9 -1
- data/lib/chef/data_bag.rb +1 -1
- data/lib/chef/data_bag_item.rb +1 -1
- data/lib/chef/encrypted_data_bag_item.rb +126 -0
- data/lib/chef/environment.rb +386 -0
- data/lib/chef/exceptions.rb +82 -1
- data/lib/chef/index_queue/amqp_client.rb +15 -12
- data/lib/chef/index_queue/indexable.rb +38 -4
- data/lib/chef/json_compat.rb +3 -3
- data/lib/chef/knife.rb +97 -202
- data/lib/chef/knife/bootstrap.rb +27 -61
- data/lib/chef/knife/bootstrap/archlinux-gems.erb +4 -2
- data/lib/chef/knife/bootstrap/centos5-gems.erb +6 -15
- data/lib/chef/knife/bootstrap/fedora13-gems.erb +3 -4
- data/lib/chef/knife/bootstrap/ubuntu10.04-apt.erb +2 -2
- data/lib/chef/knife/bootstrap/ubuntu10.04-gems.erb +6 -5
- data/lib/chef/knife/client_bulk_delete.rb +6 -3
- data/lib/chef/knife/client_create.rb +13 -10
- data/lib/chef/knife/client_delete.rb +10 -7
- data/lib/chef/knife/client_edit.rb +9 -6
- data/lib/chef/knife/client_list.rb +8 -5
- data/lib/chef/knife/client_reregister.rb +9 -6
- data/lib/chef/knife/client_show.rb +9 -6
- data/lib/chef/knife/configure.rb +15 -19
- data/lib/chef/knife/configure_client.rb +4 -4
- data/lib/chef/knife/cookbook_bulk_delete.rb +11 -8
- data/lib/chef/knife/cookbook_create.rb +120 -55
- data/lib/chef/knife/cookbook_delete.rb +18 -12
- data/lib/chef/knife/cookbook_download.rb +10 -6
- data/lib/chef/knife/cookbook_list.rb +15 -6
- data/lib/chef/knife/cookbook_metadata.rb +41 -21
- data/lib/chef/knife/cookbook_metadata_from_file.rb +4 -0
- data/lib/chef/knife/cookbook_show.rb +16 -5
- data/lib/chef/knife/cookbook_site_download.rb +2 -2
- data/lib/chef/knife/cookbook_site_share.rb +18 -13
- data/lib/chef/knife/cookbook_site_unshare.rb +7 -4
- data/lib/chef/knife/cookbook_site_vendor.rb +21 -18
- data/lib/chef/knife/cookbook_test.rb +14 -14
- data/lib/chef/knife/cookbook_upload.rb +91 -40
- data/lib/chef/knife/data_bag_create.rb +41 -6
- data/lib/chef/knife/data_bag_delete.rb +5 -3
- data/lib/chef/knife/data_bag_edit.rb +55 -11
- data/lib/chef/knife/data_bag_from_file.rb +47 -7
- data/lib/chef/knife/data_bag_list.rb +4 -1
- data/lib/chef/knife/data_bag_show.rb +44 -4
- data/lib/chef/knife/environment_create.rb +53 -0
- data/lib/chef/knife/environment_delete.rb +45 -0
- data/lib/chef/knife/environment_edit.rb +45 -0
- data/lib/chef/knife/environment_from_file.rb +39 -0
- data/lib/chef/knife/environment_list.rb +42 -0
- data/lib/chef/knife/environment_show.rb +46 -0
- data/lib/chef/knife/exec.rb +1 -1
- data/lib/chef/knife/index_rebuild.rb +8 -9
- data/lib/chef/knife/node_bulk_delete.rb +9 -6
- data/lib/chef/knife/node_create.rb +9 -6
- data/lib/chef/knife/node_delete.rb +10 -7
- data/lib/chef/knife/node_edit.rb +129 -10
- data/lib/chef/knife/node_from_file.rb +10 -7
- data/lib/chef/knife/node_list.rb +11 -6
- data/lib/chef/knife/node_run_list_add.rb +10 -7
- data/lib/chef/knife/node_run_list_remove.rb +9 -6
- data/lib/chef/knife/node_show.rb +15 -7
- data/lib/chef/knife/recipe_list.rb +4 -3
- data/lib/chef/knife/role_bulk_delete.rb +9 -6
- data/lib/chef/knife/role_create.rb +9 -6
- data/lib/chef/knife/role_delete.rb +10 -7
- data/lib/chef/knife/role_edit.rb +11 -8
- data/lib/chef/knife/role_from_file.rb +10 -7
- data/lib/chef/knife/role_list.rb +8 -5
- data/lib/chef/knife/role_show.rb +11 -8
- data/lib/chef/knife/search.rb +33 -10
- data/lib/chef/knife/ssh.rb +33 -61
- data/lib/chef/knife/status.rb +7 -4
- data/lib/chef/knife/subcommand_loader.rb +101 -0
- data/lib/chef/knife/tag_create.rb +31 -0
- data/lib/chef/knife/tag_delete.rb +31 -0
- data/lib/chef/knife/tag_list.rb +29 -0
- data/lib/chef/knife/ui.rb +229 -0
- data/lib/chef/knife/windows_bootstrap.rb +8 -5
- data/lib/chef/log.rb +5 -59
- data/lib/chef/mash.rb +211 -0
- data/lib/chef/mixins.rb +1 -2
- data/lib/chef/nil_argument.rb +3 -0
- data/lib/chef/node.rb +96 -34
- data/lib/chef/platform.rb +27 -0
- data/lib/chef/provider/cookbook_file.rb +21 -20
- data/lib/chef/provider/deploy/revision.rb +3 -0
- data/lib/chef/provider/file.rb +20 -11
- data/lib/chef/provider/git.rb +26 -26
- data/lib/chef/provider/group/aix.rb +70 -0
- data/lib/chef/provider/group/groupadd.rb +7 -4
- data/lib/chef/provider/group/usermod.rb +1 -1
- data/lib/chef/provider/package.rb +28 -28
- data/lib/chef/provider/package/dpkg.rb +1 -1
- data/lib/chef/provider/package/portage.rb +50 -39
- data/lib/chef/provider/package/rubygems.rb +1 -1
- data/lib/chef/provider/package/zypper.rb +3 -20
- data/lib/chef/provider/remote_directory.rb +0 -2
- data/lib/chef/provider/remote_file.rb +2 -3
- data/lib/chef/provider/service/arch.rb +28 -35
- data/lib/chef/provider/service/simple.rb +1 -1
- data/lib/chef/provider/subversion.rb +22 -22
- data/lib/chef/providers.rb +1 -0
- data/lib/chef/recipe.rb +10 -12
- data/lib/chef/resource.rb +49 -42
- data/lib/chef/resource/gem_package.rb +7 -3
- data/lib/chef/resource/git.rb +5 -5
- data/lib/chef/resource/package.rb +7 -7
- data/lib/chef/resource/scm.rb +2 -1
- data/lib/chef/resource/solaris_package.rb +0 -1
- data/lib/chef/resource/yum_package.rb +0 -1
- data/lib/chef/rest.rb +7 -16
- data/lib/chef/rest/rest_request.rb +0 -16
- data/lib/chef/role.rb +67 -13
- data/lib/chef/run_context.rb +37 -21
- data/lib/chef/run_list.rb +30 -15
- data/lib/chef/run_list/run_list_expansion.rb +41 -20
- data/lib/chef/run_list/run_list_item.rb +20 -6
- data/lib/chef/run_list/versioned_recipe_list.rb +68 -0
- data/lib/chef/runner.rb +7 -15
- data/lib/chef/search/query.rb +12 -7
- data/lib/chef/shef.rb +6 -7
- data/lib/chef/shef/shef_session.rb +40 -35
- data/lib/chef/shell_out.rb +22 -201
- data/lib/chef/shell_out/unix.rb +224 -0
- data/lib/chef/shell_out/windows.rb +95 -0
- data/lib/chef/solr_query.rb +187 -0
- data/lib/chef/solr_query/lucene.treetop +145 -0
- data/lib/chef/solr_query/lucene_nodes.rb +285 -0
- data/lib/chef/solr_query/query_transform.rb +65 -0
- data/lib/chef/solr_query/solr_http_request.rb +118 -0
- data/lib/chef/version.rb +4 -2
- data/lib/chef/version_class.rb +70 -0
- data/lib/chef/version_constraint.rb +116 -0
- metadata +68 -37
- data/lib/chef/cookbook/metadata/version.rb +0 -87
- data/lib/chef/knife/bluebox_images_list.rb +0 -54
- data/lib/chef/knife/bluebox_server_create.rb +0 -157
- data/lib/chef/knife/bluebox_server_delete.rb +0 -63
- data/lib/chef/knife/bluebox_server_list.rb +0 -59
- data/lib/chef/knife/ec2_instance_data.rb +0 -46
- data/lib/chef/knife/ec2_server_create.rb +0 -218
- data/lib/chef/knife/ec2_server_delete.rb +0 -87
- data/lib/chef/knife/ec2_server_list.rb +0 -89
- data/lib/chef/knife/rackspace_server_create.rb +0 -184
- data/lib/chef/knife/rackspace_server_delete.rb +0 -57
- data/lib/chef/knife/rackspace_server_list.rb +0 -59
- data/lib/chef/knife/slicehost_images_list.rb +0 -53
- data/lib/chef/knife/slicehost_server_create.rb +0 -103
- data/lib/chef/knife/slicehost_server_delete.rb +0 -61
- data/lib/chef/knife/slicehost_server_list.rb +0 -64
- data/lib/chef/knife/terremark_server_create.rb +0 -152
- data/lib/chef/knife/terremark_server_delete.rb +0 -87
- data/lib/chef/knife/terremark_server_list.rb +0 -77
- data/lib/chef/mixin/find_preferred_file.rb +0 -92
@@ -0,0 +1,145 @@
|
|
1
|
+
#
|
2
|
+
# Author:: Seth Falcon (<seth@opscode.com>)
|
3
|
+
# Copyright:: Copyright (c) 2010-2011 Opscode, Inc.
|
4
|
+
# License:: Apache License, Version 2.0
|
5
|
+
#
|
6
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
7
|
+
# you may not use this file except in compliance with the License.
|
8
|
+
# You may obtain a copy of the License at
|
9
|
+
#
|
10
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
11
|
+
#
|
12
|
+
# Unless required by applicable law or agreed to in writing, software
|
13
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
14
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
15
|
+
# See the License for the specific language governing permissions and
|
16
|
+
# limitations under the License.
|
17
|
+
#
|
18
|
+
|
19
|
+
grammar Lucene
|
20
|
+
|
21
|
+
rule body
|
22
|
+
(expression / space)* <Body>
|
23
|
+
end
|
24
|
+
|
25
|
+
rule expression
|
26
|
+
operation / group / field / field_range / term / string
|
27
|
+
end
|
28
|
+
|
29
|
+
rule term
|
30
|
+
keyword valid_letter+ <Term> / !keyword valid_letter+ <Term>
|
31
|
+
end
|
32
|
+
|
33
|
+
rule field
|
34
|
+
field_name ":" (term/string/group) <Field>
|
35
|
+
end
|
36
|
+
|
37
|
+
rule field_range
|
38
|
+
field_name ":" "[" range_value " TO " range_value "]" <InclFieldRange>
|
39
|
+
/
|
40
|
+
field_name ":" "{" range_value " TO " range_value "}" <ExclFieldRange>
|
41
|
+
end
|
42
|
+
|
43
|
+
rule field_name
|
44
|
+
!keyword valid_letter+ <FieldName>
|
45
|
+
end
|
46
|
+
|
47
|
+
rule range_value
|
48
|
+
valid_letter+ <RangeValue>
|
49
|
+
end
|
50
|
+
|
51
|
+
rule group
|
52
|
+
space? '(' body ')' space? <Group>
|
53
|
+
end
|
54
|
+
|
55
|
+
rule operation
|
56
|
+
binary_op / unary_op / fuzzy_op / boost_op
|
57
|
+
end
|
58
|
+
|
59
|
+
rule unary_op
|
60
|
+
not_op / required_op / prohibited_op
|
61
|
+
end
|
62
|
+
|
63
|
+
rule binary_op
|
64
|
+
(group / field / field_range / term) space? boolean_operator space+ body <BinaryOp>
|
65
|
+
end
|
66
|
+
|
67
|
+
rule boolean_operator
|
68
|
+
and_operator / or_operator
|
69
|
+
end
|
70
|
+
|
71
|
+
rule and_operator
|
72
|
+
'AND' <AndOperator> / '&&' <AndOperator>
|
73
|
+
end
|
74
|
+
|
75
|
+
rule or_operator
|
76
|
+
'OR' <OrOperator> / '||' <OrOperator>
|
77
|
+
end
|
78
|
+
|
79
|
+
rule not_op
|
80
|
+
not_operator space (group / field / field_range / term / string) <UnaryOp>
|
81
|
+
/
|
82
|
+
bang_operator space? (group / field / field_range / term / string) <UnaryOp>
|
83
|
+
end
|
84
|
+
|
85
|
+
rule not_operator
|
86
|
+
'NOT' <NotOperator>
|
87
|
+
end
|
88
|
+
|
89
|
+
rule bang_operator
|
90
|
+
'!' <NotOperator>
|
91
|
+
end
|
92
|
+
|
93
|
+
rule required_op
|
94
|
+
!valid_letter required_operator (term/string) <UnaryOp>
|
95
|
+
/
|
96
|
+
required_operator (term/string) <UnaryOp>
|
97
|
+
end
|
98
|
+
|
99
|
+
rule required_operator
|
100
|
+
'+' <RequiredOperator>
|
101
|
+
end
|
102
|
+
|
103
|
+
rule prohibited_op
|
104
|
+
!valid_letter prohibited_operator (field/field_range/term/string) <UnaryOp>
|
105
|
+
/
|
106
|
+
prohibited_operator (field/field_range/term/string) <UnaryOp>
|
107
|
+
end
|
108
|
+
|
109
|
+
rule prohibited_operator
|
110
|
+
'-' <ProhibitedOperator>
|
111
|
+
end
|
112
|
+
|
113
|
+
rule boost_op
|
114
|
+
(term/string) '^' fuzzy_param <BoostOp>
|
115
|
+
end
|
116
|
+
|
117
|
+
rule fuzzy_op
|
118
|
+
(term/string) '~' fuzzy_param? <FuzzyOp>
|
119
|
+
end
|
120
|
+
|
121
|
+
rule fuzzy_param
|
122
|
+
[0-9] '.'? [0-9] <FuzzyParam> / [0-9]+ <FuzzyParam>
|
123
|
+
end
|
124
|
+
|
125
|
+
rule string
|
126
|
+
#'"' (!'"' . / '\"')* '"' <Phrase>
|
127
|
+
'"' term (space term)* '"' <Phrase>
|
128
|
+
end
|
129
|
+
|
130
|
+
rule keyword
|
131
|
+
'AND' / 'OR' / 'NOT'
|
132
|
+
end
|
133
|
+
|
134
|
+
rule valid_letter
|
135
|
+
[a-zA-Z0-9*_+.-] / '\\' special_char
|
136
|
+
end
|
137
|
+
|
138
|
+
rule special_char
|
139
|
+
[!(){}\[\]^"~*?:\\]
|
140
|
+
end
|
141
|
+
|
142
|
+
rule space
|
143
|
+
[\s]+
|
144
|
+
end
|
145
|
+
end
|
@@ -0,0 +1,285 @@
|
|
1
|
+
#
|
2
|
+
# Author:: Seth Falcon (<seth@opscode.com>)
|
3
|
+
# Copyright:: Copyright (c) 2010-2011 Opscode, Inc.
|
4
|
+
# License:: Apache License, Version 2.0
|
5
|
+
#
|
6
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
7
|
+
# you may not use this file except in compliance with the License.
|
8
|
+
# You may obtain a copy of the License at
|
9
|
+
#
|
10
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
11
|
+
#
|
12
|
+
# Unless required by applicable law or agreed to in writing, software
|
13
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
14
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
15
|
+
# See the License for the specific language governing permissions and
|
16
|
+
# limitations under the License.
|
17
|
+
#
|
18
|
+
|
19
|
+
require 'treetop'
|
20
|
+
|
21
|
+
module Lucene
|
22
|
+
SEP = "__=__"
|
23
|
+
|
24
|
+
class Term < Treetop::Runtime::SyntaxNode
|
25
|
+
def to_array
|
26
|
+
"T:#{self.text_value}"
|
27
|
+
end
|
28
|
+
|
29
|
+
def transform
|
30
|
+
self.text_value
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
class Field < Treetop::Runtime::SyntaxNode
|
35
|
+
def to_array
|
36
|
+
field = self.elements[0].text_value
|
37
|
+
term = self.elements[1].to_array
|
38
|
+
"(F:#{field} #{term})"
|
39
|
+
end
|
40
|
+
|
41
|
+
def transform
|
42
|
+
field = self.elements[0].text_value
|
43
|
+
term = self.elements[1]
|
44
|
+
if term.is_a? Phrase
|
45
|
+
str = term.transform
|
46
|
+
# remove quotes
|
47
|
+
str = str[1 ... (str.length - 1)]
|
48
|
+
"content:\"#{field}#{SEP}#{str}\""
|
49
|
+
else
|
50
|
+
"content:#{field}#{SEP}#{term.transform}"
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
class FieldRange < Treetop::Runtime::SyntaxNode
|
56
|
+
|
57
|
+
def to_array
|
58
|
+
field = self.elements[0].text_value
|
59
|
+
range_start = self.elements[1].to_array
|
60
|
+
range_end = self.elements[2].to_array
|
61
|
+
"(FR:#{field} #{left}#{range_start}#{right} #{left}#{range_end}#{right})"
|
62
|
+
end
|
63
|
+
|
64
|
+
def transform
|
65
|
+
field = self.elements[0].text_value
|
66
|
+
range_start = self.elements[1].transform
|
67
|
+
range_end = self.elements[2].transform
|
68
|
+
# FIXME: handle special cases for missing start/end
|
69
|
+
if ("*" == range_start && "*" == range_end)
|
70
|
+
"content:#{field}#{SEP}*"
|
71
|
+
elsif "*" == range_end
|
72
|
+
"content:#{left}#{field}#{SEP}#{range_start} TO #{field}#{SEP}\\ufff0#{right}"
|
73
|
+
elsif "*" == range_start
|
74
|
+
"content:#{left}#{field}#{SEP} TO #{field}#{SEP}#{range_end}#{right}"
|
75
|
+
else
|
76
|
+
"content:#{left}#{field}#{SEP}#{range_start} TO #{field}#{SEP}#{range_end}#{right}"
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
end
|
81
|
+
|
82
|
+
class InclFieldRange < FieldRange
|
83
|
+
def left
|
84
|
+
"["
|
85
|
+
end
|
86
|
+
def right
|
87
|
+
"]"
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
class ExclFieldRange < FieldRange
|
92
|
+
def left
|
93
|
+
"{"
|
94
|
+
end
|
95
|
+
def right
|
96
|
+
"}"
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
class RangeValue < Treetop::Runtime::SyntaxNode
|
101
|
+
def to_array
|
102
|
+
self.text_value
|
103
|
+
end
|
104
|
+
|
105
|
+
def transform
|
106
|
+
to_array
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
class FieldName < Treetop::Runtime::SyntaxNode
|
111
|
+
def to_array
|
112
|
+
self.text_value
|
113
|
+
end
|
114
|
+
|
115
|
+
def transform
|
116
|
+
to_array
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
120
|
+
|
121
|
+
class Body < Treetop::Runtime::SyntaxNode
|
122
|
+
def to_array
|
123
|
+
self.elements.map { |x| x.to_array }.join(" ")
|
124
|
+
end
|
125
|
+
|
126
|
+
def transform
|
127
|
+
self.elements.map { |x| x.transform }.join(" ")
|
128
|
+
end
|
129
|
+
end
|
130
|
+
|
131
|
+
class Group < Treetop::Runtime::SyntaxNode
|
132
|
+
def to_array
|
133
|
+
"(" + self.elements[0].to_array + ")"
|
134
|
+
end
|
135
|
+
|
136
|
+
def transform
|
137
|
+
"(" + self.elements[0].transform + ")"
|
138
|
+
end
|
139
|
+
end
|
140
|
+
|
141
|
+
class BinaryOp < Treetop::Runtime::SyntaxNode
|
142
|
+
def to_array
|
143
|
+
op = self.elements[1].to_array
|
144
|
+
a = self.elements[0].to_array
|
145
|
+
b = self.elements[2].to_array
|
146
|
+
"(#{op} #{a} #{b})"
|
147
|
+
end
|
148
|
+
|
149
|
+
def transform
|
150
|
+
op = self.elements[1].transform
|
151
|
+
a = self.elements[0].transform
|
152
|
+
b = self.elements[2].transform
|
153
|
+
"#{a} #{op} #{b}"
|
154
|
+
end
|
155
|
+
end
|
156
|
+
|
157
|
+
class AndOperator < Treetop::Runtime::SyntaxNode
|
158
|
+
def to_array
|
159
|
+
"OP:AND"
|
160
|
+
end
|
161
|
+
|
162
|
+
def transform
|
163
|
+
"AND"
|
164
|
+
end
|
165
|
+
end
|
166
|
+
|
167
|
+
class OrOperator < Treetop::Runtime::SyntaxNode
|
168
|
+
def to_array
|
169
|
+
"OP:OR"
|
170
|
+
end
|
171
|
+
|
172
|
+
def transform
|
173
|
+
"OR"
|
174
|
+
end
|
175
|
+
end
|
176
|
+
|
177
|
+
class FuzzyOp < Treetop::Runtime::SyntaxNode
|
178
|
+
def to_array
|
179
|
+
a = self.elements[0].to_array
|
180
|
+
param = self.elements[1]
|
181
|
+
if param
|
182
|
+
"(OP:~ #{a} #{param.to_array})"
|
183
|
+
else
|
184
|
+
"(OP:~ #{a})"
|
185
|
+
end
|
186
|
+
end
|
187
|
+
|
188
|
+
def transform
|
189
|
+
a = self.elements[0].transform
|
190
|
+
param = self.elements[1]
|
191
|
+
if param
|
192
|
+
"#{a}~#{param.transform}"
|
193
|
+
else
|
194
|
+
"#{a}~"
|
195
|
+
end
|
196
|
+
end
|
197
|
+
end
|
198
|
+
|
199
|
+
class BoostOp < Treetop::Runtime::SyntaxNode
|
200
|
+
def to_array
|
201
|
+
a = self.elements[0].to_array
|
202
|
+
param = self.elements[1]
|
203
|
+
"(OP:^ #{a} #{param.to_array})"
|
204
|
+
end
|
205
|
+
|
206
|
+
def transform
|
207
|
+
a = self.elements[0].transform
|
208
|
+
param = self.elements[1]
|
209
|
+
"#{a}^#{param.transform}"
|
210
|
+
end
|
211
|
+
end
|
212
|
+
|
213
|
+
class FuzzyParam < Treetop::Runtime::SyntaxNode
|
214
|
+
def to_array
|
215
|
+
self.text_value
|
216
|
+
end
|
217
|
+
|
218
|
+
def transform
|
219
|
+
self.text_value
|
220
|
+
end
|
221
|
+
end
|
222
|
+
|
223
|
+
class UnaryOp < Treetop::Runtime::SyntaxNode
|
224
|
+
def to_array
|
225
|
+
op = self.elements[0].to_array
|
226
|
+
a = self.elements[1].to_array
|
227
|
+
"(#{op} #{a})"
|
228
|
+
end
|
229
|
+
|
230
|
+
def transform
|
231
|
+
op = self.elements[0].transform
|
232
|
+
a = self.elements[1].transform
|
233
|
+
spc = case op
|
234
|
+
when "+", "-"
|
235
|
+
""
|
236
|
+
else
|
237
|
+
" "
|
238
|
+
end
|
239
|
+
"#{op}#{spc}#{a}"
|
240
|
+
end
|
241
|
+
|
242
|
+
end
|
243
|
+
|
244
|
+
class NotOperator < Treetop::Runtime::SyntaxNode
|
245
|
+
def to_array
|
246
|
+
"OP:NOT"
|
247
|
+
end
|
248
|
+
|
249
|
+
def transform
|
250
|
+
"NOT"
|
251
|
+
end
|
252
|
+
|
253
|
+
end
|
254
|
+
|
255
|
+
class RequiredOperator < Treetop::Runtime::SyntaxNode
|
256
|
+
def to_array
|
257
|
+
"OP:+"
|
258
|
+
end
|
259
|
+
|
260
|
+
def transform
|
261
|
+
"+"
|
262
|
+
end
|
263
|
+
|
264
|
+
end
|
265
|
+
|
266
|
+
class ProhibitedOperator < Treetop::Runtime::SyntaxNode
|
267
|
+
def to_array
|
268
|
+
"OP:-"
|
269
|
+
end
|
270
|
+
|
271
|
+
def transform
|
272
|
+
"-"
|
273
|
+
end
|
274
|
+
end
|
275
|
+
|
276
|
+
class Phrase < Treetop::Runtime::SyntaxNode
|
277
|
+
def to_array
|
278
|
+
"STR:#{self.text_value}"
|
279
|
+
end
|
280
|
+
|
281
|
+
def transform
|
282
|
+
"#{self.text_value}"
|
283
|
+
end
|
284
|
+
end
|
285
|
+
end
|
@@ -0,0 +1,65 @@
|
|
1
|
+
#
|
2
|
+
# Author:: Seth Falcon (<seth@opscode.com>)
|
3
|
+
# Copyright:: Copyright (c) 2010-2011 Opscode, Inc.
|
4
|
+
# License:: Apache License, Version 2.0
|
5
|
+
#
|
6
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
7
|
+
# you may not use this file except in compliance with the License.
|
8
|
+
# You may obtain a copy of the License at
|
9
|
+
#
|
10
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
11
|
+
#
|
12
|
+
# Unless required by applicable law or agreed to in writing, software
|
13
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
14
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
15
|
+
# See the License for the specific language governing permissions and
|
16
|
+
# limitations under the License.
|
17
|
+
#
|
18
|
+
require 'treetop'
|
19
|
+
require 'chef/solr_query/lucene_nodes'
|
20
|
+
|
21
|
+
class Chef
|
22
|
+
class Exceptions
|
23
|
+
class QueryParseError < StandardError
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
class Chef
|
29
|
+
class SolrQuery
|
30
|
+
class QueryTransform
|
31
|
+
@@base_path = File.expand_path(File.dirname(__FILE__))
|
32
|
+
Treetop.load(File.join(@@base_path, 'lucene.treetop'))
|
33
|
+
@@parser = LuceneParser.new
|
34
|
+
|
35
|
+
def self.parse(data)
|
36
|
+
tree = @@parser.parse(data)
|
37
|
+
msg = "Parse error at offset: #{@@parser.index}\n"
|
38
|
+
msg += "Reason: #{@@parser.failure_reason}"
|
39
|
+
raise Chef::Exceptions::QueryParseError, msg if tree.nil?
|
40
|
+
self.clean_tree(tree)
|
41
|
+
tree.to_array
|
42
|
+
end
|
43
|
+
|
44
|
+
def self.transform(data)
|
45
|
+
return "*:*" if data == "*:*"
|
46
|
+
tree = @@parser.parse(data)
|
47
|
+
msg = "Parse error at offset: #{@@parser.index}\n"
|
48
|
+
msg += "Reason: #{@@parser.failure_reason}"
|
49
|
+
raise Chef::Exceptions::QueryParseError, msg if tree.nil?
|
50
|
+
self.clean_tree(tree)
|
51
|
+
tree.transform
|
52
|
+
end
|
53
|
+
|
54
|
+
private
|
55
|
+
|
56
|
+
def self.clean_tree(root_node)
|
57
|
+
return if root_node.elements.nil?
|
58
|
+
root_node.elements.delete_if do |node|
|
59
|
+
node.class.name == "Treetop::Runtime::SyntaxNode"
|
60
|
+
end
|
61
|
+
root_node.elements.each { |node| self.clean_tree(node) }
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|