rxfileio 0.1.0

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 51196195f39fefa5fb7e4472ac7e0623c0acae742f1ab19cab76f2a3093043ec
4
+ data.tar.gz: e69a15e41f099c5a20b4ffa4f331a91c6b9f2e09457e0c875ad5bc5b5ac0e392
5
+ SHA512:
6
+ metadata.gz: 42deedd193e376d19431b6bc645c055041b7bbd5a5b68a750295230e83c129c40086cbaf2863d425af27a99bc1ee889d38e4997b186ac365134d7060c38470f0
7
+ data.tar.gz: 56926ba5327e8b9ef12a74e367b141cbd5608fcca06f518cff16f67124dd11ace3c54b53eb1e5c729246f5df4cecff912d320513f319496c577186e09a1ecb62
checksums.yaml.gz.sig ADDED
Binary file
data/lib/rxfileio.rb ADDED
@@ -0,0 +1,409 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ # file: rxfileio.rb
4
+
5
+ require 'rxfreadwrite'
6
+ require 'dir-to-xml'
7
+ require 'mymedia_ftp'
8
+
9
+
10
+
11
+ module RXFileIOModule
12
+ include RXFReadWriteModule
13
+
14
+ def DirX.chdir(s) RXFileIO.chdir(s) end
15
+ def DirX.mkdir(s) RXFileIO.mkdir(s) end
16
+ def DirX.pwd() RXFileIO.pwd() end
17
+
18
+ def FileX.chdir(s) RXFileIO.chdir(s) end
19
+
20
+ def FileX.directory?(filename)
21
+
22
+ type = FileX.filetype(filename)
23
+
24
+ filex = case type
25
+ when :file
26
+ File
27
+ when :dfs
28
+ DfsFile
29
+ else
30
+ nil
31
+ end
32
+
33
+ return nil unless filex
34
+
35
+ filex.directory? filename
36
+
37
+ end
38
+
39
+ def FileX.exist?(filename)
40
+ exists? filename
41
+ end
42
+
43
+ def FileX.chmod(num, s) RXFileIO.chmod(num, s) end
44
+ def FileX.cp(s, s2) RXFileIO.cp(s, s2) end
45
+ def FileX.ls(s) RXFileIO.ls(s) end
46
+ def FileX.mkdir(s) RXFileIO.mkdir(s) end
47
+ def FileX.mkdir_p(s) RXFileIO.mkdir_p(s) end
48
+ def FileX.mv(s, s2) RXFileIO.mv(s, s2) end
49
+ def FileX.pwd() RXFileIO.pwd() end
50
+ def FileX.read(x) RXFileIO.read(x).first end
51
+ def FileX.rm(s) RXFileIO.rm(s) end
52
+
53
+ def FileX.rm_r(s, force: false)
54
+ RXFileIO.rm_r(s, force: force)
55
+ end
56
+
57
+ def FileX.ru(s) RXFileIO.ru(s) end
58
+ def FileX.ru_r(s) RXFileIO.ru_r(s) end
59
+
60
+ def FileX.touch(s, mtime: Time.now)
61
+ RXFileIO.touch(s, mtime: mtime)
62
+ end
63
+
64
+ def FileX.write(x, s) RXFileIO.write(x, s) end
65
+ def FileX.zip(s, a) RXFileIO.zip(s, a) end
66
+
67
+ end
68
+
69
+
70
+ class RXFileIOException < Exception
71
+ end
72
+
73
+ class RXFileIO < RXFReadWrite
74
+ using ColouredText
75
+
76
+ @fs = :local
77
+
78
+ def self.chmod(permissions, s)
79
+
80
+ return unless permissions.is_a? Integer
81
+ return unless s.is_a? String
82
+
83
+ if s[/^dfs:\/\//] or @fs[0..2] == 'dfs' then
84
+ DfsFile.chmod permissions, s
85
+ else
86
+ FileUtils.chmod permissions, s
87
+ end
88
+
89
+ end
90
+
91
+ def self.cp(s1, s2, debug: false)
92
+
93
+ found = [s1,s2].grep /^\w+:\/\//
94
+ puts 'found: ' + found.inspect if debug
95
+
96
+ if found.any? then
97
+
98
+ case found.first[/^\w+(?=:\/\/)/]
99
+
100
+ when 'dfs'
101
+ DfsFile.cp(s1, s2)
102
+ when 'ftp'
103
+ MyMediaFTP.cp s1, s2
104
+ else
105
+
106
+ end
107
+
108
+ else
109
+
110
+ FileUtils.cp s1, s2
111
+
112
+ end
113
+ end
114
+
115
+ def self.chdir(x)
116
+
117
+ # We can use @fs within chdir() to flag the current file system.
118
+ # Allowing us to use relative paths with FileX operations instead
119
+ # of explicitly stating the path each time. e.g. touch 'foo.txt'
120
+ #
121
+
122
+ if x[/^file:\/\//] or File.exists?(File.dirname(x)) then
123
+
124
+ @fs = :local
125
+ FileUtils.chdir x
126
+
127
+ elsif x[/^dfs:\/\//]
128
+
129
+ host = x[/(?<=dfs:\/\/)[^\/]+/]
130
+ @fs = 'dfs://' + host
131
+ DfsFile.chdir x
132
+
133
+ end
134
+
135
+ end
136
+
137
+ def self.ls(x='*')
138
+
139
+ return Dir[x] if File.exists?(File.dirname(x))
140
+
141
+ case x[/^\w+(?=:\/\/)/]
142
+ when 'file'
143
+ Dir[x]
144
+ when 'dfs'
145
+ DfsFile.ls x
146
+ when 'ftp'
147
+ MyMediaFTP.ls x
148
+ else
149
+
150
+ end
151
+
152
+ end
153
+
154
+ def self.mkdir(x)
155
+
156
+ if x[/^file:\/\//] or File.exists?(File.dirname(x)) then
157
+ FileUtils.mkdir x
158
+ elsif x[/^dfs:\/\//]
159
+ DfsFile.mkdir x
160
+ end
161
+
162
+ end
163
+
164
+ def self.mkdir_p(x)
165
+
166
+ if x[/^dfs:\/\//] or @fs[0..2] == 'dfs' then
167
+ DfsFile.mkdir_p x
168
+ else
169
+ FileUtils.mkdir_p x
170
+ end
171
+
172
+ end
173
+
174
+ def self.mv(s1, s2)
175
+ DfsFile.mv(s1, s2)
176
+ end
177
+
178
+
179
+ def self.pwd()
180
+
181
+ DfsFile.pwd
182
+
183
+ end
184
+
185
+ def self.read(x, h={})
186
+
187
+ opt = {debug: false}.merge(h)
188
+
189
+ debug = opt[:debug]
190
+
191
+ puts 'x: ' + x.inspect if opt[:debug]
192
+ raise RXFileIOException, 'nil found, expected a string' if x.nil?
193
+
194
+ if x.class.to_s =~ /Rexle$/ then
195
+
196
+ [x.xml, :rexle]
197
+
198
+ elsif x.strip[/^<(\?xml|[^\?])/] then
199
+
200
+ [x, :xml]
201
+
202
+ elsif x.lines.length == 1 then
203
+
204
+ puts 'x.lines == 1'.info if debug
205
+
206
+ if x[/^https?:\/\//] then
207
+
208
+ puts 'before GPDRequest'.info if debug
209
+
210
+ r = if opt[:username] and opt[:password] then
211
+ GPDRequest.new(opt[:username], opt[:password]).get(x)
212
+ else
213
+ response = RestClient.get(x)
214
+ end
215
+
216
+ case r.code
217
+ when '404'
218
+ raise(RXFileIOException, "404 %s not found" % x)
219
+ when '401'
220
+ raise(RXFileIOException, "401 %s unauthorized access" % x)
221
+ end
222
+
223
+ [r.body, :url]
224
+
225
+ elsif x[/^dfs:\/\//] then
226
+
227
+ r = DfsFile.read(x)
228
+ [r.force_encoding('UTF-8'), :dfs]
229
+
230
+ elsif x[/^ftp:\/\//] then
231
+
232
+ [MyMediaFTP.read(x), :ftp]
233
+
234
+ elsif x[/^file:\/\//] or File.exists?(x) then
235
+
236
+ contents = File.read(File.expand_path(x.sub(%r{^file://}, '')))
237
+
238
+ puts 'contents2: ' + contents.inspect if opt[:debug]
239
+
240
+ puts 'opt: ' + opt.inspect if opt[:debug]
241
+
242
+ [contents, :file]
243
+
244
+ elsif x =~ /\s/
245
+ [x, :text]
246
+ elsif DfsFile.exists?(x)
247
+ [DfsFile.read(x).force_encoding('UTF-8'), :dfs]
248
+ else
249
+ [x, :unknown]
250
+ end
251
+
252
+ else
253
+
254
+ [x.force_encoding("UTF-8"), :unknown]
255
+ end
256
+ end
257
+
258
+ def self.rm(filename)
259
+
260
+ case filename[/^\w+(?=:\/\/)/]
261
+ when 'dfs'
262
+ DfsFile.rm filename
263
+ when 'ftp'
264
+ MyMediaFTP.rm filename
265
+ else
266
+
267
+ if File.basename(filename) =~ /\*/ then
268
+
269
+ Dir.glob(filename).each do |file|
270
+
271
+ begin
272
+ FileUtils.rm file
273
+ rescue
274
+ puts ('RXFileIO#rm: ' + file + ' is a Directory').warning
275
+ end
276
+
277
+ end
278
+
279
+ else
280
+ FileUtils.rm filename
281
+ end
282
+
283
+ end
284
+
285
+ end
286
+
287
+ def self.rm_r(filename, force: false)
288
+
289
+ case filename[/^\w+(?=:\/\/)/]
290
+ when 'dfs'
291
+ DfsFile.rm_r filename, force: force
292
+ #when 'ftp'
293
+ # MyMediaFTP.rm filename
294
+ else
295
+
296
+ if File.basename(filename) =~ /\*/ then
297
+
298
+ Dir.glob(filename).each do |file|
299
+
300
+ begin
301
+ FileUtils.rm_r file, force: force
302
+ rescue
303
+ puts ('RXFileIO#rm: ' + file + ' is a Directory').warning
304
+ end
305
+
306
+ end
307
+
308
+ else
309
+ FileUtils.rm_r filename, force: force
310
+ end
311
+
312
+ end
313
+
314
+ end
315
+
316
+ # recently_updated
317
+ #
318
+ def self.ru(path='.')
319
+
320
+ case path[/^\w+(?=:\/\/)/]
321
+ when 'dfs'
322
+ DfsFile.ru path
323
+
324
+ else
325
+
326
+ DirToXML.new(path, recursive: false, verbose: false).latest
327
+
328
+ end
329
+
330
+ end
331
+
332
+ # recently updated recursively check directories
333
+ #
334
+ def self.ru_r(path='.')
335
+
336
+ case path[/^\w+(?=:\/\/)/]
337
+ when 'dfs'
338
+ DfsFile.ru_r path
339
+
340
+ else
341
+
342
+ DirToXML.new(path, recursive: true, verbose: false).latest
343
+
344
+ end
345
+
346
+ end
347
+
348
+ def self.touch(filename, mtime: Time.now)
349
+
350
+ if @fs[0..2] == 'dfs' then
351
+ return DfsFile.touch(@fs + pwd + '/' + filename, mtime: mtime)
352
+ end
353
+
354
+ case filename[/^\w+(?=:\/\/)/]
355
+ when 'dfs'
356
+ DfsFile.touch filename, mtime: mtime
357
+ #when 'ftp'
358
+ # MyMediaFTP.touch filename
359
+ else
360
+ FileUtils.touch filename, mtime: mtime
361
+ end
362
+
363
+ end
364
+
365
+ def self.write(location, s=nil)
366
+
367
+ case location
368
+ when /^dfs:\/\//
369
+
370
+ DfsFile.write location, s
371
+
372
+ when /^ftp:\/\// then
373
+
374
+ MyMediaFTP.write location, s
375
+
376
+ else
377
+
378
+ if DfsFile.exists?(File.dirname(location)) then
379
+ DfsFile.write location, s
380
+ else
381
+ File.write(location, s)
382
+ end
383
+
384
+ end
385
+
386
+ end
387
+
388
+ def self.writeable?(source)
389
+
390
+ return false if source.lines.length > 1
391
+
392
+ if not source =~ /:\/\// then
393
+
394
+ return true if File.exists? source
395
+
396
+ else
397
+
398
+ return true if source =~ /^dfs:/
399
+
400
+ end
401
+
402
+ return false
403
+ end
404
+
405
+ def self.zip(filename, a)
406
+ DfsFile.zip(filename, a)
407
+ end
408
+
409
+ end
data.tar.gz.sig ADDED
Binary file
metadata ADDED
@@ -0,0 +1,130 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rxfileio
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - James Robertson
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain:
11
+ - |
12
+ -----BEGIN CERTIFICATE-----
13
+ MIIEXjCCAsagAwIBAgIBATANBgkqhkiG9w0BAQsFADAsMSowKAYDVQQDDCFnZW1t
14
+ YXN0ZXIvREM9amFtZXNyb2JlcnRzb24vREM9ZXUwHhcNMjIwMjIwMTkyMTEyWhcN
15
+ MjMwMjIwMTkyMTEyWjAsMSowKAYDVQQDDCFnZW1tYXN0ZXIvREM9amFtZXNyb2Jl
16
+ cnRzb24vREM9ZXUwggGiMA0GCSqGSIb3DQEBAQUAA4IBjwAwggGKAoIBgQC1G5tR
17
+ 9YA09a3u3jd/GHeUFfcSkzj4Z5T+m+yrZ8i2klrqaG1HxVfP1QakO3tP2H+Uqm9g
18
+ 2HVQbwPk3Th3uxgvEHgAFqKshXCFl3FvGGsEjAC3U/HmlbWk+wznngylczCv3vY0
19
+ a7khkBedAa/NMn0MgnSydWnXHAk95iDR8lLVTPgnDsaOhe67Ng3yriAc9RKNj6kH
20
+ YwmyBWsx/3eR790bvq2UU57uA50iUFj4hkcWV3Yef4txZi4lFWO3PQ5xQ+ExfFYX
21
+ RUWB5efoEOH5AzfX6pydgqzpLNd5GuIYUn0OVYVo8skwa//VxkRUGnOUN0aM16jG
22
+ 9tDXjNPECUk3DmsoMWCcHYOHJZeYcskjQLX6w1fJxh7o+QRmmNzmF2WSc7QQItJD
23
+ YcTcw8Y2YsQO1MatNiYygQoazzqEAO63S8XrW5Oxh1rKWyiui1A9Z1nraoKNibAJ
24
+ FL8jeIdD+FO6O/2WE+hFOsqZBnTdGYgvecpd0zowa0jACz9MC2ILxc+cHlUCAwEA
25
+ AaOBijCBhzAJBgNVHRMEAjAAMAsGA1UdDwQEAwIEsDAdBgNVHQ4EFgQU9J1TNQHe
26
+ xKsl3W0k1DBZMlzRRqgwJgYDVR0RBB8wHYEbZ2VtbWFzdGVyQGphbWVzcm9iZXJ0
27
+ c29uLmV1MCYGA1UdEgQfMB2BG2dlbW1hc3RlckBqYW1lc3JvYmVydHNvbi5ldTAN
28
+ BgkqhkiG9w0BAQsFAAOCAYEAWJxtW3MRz4XHR36uE9yUXGjBsY0rQ5RfmhfAm6fZ
29
+ 6A6Y1zppkFi0IycsIZInWtKdnRIJRKta0tpvAdUuG3c4qu/NBBvgsKs540bgXLXl
30
+ 2O0Rg3yFdaXKpi+1E2FyAnEbJWprcmXybAfZEvUTD15jD7r0R4+7zRzJPtTGrgrk
31
+ XNzrBRQxYD4SmoiwNQJUY1qrwAvDdAOtD+q9u+XGCRDbDg8qw8iA4OnVNGNJOTK+
32
+ cmGW1h+SdJeghPuWIuoNzjxaMbL63AN3/k4OO/zufUyVGRF+5ryb4CtPnKMqXody
33
+ 1EMYF5a63W08SlnsP9Hd/EnQsSq+frAHJ8g9axfSo++kbLceXviBBguFUJtIr1Gl
34
+ w9puzSUnpdumy2pVQ3cLIiFixZJ5ghdeu8ma2aH7urQXIckr7BbdLgWFAmVxfh2k
35
+ yLO5YIYbN1F1F4bnaaoKLedXnnC+5VCarLA4HblYDwqrZ78CQIBelACSnxeY9gD3
36
+ oyr0nnshzqXtH7vQD0nI5kqL
37
+ -----END CERTIFICATE-----
38
+ date: 2022-02-20 00:00:00.000000000 Z
39
+ dependencies:
40
+ - !ruby/object:Gem::Dependency
41
+ name: rxfreadwrite
42
+ requirement: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - "~>"
45
+ - !ruby/object:Gem::Version
46
+ version: '0.1'
47
+ - - ">="
48
+ - !ruby/object:Gem::Version
49
+ version: 0.1.2
50
+ type: :runtime
51
+ prerelease: false
52
+ version_requirements: !ruby/object:Gem::Requirement
53
+ requirements:
54
+ - - "~>"
55
+ - !ruby/object:Gem::Version
56
+ version: '0.1'
57
+ - - ">="
58
+ - !ruby/object:Gem::Version
59
+ version: 0.1.2
60
+ - !ruby/object:Gem::Dependency
61
+ name: dir-to-xml
62
+ requirement: !ruby/object:Gem::Requirement
63
+ requirements:
64
+ - - "~>"
65
+ - !ruby/object:Gem::Version
66
+ version: '1.2'
67
+ - - ">="
68
+ - !ruby/object:Gem::Version
69
+ version: 1.2.0
70
+ type: :runtime
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - "~>"
75
+ - !ruby/object:Gem::Version
76
+ version: '1.2'
77
+ - - ">="
78
+ - !ruby/object:Gem::Version
79
+ version: 1.2.0
80
+ - !ruby/object:Gem::Dependency
81
+ name: mymedia_ftp
82
+ requirement: !ruby/object:Gem::Requirement
83
+ requirements:
84
+ - - "~>"
85
+ - !ruby/object:Gem::Version
86
+ version: '0.3'
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: 0.3.3
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '0.3'
97
+ - - ">="
98
+ - !ruby/object:Gem::Version
99
+ version: 0.3.3
100
+ description:
101
+ email: digital.robertson@gmail.com
102
+ executables: []
103
+ extensions: []
104
+ extra_rdoc_files: []
105
+ files:
106
+ - lib/rxfileio.rb
107
+ homepage: https://github.com/jrobertson/rxfileio
108
+ licenses:
109
+ - MIT
110
+ metadata: {}
111
+ post_install_message:
112
+ rdoc_options: []
113
+ require_paths:
114
+ - lib
115
+ required_ruby_version: !ruby/object:Gem::Requirement
116
+ requirements:
117
+ - - ">="
118
+ - !ruby/object:Gem::Version
119
+ version: '0'
120
+ required_rubygems_version: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ requirements: []
126
+ rubygems_version: 3.2.22
127
+ signing_key:
128
+ specification_version: 4
129
+ summary: Features remote file operations using the DFS protocol and more.
130
+ test_files: []
metadata.gz.sig ADDED
Binary file