totarxz 0.0.21

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: 041d128c94b8979ede5d42c7236036a7c1746207e8259acb83a2026f958f401e
4
+ data.tar.gz: 06b353729028faf46806e9e999eddf1c5f558fbff65df693f2e1b641014be418
5
+ SHA512:
6
+ metadata.gz: 57249625798e98c90aa9daed9ec8ad176d25e8bd6fa64be3ad688e3b8a7aab11b31f7c8b6b2d6f947b7eec98f799499ec89dd9902779ff0b1e33550286e8bc06
7
+ data.tar.gz: 2fc30705629fdf40c525252e36a7bc25712ad3b30a8e848432b839d57aac38f4b0b7eb7a5409cb2b80abb735a2c14761ed13e69e69fbb0aea950910fbce9e2fb
data/bin/totarxz ADDED
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/ruby -w
2
+ # Encoding: UTF-8
3
+ # frozen_string_literal: true
4
+ # =========================================================================== #
5
+ require 'totarxz/totarxz.rb'
6
+
7
+ ToTarXz.new(ARGV) { :be_silent }
@@ -0,0 +1,26 @@
1
+ #!/usr/bin/ruby -w
2
+ # Encoding: UTF-8
3
+ # frozen_string_literal: true
4
+ # =========================================================================== #
5
+ # require 'totarxz/constants.rb'
6
+ # =========================================================================== #
7
+ class ToTarXz # === Totarxz.new
8
+
9
+ # ========================================================================= #
10
+ # === TAR_XZ_EXTENSION
11
+ # ========================================================================= #
12
+ TAR_XZ_EXTENSION = '.tar.xz'
13
+
14
+ # ========================================================================= #
15
+ # === TAR_BZ2_EXTENSION
16
+ # ========================================================================= #
17
+ TAR_BZ2_EXTENSION = '.tar.bz2'
18
+
19
+ # ========================================================================= #
20
+ # === BE_VERBOSE
21
+ #
22
+ # Whether to be verbose by default or whether we will not be verbose.
23
+ # ========================================================================= #
24
+ BE_VERBOSE = true
25
+
26
+ end
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/ruby -w
2
+ # Encoding: UTF-8
3
+ # frozen_string_literal: true
4
+ # =========================================================================== #
5
+ require 'fileutils'
6
+ require 'opn'
7
+ require 'colours'
@@ -0,0 +1,347 @@
1
+ #!/usr/bin/ruby -w
2
+ # Encoding: UTF-8
3
+ # frozen_string_literal: true
4
+ # =========================================================================== #
5
+ # === ToTarXz
6
+ #
7
+ # This class will essentially just create a .tar.xz package.
8
+ #
9
+ # The normal command for this is on Linux is:
10
+ #
11
+ # tar cfJ <archive.tar.xz> <files>
12
+ # tar cfJ rbt-04.09.2015.tar.xz rbt-04.09.2015/
13
+ #
14
+ # =========================================================================== #
15
+ # require 'totarxz/totarxz.rb'
16
+ # =========================================================================== #
17
+ class ToTarXz # === Totarxz
18
+
19
+ require 'totarxz/requires/base_requires.rb'
20
+ require 'totarxz/version/version.rb'
21
+ require 'totarxz/constants.rb'
22
+
23
+ include Colours
24
+
25
+ # ========================================================================= #
26
+ # === initialize
27
+ #
28
+ # The first argument is the target to become a .tar.xz archive.
29
+ # ========================================================================= #
30
+ def initialize(
31
+ package_this_target = nil,
32
+ be_verbose = BE_VERBOSE,
33
+ run_already = true,
34
+ &block
35
+ )
36
+ @be_verbose = be_verbose # default
37
+ reset # This must come after @be_verbose was set.
38
+ be_verbose if be_verbose # Be silent not before calling sanitize_data().
39
+ set_package_this_target(
40
+ package_this_target
41
+ )
42
+ case run_already
43
+ # ======================================================================= #
44
+ # === --help
45
+ # ======================================================================= #
46
+ when /^-?-?help$/i
47
+ show_help_then_exit
48
+ # ======================================================================= #
49
+ # === --date
50
+ # ======================================================================= #
51
+ when /^-?-?date$/i,
52
+ 'TODAY','WITH_DATE'
53
+ @repackage_archive_to_todays_date = true
54
+ run_already = true
55
+ end
56
+ # ======================================================================= #
57
+ # === Handle blocks next
58
+ #
59
+ # Intercept blocks here. Handle :be_verbose as argument, but also
60
+ # certain keys in a Hash, since as of June 2020.
61
+ # ======================================================================= #
62
+ if block_given?
63
+ yielded = yield
64
+ case yielded
65
+ when :be_silent
66
+ @be_verbose = false
67
+ when :be_verbose
68
+ @be_verbose = true
69
+ else
70
+ if yielded.is_a? Hash
71
+ # ================================================================= #
72
+ # === :use_this_archive_name => "htop-2.2.0"
73
+ # ================================================================= #
74
+ if yielded.has_key? :use_this_archive_name
75
+ set_tar_xz_name(yielded.delete(:use_this_archive_name))
76
+ end
77
+ end
78
+ end
79
+ end
80
+ run if run_already
81
+ end
82
+
83
+ # ========================================================================= #
84
+ # === reset (reset tag)
85
+ # ========================================================================= #
86
+ def reset
87
+ if @be_verbose
88
+ @cmd = 'tar cJvf ' # v stands for verbosity here.
89
+ else
90
+ @cmd = 'tar cJf ' # v stands for verbosity here.
91
+ end
92
+ # ======================================================================= #
93
+ # === @cmd
94
+ # ======================================================================= #
95
+ @cmd = @cmd.dup
96
+ # ======================================================================= #
97
+ # === @archive_type
98
+ # ======================================================================= #
99
+ @archive_type = '.tar.xz'
100
+ # ======================================================================= #
101
+ # === @repackage_archive_to_todays_date
102
+ # ======================================================================= #
103
+ @repackage_archive_to_todays_date = false
104
+ # ======================================================================= #
105
+ # === @orig_stdout
106
+ # ======================================================================= #
107
+ @orig_stdout = nil
108
+ end
109
+
110
+ # ========================================================================= #
111
+ # === be_silent?
112
+ # ========================================================================= #
113
+ def be_silent?
114
+ !@be_verbose
115
+ end
116
+
117
+ # ========================================================================= #
118
+ # === be_verbose?
119
+ # ========================================================================= #
120
+ def be_verbose?
121
+ @be_verbose
122
+ end
123
+
124
+ # ========================================================================= #
125
+ # === show_help
126
+ # ========================================================================= #
127
+ def show_help
128
+ e 'To package up with the date, use DATE or TODAY.'
129
+ end
130
+
131
+ # ========================================================================= #
132
+ # === show_help_then_exit
133
+ # ========================================================================= #
134
+ def show_help_then_exit
135
+ show_help
136
+ exit
137
+ end
138
+
139
+ # ========================================================================= #
140
+ # === abort_then_exit
141
+ # ========================================================================= #
142
+ def abort_then_exit
143
+ abort "class ToTarXz: No file was provided or could be found. Please \n"\
144
+ "supply a valid argument (an existing file) and try again."
145
+ exit
146
+ end
147
+
148
+ # ========================================================================= #
149
+ # === set_package_this_target
150
+ #
151
+ # This method will be called from within initialize().
152
+ # ========================================================================= #
153
+ def set_package_this_target(
154
+ i = nil
155
+ )
156
+ if i.is_a? Array and !i.empty?
157
+ i = i.join(' ').strip
158
+ end
159
+ if i and i.end_with?('*')
160
+ # In this case continue.
161
+ elsif i.nil? or !File.exist?(i.to_s)
162
+ abort_then_exit
163
+ end
164
+ case i
165
+ # ======================================================================= #
166
+ # === --help
167
+ # ======================================================================= #
168
+ when /^-?-?help$/i
169
+ show_help_then_exit
170
+ end
171
+ i = i.to_s.dup
172
+ unless i.end_with? '*'
173
+ i << '/' unless i.end_with? '/'
174
+ end
175
+ i.delete_suffix!('.tar.xz') if i.include?('.tar.xz')
176
+ i.delete_suffix!('.tar.bz2') if i.include?('.tar.bz2')
177
+ @package_this_target = i
178
+ # ======================================================================= #
179
+ # Now we can determine the .tar.xz name.
180
+ # ======================================================================= #
181
+ determine_tar_xz_name
182
+ end; alias set_archive_filename set_package_this_target # === set_archive_filename
183
+ alias directory= set_package_this_target # === directory=
184
+ alias extract_to_this_directory= set_package_this_target # === extract_to_this_directory=
185
+
186
+ # ========================================================================= #
187
+ # === silence
188
+ # ========================================================================= #
189
+ def silence
190
+ @be_verbose = false
191
+ @orig_stdout = $stdout # Be silent.
192
+ $stdout = File.new('/dev/null', 'w')
193
+ end
194
+
195
+ # ========================================================================= #
196
+ # === extract_to_this_directory?
197
+ # ========================================================================= #
198
+ def extract_to_this_directory?
199
+ @tar_xz_name
200
+ end; alias directory? extract_to_this_directory? # === directory?
201
+ alias dir? extract_to_this_directory? # === dir?
202
+ alias tar_xz_name? extract_to_this_directory? # === tar_xz_name?
203
+ alias archive_location? extract_to_this_directory? # === archive_location?
204
+ alias result? extract_to_this_directory? # === result?
205
+
206
+ # ========================================================================= #
207
+ # === location?
208
+ # ========================================================================= #
209
+ def location?
210
+ determine_tar_xz_name # Yes, we will determine anew.
211
+ end
212
+
213
+ # ========================================================================= #
214
+ # === package_this_target?
215
+ # ========================================================================= #
216
+ def package_this_target?
217
+ @package_this_target
218
+ end; alias input? package_this_target? # === input?
219
+ alias archive_filename? package_this_target? # === archive_filename?
220
+ alias archive? package_this_target? # === archive?
221
+
222
+ # ========================================================================= #
223
+ # === mv
224
+ # ========================================================================= #
225
+ def mv(old, new)
226
+ FileUtils.mv(old, new)
227
+ end
228
+
229
+ # ========================================================================= #
230
+ # === today?
231
+ # ========================================================================= #
232
+ def today?
233
+ Time.now.strftime '%d.%m.%Y'
234
+ end
235
+
236
+ # ========================================================================= #
237
+ # === set_cmd
238
+ # ========================================================================= #
239
+ def set_cmd(i)
240
+ unless i.end_with? ' '
241
+ i = i.dup if i.frozen?
242
+ i << ' '
243
+ end
244
+ @cmd = i
245
+ end
246
+
247
+ # ========================================================================= #
248
+ # === run_cmd
249
+ # ========================================================================= #
250
+ def run_cmd
251
+ e @cmd
252
+ system @cmd
253
+ # ======================================================================= #
254
+ # Next, we will apply a mv-action if we repackage to another name.
255
+ # ======================================================================= #
256
+ if rename?
257
+ new_name = File.basename(archive?).sub(/\.tar\.xz$/, '')+
258
+ '-'+
259
+ today?+
260
+ @archive_type
261
+ opn; e 'Next renaming the archive to `'+sfancy(new_name)+'`.'
262
+ mv(archive?, new_name)
263
+ end
264
+ if @orig_stdout
265
+ $stdout = @orig_stdout unless be_verbose? # Restore stdout again.
266
+ end
267
+ end; alias create_tarxz_package run_cmd # === create_tarxz
268
+
269
+ # ========================================================================= #
270
+ # === create_tarxz_package
271
+ # ========================================================================= #
272
+ def create_tarxz_package
273
+ build_cmd_string
274
+ run_cmd
275
+ end
276
+
277
+ # ========================================================================= #
278
+ # === rename?
279
+ #
280
+ # Whether we will rename our archive or whether we will not.
281
+ # ========================================================================= #
282
+ def rename?
283
+ @repackage_archive_to_todays_date
284
+ end
285
+
286
+ # ========================================================================= #
287
+ # === determine_tar_xz_name
288
+ #
289
+ # Note that this method will always append .tar.xz to the name. This
290
+ # is fine for .tar.xz archives but not for .tar.bz2 archives.
291
+ # ========================================================================= #
292
+ def determine_tar_xz_name(
293
+ i = input?.delete('/')+
294
+ TAR_XZ_EXTENSION
295
+ )
296
+ @tar_xz_name = i
297
+ end; alias determine_the_name_of_the_archive determine_tar_xz_name # === determine_the_name_of_the_archive
298
+
299
+ # ========================================================================= #
300
+ # === set_tar_xz_name
301
+ # ========================================================================= #
302
+ def set_tar_xz_name(i)
303
+ if i.frozen?
304
+ i = i.dup
305
+ end
306
+ i << TAR_XZ_EXTENSION unless i.end_with? TAR_XZ_EXTENSION
307
+ @tar_xz_name = i
308
+ end
309
+
310
+ # ========================================================================= #
311
+ # === build_cmd_string
312
+ # ========================================================================= #
313
+ def build_cmd_string
314
+ @cmd << @tar_xz_name << ' ' << input? # Simply append.
315
+ end
316
+
317
+ # ========================================================================= #
318
+ # === run (run tag)
319
+ # ========================================================================= #
320
+ def run
321
+ create_tarxz_package
322
+ end
323
+
324
+ # ========================================================================= #
325
+ # === ToTarXz[]
326
+ # ========================================================================= #
327
+ def self.[](i)
328
+ new(i)
329
+ end
330
+
331
+ end
332
+
333
+ if __FILE__ == $PROGRAM_NAME
334
+ require 'opn'
335
+ require 'colours/colours_e_autoinclude.rb'
336
+ if ARGV[1]
337
+ if ARGV[1].include?('TODAY') or ARGV[1].include?('DATE') # Handle TODAY and DATE differently.
338
+ ToTarXz.new(ARGV.first, ARGV[1])
339
+ end
340
+ else
341
+ ARGV.each {|entry|
342
+ _ = ToTarXz.new(entry) { :be_silent }
343
+ Opn.opn(namespace: ToTarXz.to_s)
344
+ puts 'You can now find everything at: '+simp(_.archive_location?)
345
+ }
346
+ end
347
+ end # tottarxz GEAS TODAY
@@ -0,0 +1,19 @@
1
+ #!/usr/bin/ruby -w
2
+ # Encoding: UTF-8
3
+ # frozen_string_literal: true
4
+ # =========================================================================== #
5
+ # require 'totarxz/version/version.rb'
6
+ # =========================================================================== #
7
+ class ToTarXz
8
+
9
+ # ========================================================================= #
10
+ # === ToTarXz
11
+ # ========================================================================= #
12
+ VERSION = '0.0.21'
13
+
14
+ # ========================================================================= #
15
+ # === LAST_UPDATE
16
+ # ========================================================================= #
17
+ LAST_UPDATE = '16.03.2024'
18
+
19
+ end
data/lib/totarxz.rb ADDED
@@ -0,0 +1 @@
1
+ require 'totarxz/totarxz.rb'
@@ -0,0 +1,29 @@
1
+ #!/usr/bin/ruby -w
2
+ # Encoding: UTF-8
3
+ # frozen_string_literal: true
4
+ # =========================================================================== #
5
+ require 'fileutils'
6
+ require 'cliner'
7
+ require 'totarxz'
8
+ require 'colours/colours_e_autoinclude.rb'
9
+ require 'extracter'
10
+
11
+ e "Now testing #{sfancy('class ToTarXz')}."
12
+ htop = '/Users/x/SRC/htop/htop-1.0.3.tar.xz'
13
+ target_dir = '/Depot/jjjj/'
14
+ FileUtils.cp(htop, target_dir)
15
+ Dir.chdir(target_dir)
16
+ target = target_dir+File.basename(htop)
17
+ e 'First extracting '+target+'.'
18
+ _ = Extracter.new target, Dir.pwd
19
+ pp Dir['*']
20
+ cliner
21
+ e sfancy(_.extracted_to?)
22
+ File.delete(target) # Kill the old archive.
23
+ e 'Now packaging up this here:'
24
+ e ' '+sfancy(target)
25
+ location = ToTarXz[target].location?
26
+ e 'It can now be found here:'
27
+ e
28
+ e ' '+sfancy(location)
29
+ e
data/totarxz.gemspec ADDED
@@ -0,0 +1,46 @@
1
+ # =========================================================================== #
2
+ # Gemspec for Project Totarxz.
3
+ # =========================================================================== #
4
+ require 'totarxz/version/version.rb'
5
+ require 'roebe'
6
+
7
+ Gem::Specification.new { |s|
8
+
9
+ s.name = 'totarxz'
10
+ s.version = ToTarXz::VERSION
11
+ s.date = Time.now.strftime('%Y-%m-%d')
12
+
13
+ s.summary = <<-EOF
14
+
15
+ This library is called totarxz. It will create a .tar.xz
16
+ file from the given input at hand.
17
+
18
+ EOF
19
+
20
+ s.description = <<-EOF
21
+
22
+ This library is called totarxz. It will create a .tar.xz
23
+ file from the given input at hand.
24
+
25
+ EOF
26
+
27
+ s.extra_rdoc_files = %w()
28
+
29
+ s.authors = ['Robert A. Heiler']
30
+ s.email = Roebe.email?
31
+ s.files = Dir['**/*']
32
+ s.license = 'GPL-2.0-only'
33
+ s.executables = Dir['bin/*'].map { |f| File.basename(f) }
34
+ s.homepage = 'https://rubygems.org/gems/totarxz'
35
+
36
+ s.required_ruby_version = '>= '+RUBY_VERSION
37
+ s.required_rubygems_version = '>= '+Gem::VERSION
38
+ s.rubygems_version = '>= '+Gem::VERSION
39
+
40
+ # ========================================================================= #
41
+ # Dependencies for the project:
42
+ # ========================================================================= #
43
+ s.add_dependency 'colours'
44
+ s.add_dependency 'opn'
45
+
46
+ }
metadata ADDED
@@ -0,0 +1,85 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: totarxz
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.21
5
+ platform: ruby
6
+ authors:
7
+ - Robert A. Heiler
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2024-03-16 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 totarxz. It will create a .tar.xz
44
+ file from the given input at hand.
45
+
46
+ email: shevy@inbox.lt
47
+ executables:
48
+ - totarxz
49
+ extensions: []
50
+ extra_rdoc_files: []
51
+ files:
52
+ - bin/totarxz
53
+ - lib/totarxz.rb
54
+ - lib/totarxz/constants.rb
55
+ - lib/totarxz/requires/base_requires.rb
56
+ - lib/totarxz/totarxz.rb
57
+ - lib/totarxz/version/version.rb
58
+ - test/testing_totarxz.rb
59
+ - totarxz.gemspec
60
+ homepage: https://rubygems.org/gems/totarxz
61
+ licenses:
62
+ - GPL-2.0-only
63
+ metadata: {}
64
+ post_install_message:
65
+ rdoc_options: []
66
+ require_paths:
67
+ - lib
68
+ required_ruby_version: !ruby/object:Gem::Requirement
69
+ requirements:
70
+ - - ">="
71
+ - !ruby/object:Gem::Version
72
+ version: 3.3.0
73
+ required_rubygems_version: !ruby/object:Gem::Requirement
74
+ requirements:
75
+ - - ">="
76
+ - !ruby/object:Gem::Version
77
+ version: 3.5.6
78
+ requirements: []
79
+ rubygems_version: 3.5.6
80
+ signing_key:
81
+ specification_version: 4
82
+ summary: This library is called totarxz. It will create a .tar.xz file from the given
83
+ input at hand.
84
+ test_files: []
85
+ ...