wikirofs 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/Gemfile +4 -0
- data/LICENSE +116 -0
- data/README.md +79 -0
- data/Rakefile +2 -0
- data/bin/console +14 -0
- data/bin/mount.wikiro +1 -0
- data/bin/setup +8 -0
- data/lib/wikipedia.rb +123 -0
- data/lib/wikirofs/version.rb +3 -0
- data/lib/wikirofs.rb +5 -0
- data/main.rb +176 -0
- data/wikirofs.gemspec +30 -0
- metadata +128 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: cba44ca62b8cb045b951ccd57c9e899ac8a5f95c
|
4
|
+
data.tar.gz: 15eedefef3efbd3d8a5c7047a522bd7912270bfd
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 9ddb38ae2d2f4edf988abb0e746440a071ea67928d058360019833e698e50eba9bb9a6d91a72972fb90a741bd1030f25ae9c999fe9f48def7287b42f00c938f9
|
7
|
+
data.tar.gz: 2dbd8461445fa3e851fca87a4eb85c84626fa3cd32304c2b4aea8d03fcb98c25310ee42bc9731db470408193db5c8a173f01c0cce76366cdbaa7d3b51b57c5c3
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,116 @@
|
|
1
|
+
CC0 1.0 Universal
|
2
|
+
|
3
|
+
Statement of Purpose
|
4
|
+
|
5
|
+
The laws of most jurisdictions throughout the world automatically confer
|
6
|
+
exclusive Copyright and Related Rights (defined below) upon the creator and
|
7
|
+
subsequent owner(s) (each and all, an "owner") of an original work of
|
8
|
+
authorship and/or a database (each, a "Work").
|
9
|
+
|
10
|
+
Certain owners wish to permanently relinquish those rights to a Work for the
|
11
|
+
purpose of contributing to a commons of creative, cultural and scientific
|
12
|
+
works ("Commons") that the public can reliably and without fear of later
|
13
|
+
claims of infringement build upon, modify, incorporate in other works, reuse
|
14
|
+
and redistribute as freely as possible in any form whatsoever and for any
|
15
|
+
purposes, including without limitation commercial purposes. These owners may
|
16
|
+
contribute to the Commons to promote the ideal of a free culture and the
|
17
|
+
further production of creative, cultural and scientific works, or to gain
|
18
|
+
reputation or greater distribution for their Work in part through the use and
|
19
|
+
efforts of others.
|
20
|
+
|
21
|
+
For these and/or other purposes and motivations, and without any expectation
|
22
|
+
of additional consideration or compensation, the person associating CC0 with a
|
23
|
+
Work (the "Affirmer"), to the extent that he or she is an owner of Copyright
|
24
|
+
and Related Rights in the Work, voluntarily elects to apply CC0 to the Work
|
25
|
+
and publicly distribute the Work under its terms, with knowledge of his or her
|
26
|
+
Copyright and Related Rights in the Work and the meaning and intended legal
|
27
|
+
effect of CC0 on those rights.
|
28
|
+
|
29
|
+
1. Copyright and Related Rights. A Work made available under CC0 may be
|
30
|
+
protected by copyright and related or neighboring rights ("Copyright and
|
31
|
+
Related Rights"). Copyright and Related Rights include, but are not limited
|
32
|
+
to, the following:
|
33
|
+
|
34
|
+
i. the right to reproduce, adapt, distribute, perform, display, communicate,
|
35
|
+
and translate a Work;
|
36
|
+
|
37
|
+
ii. moral rights retained by the original author(s) and/or performer(s);
|
38
|
+
|
39
|
+
iii. publicity and privacy rights pertaining to a person's image or likeness
|
40
|
+
depicted in a Work;
|
41
|
+
|
42
|
+
iv. rights protecting against unfair competition in regards to a Work,
|
43
|
+
subject to the limitations in paragraph 4(a), below;
|
44
|
+
|
45
|
+
v. rights protecting the extraction, dissemination, use and reuse of data in
|
46
|
+
a Work;
|
47
|
+
|
48
|
+
vi. database rights (such as those arising under Directive 96/9/EC of the
|
49
|
+
European Parliament and of the Council of 11 March 1996 on the legal
|
50
|
+
protection of databases, and under any national implementation thereof,
|
51
|
+
including any amended or successor version of such directive); and
|
52
|
+
|
53
|
+
vii. other similar, equivalent or corresponding rights throughout the world
|
54
|
+
based on applicable law or treaty, and any national implementations thereof.
|
55
|
+
|
56
|
+
2. Waiver. To the greatest extent permitted by, but not in contravention of,
|
57
|
+
applicable law, Affirmer hereby overtly, fully, permanently, irrevocably and
|
58
|
+
unconditionally waives, abandons, and surrenders all of Affirmer's Copyright
|
59
|
+
and Related Rights and associated claims and causes of action, whether now
|
60
|
+
known or unknown (including existing as well as future claims and causes of
|
61
|
+
action), in the Work (i) in all territories worldwide, (ii) for the maximum
|
62
|
+
duration provided by applicable law or treaty (including future time
|
63
|
+
extensions), (iii) in any current or future medium and for any number of
|
64
|
+
copies, and (iv) for any purpose whatsoever, including without limitation
|
65
|
+
commercial, advertising or promotional purposes (the "Waiver"). Affirmer makes
|
66
|
+
the Waiver for the benefit of each member of the public at large and to the
|
67
|
+
detriment of Affirmer's heirs and successors, fully intending that such Waiver
|
68
|
+
shall not be subject to revocation, rescission, cancellation, termination, or
|
69
|
+
any other legal or equitable action to disrupt the quiet enjoyment of the Work
|
70
|
+
by the public as contemplated by Affirmer's express Statement of Purpose.
|
71
|
+
|
72
|
+
3. Public License Fallback. Should any part of the Waiver for any reason be
|
73
|
+
judged legally invalid or ineffective under applicable law, then the Waiver
|
74
|
+
shall be preserved to the maximum extent permitted taking into account
|
75
|
+
Affirmer's express Statement of Purpose. In addition, to the extent the Waiver
|
76
|
+
is so judged Affirmer hereby grants to each affected person a royalty-free,
|
77
|
+
non transferable, non sublicensable, non exclusive, irrevocable and
|
78
|
+
unconditional license to exercise Affirmer's Copyright and Related Rights in
|
79
|
+
the Work (i) in all territories worldwide, (ii) for the maximum duration
|
80
|
+
provided by applicable law or treaty (including future time extensions), (iii)
|
81
|
+
in any current or future medium and for any number of copies, and (iv) for any
|
82
|
+
purpose whatsoever, including without limitation commercial, advertising or
|
83
|
+
promotional purposes (the "License"). The License shall be deemed effective as
|
84
|
+
of the date CC0 was applied by Affirmer to the Work. Should any part of the
|
85
|
+
License for any reason be judged legally invalid or ineffective under
|
86
|
+
applicable law, such partial invalidity or ineffectiveness shall not
|
87
|
+
invalidate the remainder of the License, and in such case Affirmer hereby
|
88
|
+
affirms that he or she will not (i) exercise any of his or her remaining
|
89
|
+
Copyright and Related Rights in the Work or (ii) assert any associated claims
|
90
|
+
and causes of action with respect to the Work, in either case contrary to
|
91
|
+
Affirmer's express Statement of Purpose.
|
92
|
+
|
93
|
+
4. Limitations and Disclaimers.
|
94
|
+
|
95
|
+
a. No trademark or patent rights held by Affirmer are waived, abandoned,
|
96
|
+
surrendered, licensed or otherwise affected by this document.
|
97
|
+
|
98
|
+
b. Affirmer offers the Work as-is and makes no representations or warranties
|
99
|
+
of any kind concerning the Work, express, implied, statutory or otherwise,
|
100
|
+
including without limitation warranties of title, merchantability, fitness
|
101
|
+
for a particular purpose, non infringement, or the absence of latent or
|
102
|
+
other defects, accuracy, or the present or absence of errors, whether or not
|
103
|
+
discoverable, all to the greatest extent permissible under applicable law.
|
104
|
+
|
105
|
+
c. Affirmer disclaims responsibility for clearing rights of other persons
|
106
|
+
that may apply to the Work or any use thereof, including without limitation
|
107
|
+
any person's Copyright and Related Rights in the Work. Further, Affirmer
|
108
|
+
disclaims responsibility for obtaining any necessary consents, permissions
|
109
|
+
or other rights required for any use of the Work.
|
110
|
+
|
111
|
+
d. Affirmer understands and acknowledges that Creative Commons is not a
|
112
|
+
party to this document and has no duty or obligation with respect to this
|
113
|
+
CC0 or use of the Work.
|
114
|
+
|
115
|
+
For more information, please see
|
116
|
+
<http://creativecommons.org/publicdomain/zero/1.0/>
|
data/README.md
ADDED
@@ -0,0 +1,79 @@
|
|
1
|
+
# WikiroFS
|
2
|
+
|
3
|
+
Wikiro is a virtual filesystem designed to mount Wikipedia in your filesystem.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
```bash
|
8
|
+
> sudo su
|
9
|
+
> gem install wikirofs
|
10
|
+
```
|
11
|
+
|
12
|
+
## Usage
|
13
|
+
```bash
|
14
|
+
# mount (eg. in /mnt/test)
|
15
|
+
> mount.wikiro /mnt/test
|
16
|
+
|
17
|
+
# default wikis
|
18
|
+
> ls /mnt/test
|
19
|
+
wikipedia-ceb
|
20
|
+
wikipedia-de
|
21
|
+
wikipedia-en
|
22
|
+
wikipedia-es
|
23
|
+
...
|
24
|
+
|
25
|
+
# main articles
|
26
|
+
> ls /mnt/test/wikipedia-en
|
27
|
+
Abacus.txt
|
28
|
+
Abiogenesis.txt
|
29
|
+
Abolitionism.txt
|
30
|
+
Abortion.txt
|
31
|
+
...
|
32
|
+
|
33
|
+
# not listed wikis
|
34
|
+
> mkdir /mnt/test/wikipedia-simple
|
35
|
+
> ls /mnt/test/wikipedia-simple
|
36
|
+
Abraham_Lincoln.txt
|
37
|
+
Acceleration.txt
|
38
|
+
Acid.txt
|
39
|
+
Adam_Smith.txt
|
40
|
+
...
|
41
|
+
|
42
|
+
# view article (even if it's not listed)
|
43
|
+
> cat /mnt/test/wikipedia-en/Moon.txt
|
44
|
+
{{about |Earths natural satellite |moons in general |Natural satellite |other uses}}
|
45
|
+
{{pp-semi-protected |small=yes}}
|
46
|
+
{{pp-move-indef}}
|
47
|
+
{{Use dmy dates|date=January 2017}}
|
48
|
+
...
|
49
|
+
|
50
|
+
# remove a wiki from the list (it doesn't affect the real Wikipedia)
|
51
|
+
> rmdir /mnt/test/wikipedia-ceb
|
52
|
+
> ls /mnt/test
|
53
|
+
wikipedia-ceb
|
54
|
+
wikipedia-de
|
55
|
+
wikipedia-en
|
56
|
+
...
|
57
|
+
|
58
|
+
# remove article from the list (it doesn't affect the real Wikipedia)
|
59
|
+
> rm /mnt/test/wikipedia-en/Abacus.txt
|
60
|
+
> ls /mnt/test/wikipedia-en
|
61
|
+
Abiogenesis.txt
|
62
|
+
Abolitionism.txt
|
63
|
+
Abortion.txt
|
64
|
+
...
|
65
|
+
|
66
|
+
# umount
|
67
|
+
> sudo umount /mnt/test
|
68
|
+
```
|
69
|
+
|
70
|
+
<!-- ## Mounting on boot
|
71
|
+
1. edit your /etc/fstab
|
72
|
+
2. add something like this:
|
73
|
+
```
|
74
|
+
/usr/sbin/mount.wikiro /mnt/test fuse user,noauto 0 0
|
75
|
+
```
|
76
|
+
-->
|
77
|
+
## Contributing
|
78
|
+
|
79
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/loureirorg/wikirofs.
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "wikirofs"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start(__FILE__)
|
data/bin/mount.wikiro
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
../main.rb
|
data/bin/setup
ADDED
data/lib/wikipedia.rb
ADDED
@@ -0,0 +1,123 @@
|
|
1
|
+
class WikiReader
|
2
|
+
# Libraries
|
3
|
+
require 'openssl'
|
4
|
+
require 'httpclient'
|
5
|
+
require 'nokogiri'
|
6
|
+
|
7
|
+
# HTTP
|
8
|
+
@@http = HTTPClient.new
|
9
|
+
|
10
|
+
# Our database
|
11
|
+
# Format: @db = {'en' => ['link_a', 'link_b', ...], 'pt' => ['link_c', ...]}
|
12
|
+
# A language with a "nil" value means it wasn't initialized yet and we should
|
13
|
+
# call fetch_vital before use it
|
14
|
+
@@db = nil
|
15
|
+
@@sizes = {}
|
16
|
+
|
17
|
+
# all articles in memory
|
18
|
+
def self.articles(language = 'en')
|
19
|
+
return nil if ! db.key?(language) # invalid language
|
20
|
+
db[language] = fetch_vital(language) if ! db[language] # not initialized
|
21
|
+
|
22
|
+
db[language]
|
23
|
+
end
|
24
|
+
|
25
|
+
def self.languages
|
26
|
+
db.keys
|
27
|
+
end
|
28
|
+
|
29
|
+
def self.article(title, language = 'en')
|
30
|
+
raise Errno::ENOENT if ! db.key?(language) # invalid language
|
31
|
+
db[language] = fetch_vital(language) if ! db[language] # not initialized
|
32
|
+
|
33
|
+
art = fetch_article(title, language) # read from the internet
|
34
|
+
raise Errno::ENOENT if ! art
|
35
|
+
db[language] << title if art && ! db[language].index(title) # adds in our list
|
36
|
+
|
37
|
+
@@sizes[language] ||= {}
|
38
|
+
@@sizes[language][title] = art.bytesize
|
39
|
+
|
40
|
+
art
|
41
|
+
end
|
42
|
+
|
43
|
+
def self.size(title, language = 'en')
|
44
|
+
@@sizes[language] ||= {}
|
45
|
+
@@sizes[language][title] || 1
|
46
|
+
end
|
47
|
+
|
48
|
+
def self.db
|
49
|
+
return @@db if @@db
|
50
|
+
@@db = Hash[fetch_languages.collect { |item| [item, nil] }]
|
51
|
+
end
|
52
|
+
|
53
|
+
private
|
54
|
+
|
55
|
+
def self.fetch_article(title, language = 'en')
|
56
|
+
begin
|
57
|
+
url = "https://#{language}.wikipedia.org/wiki/#{URI::encode(title)}?action=raw"
|
58
|
+
@@http.get_content(url)
|
59
|
+
rescue => e
|
60
|
+
puts e
|
61
|
+
nil
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
def self.fetch_languages
|
66
|
+
# hardcoded list (used as fallback)
|
67
|
+
default = [
|
68
|
+
'en', 'ceb', 'sv', 'de', 'nl', 'fr', 'ru', 'it', 'es', 'war', 'pl', 'vi',
|
69
|
+
'ja', 'pt', 'zh', 'uk', 'ca', 'fa', 'ar', 'no', 'sh', 'fi', 'hu', 'id',
|
70
|
+
'cs', 'ko', 'ro', 'sr', 'tr', 'ms', 'eu', 'eo', 'bg', 'da', 'min', 'kk',
|
71
|
+
'hy', 'sk', 'zh-min-nan', 'he', 'lt', 'hr', 'ce', 'et', 'sl', 'be', 'gl',
|
72
|
+
'nn', 'el', 'uz', 'la', 'simple', 'vo', 'ur', 'hi', 'az', 'th', 'ka'
|
73
|
+
]
|
74
|
+
|
75
|
+
# fetch from the internet
|
76
|
+
lst = nil
|
77
|
+
begin
|
78
|
+
url = 'https://meta.wikimedia.org/wiki/List_of_Wikipedias'
|
79
|
+
doc = Nokogiri::HTML(@@http.get_content(url))
|
80
|
+
lst = doc.at_css('[id="1_000_000.2B_articles"]').xpath('./ancestor::h3')[0].next.next.children.xpath('td[4]').map {|e| e.text}
|
81
|
+
lst += doc.at_css('[id="100_000.2B_articles"]').xpath('./ancestor::h3')[0].next.next.children.xpath('td[4]').map {|e| e.text}
|
82
|
+
rescue
|
83
|
+
end
|
84
|
+
|
85
|
+
# uses default list if theres no results
|
86
|
+
lst = (lst.class == Array) && lst.any? ? lst : default
|
87
|
+
lst[0, 15]
|
88
|
+
end
|
89
|
+
|
90
|
+
def self.fetch_vital(language = 'en')
|
91
|
+
lst = []
|
92
|
+
|
93
|
+
begin
|
94
|
+
url = 'https://en.wikipedia.org/wiki/Wikipedia:Vital_articles'
|
95
|
+
doc = Nokogiri::HTML(@@http.get_content(url))
|
96
|
+
|
97
|
+
# not english, click on "Languages" section (left column)
|
98
|
+
if language != 'en'
|
99
|
+
link = doc.at_css("a.interlanguage-link-target[lang='#{language}']")
|
100
|
+
return [] if ! link
|
101
|
+
url = link.attribute('href')
|
102
|
+
doc = Nokogiri::HTML(@@http.get_content(url))
|
103
|
+
return [] if ! doc
|
104
|
+
end
|
105
|
+
|
106
|
+
# get all links starting with "/wiki/" and with no class (it will get some extra non-vital articles, but it's ok)
|
107
|
+
lst = doc.xpath('//li/a[not (@class)][starts-with(@href, "/wiki/")]').map do |e|
|
108
|
+
href = e.attribute('href').text[6..-1] # remove initial '/wiki/'
|
109
|
+
href = URI::decode(href) # convert non-ascii chars
|
110
|
+
pos = href.index('#')
|
111
|
+
href = href[0, href.index('#')] if pos # remove anchor
|
112
|
+
href
|
113
|
+
end
|
114
|
+
|
115
|
+
lst.uniq!
|
116
|
+
|
117
|
+
rescue
|
118
|
+
end # rescue
|
119
|
+
|
120
|
+
lst
|
121
|
+
end
|
122
|
+
|
123
|
+
end
|
data/lib/wikirofs.rb
ADDED
data/main.rb
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/wikirofs.gemspec
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'wikirofs/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "wikirofs"
|
8
|
+
spec.version = Wikirofs::VERSION
|
9
|
+
spec.authors = ["Daniel Loureiro"]
|
10
|
+
spec.email = ["loureirorg@gmail.com"]
|
11
|
+
spec.licenses = ['CC0-1.0']
|
12
|
+
|
13
|
+
spec.summary = %q{Wikipedia Virtual FileSystem (read-only)}
|
14
|
+
spec.description = %q{A virtual filesystem to mount wikipedia.}
|
15
|
+
spec.homepage = "http://www.learnwithdaniel.com"
|
16
|
+
|
17
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
18
|
+
f.match(%r{^(test|spec|features)/})
|
19
|
+
end
|
20
|
+
spec.bindir = "bin"
|
21
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
22
|
+
spec.require_paths = ["lib"]
|
23
|
+
spec.executables << 'mount.wikiro'
|
24
|
+
|
25
|
+
spec.add_development_dependency "bundler", "~> 1.14"
|
26
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
27
|
+
spec.add_runtime_dependency "nokogiri", "~> 1.7"
|
28
|
+
spec.add_runtime_dependency "rfusefs", "~> 1.0"
|
29
|
+
spec.add_runtime_dependency "httpclient", "~> 2.8"
|
30
|
+
end
|
metadata
ADDED
@@ -0,0 +1,128 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: wikirofs
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Daniel Loureiro
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-04-05 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.14'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.14'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: nokogiri
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '1.7'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.7'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rfusefs
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '1.0'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '1.0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: httpclient
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '2.8'
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '2.8'
|
83
|
+
description: A virtual filesystem to mount wikipedia.
|
84
|
+
email:
|
85
|
+
- loureirorg@gmail.com
|
86
|
+
executables:
|
87
|
+
- mount.wikiro
|
88
|
+
extensions: []
|
89
|
+
extra_rdoc_files: []
|
90
|
+
files:
|
91
|
+
- ".gitignore"
|
92
|
+
- Gemfile
|
93
|
+
- LICENSE
|
94
|
+
- README.md
|
95
|
+
- Rakefile
|
96
|
+
- bin/console
|
97
|
+
- bin/mount.wikiro
|
98
|
+
- bin/setup
|
99
|
+
- lib/wikipedia.rb
|
100
|
+
- lib/wikirofs.rb
|
101
|
+
- lib/wikirofs/version.rb
|
102
|
+
- main.rb
|
103
|
+
- wikirofs.gemspec
|
104
|
+
homepage: http://www.learnwithdaniel.com
|
105
|
+
licenses:
|
106
|
+
- CC0-1.0
|
107
|
+
metadata: {}
|
108
|
+
post_install_message:
|
109
|
+
rdoc_options: []
|
110
|
+
require_paths:
|
111
|
+
- lib
|
112
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
113
|
+
requirements:
|
114
|
+
- - ">="
|
115
|
+
- !ruby/object:Gem::Version
|
116
|
+
version: '0'
|
117
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
118
|
+
requirements:
|
119
|
+
- - ">="
|
120
|
+
- !ruby/object:Gem::Version
|
121
|
+
version: '0'
|
122
|
+
requirements: []
|
123
|
+
rubyforge_project:
|
124
|
+
rubygems_version: 2.5.1
|
125
|
+
signing_key:
|
126
|
+
specification_version: 4
|
127
|
+
summary: Wikipedia Virtual FileSystem (read-only)
|
128
|
+
test_files: []
|