mcfs 0.0.2
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 +7 -0
- data/bin/mcfs +4 -0
- data/lib/mcfs.rb +9 -0
- data/lib/mcfs/filesystem.rb +82 -0
- data/lib/mcfs/stores/dropbox.rb +62 -0
- metadata +88 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 7036585a4107367e905f4f92bd2e0a43c7c5b126
|
4
|
+
data.tar.gz: 6da3ef4d704728fcfb934bedb304703180e39f05
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: a298fe05047e1330e62c53a38c911833285d5068a7435e511bf7f97fa3eec0fa071c4af3bb354b03d648c042880d4fb7100ca196d5734e38c4b1eda378383a6f
|
7
|
+
data.tar.gz: 8a7dbc56d8f9a62febad2da02efc62a64c3305920ba5551941f49dae8ab5ef6d15164b225e90b4052771eb1b32d6713c97328d940cb4f4dc114d2df9e6d15b7e
|
data/bin/mcfs
ADDED
data/lib/mcfs.rb
ADDED
@@ -0,0 +1,82 @@
|
|
1
|
+
|
2
|
+
require 'set'
|
3
|
+
require 'yaml'
|
4
|
+
|
5
|
+
require_relative 'stores/dropbox'
|
6
|
+
|
7
|
+
module McFS
|
8
|
+
class Filesystem
|
9
|
+
|
10
|
+
def initialize
|
11
|
+
@stores = []
|
12
|
+
dbcfg1 = YAML.load_file(ENV['HOME'] + '/.mcfs/dropbox1.yml')
|
13
|
+
dbcfg2 = YAML.load_file(ENV['HOME'] + '/.mcfs/dropbox2.yml')
|
14
|
+
|
15
|
+
@stores << Stores::Dropbox.new(dbcfg1.access_token)
|
16
|
+
@stores << Stores::Dropbox.new(dbcfg2.access_token)
|
17
|
+
|
18
|
+
end
|
19
|
+
|
20
|
+
def contents(path)
|
21
|
+
files = []
|
22
|
+
@stores.each do |store|
|
23
|
+
files += store.contents(path)
|
24
|
+
end
|
25
|
+
files.uniq
|
26
|
+
end
|
27
|
+
|
28
|
+
def file?(path)
|
29
|
+
true
|
30
|
+
end
|
31
|
+
|
32
|
+
def can_write?(path)
|
33
|
+
true
|
34
|
+
end
|
35
|
+
|
36
|
+
def read_file(path)
|
37
|
+
puts "Read File: #{path}"
|
38
|
+
contents = {}
|
39
|
+
|
40
|
+
@stores.each do |store|
|
41
|
+
contents.merge! store.read_file(path)
|
42
|
+
end
|
43
|
+
|
44
|
+
data = ''
|
45
|
+
|
46
|
+
contents.sort.each do |chunk|
|
47
|
+
data << chunk[1]
|
48
|
+
end
|
49
|
+
|
50
|
+
data
|
51
|
+
end
|
52
|
+
|
53
|
+
def write_to(path, str)
|
54
|
+
puts "write_to: #{path}, #{str}"
|
55
|
+
buf = ''
|
56
|
+
cnt = 0
|
57
|
+
idx = 0
|
58
|
+
|
59
|
+
str.each_byte do |b|
|
60
|
+
buf << b
|
61
|
+
cnt += 1
|
62
|
+
|
63
|
+
if cnt == 4096 then
|
64
|
+
@stores[idx % @stores.size].write_to(path, idx, buf)
|
65
|
+
buf = ''
|
66
|
+
idx += 1
|
67
|
+
cnt = 0
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
if buf.size > 0 then
|
72
|
+
puts buf.size
|
73
|
+
puts idx
|
74
|
+
p @stores
|
75
|
+
puts @stores[idx % (@stores.size)]
|
76
|
+
@stores[idx % @stores.size].write_to(path, idx, buf)
|
77
|
+
end
|
78
|
+
|
79
|
+
end
|
80
|
+
|
81
|
+
end
|
82
|
+
end
|
@@ -0,0 +1,62 @@
|
|
1
|
+
require 'dropbox_sdk'
|
2
|
+
|
3
|
+
class DropboxConfig
|
4
|
+
attr_reader :app_key, :app_secret, :access_token, :user_id
|
5
|
+
|
6
|
+
def initialize(key, secret, token, user)
|
7
|
+
@app_key = key
|
8
|
+
@app_secret = secret
|
9
|
+
@access_token = token
|
10
|
+
@user_id = user
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
module McFS
|
15
|
+
module Stores
|
16
|
+
|
17
|
+
class Dropbox
|
18
|
+
|
19
|
+
def initialize(token)
|
20
|
+
@client = DropboxClient.new(token)
|
21
|
+
end
|
22
|
+
|
23
|
+
# list contents under directory
|
24
|
+
def contents(dir)
|
25
|
+
puts "Path: #{dir}"
|
26
|
+
@client.metadata('/McFS' + dir)['contents'].map do |entry|
|
27
|
+
# entry['path'].split('/')[-1]
|
28
|
+
# TODO: File.basename may have issues with path separator
|
29
|
+
File.basename(entry['path'], '.*')
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def read_file(path)
|
34
|
+
puts "Read: #{path}"
|
35
|
+
|
36
|
+
filenames = @client.metadata(File.dirname('/McFS' + path))['contents'].map do |e|
|
37
|
+
e['path'] if File.basename(e['path'], '.*') == File.basename('/McFS' + path)
|
38
|
+
end
|
39
|
+
|
40
|
+
contents = {}
|
41
|
+
|
42
|
+
filenames.each do |file|
|
43
|
+
if file then
|
44
|
+
puts file
|
45
|
+
|
46
|
+
index = File.extname(file)[1..-1].to_i
|
47
|
+
data, metadata = @client.get_file_and_metadata(file)
|
48
|
+
contents[index] = data
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
return contents
|
53
|
+
end
|
54
|
+
|
55
|
+
def write_to(path, index, str)
|
56
|
+
puts "write: #{path}, #{index}, #{str}"
|
57
|
+
@client.put_file('/McFS' + path + ".#{index}", str, true)
|
58
|
+
end
|
59
|
+
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
metadata
ADDED
@@ -0,0 +1,88 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: mcfs
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.2
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Jinesh Jayakumar
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-02-08 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: dropbox-sdk
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.6'
|
20
|
+
- - '='
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: 1.6.4
|
23
|
+
type: :runtime
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
26
|
+
requirements:
|
27
|
+
- - "~>"
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '1.6'
|
30
|
+
- - '='
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: 1.6.4
|
33
|
+
- !ruby/object:Gem::Dependency
|
34
|
+
name: rfusefs
|
35
|
+
requirement: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - "~>"
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: '1.0'
|
40
|
+
- - '='
|
41
|
+
- !ruby/object:Gem::Version
|
42
|
+
version: 1.0.3
|
43
|
+
type: :runtime
|
44
|
+
prerelease: false
|
45
|
+
version_requirements: !ruby/object:Gem::Requirement
|
46
|
+
requirements:
|
47
|
+
- - "~>"
|
48
|
+
- !ruby/object:Gem::Version
|
49
|
+
version: '1.0'
|
50
|
+
- - '='
|
51
|
+
- !ruby/object:Gem::Version
|
52
|
+
version: 1.0.3
|
53
|
+
description: mcfs description
|
54
|
+
email: jineshkj at gmail dot com
|
55
|
+
executables:
|
56
|
+
- mcfs
|
57
|
+
extensions: []
|
58
|
+
extra_rdoc_files: []
|
59
|
+
files:
|
60
|
+
- bin/mcfs
|
61
|
+
- lib/mcfs.rb
|
62
|
+
- lib/mcfs/filesystem.rb
|
63
|
+
- lib/mcfs/stores/dropbox.rb
|
64
|
+
homepage: https://github.com/jineshkj/mcfs
|
65
|
+
licenses:
|
66
|
+
- LGPLv3
|
67
|
+
metadata: {}
|
68
|
+
post_install_message:
|
69
|
+
rdoc_options: []
|
70
|
+
require_paths:
|
71
|
+
- lib
|
72
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
73
|
+
requirements:
|
74
|
+
- - ">="
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: '0'
|
77
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
78
|
+
requirements:
|
79
|
+
- - ">="
|
80
|
+
- !ruby/object:Gem::Version
|
81
|
+
version: '0'
|
82
|
+
requirements: []
|
83
|
+
rubyforge_project:
|
84
|
+
rubygems_version: 2.4.5
|
85
|
+
signing_key:
|
86
|
+
specification_version: 4
|
87
|
+
summary: mcfs summary
|
88
|
+
test_files: []
|