symlink 0.0.29

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: b9214d75d8fd31c8d6d1985d2cb442d333580337428cec19766db16c859b7722
4
+ data.tar.gz: dbe997101df9a182490baf53a26fc8c1f7c813ffa5897a340d44c9ede4478910
5
+ SHA512:
6
+ metadata.gz: be40aa34226d315978dd1492092a8e3c885857c4e0071e229ddea7ddd5aa7a0a46b6583012726063fcaee3b1fdd2a64a8b841669c2a2f647f7d49c56a68a69f0
7
+ data.tar.gz: 4962b35584df6b22cc51abd694365246e8f2b03bdc8e204cea9746c01cfee9ed4fad61022a0973ea92ac6a1eaaeb659b56c8cd3fde7e315868bc3806dc57f033
@@ -0,0 +1,17 @@
1
+ #!/usr/bin/ruby -w
2
+ # Encoding: UTF-8
3
+ # frozen_string_literal: true
4
+ # =========================================================================== #
5
+ class Symlink
6
+
7
+ # ========================================================================= #
8
+ # === NAMESPACE
9
+ # ========================================================================= #
10
+ NAMESPACE = inspect
11
+
12
+ # ========================================================================= #
13
+ # === USE_ABSOLUTE_SYMLINKING
14
+ # ========================================================================= #
15
+ USE_ABSOLUTE_SYMLINKING = false
16
+
17
+ end
@@ -0,0 +1,345 @@
1
+ #!/usr/bin/ruby -w
2
+ # Encoding: UTF-8
3
+ # frozen_string_literal: true
4
+ # =========================================================================== #
5
+ # === Symlink
6
+ #
7
+ # This general class will allow you to symlink one target to the other.
8
+ #
9
+ # Usage example:
10
+ #
11
+ # Symlink.new
12
+ #
13
+ # =========================================================================== #
14
+ # require 'symlink/symlink.rb'
15
+ # =========================================================================== #
16
+ class Symlink # === Symlink
17
+
18
+ require 'fileutils'
19
+ require 'opn'
20
+ # ========================================================================= #
21
+ # Add a few colours for support:
22
+ # ========================================================================= #
23
+ require 'colours/e/e.rb'
24
+ require 'colours/requires/require_the_colour_methods.rb'
25
+ # ========================================================================= #
26
+ # And next pull in .rb files that are specific for Symlink:
27
+ # ========================================================================= #
28
+ require 'symlink/version/version.rb'
29
+ require 'symlink/constants.rb'
30
+
31
+ include Colours::E
32
+
33
+ # ========================================================================= #
34
+ # === initialize
35
+ # ========================================================================= #
36
+ def initialize(
37
+ old_existing_location,
38
+ new_location,
39
+ be_verbose = true,
40
+ run_already = true
41
+ )
42
+ reset
43
+ set_existing_location(old_existing_location) # from
44
+ set_new_location(new_location) # to
45
+ set_be_verbose(be_verbose) # Whether we are silent or not.
46
+ if block_given?
47
+ yielded = yield
48
+ if yielded.is_a? Hash
49
+ # === prepend_this_to_namespace
50
+ if yielded.has_key? :prepend_this_to_namespace
51
+ prepend_this_to_namespace(yielded.delete(:prepend_this_to_namespace))
52
+ end
53
+ end
54
+ end
55
+ case run_already
56
+ when :do_not_run_yet
57
+ run_already = false
58
+ end
59
+ run if run_already
60
+ end
61
+
62
+ # ========================================================================= #
63
+ # === reset (reset tag)
64
+ # ========================================================================= #
65
+ def reset
66
+ # === @use_absolute_symlinking
67
+ @use_absolute_symlinking = USE_ABSOLUTE_SYMLINKING
68
+ # === @use_opn
69
+ @use_opn = true
70
+ # === @be_verbose
71
+ @be_verbose = true
72
+ @use_colours = true
73
+ @namespace = NAMESPACE # This can be changed.
74
+ end
75
+
76
+ # ========================================================================= #
77
+ # === prepend_this_to_namespace
78
+ # ========================================================================= #
79
+ def prepend_this_to_namespace(i)
80
+ @namespace.prepend(i.to_s.dup)
81
+ end
82
+
83
+ # ========================================================================= #
84
+ # === shall_we_use_colours?
85
+ #
86
+ # This method requires one mandatory argument.
87
+ # ========================================================================= #
88
+ def shall_we_use_colours?(true_or_false)
89
+ if true_or_false == false
90
+ disable_colours
91
+ else
92
+ enable_colours
93
+ end
94
+ end
95
+
96
+ # ========================================================================= #
97
+ # === disable_colours
98
+ # ========================================================================= #
99
+ def disable_colours
100
+ @use_colours = false
101
+ end
102
+
103
+ # ========================================================================= #
104
+ # === enable_colours
105
+ # ========================================================================= #
106
+ def enable_colours
107
+ @use_colours = true
108
+ end
109
+
110
+ # ========================================================================= #
111
+ # === use_colours?
112
+ # ========================================================================= #
113
+ def use_colours?
114
+ @use_colours
115
+ end
116
+
117
+ # ========================================================================= #
118
+ # === use_absolute_symlinking
119
+ # ========================================================================= #
120
+ def use_absolute_symlinking
121
+ @use_absolute_symlinking = true
122
+ # ======================================================================= #
123
+ # We must also sync @existing_location.
124
+ # ======================================================================= #
125
+ set_existing_location(existing?)
126
+ end
127
+
128
+ # ========================================================================= #
129
+ # === set_be_verbose
130
+ # ========================================================================= #
131
+ def set_be_verbose(i)
132
+ @be_verbose = i
133
+ end
134
+
135
+ # ========================================================================= #
136
+ # === use_absolute_symlinking?
137
+ # ========================================================================= #
138
+ def use_absolute_symlinking?
139
+ @use_absolute_symlinking
140
+ end
141
+
142
+ # ========================================================================= #
143
+ # === set_existing_location
144
+ #
145
+ # This must be an existing file.
146
+ # ========================================================================= #
147
+ def set_existing_location(i = '')
148
+ i = i.first if i.is_a? Array
149
+ i = i.to_s.dup
150
+ i = rds(i)
151
+ if use_absolute_symlinking?
152
+ i = "../../../..#{i}"
153
+ end
154
+ @existing_location = i
155
+ end; alias set_old_target set_existing_location # === set_old_target
156
+
157
+ # ========================================================================= #
158
+ # === delete
159
+ #
160
+ # This will only ever delete files, not directories.
161
+ # ========================================================================= #
162
+ def delete(i)
163
+ i = i.dup if i.frozen?
164
+ i.strip!
165
+ if (rds(i) == '/')
166
+ ewarn 'We can never delete /'
167
+ else
168
+ File.delete(i)
169
+ end
170
+ end; alias remove delete # === remove
171
+
172
+ # ========================================================================= #
173
+ # === be_verbose?
174
+ # ========================================================================= #
175
+ def be_verbose?
176
+ @be_verbose
177
+ end
178
+
179
+ # ========================================================================= #
180
+ # === rds
181
+ # ========================================================================= #
182
+ def rds(i)
183
+ i.squeeze('/')
184
+ end
185
+
186
+ # ========================================================================= #
187
+ # === set_new_location
188
+ # ========================================================================= #
189
+ def set_new_location(i = '')
190
+ i = i.to_s.dup
191
+ i = rds(i)
192
+ @new_location = i
193
+ end; alias set_new_target set_new_location # === set_new_target
194
+
195
+ # ========================================================================= #
196
+ # === old?
197
+ # ========================================================================= #
198
+ def old?
199
+ @existing_location
200
+ end; alias existing? old? # === existing?
201
+ alias old_target? old? # === old_target?
202
+ alias from? old? # === from?
203
+
204
+ # ========================================================================= #
205
+ # === new?
206
+ # ========================================================================= #
207
+ def new?
208
+ @new_location
209
+ end; alias new_target? new? # === new_target?
210
+ alias to? new? # === to?
211
+
212
+ # ========================================================================= #
213
+ # === do_symlink
214
+ #
215
+ # This is the actual method that will perform the symlink-operation in
216
+ # question.
217
+ # ========================================================================= #
218
+ def do_symlink(
219
+ be_verbose = be_verbose?
220
+ )
221
+ new_target = new_target?
222
+ old_target = old_target?
223
+ # ======================================================================= #
224
+ # We must first check whether the target at new? exists or whether
225
+ # it does not.
226
+ # ======================================================================= #
227
+ if File.exist? new_target
228
+ # ===================================================================== #
229
+ # === Append a '/' if necessary
230
+ # ===================================================================== #
231
+ if File.directory?(new_target) and File.directory?(old_target) and
232
+ !old_target.end_with?('/')
233
+ set_old_target("#{old_target}/")
234
+ old_target = old_target?
235
+ end
236
+ old_target = old_target.dup
237
+ # if File.directory?(new_target) and File.directory?(old_target) and
238
+ # !( File.basename(new_target) == File.basename(old_target) )
239
+ # # =================================================================== #
240
+ # # This is specifically used to change
241
+ # # /home/Programs/Htslib/1.12/include/htslib/ and
242
+ # # /usr/include/ into /usr/include/htslib/.
243
+ # # =================================================================== #
244
+ # new_target << rds("#{File.basename(old_target)}")
245
+ # end
246
+ #^^^ this does not work correctly... in April 2021.
247
+ if File.directory?(new_target) and File.file?(old_target) # Silent renaming then.
248
+ _ = new_target+File.basename(old_target)
249
+ set_new_target(_)
250
+ end
251
+ if File.symlink? new_target
252
+ delete(new_target)
253
+ end
254
+ end
255
+ if be_verbose
256
+ opnn if use_opn?
257
+ e "Symlinking #{sfile(existing?)}#{rev} into #{sfile(new_target)}#{rev}."
258
+ end
259
+ begin
260
+ File.symlink(existing?, new_target)
261
+ rescue Errno::ENOENT => error # No such file or directory
262
+ opnn if use_opn?
263
+ e "#{rev}Can not symlink - no such file exists, "\
264
+ "at `#{sfile(new_target)}#{rev}`."
265
+ pp error
266
+ rescue Errno::EEXIST => error # The file does not exist.
267
+ opnn if use_opn?
268
+ e "Can not symlink - the file at `#{sfile(new_target)}#{rev}` already exists."
269
+ pp error
270
+ end
271
+ end
272
+
273
+ # ========================================================================= #
274
+ # === do_not_use_opn
275
+ # ========================================================================= #
276
+ def do_not_use_opn
277
+ @use_opn = false
278
+ end; alias disable_opn do_not_use_opn # === disable_opn
279
+
280
+ # ========================================================================= #
281
+ # === use_opn?
282
+ # ========================================================================= #
283
+ def use_opn?
284
+ @use_opn
285
+ end
286
+
287
+ # ========================================================================= #
288
+ # === namespace?
289
+ # ========================================================================= #
290
+ def namespace?
291
+ @namespace
292
+ end
293
+
294
+ # ========================================================================= #
295
+ # === sfile
296
+ # ========================================================================= #
297
+ def sfile(i)
298
+ return Colours.sfile(i) if use_colours?
299
+ return i
300
+ end
301
+
302
+ # ========================================================================= #
303
+ # === sdir
304
+ # ========================================================================= #
305
+ def sdir(i)
306
+ return Colours.sdir(i) if use_colours?
307
+ return i
308
+ end
309
+
310
+ # ========================================================================= #
311
+ # === opnn
312
+ # ========================================================================= #
313
+ def opnn
314
+ Opn.opn(
315
+ namespace: @namespace,
316
+ use_colours: use_colours?
317
+ )
318
+ end
319
+
320
+ # ========================================================================= #
321
+ # === rev
322
+ # ========================================================================= #
323
+ def rev
324
+ ::Colours.rev
325
+ end
326
+
327
+ # ========================================================================= #
328
+ # === run (run tag)
329
+ # ========================================================================= #
330
+ def run
331
+ do_symlink
332
+ end
333
+
334
+ # ========================================================================= #
335
+ # === Symlink[]
336
+ # ========================================================================= #
337
+ def self.[](old, new)
338
+ new(old, new)
339
+ end
340
+
341
+ end
342
+
343
+ if __FILE__ == $PROGRAM_NAME
344
+ Symlink.new(ARGV.first, ARGV[1])
345
+ end # rubysymlink /Depot/j/foo.mp3 /Depot/j/bar.mp3
@@ -0,0 +1,17 @@
1
+ #!/usr/bin/ruby -w
2
+ # Encoding: UTF-8
3
+ # frozen_string_literal: true
4
+ # =========================================================================== #
5
+ class Symlink
6
+
7
+ # ========================================================================= #
8
+ # === VERSION
9
+ # ========================================================================= #
10
+ VERSION = '0.0.29'
11
+
12
+ # ========================================================================= #
13
+ # === LAST_UPDATE
14
+ # ========================================================================= #
15
+ LAST_UPDATE = '17.02.2024'
16
+
17
+ end
data/lib/symlink.rb ADDED
@@ -0,0 +1 @@
1
+ require 'symlink/symlink.rb'
data/symlink.gemspec ADDED
@@ -0,0 +1,43 @@
1
+ # =========================================================================== #
2
+ # Gemspec for Project Symlink.
3
+ # =========================================================================== #
4
+ require 'symlink/version/version.rb'
5
+ require 'roebe'
6
+
7
+ Gem::Specification.new { |s|
8
+
9
+ s.name = 'symlink'
10
+ s.version = Symlink::VERSION
11
+ s.date = Time.now.strftime('%Y-%m-%d')
12
+
13
+ DESCRIPTION = <<-EOF
14
+
15
+ This library is called symlink. It can be used to symlink
16
+ files or directories, from within ruby.
17
+
18
+ General syntax is:
19
+
20
+ Symlink.new(from, to)
21
+
22
+ EOF
23
+
24
+ s.summary = DESCRIPTION
25
+ s.description = DESCRIPTION
26
+
27
+ s.authors = ['Robert A. Heiler']
28
+ s.email = Roebe.email?
29
+ s.files = Dir['**/*']
30
+
31
+ s.license = 'MIT'
32
+
33
+ s.required_ruby_version = '>= '+Roebe.third_most_stable_version_of_ruby
34
+ s.required_rubygems_version = '>= '+Gem::VERSION
35
+ s.rubygems_version = '>= '+Gem::VERSION
36
+
37
+ # ========================================================================= #
38
+ # Dependencies for the project:
39
+ # ========================================================================= #
40
+ s.add_dependency 'colours'
41
+ s.add_dependency 'opn'
42
+
43
+ }
@@ -0,0 +1,10 @@
1
+ #!/usr/bin/ruby -w
2
+ # Encoding: UTF-8
3
+ # frozen_string_literal: true
4
+ # =========================================================================== #
5
+ require 'symlink'
6
+ require 'colours/autoinclude'
7
+ Symlink[
8
+ '/Programs/Applewmproto/1.4.2/',
9
+ '/Programs/Applewmproto/Current'
10
+ ] # $RSRC/symlink/test/testing_symlink.rb
metadata ADDED
@@ -0,0 +1,86 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: symlink
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.29
5
+ platform: ruby
6
+ authors:
7
+ - Robert A. Heiler
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2024-02-17 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: colours
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: opn
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ description: |2+
42
+
43
+ This library is called symlink. It can be used to symlink
44
+ files or directories, from within ruby.
45
+
46
+ General syntax is:
47
+
48
+ Symlink.new(from, to)
49
+
50
+ email: shevy@inbox.lt
51
+ executables: []
52
+ extensions: []
53
+ extra_rdoc_files: []
54
+ files:
55
+ - lib/symlink.rb
56
+ - lib/symlink/constants.rb
57
+ - lib/symlink/symlink.rb
58
+ - lib/symlink/version/version.rb
59
+ - symlink.gemspec
60
+ - test/testing_symlink.rb
61
+ homepage:
62
+ licenses:
63
+ - MIT
64
+ metadata: {}
65
+ post_install_message:
66
+ rdoc_options: []
67
+ require_paths:
68
+ - lib
69
+ required_ruby_version: !ruby/object:Gem::Requirement
70
+ requirements:
71
+ - - ">="
72
+ - !ruby/object:Gem::Version
73
+ version: 2.7.6
74
+ required_rubygems_version: !ruby/object:Gem::Requirement
75
+ requirements:
76
+ - - ">="
77
+ - !ruby/object:Gem::Version
78
+ version: 3.5.3
79
+ requirements: []
80
+ rubygems_version: 3.5.3
81
+ signing_key:
82
+ specification_version: 4
83
+ summary: 'This library is called symlink. It can be used to symlink files or directories,
84
+ from within ruby. General syntax is: Symlink.new(from, to)'
85
+ test_files: []
86
+ ...