zeiger 0.0.3 → 0.0.7

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 23b194662e74f40eada24a6f9ce7e25efcaa34ac
4
- data.tar.gz: 5bb3af605cfc175cd66423aed69186124cd54f6e
2
+ SHA256:
3
+ metadata.gz: f181861f454f2ab4812f3d9a2ec6d410967a2daf88f1c7d862a7bf6e4158bf87
4
+ data.tar.gz: ff327d5f231e04c7696e6abb7ec262ab7596e5285388a131a821de2415f7b461
5
5
  SHA512:
6
- metadata.gz: 510a9d31b51b965f131411e08b682f817dd9f2571ba1dba99020696ed360825ba651933d6619d85fedb72fe393f321a496c3b88a4dc868b1a090db82e913da72
7
- data.tar.gz: 3a5f35825f6c516d7609623829fdaa248f989a446d739f37ef93a2ca6bdaa42022bf67d8e3868b9a3cb9405b9d8e4b5bd0dca41a3fdae5764083e436ec4a85d2
6
+ metadata.gz: 9c43b528593313f6a9cff99e4d938e1cd727dc5d485b149f7efce20b708b15f66e751c341091244d6fa2dad08004025ae9622ebda3436b7507a70db8d544b96c
7
+ data.tar.gz: 8c428d4830af1f08500ffdc10a8bc0b770467c9923f110ec778e6b39320aafc2c333665e0f08208c1ed5bd1c84eed601ac8a106a978917b7f351e6b85134b95c
data/README.md CHANGED
@@ -50,6 +50,7 @@ ignore:
50
50
  - .gif$
51
51
  - .zip$
52
52
  - .jpg$
53
+ - .ico$
53
54
  - .xcf$
54
55
  - .mpg$
55
56
  ```
@@ -60,6 +61,9 @@ When you invoke `zeiger search ...` or `zeiger files ...`, zeiger will consider
60
61
 
61
62
  Zeiger considers a project root any directory containing any one of the following: `%w{ .zeiger.yml .git .hg Makefile Rakefile Gemfile build.xml }` (see `ROOT_FILES` constant in `index.rb`)
62
63
 
64
+ ## TODO
65
+
66
+ Use `Listen` gem instead of manual filesystem scan
63
67
 
64
68
  ## Contributing
65
69
 
data/bin/zeiger CHANGED
@@ -12,6 +12,7 @@ when "server" ; Zeiger::Server.new.run *$*
12
12
  when "search" ; Zeiger::Client.new.send({ command: :search, pwd: pwd, search: query })
13
13
  when "files" ; Zeiger::Client.new.send({ command: :files , pwd: pwd, files: query })
14
14
  when "stats" ; Zeiger::Client.new.send({ command: :stats , pwd: pwd })
15
+ else puts "Zeiger version #{Zeiger::VERSION}, usage `zeiger server|search|files|stats`"
15
16
  end
16
17
 
17
18
  # define file groups
data/lib/zeiger/index.rb CHANGED
@@ -2,7 +2,19 @@ module Zeiger
2
2
  INDICES = { }
3
3
 
4
4
  class Index
5
- ROOT_FILES = %w{ .zeiger.yml .git .hg Makefile Rakefile Gemfile build.xml }
5
+ ROOT_GLOBS = [%w{ *.gemspec }]
6
+ ROOT_GROUPS = [%w{ .zeiger.yml },
7
+ %w{ .git },
8
+ %w{ .hg },
9
+ %w{ Makefile },
10
+ %w{ Rakefile },
11
+ %w{ Gemfile },
12
+ %w{ build.xml },
13
+ %w{ lib LICENSE },
14
+ %w{ lib spec },
15
+ %w{ lib MIT-LICENSE },
16
+ %w{ lib README.md },
17
+ ]
6
18
  NGRAM_SIZE = 3
7
19
 
8
20
  attr_accessor :index, :dir, :name, :includes, :ignore, :files, :config, :monitor, :stats
@@ -33,7 +45,8 @@ module Zeiger
33
45
  raise "no path! #{path.inspect}" if path == nil || path.strip == ''
34
46
  return INDICES[path] if INDICES[path]
35
47
  return nil if path == '/'
36
- return (INDICES[path] = new(path)) if ROOT_FILES.any? { |f| File.exist?(File.join path, f) }
48
+ return (INDICES[path] = new(path)) if ROOT_GROUPS.any? { |rg| rg.all? { |f| File.exist?(File.join path, f) } }
49
+ return (INDICES[path] = new(path)) if ROOT_GLOBS.any? { |rg| rg.all? { |f| Dir.glob(File.join path, f).size > 0 } }
37
50
  return from_path(File.dirname path)
38
51
  end
39
52
 
@@ -58,17 +71,36 @@ module Zeiger
58
71
  }
59
72
 
60
73
  puts "#{info.summary} : re-index"
74
+ rescue Exception => e
75
+ puts "Not able to read #{file}"
76
+ while e
77
+ puts e.message
78
+ puts e.backtrace.join("\n")
79
+ puts
80
+ e = e.cause
81
+ end
61
82
  end
62
83
 
63
84
  def glob pattern ; Dir.glob(File.join(dir, pattern)) ; end
64
85
  def rescan ; monitor.build_index ; end
65
- def get_ngram_lines ngrams ; ngrams.map { |ngram| result = index[ngram] || [] }.reduce(&:&) ; end
86
+ def get_ngram_lines ngrams ; ngrams.map { |ngram| index[ngram] || [] }.reduce(&:&) ; end
66
87
  def exec_query regex, ngrams ; get_ngram_lines(ngrams).select { |line| line.matches? regex } ; end
67
88
  def sort_by_filename lines ; lines.sort_by { |line| [line.file.local_filename, line.line_number] } ; end
89
+ def all_matching q ; index.keys.select { |k| k.match q }.map { |k| index[k] }.reduce(&:|) ; end
68
90
 
69
91
  def query txt
70
92
  puts "got query #{txt.inspect}"
71
- sort_by_filename exec_query Regexp.compile(Regexp.escape txt), txt.ngrams(NGRAM_SIZE)
93
+
94
+ lines = if (txt.strip.to_s == '')
95
+ puts "empty query, not searching!"
96
+ []
97
+ elsif txt.length <= NGRAM_SIZE
98
+ all_matching Regexp.compile(Regexp.escape txt)
99
+ else
100
+ exec_query Regexp.compile(Regexp.escape txt), txt.ngrams(NGRAM_SIZE)
101
+ end
102
+
103
+ sort_by_filename(lines)
72
104
  end
73
105
 
74
106
  def file_list name
@@ -5,7 +5,7 @@ module Zeiger
5
5
  def initialize dir, index, attrs
6
6
  @dir, @index, @stat = dir, index, Hash.new
7
7
  @includes = attrs["search"] || %w{ app/**/* bin/**/* config/**/* lib/**/* spec/**/* test/**/* }
8
- @ignore = attrs["ignore"] || %w{ .gz$ .png$ .jpg$ .pdf$ }
8
+ @ignore = attrs["ignore"] || %w{ .gz$ .png$ .jpg$ .pdf$ .ico$ }
9
9
  end
10
10
 
11
11
  def ignore? filename
data/lib/zeiger/server.rb CHANGED
@@ -4,16 +4,19 @@ module Zeiger
4
4
  SOCKET_NAME = "/tmp/zeiger-index"
5
5
 
6
6
  class Server
7
- def run command, *args
7
+ def run command, sleepytime=nil, *args
8
+ sleepytime = (sleepytime || 10).to_f
9
+ raise "sleep time must be greater than zero, got #{sleepytime.inspect}" unless sleepytime > 0.0
10
+ puts "starting server with sleep interval of #{sleepytime} seconds"
8
11
  Thread.new do
9
12
  begin
10
13
  while true do
11
14
  indices = Zeiger::INDICES.values
12
15
  indices.each do |index|
13
- puts "scanning #{index.name} at #{index.dir}"
16
+ puts "#{Time.now} scanning #{index.name} at #{index.dir}"
14
17
  index.rescan
15
18
  end
16
- sleep 10
19
+ sleep sleepytime
17
20
  end
18
21
  rescue Exception => e
19
22
  puts e.message
@@ -29,15 +32,21 @@ module Zeiger
29
32
  puts incoming.to_yaml
30
33
 
31
34
  index = Index.from_path incoming[:pwd]
32
- puts "querying index #{index.name}"
33
-
34
- case incoming[:command]
35
- when :search
36
- index.query(incoming[:search]).each { |res| sock.puts res.to_s }
37
- when :stats
38
- sock.puts index.stats.stats.to_yaml
39
- when :files
40
- index.file_list(incoming[:files]).each { |f| sock.puts f.local_filename }
35
+
36
+ if index
37
+ puts "querying index #{index.name}"
38
+
39
+ case incoming[:command]
40
+ when :search
41
+ index.query(incoming[:search]).each { |res| sock.puts res.to_s }
42
+ when :stats
43
+ sock.puts index.stats.stats.to_yaml
44
+ when :files
45
+ index.file_list(incoming[:files]).each { |f| sock.puts f.local_filename }
46
+ end
47
+
48
+ else
49
+ puts "no index found for path #{incoming[:pwd].inspect}"
41
50
  end
42
51
 
43
52
  ensure
@@ -1,3 +1,3 @@
1
1
  module Zeiger
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.7"
3
3
  end
data/zeiger.gemspec CHANGED
@@ -18,6 +18,6 @@ Gem::Specification.new do |spec|
18
18
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
19
  spec.require_paths = ["lib"]
20
20
 
21
- spec.add_development_dependency "bundler", "~> 1.7"
21
+ spec.add_development_dependency "bundler"
22
22
  spec.add_development_dependency "rake", "~> 10.0"
23
23
  end
metadata CHANGED
@@ -1,29 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: zeiger
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - conanite
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-08-03 00:00:00.000000000 Z
11
+ date: 2021-09-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "~>"
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: '1.7'
19
+ version: '0'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - "~>"
24
+ - - ">="
25
25
  - !ruby/object:Gem::Version
26
- version: '1.7'
26
+ version: '0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rake
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -83,8 +83,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
83
83
  - !ruby/object:Gem::Version
84
84
  version: '0'
85
85
  requirements: []
86
- rubyforge_project:
87
- rubygems_version: 2.2.2
86
+ rubygems_version: 3.0.3
88
87
  signing_key:
89
88
  specification_version: 4
90
89
  summary: Provide text index of files in current directory tree and a unix socket to