drb_fileclient 0.2.0 → 0.2.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 2acd6009e3a7703f659abb25bfa4ec482669bede
4
- data.tar.gz: 58e4aa65be961f907f19c8ba5bcf9476b0351bce
2
+ SHA256:
3
+ metadata.gz: b2a277d060d30cdf5174b0d76f89a0cec60e6ff399f183165022b584e4ec1fbe
4
+ data.tar.gz: 4393a67153df3e323ae422f6d9acac44aed1cc6f32a9037571fb0a735191cd49
5
5
  SHA512:
6
- metadata.gz: 01dd234914af6e493790eeb66787fbcca94278cd27bf0a4942bf8f5619c99ae7d345122adbf1b909fccb1b8082d93288e4cbe3215c71340f807b207102b70ebd
7
- data.tar.gz: 03aaf68ad10862a095409a1080f44e3c35d85897cd25c816c58d90de7a8c2d9ccbe3598ed6302bdbb3265c8a22d441fa4186b269bb74d502d5d6cffde2dfc72e
6
+ metadata.gz: 16593a3b669406cb2b2ee8f6d6ed53240110ef8fc51ee7cd0ecbc88f079b6273b77901add42949d8ec9aa60d5975fa3d6140bec222d03e331a948cdc3f0a5991
7
+ data.tar.gz: 33b4810bfbbb01403fd8153ea9af854e806f2196822b27a687230b1861c52c59073f67ff8593ff966e90283f520df6710b655f49fac7370ab77673bc58ed8fe4
Binary file
data.tar.gz.sig CHANGED
Binary file
@@ -13,72 +13,127 @@ class DRbFileClient
13
13
 
14
14
  host = location[/(?<=^dfs:\/\/)[^\/:]+/]
15
15
  port = location[/(?<=^dfs:\/\/)[^:]+:(\d+)/,1] || '61010'
16
- @filename = location[/(?<=^dfs:\/\/)[^\/]+\/(.*)/,1]
16
+ @directory = location[/(?<=^dfs:\/\/)[^\/]+\/(.*)/,1]
17
17
 
18
18
  end
19
19
 
20
20
  DRb.start_service
21
-
22
- # attach to the DRb server via a URI given on the command line
23
- @file = DRbObject.new nil, "druby://#{host}:#{port}" if host
24
21
 
25
22
  end
26
23
 
24
+ def chdir(raw_path)
25
+
26
+ directory = if raw_path[0] == '/' then
27
+ raw_path[1..-1]
28
+ elsif raw_path =~ /^dfs:\/\//
29
+ parse_path(raw_path)
30
+ else
31
+ File.join(@directory, raw_path)
32
+ end
33
+
34
+ if @file.exists? directory then
35
+ @directory = directory
36
+ else
37
+ 'No such file or directory'
38
+ end
39
+
40
+ end
41
+
27
42
  def exists?(filename=@filename)
28
43
 
29
- filename2 = parse_path(filename)
30
- @file.exists? filename2
44
+ filename2 = if filename =~ /^dfs:\/\// then
45
+ parse_path(filename)
46
+ else
47
+ filename
48
+ end
49
+
50
+ @file.exists? File.join(@directory, filename2)
31
51
 
32
52
  end
53
+
54
+ def mkdir(name)
55
+ path = parse_path(name)
56
+ @file.mkdir path
57
+ end
58
+
59
+ def mkdir_p(raw_path)
60
+ path = parse_path(raw_path)
61
+ @file.mkdir_p path
62
+ end
63
+
64
+ def pwd()
65
+
66
+ '/' + @directory if @file
67
+
68
+ end
33
69
 
34
70
  def read(filename=@filename)
35
71
 
36
- filename2 = parse_path(filename)
37
- @file.read filename2
72
+ path = if filename =~ /^dfs:\/\// then
73
+ parse_path(filename)
74
+ else
75
+ File.join(@directory, filename)
76
+ end
38
77
 
78
+ @file.read path
39
79
  end
40
80
 
41
81
  def write(filename=@filename, s)
82
+
83
+ path = if filename =~ /^dfs:\/\// then
84
+ parse_path(filename)
85
+ else
86
+ File.join(@directory, filename)
87
+ end
42
88
 
43
- filename2 = parse_path(filename)
44
- @file.write filename2, s
89
+ @file.write path, s
45
90
 
46
91
  end
47
92
 
48
93
  private
49
94
 
50
95
  def parse_path(filename)
51
-
52
- if @file then
53
-
54
- filename
55
-
56
- else
57
-
58
- host = filename[/(?<=^dfs:\/\/)[^\/:]+/]
59
- port = filename[/(?<=^dfs:\/\/)[^:]+:(\d+)/,1] || '61010'
60
96
 
61
- @file = DRbObject.new nil, "druby://#{host}:#{port}"
62
- filename[/(?<=^dfs:\/\/)[^\/]+\/(.*)/,1]
63
-
64
- end
65
-
97
+ host = filename[/(?<=^dfs:\/\/)[^\/:]+/]
98
+ port = filename[/(?<=^dfs:\/\/)[^:]+:(\d+)/,1] || '61010'
99
+
100
+ @file = DRbObject.new nil, "druby://#{host}:#{port}"
101
+ filename[/(?<=^dfs:\/\/)[^\/]+\/(.*)/,1]
102
+
66
103
  end
67
104
 
68
105
  end
69
106
 
70
107
  class DfsFile
71
108
 
109
+ @client = DRbFileClient.new
110
+
72
111
  def self.exists?(filename)
73
- DRbFileClient.new(filename).exists?
112
+ @client.exists?(filename)
74
113
  end
75
114
 
115
+ def self.chdir(path)
116
+ @client.chdir(path)
117
+ end
118
+
119
+ def self.mkdir(name)
120
+ @client.mkdir(name)
121
+ end
122
+
123
+ def self.mkdir_p(path)
124
+ @client.mkdir_p(path)
125
+ end
126
+
127
+ def self.pwd()
128
+ @client.pwd()
129
+ end
130
+
76
131
  def self.read(filename)
77
- DRbFileClient.new.read(filename)
132
+ @client.read(filename)
78
133
  end
79
134
 
80
135
  def self.write(filename, s)
81
- DRbFileClient.new.write(filename, s)
136
+ @client.write(filename, s)
82
137
  end
83
138
 
84
139
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: drb_fileclient
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - James Robertson
@@ -30,7 +30,7 @@ cert_chain:
30
30
  2aIZ9lf6/AT4LP07t9jB5oYLHlr2nBLIqtPXdJvg5RKKr79CQVmpJ5LCTjwTg9h+
31
31
  g1Q=
32
32
  -----END CERTIFICATE-----
33
- date: 2018-05-26 00:00:00.000000000 Z
33
+ date: 2018-08-11 00:00:00.000000000 Z
34
34
  dependencies: []
35
35
  description:
36
36
  email: james@jamesrobertson.eu
@@ -59,7 +59,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
59
59
  version: '0'
60
60
  requirements: []
61
61
  rubyforge_project:
62
- rubygems_version: 2.6.13
62
+ rubygems_version: 2.7.6
63
63
  signing_key:
64
64
  specification_version: 4
65
65
  summary: Reads or writes files from a remote DRb server. Simple as DfsFile.read or
metadata.gz.sig CHANGED
Binary file