filewatch-ext 0.1.4 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f4686023797b04eae09ab5bec38217d1165d3b25
4
- data.tar.gz: 4a09a85762f5d60cf45997e4ee67bfb0c36299fb
3
+ metadata.gz: cc1631829006d12daf285a4bb9c69a0cd10046b0
4
+ data.tar.gz: f7c888de7dbdcef2e7b9fe4feccb0d40a779b024
5
5
  SHA512:
6
- metadata.gz: f94fb66a38aaf7362462b540117c5e782d306db617b35475983064766dfc855c3036aaecaa49ef922b4dfc08e486b3902e9d912d5641f43604d36868247dda83
7
- data.tar.gz: 4b72a4ae0e6bc4a573749206a977b53faa36cdee65668995a468695fbe1b10b0159bed321379c14117b416bc6c0587d291c3433bcd9dc67404e26339f9966f44
6
+ metadata.gz: 8b1834ba248c5ad86782e84e6ae298e943961b08f3ad7c08c6f79b41ffa6b7d302404f7c3fc0372028660ea3e414d22f1518ebcc72b26ecf4f9b756aaff6d50c
7
+ data.tar.gz: 1da4321b826abfed34c76af4a3e6d23a026b23c5fe8aa66e5611c17eb2dfa49e17106e8958e49495a60c56b3337650f36d854d0a9b077a6e9a3327e2cfdf42f8
metadata CHANGED
@@ -1,84 +1,40 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: filewatch-ext
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
- - Dietmar Duft
7
+ - dduft
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-04-14 00:00:00.000000000 Z
11
+ date: 2014-12-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: filewatch
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ~>
17
+ - - "~>"
18
18
  - !ruby/object:Gem::Version
19
19
  version: 0.5.1
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ~>
24
+ - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: 0.5.1
27
- - !ruby/object:Gem::Dependency
28
- name: simple_xlsx_reader
29
- requirement: !ruby/object:Gem::Requirement
30
- requirements:
31
- - - ~>
32
- - !ruby/object:Gem::Version
33
- version: 0.9.8
34
- type: :runtime
35
- prerelease: false
36
- version_requirements: !ruby/object:Gem::Requirement
37
- requirements:
38
- - - ~>
39
- - !ruby/object:Gem::Version
40
- version: 0.9.8
41
- - !ruby/object:Gem::Dependency
42
- name: axlsx
43
- requirement: !ruby/object:Gem::Requirement
44
- requirements:
45
- - - ~>
46
- - !ruby/object:Gem::Version
47
- version: 2.0.1
48
- type: :runtime
49
- prerelease: false
50
- version_requirements: !ruby/object:Gem::Requirement
51
- requirements:
52
- - - ~>
53
- - !ruby/object:Gem::Version
54
- version: 2.0.1
55
- - !ruby/object:Gem::Dependency
56
- name: spreadsheet
57
- requirement: !ruby/object:Gem::Requirement
58
- requirements:
59
- - - ~>
60
- - !ruby/object:Gem::Version
61
- version: 0.9.7
62
- type: :runtime
63
- prerelease: false
64
- version_requirements: !ruby/object:Gem::Requirement
65
- requirements:
66
- - - ~>
67
- - !ruby/object:Gem::Version
68
- version: 0.9.7
69
- description: Extensions for ruby-filewatcher, like xls, xlsx
27
+ description: Extensions for ruby-filewatcher
70
28
  email:
71
29
  - dietmar@signifydata.com
72
30
  executables: []
73
31
  extensions: []
74
32
  extra_rdoc_files: []
75
33
  files:
76
- - lib/filewatch/winhelper.rb
77
- - lib/filewatch/ext/tailbase.rb
78
- - lib/filewatch/ext/filetail.rb
79
- - lib/filewatch/ext/xlsxtail.rb
80
- - lib/filewatch/ext/xlstail.rb
81
34
  - lib/JRubyFileExtension.jar
35
+ - lib/filewatch/ext/filetail.rb
36
+ - lib/filewatch/ext/tailbase.rb
37
+ - lib/filewatch/winhelper.rb
82
38
  homepage: https://bitbucket.org/signify/ruby-filewatch-ext
83
39
  licenses:
84
40
  - MIT
@@ -90,19 +46,18 @@ require_paths:
90
46
  - lib
91
47
  required_ruby_version: !ruby/object:Gem::Requirement
92
48
  requirements:
93
- - - '>='
49
+ - - ">="
94
50
  - !ruby/object:Gem::Version
95
51
  version: '0'
96
52
  required_rubygems_version: !ruby/object:Gem::Requirement
97
53
  requirements:
98
- - - '>='
54
+ - - ">="
99
55
  - !ruby/object:Gem::Version
100
56
  version: '0'
101
57
  requirements: []
102
58
  rubyforge_project:
103
- rubygems_version: 2.0.3
59
+ rubygems_version: 2.2.2
104
60
  signing_key:
105
61
  specification_version: 4
106
62
  summary: filewatch extensions
107
63
  test_files: []
108
- has_rdoc:
@@ -1,153 +0,0 @@
1
- require "filewatch/ext/tailbase"
2
- require "spreadsheet"
3
-
4
- module FileWatch::Ext
5
- class XlsTail < FileWatch::Ext::TailBase
6
-
7
- public
8
- def initialize(opts={})
9
- @pos = {}
10
- super
11
- end
12
-
13
- public
14
- def subscribe(&block)
15
- # subscribe(stat_interval = 1, discover_interval = 5, &block)
16
- @watch.subscribe(@opts[:stat_interval],
17
- @opts[:discover_interval]) do |event, path|
18
- case event
19
- when :create, :create_initial
20
- if @files.member?(path)
21
- @logger.debug("#{event} for #{path}: already exists in @files")
22
- next
23
- end
24
- if _open_file(path, event)
25
- _read_file(path, &block)
26
- end
27
- when :modify
28
- @logger.debug(":modify for #{path}")
29
- when :delete
30
- @logger.debug(":delete for #{path}, deleted from @files")
31
-
32
- _progressdb_delete(path, &block) if @opts[:progressdb] && @opts[:progressdb_del]
33
-
34
- @files.delete(path)
35
- _sincedb_delete(path)
36
- @statcache.delete(path)
37
- else
38
- @logger.warn("unknown event type #{event} for #{path}")
39
- end
40
- end # @watch.subscribe
41
- end # def each
42
-
43
- private
44
- def get_size(path)
45
- workbook = Spreadsheet.open(path)
46
- pos = 0
47
- workbook.worksheets.each do |worksheet|
48
- pos += worksheet.rows.length
49
- end
50
- @size = pos
51
- end
52
-
53
- private
54
- def _open_file(path, event)
55
- @logger.debug("_open_file: #{path}: opening")
56
- begin
57
- #Spreadsheet.client_encoding = 'UTF-8'
58
- @files[path] = Spreadsheet.open(path)
59
- rescue
60
- # don't emit this message too often. if a file that we can't
61
- # read is changing a lot, we'll try to open it more often,
62
- # and might be spammy.
63
- now = Time.now.to_i
64
- if now - @lastwarn[path] > OPEN_WARN_INTERVAL
65
- @logger.warn("failed to open #{path}: #{$!}")
66
- @lastwarn[path] = now
67
- else
68
- @logger.debug("(warn supressed) failed to open #{path}: #{$!}")
69
- end
70
- #@files.delete(path)
71
- return false
72
- end
73
-
74
- stat = File::Stat.new(path)
75
- size = get_size(path)
76
-
77
- if @iswindows
78
- fileId = Winhelper.GetWindowsUniqueFileIdentifier(path)
79
- inode = [fileId, stat.dev_major, stat.dev_minor]
80
- else
81
- inode = [stat.ino.to_s, stat.dev_major, stat.dev_minor]
82
- end
83
-
84
- @statcache[path] = inode
85
-
86
- if @sincedb.member?(inode)
87
- last_size = @sincedb[inode][:pos]
88
- @logger.debug("#{path}: sincedb last value #{@sincedb[inode]}, cur size #{size}")
89
- if last_size <= size
90
- @logger.debug("#{path}: sincedb: seeking to #{last_size}")
91
- @pos[path] = last_size
92
- else
93
- @logger.debug("#{path}: last value size is greater than current value, starting over")
94
- @sincedb[inode] = {:size => size, :pos => 0}
95
- end
96
- elsif event == :create_initial && @files[path]
97
- # TODO(sissel): Allow starting at beginning of the file.
98
- if @opts[:start_new_files_at] == :beginning
99
- @logger.debug("#{path}: initial create, no sincedb, seeking to beginning of file")
100
- @pos[path] = 0
101
- @sincedb[inode] = {:size => size, :pos => 0}
102
- else
103
- # seek to end
104
- @logger.debug("#{path}: initial create, no sincedb, seeking to end #{size}")
105
- @pos[path] = size
106
- @sincedb[inode] = {:size => size, :pos => size}
107
- end
108
- elsif event == :create
109
- @pos[path] = 0
110
- @sincedb[inode] = {:size => size, :pos => 0}
111
- else
112
- @logger.debug("#{path}: staying at position 0, no sincedb")
113
- end
114
-
115
- return true
116
- end # def _open_file
117
-
118
- private
119
- def _read_file(path, &block)
120
- changed = false
121
- pos = 0
122
-
123
- worksheets = @files[path].worksheets
124
-
125
- worksheets.each_with_index do |worksheet, index_sheet|
126
-
127
- worksheet.each_with_index do |row, index_row|
128
- pos += 1
129
-
130
- if pos > @pos[path]
131
- changed = true
132
-
133
- sheet_name = worksheet.name.empty? ? "Sheet#{index_sheet+1}" : worksheet.name
134
-
135
- if pos == @size #end of file is reached
136
- data = {:row => row, :wsname => sheet_name, :eof => true}
137
- else
138
- data = {:row => row, :wsname => sheet_name, :eof => false}
139
- end
140
-
141
- yield(path, data, :log)
142
-
143
- @pos[path] = pos
144
- @sincedb[@statcache[path]][:pos] = pos
145
- _check_sincedb(false, path, &block)
146
- end
147
- end
148
- end
149
- _check_sincedb(true, path, &block) if changed
150
- end # def _read_file
151
-
152
- end # class Tail
153
- end # module FileWatch
@@ -1,151 +0,0 @@
1
- require "filewatch/ext/tailbase"
2
- require "simple_xlsx_reader"
3
-
4
- module FileWatch::Ext
5
- class XlsxTail < FileWatch::Ext::TailBase
6
-
7
- public
8
- def initialize(opts={})
9
- @pos = {}
10
- super
11
- end
12
-
13
- public
14
- def subscribe(&block)
15
- # subscribe(stat_interval = 1, discover_interval = 5, &block)
16
- @watch.subscribe(@opts[:stat_interval],
17
- @opts[:discover_interval]) do |event, path|
18
- case event
19
- when :create, :create_initial
20
- if @files.member?(path)
21
- @logger.debug("#{event} for #{path}: already exists in @files")
22
- next
23
- end
24
- if _open_file(path, event)
25
- _read_file(path, &block)
26
- end
27
- when :modify
28
- @logger.debug(":modify for #{path}")
29
- when :delete
30
- @logger.debug(":delete for #{path}, deleted from @files")
31
-
32
- _progressdb_delete(path, &block) if @opts[:progressdb] && @opts[:progressdb_del]
33
-
34
- @files.delete(path)
35
- _sincedb_delete(path)
36
- @statcache.delete(path)
37
- else
38
- @logger.warn("unknown event type #{event} for #{path}")
39
- end
40
- end # @watch.subscribe
41
- end # def each
42
-
43
- private
44
- def get_size(path)
45
- doc = SimpleXlsxReader.open(path)
46
- pos = 0
47
- doc.sheets.each do |worksheet|
48
- pos += worksheet.rows.length
49
- end
50
- @size = pos
51
- end
52
-
53
- private
54
- def _open_file(path, event)
55
- @logger.debug("_open_file: #{path}: opening")
56
- begin
57
- @files[path] = SimpleXlsxReader.open(path)
58
- rescue
59
- # don't emit this message too often. if a file that we can't
60
- # read is changing a lot, we'll try to open it more often,
61
- # and might be spammy.
62
- now = Time.now.to_i
63
- if now - @lastwarn[path] > OPEN_WARN_INTERVAL
64
- @logger.warn("failed to open #{path}: #{$!}")
65
- @lastwarn[path] = now
66
- else
67
- @logger.debug("(warn supressed) failed to open #{path}: #{$!}")
68
- end
69
- #@files.delete(path)
70
- return false
71
- end
72
-
73
- stat = File::Stat.new(path)
74
- size = get_size(path)
75
-
76
- if @iswindows
77
- fileId = Winhelper.GetWindowsUniqueFileIdentifier(path)
78
- inode = [fileId, stat.dev_major, stat.dev_minor]
79
- else
80
- inode = [stat.ino.to_s, stat.dev_major, stat.dev_minor]
81
- end
82
-
83
- @statcache[path] = inode
84
-
85
- if @sincedb.member?(inode)
86
- last_size = @sincedb[inode][:pos]
87
- @logger.debug("#{path}: sincedb last value #{@sincedb[inode]}, cur size #{size}")
88
- if last_size <= size
89
- @logger.debug("#{path}: sincedb: seeking to #{last_size}")
90
- @pos[path] = last_size
91
- else
92
- @logger.debug("#{path}: last value size is greater than current value, starting over")
93
- @sincedb[inode] = {:size => size, :pos => 0}
94
- end
95
- elsif event == :create_initial && @files[path]
96
- # TODO(sissel): Allow starting at beginning of the file.
97
- if @opts[:start_new_files_at] == :beginning
98
- @logger.debug("#{path}: initial create, no sincedb, seeking to beginning of file")
99
- @pos[path] = 0
100
- @sincedb[inode] = {:size => size, :pos => 0}
101
- else
102
- # seek to end
103
- @logger.debug("#{path}: initial create, no sincedb, seeking to end #{size}")
104
- @pos[path] = size
105
- @sincedb[inode] = {:size => size, :pos => size}
106
- end
107
- elsif event == :create
108
- @pos[path] = 0
109
- @sincedb[inode] = {:size => size, :pos => 0}
110
- else
111
- @logger.debug("#{path}: staying at position 0, no sincedb")
112
- end
113
-
114
- return true
115
- end # def _open_file
116
-
117
- private
118
- def _read_file(path, &block)
119
- changed = false
120
- pos = 0
121
-
122
- worksheets = @files[path].sheets
123
-
124
- worksheets.each_with_index do |worksheet, index_sheet|
125
-
126
- worksheet.rows.each_with_index do |row, index_row|
127
- pos += 1
128
-
129
- if pos > @pos[path]
130
- changed = true
131
- sheet_name = worksheet.name.empty? ? "Sheet#{index_sheet+1}" : worksheet.name
132
-
133
- if pos == @size #end of file is reached
134
- data = {:row => row, :wsname => sheet_name, :eof => true}
135
- else
136
- data = {:row => row, :wsname => sheet_name, :eof => false}
137
- end
138
-
139
- yield(path, data, :log)
140
-
141
- @pos[path] = pos
142
- @sincedb[@statcache[path]][:pos] = pos
143
- _check_sincedb(false, path, &block)
144
- end
145
- end
146
- end
147
- _check_sincedb(true, path, &block) if changed
148
- end # def _read_file
149
-
150
- end # class Tail
151
- end # module FileWatch