maid 0.8.0.alpha.1 → 0.8.0.alpha.2

Sign up to get free protection for your applications and to get access to all the features.
data/ChangeLog CHANGED
@@ -7,6 +7,7 @@ maid (0.8.0) unstable; urgency=low
7
7
  * Song Chen Wen: Added "hidden?", "has_been_used?", "used_at", "added_at"
8
8
  tools, using OSX Spotlight metadata when available
9
9
  * Song Chen Wen: Added Aria2 and Tunder support to "downloading?" tool
10
+ * Song Chen Wen: Reduce "watch" CPU usage by throttling (Closes: #149, #150)
10
11
 
11
12
  -- Benjamin Oakes <hello@benjaminoakes.com> TODO
12
13
 
data/lib/maid.rb CHANGED
@@ -4,6 +4,7 @@ Deprecated.set_action(:warn)
4
4
 
5
5
  # Must be in this order:
6
6
  require 'maid/version'
7
+ require 'maid/downloading'
7
8
  require 'maid/tools'
8
9
  require 'maid/rule_container'
9
10
  require 'maid/maid'
@@ -0,0 +1,19 @@
1
+ module Maid::Downloading
2
+ class << self
3
+ def downloading?(path)
4
+ !!(downloading_file_regexps.any? { |re| path.match(re) } || firefox_extra?(path) || aria2_extra?(path))
5
+ end
6
+
7
+ def downloading_file_regexps
8
+ [/\.crdownload$/, /\.download$/, /\.aria2$/, /\.td$/, /\.td.cfg$/, /\.part$/]
9
+ end
10
+
11
+ def firefox_extra?(path)
12
+ File.exist?("#{path}.part")
13
+ end
14
+
15
+ def aria2_extra?(path)
16
+ File.exist?("#{path}.aria2")
17
+ end
18
+ end
19
+ end
data/lib/maid/tools.rb CHANGED
@@ -358,11 +358,12 @@ module Maid::Tools
358
358
  mdls_to_array(path, 'kMDItemWhereFroms')
359
359
  end
360
360
 
361
+ include Maid::Downloading
361
362
  # Detect whether the path is currently being downloaded in Chrome, Firefox or Safari.
362
363
  #
363
364
  # See also: `dir_safe`
364
365
  def downloading?(path)
365
- !!(chrome_downloading?(path) || firefox_downloading?(path) || safari_downloading?(path) || aria2_downloading?(path) || thunder_downloading?(path))
366
+ Maid::Downloading.downloading?(path)
366
367
  end
367
368
 
368
369
  # Find all duplicate files in the given globs.
@@ -940,27 +941,6 @@ module Maid::Tools
940
941
 
941
942
  private
942
943
 
943
- def firefox_downloading?(path)
944
- path =~ /\.part$/ ||
945
- File.exist?("#{path}.part")
946
- end
947
-
948
- def chrome_downloading?(path)
949
- path =~ /\.crdownload$/
950
- end
951
-
952
- def safari_downloading?(path)
953
- path =~ /\.download$/
954
- end
955
-
956
- def aria2_downloading?(path)
957
- File.exist?("#{path}.aria2") || path =~ /\.aria2$/
958
- end
959
-
960
- def thunder_downloading?(path)
961
- path =~ /\.td$/ || path =~ /\.td.cfg$/
962
- end
963
-
964
944
  def has_tag_available?()
965
945
  return Maid::Platform.osx? && system("which -s tag")
966
946
  end
data/lib/maid/version.rb CHANGED
@@ -1,4 +1,4 @@
1
1
  module Maid
2
- VERSION = '0.8.0.alpha.1'
2
+ VERSION = '0.8.0.alpha.2'
3
3
  SUMMARY = 'Be lazy. Let Maid clean up after you, based on rules you define. Think of it as "Hazel for hackers".'
4
4
  end
data/lib/maid/watch.rb CHANGED
@@ -1,12 +1,20 @@
1
1
  require 'listen'
2
2
  class Maid::Watch
3
3
  include Maid::RuleContainer
4
+ include Maid::Downloading
4
5
 
5
6
  attr_reader :path, :listener, :logger
6
7
 
7
8
  def initialize(maid, path, options = {}, &rules)
8
9
  @maid = maid
9
- @options = options
10
+ if options.nil?
11
+ @lazy = true
12
+ @options = { wait_for_delay: 10,
13
+ ignore: Maid::Downloading.downloading_file_regexps }
14
+ else
15
+ @lazy = options.delete(:lazy) { |key| true }
16
+ @options = options
17
+ end
10
18
  @logger = maid.logger # TODO: Maybe it's better to create seperate loggers?
11
19
  @path = File.expand_path(path)
12
20
  initialize_rules(&rules)
@@ -15,7 +23,9 @@ class Maid::Watch
15
23
  def run
16
24
  unless rules.empty?
17
25
  @listener = Listen.to(path, @options) do |modified, added, removed|
18
- follow_rules(modified, added, removed)
26
+ if !@lazy || added.any? || removed.any?
27
+ follow_rules(modified, added, removed)
28
+ end
19
29
  end
20
30
  @listener.start
21
31
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: maid
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.0.alpha.1
4
+ version: 0.8.0.alpha.2
5
5
  prerelease: 6
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2015-04-17 00:00:00.000000000 Z
12
+ date: 2015-05-05 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: escape
16
- requirement: &6312460 !ruby/object:Gem::Requirement
16
+ requirement: &13164820 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -24,10 +24,10 @@ dependencies:
24
24
  version: 0.1.0
25
25
  type: :runtime
26
26
  prerelease: false
27
- version_requirements: *6312460
27
+ version_requirements: *13164820
28
28
  - !ruby/object:Gem::Dependency
29
29
  name: thor
30
- requirement: &6307360 !ruby/object:Gem::Requirement
30
+ requirement: &13164080 !ruby/object:Gem::Requirement
31
31
  none: false
32
32
  requirements:
33
33
  - - ! '>='
@@ -38,10 +38,10 @@ dependencies:
38
38
  version: 1.0.0
39
39
  type: :runtime
40
40
  prerelease: false
41
- version_requirements: *6307360
41
+ version_requirements: *13164080
42
42
  - !ruby/object:Gem::Dependency
43
43
  name: deprecated
44
- requirement: &6305140 !ruby/object:Gem::Requirement
44
+ requirement: &13163360 !ruby/object:Gem::Requirement
45
45
  none: false
46
46
  requirements:
47
47
  - - ~>
@@ -49,10 +49,10 @@ dependencies:
49
49
  version: 3.0.0
50
50
  type: :runtime
51
51
  prerelease: false
52
- version_requirements: *6305140
52
+ version_requirements: *13163360
53
53
  - !ruby/object:Gem::Dependency
54
54
  name: dimensions
55
- requirement: &6303640 !ruby/object:Gem::Requirement
55
+ requirement: &13162880 !ruby/object:Gem::Requirement
56
56
  none: false
57
57
  requirements:
58
58
  - - ! '>='
@@ -63,10 +63,10 @@ dependencies:
63
63
  version: '2.0'
64
64
  type: :runtime
65
65
  prerelease: false
66
- version_requirements: *6303640
66
+ version_requirements: *13162880
67
67
  - !ruby/object:Gem::Dependency
68
68
  name: mime-types
69
- requirement: &6300180 !ruby/object:Gem::Requirement
69
+ requirement: &13162080 !ruby/object:Gem::Requirement
70
70
  none: false
71
71
  requirements:
72
72
  - - ~>
@@ -74,10 +74,10 @@ dependencies:
74
74
  version: '2.0'
75
75
  type: :runtime
76
76
  prerelease: false
77
- version_requirements: *6300180
77
+ version_requirements: *13162080
78
78
  - !ruby/object:Gem::Dependency
79
79
  name: rubyzip
80
- requirement: &6299560 !ruby/object:Gem::Requirement
80
+ requirement: &13161580 !ruby/object:Gem::Requirement
81
81
  none: false
82
82
  requirements:
83
83
  - - ~>
@@ -85,10 +85,10 @@ dependencies:
85
85
  version: 1.1.0
86
86
  type: :runtime
87
87
  prerelease: false
88
- version_requirements: *6299560
88
+ version_requirements: *13161580
89
89
  - !ruby/object:Gem::Dependency
90
90
  name: xdg
91
- requirement: &6298260 !ruby/object:Gem::Requirement
91
+ requirement: &13160980 !ruby/object:Gem::Requirement
92
92
  none: false
93
93
  requirements:
94
94
  - - ~>
@@ -96,10 +96,10 @@ dependencies:
96
96
  version: 2.2.3
97
97
  type: :runtime
98
98
  prerelease: false
99
- version_requirements: *6298260
99
+ version_requirements: *13160980
100
100
  - !ruby/object:Gem::Dependency
101
101
  name: listen
102
- requirement: &6296740 !ruby/object:Gem::Requirement
102
+ requirement: &13158260 !ruby/object:Gem::Requirement
103
103
  none: false
104
104
  requirements:
105
105
  - - ! '>='
@@ -110,10 +110,10 @@ dependencies:
110
110
  version: 2.11.0
111
111
  type: :runtime
112
112
  prerelease: false
113
- version_requirements: *6296740
113
+ version_requirements: *13158260
114
114
  - !ruby/object:Gem::Dependency
115
115
  name: rufus-scheduler
116
- requirement: &6295240 !ruby/object:Gem::Requirement
116
+ requirement: &13173700 !ruby/object:Gem::Requirement
117
117
  none: false
118
118
  requirements:
119
119
  - - ~>
@@ -121,10 +121,10 @@ dependencies:
121
121
  version: 3.0.6
122
122
  type: :runtime
123
123
  prerelease: false
124
- version_requirements: *6295240
124
+ version_requirements: *13173700
125
125
  - !ruby/object:Gem::Dependency
126
126
  name: exifr
127
- requirement: &6293880 !ruby/object:Gem::Requirement
127
+ requirement: &13172960 !ruby/object:Gem::Requirement
128
128
  none: false
129
129
  requirements:
130
130
  - - ~>
@@ -132,10 +132,10 @@ dependencies:
132
132
  version: 1.2.0
133
133
  type: :runtime
134
134
  prerelease: false
135
- version_requirements: *6293880
135
+ version_requirements: *13172960
136
136
  - !ruby/object:Gem::Dependency
137
137
  name: geocoder
138
- requirement: &6292380 !ruby/object:Gem::Requirement
138
+ requirement: &13172120 !ruby/object:Gem::Requirement
139
139
  none: false
140
140
  requirements:
141
141
  - - ~>
@@ -143,10 +143,10 @@ dependencies:
143
143
  version: 1.2.0
144
144
  type: :runtime
145
145
  prerelease: false
146
- version_requirements: *6292380
146
+ version_requirements: *13172120
147
147
  - !ruby/object:Gem::Dependency
148
148
  name: fakefs
149
- requirement: &6290640 !ruby/object:Gem::Requirement
149
+ requirement: &13169320 !ruby/object:Gem::Requirement
150
150
  none: false
151
151
  requirements:
152
152
  - - ~>
@@ -154,10 +154,10 @@ dependencies:
154
154
  version: 0.4.3
155
155
  type: :development
156
156
  prerelease: false
157
- version_requirements: *6290640
157
+ version_requirements: *13169320
158
158
  - !ruby/object:Gem::Dependency
159
159
  name: guard
160
- requirement: &6289200 !ruby/object:Gem::Requirement
160
+ requirement: &13167680 !ruby/object:Gem::Requirement
161
161
  none: false
162
162
  requirements:
163
163
  - - ~>
@@ -165,10 +165,10 @@ dependencies:
165
165
  version: 2.12.5
166
166
  type: :development
167
167
  prerelease: false
168
- version_requirements: *6289200
168
+ version_requirements: *13167680
169
169
  - !ruby/object:Gem::Dependency
170
170
  name: guard-rspec
171
- requirement: &6287740 !ruby/object:Gem::Requirement
171
+ requirement: &13167000 !ruby/object:Gem::Requirement
172
172
  none: false
173
173
  requirements:
174
174
  - - ~>
@@ -176,10 +176,10 @@ dependencies:
176
176
  version: 4.5.0
177
177
  type: :development
178
178
  prerelease: false
179
- version_requirements: *6287740
179
+ version_requirements: *13167000
180
180
  - !ruby/object:Gem::Dependency
181
181
  name: rake
182
- requirement: &6286640 !ruby/object:Gem::Requirement
182
+ requirement: &13166280 !ruby/object:Gem::Requirement
183
183
  none: false
184
184
  requirements:
185
185
  - - ~>
@@ -187,10 +187,10 @@ dependencies:
187
187
  version: 10.4.2
188
188
  type: :development
189
189
  prerelease: false
190
- version_requirements: *6286640
190
+ version_requirements: *13166280
191
191
  - !ruby/object:Gem::Dependency
192
192
  name: redcarpet
193
- requirement: &6285780 !ruby/object:Gem::Requirement
193
+ requirement: &13181680 !ruby/object:Gem::Requirement
194
194
  none: false
195
195
  requirements:
196
196
  - - ~>
@@ -198,10 +198,10 @@ dependencies:
198
198
  version: 3.2.2
199
199
  type: :development
200
200
  prerelease: false
201
- version_requirements: *6285780
201
+ version_requirements: *13181680
202
202
  - !ruby/object:Gem::Dependency
203
203
  name: rspec
204
- requirement: &6284440 !ruby/object:Gem::Requirement
204
+ requirement: &13180660 !ruby/object:Gem::Requirement
205
205
  none: false
206
206
  requirements:
207
207
  - - ~>
@@ -209,10 +209,10 @@ dependencies:
209
209
  version: 3.2.0
210
210
  type: :development
211
211
  prerelease: false
212
- version_requirements: *6284440
212
+ version_requirements: *13180660
213
213
  - !ruby/object:Gem::Dependency
214
214
  name: timecop
215
- requirement: &6282200 !ruby/object:Gem::Requirement
215
+ requirement: &13180020 !ruby/object:Gem::Requirement
216
216
  none: false
217
217
  requirements:
218
218
  - - ~>
@@ -220,10 +220,10 @@ dependencies:
220
220
  version: 0.7.0
221
221
  type: :development
222
222
  prerelease: false
223
- version_requirements: *6282200
223
+ version_requirements: *13180020
224
224
  - !ruby/object:Gem::Dependency
225
225
  name: yard
226
- requirement: &6274480 !ruby/object:Gem::Requirement
226
+ requirement: &13179340 !ruby/object:Gem::Requirement
227
227
  none: false
228
228
  requirements:
229
229
  - - ~>
@@ -231,10 +231,10 @@ dependencies:
231
231
  version: 0.8.4
232
232
  type: :development
233
233
  prerelease: false
234
- version_requirements: *6274480
234
+ version_requirements: *13179340
235
235
  - !ruby/object:Gem::Dependency
236
236
  name: rb-inotify
237
- requirement: &6270600 !ruby/object:Gem::Requirement
237
+ requirement: &13178640 !ruby/object:Gem::Requirement
238
238
  none: false
239
239
  requirements:
240
240
  - - ~>
@@ -242,10 +242,10 @@ dependencies:
242
242
  version: 0.9.0
243
243
  type: :development
244
244
  prerelease: false
245
- version_requirements: *6270600
245
+ version_requirements: *13178640
246
246
  - !ruby/object:Gem::Dependency
247
247
  name: rb-fsevent
248
- requirement: &6267620 !ruby/object:Gem::Requirement
248
+ requirement: &13178180 !ruby/object:Gem::Requirement
249
249
  none: false
250
250
  requirements:
251
251
  - - ~>
@@ -253,7 +253,7 @@ dependencies:
253
253
  version: 0.9.2
254
254
  type: :development
255
255
  prerelease: false
256
- version_requirements: *6267620
256
+ version_requirements: *13178180
257
257
  description: Be lazy. Let Maid clean up after you, based on rules you define. Think
258
258
  of it as "Hazel for hackers".
259
259
  email:
@@ -281,6 +281,7 @@ files:
281
281
  - bin/maid
282
282
  - lib/maid.rb
283
283
  - lib/maid/app.rb
284
+ - lib/maid/downloading.rb
284
285
  - lib/maid/maid.rb
285
286
  - lib/maid/numeric_extensions.rb
286
287
  - lib/maid/platform.rb
@@ -311,7 +312,7 @@ files:
311
312
  - spec/fixtures/files/ruby.jpg
312
313
  - spec/fixtures/files/sydney.jpg
313
314
  - spec/fixtures/files/unknown.foo
314
- - ! "spec/fixtures/files/ã\x81\x95.zip"
315
+ - spec/fixtures/files/さ.zip
315
316
  - spec/lib/maid/app_spec.rb
316
317
  - spec/lib/maid/maid_spec.rb
317
318
  - spec/lib/maid/numeric_extensions_spec.rb