wikirofs 0.1.0 → 0.1.1
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 +4 -4
- data/bin/mount.wikiro +176 -0
- data/lib/wikirofs/version.rb +1 -1
- metadata +1 -1
- data/bin/mount.wikiro +0 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f31bdc955a442f2945582a0b42fd19e6e31da974
|
4
|
+
data.tar.gz: 8ae39f979a56777ca7635fb31d40dd5dfc543b6d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5ccf66880e03854a5241418da5d827f5e7818b83f7a85d72ebb581fa1c384bf02719c7d5edb7a979654d3519d78cbbc4c4ee4b92df00838b0c2c38b3a26115e2
|
7
|
+
data.tar.gz: d6f7f4c1792ae7f9ab561714cf0c0e353f2580c12fb60a16b9d469b693e056fe2ad956e1925f240487269854f85d3a664ca1014b8a0ff0e61b36ace50072e060
|
data/bin/mount.wikiro
ADDED
@@ -0,0 +1,176 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
require 'rfusefs'
|
3
|
+
require './wikipedia.rb'
|
4
|
+
|
5
|
+
class WikiNgFS
|
6
|
+
class WikiFileHandle
|
7
|
+
attr_accessor :contents, :title, :language
|
8
|
+
|
9
|
+
def initialize(title, language)
|
10
|
+
@title = title
|
11
|
+
@language = language
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def touch(path, modtime = nil)
|
16
|
+
# puts "touch #{path}"
|
17
|
+
modtime = Time.now.to_i if ! modtime
|
18
|
+
language, title = parse_path(path)
|
19
|
+
raise Errno::EPERM if ! language if ! title
|
20
|
+
articles = WikiReader.articles(language)
|
21
|
+
articles << title if articles && ! articles.include?(title)
|
22
|
+
end
|
23
|
+
|
24
|
+
def can_delete?(path)
|
25
|
+
# puts "can_delete? #{path}"
|
26
|
+
language, title = parse_path(path)
|
27
|
+
articles = WikiReader.articles(language)
|
28
|
+
title && articles && articles.include?(title)
|
29
|
+
end
|
30
|
+
|
31
|
+
def delete(path)
|
32
|
+
# puts "delete #{path}"
|
33
|
+
language, title = parse_path(path)
|
34
|
+
WikiReader.articles(language).delete(title)
|
35
|
+
end
|
36
|
+
|
37
|
+
def can_mkdir?(path)
|
38
|
+
# puts "can_mkdir? #{path}"
|
39
|
+
language, title = parse_path(path)
|
40
|
+
language && ! title
|
41
|
+
end
|
42
|
+
|
43
|
+
def mkdir(path)
|
44
|
+
# puts "mkdir #{path}"
|
45
|
+
language, title = parse_path(path)
|
46
|
+
WikiReader.db[language] = nil
|
47
|
+
end
|
48
|
+
|
49
|
+
def can_rmdir?(path)
|
50
|
+
# puts "can_mkdir? #{path}"
|
51
|
+
language, title = parse_path(path)
|
52
|
+
language && ! title
|
53
|
+
end
|
54
|
+
|
55
|
+
def rmdir(path)
|
56
|
+
# puts "rmdir #{path}"
|
57
|
+
language, title = parse_path(path)
|
58
|
+
WikiReader.db.delete(language)
|
59
|
+
end
|
60
|
+
|
61
|
+
|
62
|
+
def contents(path)
|
63
|
+
# puts "contents #{path}"
|
64
|
+
if path == '/'
|
65
|
+
# adds 'wikipedia-' at beginning
|
66
|
+
lst = WikiReader.languages.dup
|
67
|
+
lst.each_with_index {|v, i| lst[i] = "wikipedia-#{v}"}
|
68
|
+
return lst
|
69
|
+
|
70
|
+
else
|
71
|
+
language, title = parse_path(path)
|
72
|
+
return nil if ! language && ! title # invalid language and title
|
73
|
+
|
74
|
+
if language && ! title # eg: "ls /wikipedia-en"
|
75
|
+
lst = WikiReader.articles(language).dup.sort
|
76
|
+
lst.each_with_index {|v, i| lst[i] = "#{v}.txt"}
|
77
|
+
lst.each {|v| v.gsub!(/^.*(\\|\/)/, '')} # "/" -> "\/"
|
78
|
+
return lst
|
79
|
+
end
|
80
|
+
return [title]
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
def file?(path)
|
85
|
+
# puts "file? #{path}"
|
86
|
+
language, title = parse_path(path)
|
87
|
+
!!(language && title)
|
88
|
+
end
|
89
|
+
|
90
|
+
def directory?(path)
|
91
|
+
# puts "directory? #{path}"
|
92
|
+
language, title = parse_path(path)
|
93
|
+
language = nil if language && ! WikiReader.languages.include?(language)
|
94
|
+
!!(language && !title)
|
95
|
+
end
|
96
|
+
|
97
|
+
def can_write?(path)
|
98
|
+
# puts "can_write? #{path}"
|
99
|
+
false
|
100
|
+
end
|
101
|
+
|
102
|
+
def rename(from_path, to_path)
|
103
|
+
# puts "rename #{path}"
|
104
|
+
delete(from_path)
|
105
|
+
touch(to_path)
|
106
|
+
end
|
107
|
+
|
108
|
+
def size(path)
|
109
|
+
# puts "size #{path}"
|
110
|
+
language, title = parse_path(path)
|
111
|
+
WikiReader.size(title, language)
|
112
|
+
end
|
113
|
+
|
114
|
+
# def read_file(path)
|
115
|
+
# language, title = parse_path(path)
|
116
|
+
# raise Errno::ENOENT if ! language || ! title
|
117
|
+
# end
|
118
|
+
|
119
|
+
def raw_open(path, mode, rfusefs = nil)
|
120
|
+
# puts "raw_open #{path}"
|
121
|
+
language, title = parse_path(path)
|
122
|
+
raise Errno::ENOENT if ! language || ! title
|
123
|
+
WikiFileHandle.new(title, language)
|
124
|
+
end
|
125
|
+
|
126
|
+
def raw_read(path, offset, size, handler = nil)
|
127
|
+
# puts "raw_read #{path}"
|
128
|
+
raise Errno::EBADF if ! handler
|
129
|
+
handler.contents ||= WikiReader.article(handler.title, handler.language)
|
130
|
+
handler.contents.b[offset, size]
|
131
|
+
end
|
132
|
+
|
133
|
+
def raw_close(path, handler = nil)
|
134
|
+
# puts "raw_close #{path}"
|
135
|
+
raise Errno::EBADF if ! handler
|
136
|
+
handler.contents = nil
|
137
|
+
end
|
138
|
+
|
139
|
+
private
|
140
|
+
|
141
|
+
def parse_path(path)
|
142
|
+
#######################
|
143
|
+
# PATH FORMAT:
|
144
|
+
# /wikipedia-<language>/<title>.txt
|
145
|
+
#######################
|
146
|
+
|
147
|
+
# break items: '/wikipedia-en/Titanic.txt' -> ['', 'wikipedia-en', 'Titanic'] -> ['wikipedia-en', 'Titanic']
|
148
|
+
items = path.split(File::SEPARATOR)
|
149
|
+
items.shift if items.first == ''
|
150
|
+
return nil if items.empty? || (items.count > 2)
|
151
|
+
|
152
|
+
# language: 'wikipedia-en' -> 'en'
|
153
|
+
pos = items[0].index('wikipedia-')
|
154
|
+
return nil if ! pos || (items[0] == 'wikipedia-')
|
155
|
+
language = items[0][pos+10..-1]
|
156
|
+
|
157
|
+
# title
|
158
|
+
title = nil
|
159
|
+
if items[1]
|
160
|
+
pos = items[1].index('.txt')
|
161
|
+
language = nil if ! pos # invalid file extension
|
162
|
+
title = items[1][0, pos] if pos
|
163
|
+
end
|
164
|
+
|
165
|
+
# result
|
166
|
+
[language, title]
|
167
|
+
end
|
168
|
+
end
|
169
|
+
|
170
|
+
# @opts = *ARGV[1..-1]
|
171
|
+
# FuseFS.mount(WikiNgFS.new, ARGV[0], @opts)
|
172
|
+
# FuseFS.mount(WikiNgFS.new, ARGV[0])
|
173
|
+
|
174
|
+
# wikifs = WikiNgFS.new
|
175
|
+
# FuseFS.start(wikifs, '/mnt/test')
|
176
|
+
FuseFS.main() { |options| WikiNgFS.new }
|
data/lib/wikirofs/version.rb
CHANGED
metadata
CHANGED
data/bin/mount.wikiro
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
../main.rb
|