gpr-search 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +35 -0
- data/Rakefile +1 -0
- data/gpr-search.gemspec +25 -0
- data/lib/gpr/actions/search.rb +55 -0
- data/lib/gpr/commands/search.rb +60 -0
- data/lib/gpr/search.rb +2 -0
- data/lib/gpr/search/version.rb +5 -0
- metadata +124 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 14ac0dbc7875c5f67cfef105643438096c4395b9
|
4
|
+
data.tar.gz: 13f669a22ef3b2dddec248dd8503c299a6dd36b9
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: a7716645ed3123c4af37b241fb83b7bcd16ac1f4443363e00c5d5ac9ce654852dcdeed3383fa3be7059c61bf1eba7e5993c853e5de8d234dd784590beed52634
|
7
|
+
data.tar.gz: 787584e44e8bf9f61438838151ce0232b5a1adf38a2709ca44b74fe206afcb7112b5d331fc49338c0e118d68921e2c498f5573d8cda5b4d6d825706329411094
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2015 kaihar4
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
# Gpr::Search
|
2
|
+
|
3
|
+
Gpr plugin to search the specified keyword in registered repositories.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your gpr's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'gpr-search'
|
11
|
+
```
|
12
|
+
|
13
|
+
## Usage
|
14
|
+
|
15
|
+
Show a list of the files that the specified keyword is included.
|
16
|
+
|
17
|
+
```
|
18
|
+
Usage:
|
19
|
+
gpr search
|
20
|
+
|
21
|
+
Options:
|
22
|
+
-f, [--file=FILE] # Filter by filename
|
23
|
+
-h, [--host=HOST] # Filter by host
|
24
|
+
-r, [--repository=REPOSITORY] # Filter by repository
|
25
|
+
|
26
|
+
Search the specified keyword in registered repositories
|
27
|
+
```
|
28
|
+
|
29
|
+

|
30
|
+
|
31
|
+
### Update the database to be used for search
|
32
|
+
|
33
|
+
```sh
|
34
|
+
$ gpr update
|
35
|
+
```
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'bundler/gem_tasks'
|
data/gpr-search.gemspec
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
$LOAD_PATH << File.expand_path('../lib', __FILE__)
|
2
|
+
require 'gpr/search/version'
|
3
|
+
|
4
|
+
Gem::Specification.new do |spec|
|
5
|
+
spec.name = 'gpr-search'
|
6
|
+
spec.version = Gpr::Search::VERSION
|
7
|
+
spec.authors = ['kaihar4']
|
8
|
+
spec.email = ['kaihar4@gmail.com']
|
9
|
+
spec.summary = 'Gpr plugin to search the specified keyword in registered repositories'
|
10
|
+
spec.description = spec.summary
|
11
|
+
spec.homepage = 'https://github.com/kaihar4/gpr-search'
|
12
|
+
spec.license = 'MIT'
|
13
|
+
|
14
|
+
spec.files = `git ls-files -z`.split("\x0")
|
15
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
16
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
17
|
+
spec.require_paths = ['lib']
|
18
|
+
|
19
|
+
spec.add_dependency 'gpr'
|
20
|
+
spec.add_dependency 'rroonga'
|
21
|
+
spec.add_dependency 'safe_colorize'
|
22
|
+
|
23
|
+
spec.add_development_dependency 'bundler'
|
24
|
+
spec.add_development_dependency 'rake'
|
25
|
+
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
require 'fileutils'
|
2
|
+
|
3
|
+
require 'groonga'
|
4
|
+
|
5
|
+
module Gpr
|
6
|
+
module Actions
|
7
|
+
module Search
|
8
|
+
DB_PATH = "#{::Gpr::APP_PATH}/.database"
|
9
|
+
|
10
|
+
def initialize_groonga
|
11
|
+
if FileTest.exist?("#{DB_PATH}/gpr.db")
|
12
|
+
Groonga::Database.open("#{DB_PATH}/gpr.db")
|
13
|
+
else
|
14
|
+
FileUtils.mkdir_p(DB_PATH)
|
15
|
+
Groonga::Context.default_options = { encoding: :utf8 }
|
16
|
+
Groonga::Database.create(path: "#{DB_PATH}/gpr.db")
|
17
|
+
Groonga::Schema.create_table('Files', type: :patricia_trie) do |t|
|
18
|
+
t.text('filename')
|
19
|
+
t.text('body')
|
20
|
+
t.text('host')
|
21
|
+
t.text('repository')
|
22
|
+
end
|
23
|
+
Groonga::Schema.create_table(
|
24
|
+
'Terms',
|
25
|
+
type: :patricia_trie,
|
26
|
+
normalizer: :NormalizerAuto,
|
27
|
+
default_tokenizer: 'TokenBigramSplitSymbolAlpha'
|
28
|
+
) do |t|
|
29
|
+
t.index('Files.body')
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def add_file(path)
|
35
|
+
repo_info = parse_repository(path)
|
36
|
+
|
37
|
+
git_ls_files(path).each do |file|
|
38
|
+
next unless FileTest.file?(file)
|
39
|
+
Groonga['Files'].add(
|
40
|
+
File.expand_path(file),
|
41
|
+
filename: File.basename(file),
|
42
|
+
body: File.open(file).read,
|
43
|
+
host: repo_info[:host],
|
44
|
+
repository: repo_info[:repository]
|
45
|
+
)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
def git_ls_files(path)
|
50
|
+
Dir.chdir(path)
|
51
|
+
`git ls-files`.split("\n")
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
require 'groonga'
|
2
|
+
require 'safe_colorize'
|
3
|
+
|
4
|
+
require 'gpr/actions/search'
|
5
|
+
|
6
|
+
module Gpr
|
7
|
+
module Commands
|
8
|
+
class Search < Base
|
9
|
+
using SafeColorize
|
10
|
+
include ::Gpr::Actions::Search
|
11
|
+
|
12
|
+
def initialize(thor)
|
13
|
+
initialize_groonga
|
14
|
+
|
15
|
+
thor.class_eval do
|
16
|
+
include ::Gpr::Actions::Search
|
17
|
+
|
18
|
+
desc 'search', 'Search the specified keyword in registered repositories'
|
19
|
+
option :file, type: :string, aliases: '-f', desc: 'Filter by filename'
|
20
|
+
option :host, type: :string, aliases: '-h', desc: 'Filter by host'
|
21
|
+
option :repository, type: :string, aliases: '-r', desc: 'Filter by repository'
|
22
|
+
def search(string)
|
23
|
+
result = Groonga['Files'].select do |record|
|
24
|
+
record.body =~ string
|
25
|
+
end
|
26
|
+
|
27
|
+
result.each do |record|
|
28
|
+
next unless FileTest.exist?(record._key)
|
29
|
+
|
30
|
+
next if options[:file] && !(record.filename =~ /#{options[:file]}/)
|
31
|
+
next if options[:host] && !(record.host == options[:host])
|
32
|
+
next if options[:repository] && !(record.repository == options[:repository])
|
33
|
+
|
34
|
+
relative_path = record._key.sub(/#{::Gpr::APP_PATH}\/#{record.host}\/#{record.repository}\//, '')
|
35
|
+
puts "#{record.host.color(:yellow)} - #{record.repository.color(:blue)} : #{relative_path.color(:red)}"
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
desc 'update', 'Update the database to be used for search'
|
40
|
+
def update
|
41
|
+
puts 'Updating...'
|
42
|
+
|
43
|
+
Groonga['Files'].truncate
|
44
|
+
|
45
|
+
# Remove unregistered directories
|
46
|
+
Dir.glob("#{::Gpr::APP_PATH}/*/*").each do |path|
|
47
|
+
# Unregistered directories returns [".", ".."].
|
48
|
+
Dir.rmdir(path) if Dir.entries(path).size == 2
|
49
|
+
end
|
50
|
+
|
51
|
+
repositories = repository_list
|
52
|
+
repositories.each do |repository|
|
53
|
+
add_file(repository)
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
data/lib/gpr/search.rb
ADDED
metadata
ADDED
@@ -0,0 +1,124 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: gpr-search
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- kaihar4
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-03-26 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: gpr
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rroonga
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: safe_colorize
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: bundler
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rake
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
description: Gpr plugin to search the specified keyword in registered repositories
|
84
|
+
email:
|
85
|
+
- kaihar4@gmail.com
|
86
|
+
executables: []
|
87
|
+
extensions: []
|
88
|
+
extra_rdoc_files: []
|
89
|
+
files:
|
90
|
+
- ".gitignore"
|
91
|
+
- Gemfile
|
92
|
+
- LICENSE.txt
|
93
|
+
- README.md
|
94
|
+
- Rakefile
|
95
|
+
- gpr-search.gemspec
|
96
|
+
- lib/gpr/actions/search.rb
|
97
|
+
- lib/gpr/commands/search.rb
|
98
|
+
- lib/gpr/search.rb
|
99
|
+
- lib/gpr/search/version.rb
|
100
|
+
homepage: https://github.com/kaihar4/gpr-search
|
101
|
+
licenses:
|
102
|
+
- MIT
|
103
|
+
metadata: {}
|
104
|
+
post_install_message:
|
105
|
+
rdoc_options: []
|
106
|
+
require_paths:
|
107
|
+
- lib
|
108
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
109
|
+
requirements:
|
110
|
+
- - ">="
|
111
|
+
- !ruby/object:Gem::Version
|
112
|
+
version: '0'
|
113
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - ">="
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
requirements: []
|
119
|
+
rubyforge_project:
|
120
|
+
rubygems_version: 2.4.5
|
121
|
+
signing_key:
|
122
|
+
specification_version: 4
|
123
|
+
summary: Gpr plugin to search the specified keyword in registered repositories
|
124
|
+
test_files: []
|