kindlefs 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -3,16 +3,16 @@ require 'rindle/mixins/regexp'
3
3
 
4
4
  module KindleFS
5
5
  class Filesystem < FuseFS::FuseDir
6
- ROOT_PATH = /^\/$/
7
- COLLECTIONS_PATH = /^\/collections$/.freeze
8
- DOCUMENTS_PATH = /^\/documents$/.freeze
9
- PICTURES_PATH = /^\/pictures$/.freeze
10
- COLLECTION_NAME = /([A-Za-z0-9_\-\s'"\.]+)/i.freeze
11
- COLLECTION_PATH = /^#{COLLECTIONS_PATH.strip}\/#{COLLECTION_NAME.strip}$/.freeze
12
- DOCUMENT_NAME = /([A-Za-z0-9_\s\-]+\.(mobi|epub|rtf|pdf|azw|azw1)+)/i.freeze
6
+ ROOT_PATH = /^\/$/
7
+ COLLECTIONS_PATH = /^\/collections$/.freeze
8
+ DOCUMENTS_PATH = /^\/documents$/.freeze
9
+ PICTURES_PATH = /^\/pictures$/.freeze
10
+ COLLECTION_NAME = /([A-Za-z0-9_\-\s'"\.]+)/i.freeze
11
+ COLLECTION_PATH = /^#{COLLECTIONS_PATH.strip}\/#{COLLECTION_NAME.strip}$/.freeze
12
+ DOCUMENT_NAME = /([A-Za-z0-9_\s,\.\[\]\(\)'&!\-]+\.(mobi|epub|rtf|pdf|azw|azw1)+)/i.freeze
13
13
  COLLECTION_DOCUMENT_PATH = /^#{COLLECTIONS_PATH.strip}\/#{COLLECTION_NAME.strip}\/#{DOCUMENT_NAME.strip}$/.freeze
14
14
  UNASSOCIATED_DOCUMENT_PATH = /^#{COLLECTIONS_PATH.strip}\/#{DOCUMENT_NAME.strip}$/.freeze
15
- DOCUMENT_PATH = /^#{DOCUMENTS_PATH.strip}\/#{DOCUMENT_NAME.strip}$/.freeze
15
+ DOCUMENT_PATH = /^#{DOCUMENTS_PATH.strip}\/#{DOCUMENT_NAME.strip}$/.freeze
16
16
 
17
17
  def contents path
18
18
  case path
@@ -28,12 +28,16 @@ module KindleFS
28
28
  else
29
29
  []
30
30
  end
31
+ rescue Exception => e
32
+ puts e
33
+ false
31
34
  end
32
35
 
33
36
  def file?(path)
34
37
  case path
35
38
  when DOCUMENT_PATH
36
- return true
39
+ doc = Rindle::Document.find_by_name $1
40
+ return !doc.nil?
37
41
  when COLLECTION_DOCUMENT_PATH
38
42
  col = Rindle::Collection.find_by_name $1
39
43
  doc = Rindle::Document.find_by_name $2
@@ -43,6 +47,9 @@ module KindleFS
43
47
  return doc.collections.empty? if doc
44
48
  end
45
49
  false
50
+ rescue Exception => e
51
+ puts e
52
+ false
46
53
  end
47
54
 
48
55
  def directory?(path)
@@ -50,10 +57,14 @@ module KindleFS
50
57
  when COLLECTIONS_PATH, DOCUMENTS_PATH, PICTURES_PATH
51
58
  true
52
59
  when COLLECTION_PATH
53
- Rindle::Collection.exists?(:named => $1)
60
+ col = Rindle::Collection.find_by_name $1
61
+ !col.nil?
54
62
  else
55
63
  false
56
64
  end
65
+ rescue Exception => e
66
+ puts e
67
+ false
57
68
  end
58
69
 
59
70
  def executable? path
@@ -61,20 +72,29 @@ module KindleFS
61
72
  end
62
73
 
63
74
  def size path
75
+ puts "size #{path}"
64
76
  doc = Rindle::Document.find_by_name File.basename(path)
65
77
  File.size File.join(Rindle.root_path, doc.path)
78
+ rescue Exception => e
79
+ puts e
80
+ false
66
81
  end
67
82
 
68
83
  def can_delete?(path)
84
+ puts "can_delete? #{path}"
69
85
  case path
70
86
  when DOCUMENTS_PATH, PICTURES_PATH, COLLECTIONS_PATH
71
87
  false
72
88
  else
73
89
  true
74
90
  end
91
+ rescue Exception => e
92
+ puts e
93
+ false
75
94
  end
76
95
 
77
96
  def can_write?(path)
97
+ puts "can_write? #{path}"
78
98
  if path !~ ROOT_PATH
79
99
  true
80
100
  else
@@ -83,6 +103,7 @@ module KindleFS
83
103
  end
84
104
 
85
105
  def can_mkdir?(path)
106
+ puts "can_mkdir? #{path}"
86
107
  case path
87
108
  when COLLECTION_PATH
88
109
  true
@@ -92,15 +113,20 @@ module KindleFS
92
113
  end
93
114
 
94
115
  def can_rmdir?(path)
116
+ puts "can_rmdir #{path}"
95
117
  case path
96
118
  when COLLECTION_PATH
97
119
  true
98
120
  else
99
121
  false
100
122
  end
123
+ rescue Exception => e
124
+ puts e
125
+ false
101
126
  end
102
127
 
103
128
  def touch(path, val = 0)
129
+ puts "touch #{path}"
104
130
  filename = File.basename(path)
105
131
  case path
106
132
  when UNASSOCIATED_DOCUMENT_PATH, DOCUMENT_PATH
@@ -112,9 +138,13 @@ module KindleFS
112
138
  else
113
139
  false
114
140
  end
141
+ rescue Exception => e
142
+ puts e
143
+ false
115
144
  end
116
145
 
117
146
  def mkdir(path)
147
+ puts "mkdir #{path}"
118
148
  if path =~ COLLECTION_PATH
119
149
  col = Rindle::Collection.find_by_name $1
120
150
  Rindle::Collection.create($1) if col.nil?
@@ -123,9 +153,13 @@ module KindleFS
123
153
  else
124
154
  false
125
155
  end
156
+ rescue Exception => e
157
+ puts e
158
+ false
126
159
  end
127
160
 
128
161
  def rmdir(path)
162
+ puts "rmdir #{path}"
129
163
  if path =~ COLLECTION_PATH
130
164
  collection = Rindle::Collection.first :named => $1
131
165
  return false unless collection
@@ -135,9 +169,13 @@ module KindleFS
135
169
  end
136
170
  Rindle.save
137
171
  true
172
+ rescue Exception => e
173
+ puts e
174
+ false
138
175
  end
139
176
 
140
177
  def delete path
178
+ puts "delete #{path}"
141
179
  case path
142
180
  when COLLECTION_DOCUMENT_PATH
143
181
  col = Rindle::Collection.find_by_name $1
@@ -149,6 +187,9 @@ module KindleFS
149
187
  end
150
188
  Rindle.save
151
189
  true
190
+ rescue Exception => e
191
+ puts e
192
+ false
152
193
  end
153
194
 
154
195
  def rename old, new
@@ -189,6 +230,9 @@ module KindleFS
189
230
  end
190
231
  Rindle.save
191
232
  true
233
+ rescue Exception => e
234
+ puts e
235
+ false
192
236
  end
193
237
 
194
238
  def write_to path, body
@@ -209,11 +253,17 @@ module KindleFS
209
253
  end
210
254
  Rindle.save
211
255
  true
256
+ rescue Exception => e
257
+ puts e
258
+ false
212
259
  end
213
260
 
214
261
  def read_file path
215
262
  doc = Rindle::Document.find_by_name File.basename(path)
216
- File.read File.join(Rindle.root_path, doc.path)
263
+ doc.filename
264
+ rescue Exception => e
265
+ puts "read file error: #{e}"
266
+ ''
217
267
  end
218
268
  end
219
269
  end
@@ -1,3 +1,3 @@
1
1
  module KindleFS
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
@@ -23,6 +23,12 @@ describe KindleFS::Filesystem do
23
23
  '/documents'.should_not match(KindleFS::Filesystem::COLLECTIONS_PATH)
24
24
  '/collections/dummy'.should_not match(KindleFS::Filesystem::COLLECTIONS_PATH)
25
25
  end
26
+
27
+ it 'should match a collections document path correctly' do
28
+ '/collections/collection1/The 4 Hour Workweek Escape 9 5 L-asin_B000PDZF70-type_EBOK-v_0.azw'.
29
+ should match KindleFS::Filesystem::COLLECTION_DOCUMENT_PATH
30
+ end
31
+
26
32
  end
27
33
 
28
34
  describe '#contents' do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kindlefs
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -13,7 +13,7 @@ date: 2012-05-20 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: guard-rspec
16
- requirement: &11542360 !ruby/object:Gem::Requirement
16
+ requirement: &19332940 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '0'
22
22
  type: :development
23
23
  prerelease: false
24
- version_requirements: *11542360
24
+ version_requirements: *19332940
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: rake
27
- requirement: &11445000 !ruby/object:Gem::Requirement
27
+ requirement: &19332380 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '0'
33
33
  type: :development
34
34
  prerelease: false
35
- version_requirements: *11445000
35
+ version_requirements: *19332380
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: rspec
38
- requirement: &11058220 !ruby/object:Gem::Requirement
38
+ requirement: &19331680 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: '0'
44
44
  type: :development
45
45
  prerelease: false
46
- version_requirements: *11058220
46
+ version_requirements: *19331680
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: rfusefs
49
- requirement: &9408900 !ruby/object:Gem::Requirement
49
+ requirement: &19330980 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ! '>='
@@ -54,10 +54,10 @@ dependencies:
54
54
  version: '0'
55
55
  type: :runtime
56
56
  prerelease: false
57
- version_requirements: *9408900
57
+ version_requirements: *19330980
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: rindle
60
- requirement: &8717100 !ruby/object:Gem::Requirement
60
+ requirement: &19330220 !ruby/object:Gem::Requirement
61
61
  none: false
62
62
  requirements:
63
63
  - - ! '>='
@@ -65,7 +65,7 @@ dependencies:
65
65
  version: '0'
66
66
  type: :runtime
67
67
  prerelease: false
68
- version_requirements: *8717100
68
+ version_requirements: *19330220
69
69
  description: KindleFS mounts the collection information of a Kindle device as file
70
70
  system in user space via the Rindle gem.
71
71
  email:
@@ -111,18 +111,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
111
111
  - - ! '>='
112
112
  - !ruby/object:Gem::Version
113
113
  version: '0'
114
- segments:
115
- - 0
116
- hash: -3452657948332476179
117
114
  required_rubygems_version: !ruby/object:Gem::Requirement
118
115
  none: false
119
116
  requirements:
120
117
  - - ! '>='
121
118
  - !ruby/object:Gem::Version
122
119
  version: '0'
123
- segments:
124
- - 0
125
- hash: -3452657948332476179
126
120
  requirements: []
127
121
  rubyforge_project:
128
122
  rubygems_version: 1.8.17