wikirofs 0.1.3 → 0.1.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/mount.wikiro +1 -175
- data/lib/wikirofs/version.rb +1 -1
- data/main.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4dc59851ec749f7910f93275d678dfa68b4ce09d
|
4
|
+
data.tar.gz: 3c3142a2356ce47cdb396a5d91abd4fe6c2b4e1f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f98964dbf6e2b473464a7c4da65a050801317c0293cdbd907aa601e6dcb1d26d9c2a82da73ad50937d3c76a0727f2caac5dfd49fa2677bc33c6bd23a78955639
|
7
|
+
data.tar.gz: 6d68fb14a47c24c5d5ebf54bb231c288854463ad6243c5efc38af71fbef9b36d91fab1928ee123db5c94df813286856ab5deb1f49caf48634ba2ffb4a7d7f1d6
|
data/bin/mount.wikiro
CHANGED
@@ -1,176 +1,2 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
-
|
3
|
-
require_relative '../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 }
|
2
|
+
require_relative '../main.rb'
|
data/lib/wikirofs/version.rb
CHANGED
data/main.rb
CHANGED