pfuse 0.7.5

Sign up to get free protection for your applications and to get access to all the features.
data/sample/yamlfs.rb ADDED
@@ -0,0 +1,168 @@
1
+ # yamlfs.rb
2
+ #
3
+
4
+ require "rubygems"
5
+ require 'fusefs'
6
+ include FuseFS
7
+
8
+ require 'yaml'
9
+
10
+ class YAMLFS < FuseFS::FuseDir
11
+ def initialize(filename)
12
+ @filename = filename
13
+ begin
14
+ @fs = YAML.load(IO.read(filename))
15
+ rescue Exception
16
+ @fs = Hash.new()
17
+ end
18
+ end
19
+ def save
20
+ File.open(@filename,'w') do |fout|
21
+ fout.puts(YAML.dump(@fs))
22
+ end
23
+ end
24
+ def contents(path)
25
+ items = scan_path(path)
26
+ node = items.inject(@fs) do |node,item|
27
+ item ? node[item] : node
28
+ end
29
+ node.keys.sort
30
+ end
31
+ def directory?(path)
32
+ items = scan_path(path)
33
+ node = items.inject(@fs) do |node,item|
34
+ item ? node[item] : node
35
+ end
36
+ node.is_a?(Hash)
37
+ end
38
+ def file?(path)
39
+ items = scan_path(path)
40
+ node = items.inject(@fs) do |node,item|
41
+ item ? node[item] : node
42
+ end
43
+ node.is_a?(String)
44
+ end
45
+ def touch(path)
46
+ puts "#{path} has been pushed like a button!"
47
+ end
48
+
49
+ # File reading
50
+ def read_file(path)
51
+ items = scan_path(path)
52
+ node = items.inject(@fs) do |node,item|
53
+ item ? node[item] : node
54
+ end
55
+ node.to_s
56
+ end
57
+
58
+ def size(path)
59
+ read_file(path).size
60
+ end
61
+
62
+ # File writing
63
+ def can_write?(path)
64
+ items = scan_path(path)
65
+ name = items.pop # Last is the filename.
66
+ node = items.inject(@fs) do |node,item|
67
+ item ? node[item] : node
68
+ end
69
+ node.is_a?(Hash)
70
+ rescue Exception => er
71
+ puts "Error! #{er}"
72
+ end
73
+ def write_to(path,body)
74
+ items = scan_path(path)
75
+ name = items.pop # Last is the filename.
76
+ node = items.inject(@fs) do |node,item|
77
+ item ? node[item] : node
78
+ end
79
+ node[name] = body
80
+ self.save
81
+ rescue Exception => er
82
+ puts "Error! #{er}"
83
+ end
84
+
85
+ # Delete a file
86
+ def can_delete?(path)
87
+ items = scan_path(path)
88
+ node = items.inject(@fs) do |node,item|
89
+ item ? node[item] : node
90
+ end
91
+ node.is_a?(String)
92
+ rescue Exception => er
93
+ puts "Error! #{er}"
94
+ end
95
+ def delete(path)
96
+ items = scan_path(path)
97
+ name = items.pop # Last is the filename.
98
+ node = items.inject(@fs) do |node,item|
99
+ item ? node[item] : node
100
+ end
101
+ node.delete(name)
102
+ self.save
103
+ rescue Exception => er
104
+ puts "Error! #{er}"
105
+ end
106
+
107
+ # mkdirs
108
+ def can_mkdir?(path)
109
+ items = scan_path(path)
110
+ name = items.pop # Last is the filename.
111
+ node = items.inject(@fs) do |node,item|
112
+ item ? node[item] : node
113
+ end
114
+ node.is_a?(Hash)
115
+ rescue Exception => er
116
+ puts "Error! #{er}"
117
+ end
118
+ def mkdir(path)
119
+ items = scan_path(path)
120
+ name = items.pop # Last is the filename.
121
+ node = items.inject(@fs) do |node,item|
122
+ item ? node[item] : node
123
+ end
124
+ node[name] = Hash.new
125
+ self.save
126
+ end
127
+
128
+ # rmdir
129
+ def can_rmdir?(path)
130
+ items = scan_path(path)
131
+ node = items.inject(@fs) do |node,item|
132
+ item ? node[item] : node
133
+ end
134
+ node.is_a?(Hash) && node.empty?
135
+ end
136
+ def rmdir(path)
137
+ items = scan_path(path)
138
+ name = items.pop # Last is the filename.
139
+ node = items.inject(@fs) do |node,item|
140
+ item ? node[item] : node
141
+ end
142
+ node.delete(name)
143
+ self.save
144
+ end
145
+ end
146
+
147
+ if (File.basename($0) == File.basename(__FILE__))
148
+ if (ARGV.size < 2)
149
+ puts "Usage: #{$0} <directory> <yamlfile> <options>"
150
+ exit
151
+ end
152
+
153
+ dirname, yamlfile = ARGV.shift, ARGV.shift
154
+
155
+ unless File.directory?(dirname)
156
+ puts "Usage: #{dirname} is not a directory."
157
+ exit
158
+ end
159
+
160
+ root = YAMLFS.new(yamlfile)
161
+
162
+ # Set the root FuseFS
163
+ FuseFS.set_root(root)
164
+
165
+ FuseFS.mount_under(dirname, *ARGV)
166
+
167
+ FuseFS.run # This doesn't return until we're unmounted.
168
+ end
@@ -0,0 +1,7 @@
1
+ require 'test_helper'
2
+
3
+ class FusefsTest < Test::Unit::TestCase
4
+ should "probably rename this file and start testing for real" do
5
+ flunk "hey buddy, you should probably rename this file and start testing for real"
6
+ end
7
+ end
@@ -0,0 +1,10 @@
1
+ require 'rubygems'
2
+ require 'test/unit'
3
+ require 'shoulda'
4
+
5
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
6
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
7
+ require 'fusefs'
8
+
9
+ class Test::Unit::TestCase
10
+ end
metadata ADDED
@@ -0,0 +1,84 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: pfuse
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.7.5
5
+ platform: ruby
6
+ authors:
7
+ - David Turnbull
8
+ - Kyle Maxwell
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+
13
+ date: 2010-02-26 00:00:00 +11:00
14
+ default_executable:
15
+ dependencies: []
16
+
17
+ description: Gemified
18
+ email: dsturnbull@gmail.com
19
+ executables: []
20
+
21
+ extensions:
22
+ - ext/extconf.rb
23
+ extra_rdoc_files:
24
+ - LICENSE
25
+ - README
26
+ - TODO
27
+ files:
28
+ - .document
29
+ - .gitignore
30
+ - API.txt
31
+ - Changes.txt
32
+ - LICENSE
33
+ - README
34
+ - Rakefile
35
+ - TODO
36
+ - VERSION
37
+ - ext/extconf.rb
38
+ - ext/fusefs_fuse.c
39
+ - ext/fusefs_fuse.h
40
+ - ext/fusefs_lib.c
41
+ - ext/fusefs_lib.h
42
+ - hello.sh
43
+ - lib/fusefs.rb
44
+ - pfuse.gemspec
45
+ - sample/demo.rb
46
+ - sample/dictfs.rb
47
+ - sample/hello.rb
48
+ - sample/openurifs.rb
49
+ - sample/railsfs.rb
50
+ - sample/sqlfs.rb
51
+ - sample/yamlfs.rb
52
+ - test/fusefs_test.rb
53
+ - test/test_helper.rb
54
+ has_rdoc: true
55
+ homepage: http://github.com/dsturnbull/pfuse
56
+ licenses: []
57
+
58
+ post_install_message:
59
+ rdoc_options:
60
+ - --charset=UTF-8
61
+ require_paths:
62
+ - lib
63
+ required_ruby_version: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - ">="
66
+ - !ruby/object:Gem::Version
67
+ version: "0"
68
+ version:
69
+ required_rubygems_version: !ruby/object:Gem::Requirement
70
+ requirements:
71
+ - - ">="
72
+ - !ruby/object:Gem::Version
73
+ version: "0"
74
+ version:
75
+ requirements: []
76
+
77
+ rubyforge_project:
78
+ rubygems_version: 1.3.5
79
+ signing_key:
80
+ specification_version: 3
81
+ summary: fusefs
82
+ test_files:
83
+ - test/fusefs_test.rb
84
+ - test/test_helper.rb