-
Notifications
You must be signed in to change notification settings - Fork 1
/
rakefile.rb
158 lines (139 loc) · 3.7 KB
/
rakefile.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
require 'rsolr-ext'
require 'yaml'
require 'rake'
require './lib/sec.rb'
require './lib/login.rb'
settings = YAML.load(File.open("conf/eri.yml"))
namespace :eri do
solr = RSolr.connect :url => settings['solr']
task :init do
include Sec
puts "initializing application"
log = "log/events.log"
#create the event log
if(File.exist? log) then
puts "log exists"
else
puts "creating event log"
File.new(log, "w")
if(File.exist? log) then
puts "event log creation successful"
else
puts "event log not created"
if(File.exist? log) then
puts "log exists"
else
puts "creating event log"
end
end
end
#create the access file
access_file = "access.txt"
if File.exist? access_file then
puts "access file exists"
else
puts "creating access file"
puts "enter a password for the admin account"
pass = STDIN.gets.chomp
line = Sec.generate_admin(pass)
File.new(access_file, "w")
File.open(access_file, 'a') do |f|
f.puts(line)
end
end
end
namespace :login do
include EriAuth
task :authenticate do
puts "enter username"
login = STDIN.gets.chomp
puts "enter password"
password = STDIN.gets.chomp
if EriAuth.test_login(login, password) then
puts "credentials are valid"
else
puts "credentials are not valid"
end
end
task :add_user do
include Sec
puts "enter username"
login = STDIN.gets.chomp
puts "enter password"
password = STDIN.gets.chomp
line = Sec.generate_user(login, password)
File.open("access.txt", 'a') do |f|
f.puts(line)
end
end
end
namespace :index do
desc "Optimize Solr index"
task :optimize do
response = solr.optimize
if response['responseHeader']['status'] == 0 then
puts "index optimized"
else
puts "error: " << response
end
end
desc "Delete all records from index"
task :nuke do
response = solr.delete_by_query '*:*'
if response['responseHeader']['status'] == 0 then
solr.commit
solr.optimize
puts "all records in index deleted"
else
puts "error: " << response
end
end
desc "Delete all records from a compent"
task :del_comp do
solr.delete_by_query("componentIdentifier:" + ENV['COMP'])
solr.commit
solr.optimize
puts "complete"
end
desc "Returns the count of records in the index"
task :get_count do
response = solr.get('select', :params => {:q=>'id:*'})
if response['responseHeader']['status'] == 0 then
puts response['response']['numFound'].to_s << " records in index"
else
puts "error: " << response
end
end
desc "Delete a single record in the index on id"
task :del_record do
solr.delete_by_query("id:" + ENV['ID'])
solr.commit
solr.optimize
end
desc "Deleta a fileType"
task :del_type do
solr.delete_by_query("fileType:" + ENV['TYPE'])
solr.commit
solr.optimize
end
desc "Deleta a mediaType"
task :del_media do
solr.delete_by_query("tikaMime:" + ENV['TYPE'])
solr.commit
solr.optimize
end
desc "Run a query"
task :query do
response = solr.get('select',
:params => {:q => ENV['Q']}
)
puts response
end
desc "Delete all records in the index for a collection"
task :del_col do
solr.delete_by_query("colId:" + ENV['COL'])
solr.commit
solr.optimize
end
end
end