repackage 1.0.30

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: 4fdc05b46d4354b945db15f713602e1e3440dad372a828edc0f8815eb274787e
4
+ data.tar.gz: 55f1972e66f6edb4867c9aabd9d60140651010140a50fcbb13d32158c4e8c285
5
+ SHA512:
6
+ metadata.gz: 8e1321698dfb40877514a0569dc87f10f2375ff0d31e0d0e65f55afc9b714d14f44c72ac40bdf2530c3b898b5a90664f5967c9cb6edc08cc003a07400bdf78de
7
+ data.tar.gz: 9f83ff0a55d551a6d517da53aec3411cc4fea1abad1975ac2f07583e28a7886ad856a91e6107f2281c013ad668db1c7d67997e3ded3bdcc7365bef46f91d2047
data/bin/repackager ADDED
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/ruby -w
2
+ # Encoding: UTF-8
3
+ # frozen_string_literal: true
4
+ # =========================================================================== #
5
+ require 'repackage'
6
+
7
+ Repackage.new(ARGV)
@@ -0,0 +1,768 @@
1
+ #!/usr/bin/ruby -w
2
+ # Encoding: UTF-8
3
+ # frozen_string_literal: true
4
+ # =========================================================================== #
5
+ # === Repackage
6
+ #
7
+ # The purpose of this class is to repackage a .tar.gz file into
8
+ # a .tar.bz2 file or into another format. Thus, the ideal input
9
+ # are files such as "foobar-1.2.3.tar.gz" or something similar
10
+ # to this.
11
+ #
12
+ # The default target format is to .tar.xz or more accurately,
13
+ # to whatever value is specified via the constant
14
+ # DEFAULT_TARGET_FORMAT_TYPE.
15
+ #
16
+ # Historically this class was first created at the end of August 2005,
17
+ # so it used to be a fairly "old" class. Over the years it has been
18
+ # extended to allow for more flexibility. In June 2021 it was re-written
19
+ # from scratch, primarily to make use of @internal_hash rather than a
20
+ # multitude of different instance variables; this coincided with
21
+ # making this functionality available via sinatra as well.
22
+ #
23
+ # Usage example:
24
+ #
25
+ # Repackage.new(ARGV)
26
+ #
27
+ # =========================================================================== #
28
+ # require 'repackage/class/repackage.rb'
29
+ # =========================================================================== #
30
+ class Repackage
31
+
32
+ require 'fileutils'
33
+ require 'repackage/version/version.rb'
34
+
35
+ require 'esystem/method'
36
+
37
+ require 'remove_file_suffix'
38
+ require 'totarxz'
39
+
40
+ begin
41
+ require 'colours'
42
+ include Colours
43
+ rescue LoadError; end
44
+
45
+ begin
46
+ require 'opn'
47
+ rescue LoadError; end
48
+
49
+ begin
50
+ require 'extracter'
51
+ rescue LoadError; end
52
+
53
+ # ========================================================================= #
54
+ # === NAMESPACE
55
+ # ========================================================================= #
56
+ NAMESPACE = inspect
57
+
58
+ # ========================================================================= #
59
+ # === LAST_DOWNLOADED_FILE
60
+ # ========================================================================= #
61
+ begin
62
+ require 'wget'
63
+ LAST_DOWNLOADED_FILE = Wget.download_to?
64
+ rescue LoadError
65
+ LAST_DOWNLOADED_FILE = ENV['HOME'].to_s+'/LAST_DOWNLOADED_FILE.md'
66
+ end
67
+
68
+ # ========================================================================= #
69
+ # === DEFAULT_TARGET_FORMAT_TYPE
70
+ #
71
+ # The target format comes here.
72
+ # ========================================================================= #
73
+ DEFAULT_TARGET_FORMAT_TYPE = '.tar.xz' # '.tar.bz2'
74
+
75
+ # ========================================================================= #
76
+ # === MY_TEMP
77
+ # ========================================================================= #
78
+ if ENV['MY_TEMP']
79
+ EXTRACT_TO = ENV['MY_TEMP'].to_s+'/' # Denote where to extract the stuff to.
80
+ else
81
+ EXTRACT_TO = '/tmp/'
82
+ end
83
+
84
+ # ========================================================================= #
85
+ # === CREATE_TAR_XZ
86
+ #
87
+ # This is the command that is used when a .tar.xz file is to be created.
88
+ # ========================================================================= #
89
+ CREATE_TAR_XZ = 'tar -vcJf'
90
+
91
+ # ========================================================================= #
92
+ # === CREATE_TAR_GZ
93
+ #
94
+ # Command to create a .tar.gz archive.
95
+ # ========================================================================= #
96
+ CREATE_TAR_GZ = 'tar cfvz'
97
+
98
+ # ========================================================================= #
99
+ # === CREATE_TAR_BZ2
100
+ #
101
+ # Command to create a .tar.bz2 archive.
102
+ # ========================================================================= #
103
+ CREATE_TAR_BZ2 = 'tar cfvj'
104
+
105
+ # ========================================================================= #
106
+ # === CREATE_ZIP
107
+ #
108
+ # Command to create a .zip archive.
109
+ # ========================================================================= #
110
+ CREATE_ZIP = 'zip -r '
111
+
112
+ # ========================================================================= #
113
+ # === SHALL_WE_DELETE_THE_OLD_ARCHIVE
114
+ #
115
+ # Remove the old source if this constant is true. Since as of June 2021
116
+ # this defaults to false, except in certain conditions met on my home
117
+ # setup.
118
+ # ========================================================================= #
119
+ SHALL_WE_DELETE_THE_OLD_ARCHIVE = false
120
+
121
+ # ========================================================================= #
122
+ # === initialize
123
+ #
124
+ # The first argument given to this class must be the name of (or path
125
+ # to) a locally existing file, such as "foobar-1.0.tar.gz".
126
+ # ========================================================================= #
127
+ def initialize(
128
+ commandline_arguments = nil,
129
+ run_already = true
130
+ )
131
+ register_sigint
132
+ reset
133
+ set_commandline_arguments(
134
+ commandline_arguments
135
+ )
136
+ # ========================================================================= #
137
+ # === Handle given blocks next
138
+ # ========================================================================= #
139
+ if block_given?
140
+ yielded = yield
141
+ case yielded
142
+ # ===================================================================== #
143
+ # === :do_not_delete_the_old_source
144
+ # ===================================================================== #
145
+ when :do_not_delete_the_old_source
146
+ set_shall_we_delete_old_source(false)
147
+ # ===================================================================== #
148
+ # === :run_already
149
+ # ===================================================================== #
150
+ when :run_already
151
+ run_already = true
152
+ end
153
+ end
154
+ run if run_already
155
+ end
156
+
157
+ # ========================================================================= #
158
+ # === reset (reset tag)
159
+ # ========================================================================= #
160
+ def reset
161
+ # ========================================================================= #
162
+ # === @internal_hash
163
+ # ========================================================================= #
164
+ @internal_hash = {}
165
+ set_start_dir
166
+ # ========================================================================= #
167
+ # === :repackage_to_this_format
168
+ # ========================================================================= #
169
+ set_repackage_to_this_format(DEFAULT_TARGET_FORMAT_TYPE)
170
+ # ========================================================================= #
171
+ # === :the_new_file_is_at
172
+ #
173
+ # This entry will keep track at which new location the file can be
174
+ # found.
175
+ # ========================================================================= #
176
+ @internal_hash[:the_new_file_is_at] = nil
177
+ # ========================================================================= #
178
+ # === :file_size
179
+ # ========================================================================= #
180
+ @internal_hash[:file_size] = 0
181
+ set_shall_we_delete_the_old_archive(:default)
182
+ set_extract_to(:default)
183
+ end
184
+
185
+ # ========================================================================= #
186
+ # === determine_file_size
187
+ # ========================================================================= #
188
+ def determine_file_size(
189
+ i = filename?
190
+ )
191
+ if i and File.exist?(i)
192
+ @internal_hash[:file_size] = File.stat(i).size? # Obtain some information.
193
+ end
194
+ end
195
+
196
+ # ========================================================================= #
197
+ # === shall_we_delete_the_old_archive?
198
+ # ========================================================================= #
199
+ def shall_we_delete_the_old_archive?
200
+ @internal_hash[:shall_we_delete_the_old_archive]
201
+ end
202
+
203
+ # ========================================================================= #
204
+ # === set_repackage_to_this_format
205
+ #
206
+ # We will repackage to this format here.
207
+ # ========================================================================= #
208
+ def set_repackage_to_this_format(
209
+ i = DEFAULT_TARGET_FORMAT_TYPE
210
+ )
211
+ i = i.downcase if i # Only want it downcased.
212
+ case i # case tag
213
+ # ========================================================================= #
214
+ # === .tar.xz
215
+ # ========================================================================= #
216
+ when 'xz',
217
+ 'tar.xz'
218
+ i = '.tar.xz'
219
+ # ========================================================================= #
220
+ # === .tar.bz2
221
+ # ========================================================================= #
222
+ when 'bz2',
223
+ '.tar.bz2'
224
+ i = '.tar.bz2'
225
+ # ========================================================================= #
226
+ # === .tar.gz
227
+ # ========================================================================= #
228
+ when 'targz',
229
+ 'gz',
230
+ 'tar.gz'
231
+ i = '.tar.gz'
232
+ # ========================================================================= #
233
+ # === nil
234
+ # ========================================================================= #
235
+ when nil # Assume a default here.
236
+ i = DEFAULT_TARGET_FORMAT_TYPE
237
+ else # else tag
238
+ # warn 'Did not find registered format type.'
239
+ end
240
+ @internal_hash[:repackage_to_this_format] = i
241
+ end; alias set_target_format_type set_repackage_to_this_format # === set_target_format_type
242
+ alias format= set_repackage_to_this_format # === format=
243
+
244
+ # ========================================================================= #
245
+ # === repackage_to_which_format?
246
+ # ========================================================================= #
247
+ def repackage_to_which_format?
248
+ @internal_hash[:repackage_to_this_format]
249
+ end; alias format? repackage_to_which_format? # === format?
250
+ alias target_format? repackage_to_which_format? # === target_format?
251
+ alias target_format_type? repackage_to_which_format? # === target_format_type?
252
+
253
+ # ========================================================================= #
254
+ # === return_pwd
255
+ # ========================================================================= #
256
+ def return_pwd
257
+ "#{Dir.pwd}/".squeeze('/')
258
+ end
259
+
260
+ # ========================================================================= #
261
+ # === register_sigint
262
+ # ========================================================================= #
263
+ def register_sigint
264
+ Signal.trap('SIGINT') { exit }
265
+ end
266
+
267
+ # ========================================================================= #
268
+ # === set_commandline_arguments
269
+ # ========================================================================= #
270
+ def set_commandline_arguments(i = '')
271
+ i = [i].flatten.compact
272
+ @commandline_arguments = i
273
+ end
274
+
275
+ # ========================================================================= #
276
+ # === commandline_arguments?
277
+ # ========================================================================= #
278
+ def commandline_arguments?
279
+ @commandline_arguments
280
+ end
281
+
282
+ # ========================================================================= #
283
+ # === first_argument?
284
+ # ========================================================================= #
285
+ def first_argument?
286
+ @commandline_arguments.first
287
+ end; alias first? first_argument? # === first?
288
+
289
+ # ========================================================================= #
290
+ # === determine_relevant_entries
291
+ # ========================================================================= #
292
+ def determine_relevant_entries
293
+ set_repackage_this_file(first?)
294
+ second_argument = @commandline_arguments[1]
295
+ if second_argument
296
+ # ===================================================================== #
297
+ # Let the user determine the format type:
298
+ # ===================================================================== #
299
+ set_target_format_type(
300
+ second_argument
301
+ )
302
+ end
303
+ end
304
+
305
+ # ========================================================================= #
306
+ # === real_file_name
307
+ #
308
+ # This method will return the filename of this class.
309
+ # ========================================================================= #
310
+ def real_file_name
311
+ return File.basename(__FILE__)+': '
312
+ end
313
+
314
+ # ========================================================================= #
315
+ # === remove
316
+ #
317
+ # Remove a file or a directory with this method.
318
+ # ========================================================================= #
319
+ def remove(i)
320
+ if File.directory?(i)
321
+ FileUtils.rm_rf(i) unless i.strip == '/'
322
+ elsif File.file?(i)
323
+ File.delete(i)
324
+ end
325
+ end
326
+
327
+ # ========================================================================= #
328
+ # === cliner
329
+ # ========================================================================= #
330
+ def cliner
331
+ e ('=' * 80)
332
+ end
333
+
334
+ # ========================================================================= #
335
+ # === set_extract_to
336
+ #
337
+ # Set the @extract_to variable here.
338
+ # ========================================================================= #
339
+ def set_extract_to(i = EXTRACT_TO)
340
+ case i
341
+ when nil, :default
342
+ i = EXTRACT_TO
343
+ end
344
+ i = i.to_s.dup
345
+ i = '/tmp/' if i.empty? # Hardcoded in this case.
346
+ i << '/' unless i.end_with? '/' # A directory has a trailing /.
347
+ @internal_hash[:extract_to] = i
348
+ end
349
+
350
+ # ========================================================================= #
351
+ # === extract_to?
352
+ #
353
+ # Defaults to /home/Temp/ on my home system.
354
+ # ========================================================================= #
355
+ def extract_to?
356
+ @internal_hash[:extract_to]
357
+ end; alias extract_to extract_to? # === extract_to
358
+
359
+ # ========================================================================= #
360
+ # === set_repackage_this_file
361
+ # ========================================================================= #
362
+ def set_repackage_this_file(i = first?)
363
+ if i.is_a? Array
364
+ i = i.first
365
+ end
366
+ case i
367
+ when nil
368
+ # ===================================================================== #
369
+ # Since as of May 2013 we try to fetch a random file from a list.
370
+ # ===================================================================== #
371
+ _ = Dir['*'].reject {|entry| File.directory? entry}
372
+ i = _.first if _.size == 1 # if we only have one entry, continue here.
373
+ # ========================================================================= #
374
+ # === --last
375
+ # ========================================================================= #
376
+ when 'LAST','LAST_DOWNLOADED',
377
+ /^-?-?last/i,
378
+ '-l'
379
+ i = File.readlines(LAST_DOWNLOADED_FILE).first
380
+ # ===================================================================== #
381
+ # The format of the file has changed a bit. We have to check
382
+ # whether it includes a '#' character. If so then we discard
383
+ # all that comes after said '#' token.
384
+ # ===================================================================== #
385
+ if i.include? '#'
386
+ i = i[0..(i.index('#')-1)].strip
387
+ end
388
+ end
389
+ i = i.to_s.dup
390
+ if File.directory?(i) and !i.end_with?('/')
391
+ i << '/'
392
+ end
393
+ if i.nil? or i.empty?
394
+ raise 'Please provide a valid archive to repackage.'
395
+ end
396
+ determine_file_size if File.exist? i
397
+ @internal_hash[:repackage_this_file] = i
398
+ # ========================================================================= #
399
+ # === :original_directory_where_the_archive_was_kept
400
+ #
401
+ # This variant will always refer to the directory where the archive
402
+ # is situated in.
403
+ # ========================================================================= #
404
+ @internal_hash[:original_directory_where_the_archive_was_kept] = rds(
405
+ File.absolute_path(
406
+ File.dirname(i)
407
+ )+'/'
408
+ )
409
+ end; alias set_package set_repackage_this_file # === set_package
410
+
411
+ # ========================================================================= #
412
+ # === rds
413
+ # ========================================================================= #
414
+ def rds(i)
415
+ i.squeeze '/'
416
+ end
417
+
418
+ # ========================================================================= #
419
+ # === change_dir_to (cd tag)
420
+ # ========================================================================= #
421
+ def change_dir_to(
422
+ where_to = extract_to?
423
+ )
424
+ Dir.chdir(where_to)
425
+ end; alias cd change_dir_to # === cd
426
+
427
+ # ========================================================================= #
428
+ # === is_on_roebe?
429
+ # ========================================================================= #
430
+ def is_on_roebe?
431
+ ENV['IS_ROEBE'].to_s == '1'
432
+ end
433
+
434
+ # ========================================================================= #
435
+ # === set_start_dir
436
+ # ========================================================================= #
437
+ def set_start_dir(
438
+ i = return_pwd
439
+ )
440
+ @internal_hash[:start_dir] = i
441
+ end
442
+
443
+ # ========================================================================= #
444
+ # === remove_archive_from
445
+ # ========================================================================= #
446
+ def remove_archive_from(i)
447
+ i.delete_suffix('.xz').
448
+ delete_suffix('.gz').
449
+ delete_suffix('.bz2').
450
+ delete_suffix('.zip').
451
+ delete_suffix('.tar')
452
+ end; alias remove_extension remove_archive_from # === remove_extensions
453
+
454
+ # ========================================================================= #
455
+ # === set_the_new_file_is_at
456
+ # ========================================================================= #
457
+ def set_the_new_file_is_at(i)
458
+ @internal_hash[:the_new_file_is_at] = i
459
+ end; alias set_final_location set_the_new_file_is_at # === set_final_location
460
+
461
+ # ========================================================================= #
462
+ # === the_final_location_is_at?
463
+ # ========================================================================= #
464
+ def the_final_location_is_at?
465
+ @internal_hash[:the_new_file_is_at]
466
+ end; alias the_new_file_is_at? the_final_location_is_at? # === the_new_file_is_at?
467
+ alias the_file_is_where? the_final_location_is_at? # === the_file_is_where?
468
+
469
+ # ========================================================================= #
470
+ # === remove_extracted_data
471
+ # ========================================================================= #
472
+ def remove_extracted_data # remove the extracted archive again.
473
+ _ = "#{extract_to?}/#{remove_extension(filename?)}"
474
+ remove(_) if File.exist? _ # We remove a possibly-existing, extracted directory first.
475
+ end
476
+
477
+ # ========================================================================= #
478
+ # === internal_hash?
479
+ # ========================================================================= #
480
+ def internal_hash?
481
+ @internal_hash
482
+ end; alias hash? internal_hash? # === hash?
483
+
484
+ # ========================================================================= #
485
+ # === create_archive_from_this_directory (create tag)
486
+ # ========================================================================= #
487
+ def create_archive_from_this_directory(
488
+ this_directory,
489
+ repackage_to_this_format = repackage_to_which_format?
490
+ )
491
+ esystem "#{CREATE_TAR_XZ} #{this_directory}#{repackage_to_this_format} #{File.basename(this_directory)}"
492
+ end; alias package_this_directory create_archive_from_this_directory # === package_this_directory
493
+
494
+ # ========================================================================= #
495
+ # === Repackage.repackage
496
+ # ========================================================================= #
497
+ def self.repackage(this)
498
+ new(this)
499
+ end; self.instance_eval { alias [] repackage } # === Repackage[]
500
+
501
+ # ========================================================================= #
502
+ # === package_full_name?
503
+ # ========================================================================= #
504
+ def package_full_name?(
505
+ i = repackage_which_file?
506
+ )
507
+ File.absolute_path(i)
508
+ end
509
+
510
+ # ========================================================================= #
511
+ # === repackage_which_file?
512
+ # ========================================================================= #
513
+ def repackage_which_file?
514
+ @internal_hash[:repackage_this_file]
515
+ end; alias filename? repackage_which_file? # === filename?
516
+
517
+ # ========================================================================= #
518
+ # === move_this_package_to (move tag)
519
+ #
520
+ # Use this method to move a package to a new location.
521
+ # ========================================================================= #
522
+ def move_this_package_to(
523
+ new_location = the_file_is_where?,
524
+ where_to = start_dir?
525
+ )
526
+ package_full_name = File.absolute_path(new_location)
527
+ if File.exist? package_full_name
528
+ opn; e 'Moving the package at '+sfile(package_full_name)+
529
+ ' to '+sfile(where_to)+' next.'
530
+ FileUtils.mv(package_full_name, where_to)
531
+ set_final_location(where_to)
532
+ else
533
+ e 'No file at '+sfile(package_full_name)+' exists, thus '\
534
+ 'we can not move anything.'
535
+ end
536
+ end
537
+
538
+ # ========================================================================= #
539
+ # === start_dir?
540
+ # ========================================================================= #
541
+ def start_dir?
542
+ @internal_hash[:start_dir]
543
+ end
544
+
545
+ # ========================================================================= #
546
+ # === cd_to_the_extract_to_directory_then_set_it_as_the_start_dir
547
+ # ========================================================================= #
548
+ def cd_to_the_extract_to_directory_then_set_it_as_the_start_dir
549
+ cd EXTRACT_TO
550
+ set_start_dir EXTRACT_TO
551
+ end
552
+
553
+ # ========================================================================= #
554
+ # === consider_refusing_the_repackaging_action
555
+ #
556
+ # This method acts as a tiny "safeguard", so we don't repackage when
557
+ # the target format is the same as the original archive format.
558
+ # ========================================================================= #
559
+ def consider_refusing_the_repackaging_action(
560
+ i = repackage_which_file?
561
+ )
562
+ target_format_type = target_format_type?
563
+ if i.include? target_format_type
564
+ opn; e "We can not repackage #{simp(i)} into the"
565
+ opn; e "same target archive format (#{sfancy(target_format_type)})."
566
+ exit
567
+ end
568
+ end
569
+
570
+ # ========================================================================= #
571
+ # === try_glob
572
+ #
573
+ # Try a glob with this method.
574
+ # ========================================================================= #
575
+ def try_glob(i)
576
+ return Dir[i+'*']
577
+ end
578
+
579
+ # ========================================================================= #
580
+ # === dir_where_the_archive_resides?
581
+ # ========================================================================= #
582
+ def dir_where_the_archive_resides?
583
+ @internal_hash[:original_directory_where_the_archive_was_kept]
584
+ end
585
+
586
+ # ========================================================================= #
587
+ # === extract (extract tag)
588
+ #
589
+ # Extract it here. Before we do so, though, we must check if the target
590
+ # does not exist yet.
591
+ # ========================================================================= #
592
+ def extract(
593
+ what = filename?
594
+ )
595
+ if what.frozen?
596
+ what = what.dup
597
+ end
598
+ unless what.include? '/'
599
+ what = dir_where_the_archive_resides?+File.basename(what)
600
+ end
601
+ remove_extracted_data
602
+ Extracter.extract_what_to(what, extract_to?)
603
+ end
604
+
605
+ # ========================================================================= #
606
+ # === warn_about_missing_file_then_exit
607
+ # ========================================================================= #
608
+ def warn_about_missing_file_then_exit(
609
+ i = target_file?
610
+ )
611
+ opn;e swarn('The file `')+
612
+ sfile(i)+
613
+ swarn('` does not exist.')
614
+ raise "The argument must be an existing (local) file. As "\
615
+ "the file does not exist, this class can not continue."
616
+ end
617
+
618
+ # ========================================================================= #
619
+ # === check_whether_the_archive_exists
620
+ # ========================================================================= #
621
+ def check_whether_the_archive_exists(
622
+ _ = dir_where_the_archive_resides?+repackage_which_file?
623
+ )
624
+ cliner
625
+ if File.file? _
626
+ opn; e "Good, the file `#{sfile(_)}` exists."
627
+ opn; e 'We will try to repackage it into `'+
628
+ simportant(target_format_type?)+'` format type.'
629
+ opn; e 'We will extract into the directory '+sdir(extract_to?)+'.'
630
+ else
631
+ # ===================================================================== #
632
+ # Ok - in this case the file does not exist. We will first try
633
+ # to check if we have a number as input; if so we then we may
634
+ # try a glob-action. And if not, we will raise an error.
635
+ # ===================================================================== #
636
+ if first? and (first? =~ /^\d$/) # If input is a (positional) number like "3"
637
+ _ = Dir['*'].sort[first?.to_i - 1]
638
+ set_repackage_this_file(_)
639
+ else
640
+ # =================================================================== #
641
+ # Try a glob first before giving up.
642
+ # =================================================================== #
643
+ _ = try_glob(first?) if first?
644
+ if _.empty?
645
+ warn_about_missing_file_then_exit
646
+ else
647
+ check_if_this_target_exists_or_not(_.first)
648
+ end
649
+ end
650
+ end
651
+ cliner
652
+ end; alias check_if_this_target_exists_or_not check_whether_the_archive_exists # === check_if_this_target_exists_or_not
653
+ alias check_if_target_exists_or_not check_whether_the_archive_exists # === check_if_target_exists_or_not
654
+
655
+ # ========================================================================= #
656
+ # === do_repackage_everything
657
+ #
658
+ # This is the main workforce of this class, the "powerhorse method".
659
+ #
660
+ # Call it when you are ready to go and wish to re-package a given
661
+ # archive.
662
+ # ========================================================================= #
663
+ def do_repackage_everything
664
+ check_whether_the_archive_exists
665
+ consider_refusing_the_repackaging_action
666
+ target_file = repackage_which_file?
667
+ # ======================================================================= #
668
+ # Next extract this file:
669
+ # ======================================================================= #
670
+ extract(target_file)
671
+ # ======================================================================= #
672
+ # Now we have to repackage the extracted directory:
673
+ # ======================================================================= #
674
+ repackage_to_this_format = repackage_to_which_format?
675
+ _ = extract_to?+remove_archive_from(File.basename(target_file))
676
+ cd extract_to? # Ideally, we should not change directory ever.
677
+ case repackage_to_this_format # case tag
678
+ when '.tar.xz',
679
+ 'xz',
680
+ '.tar.bz2',
681
+ 'tar.bz2',
682
+ 'tarbz2',
683
+ 'totarbz2',
684
+ 'tbz2',
685
+ 'zip'
686
+ if File.directory? _
687
+ create_archive_from_this_directory(_, repackage_to_this_format)
688
+ end
689
+ new_location = _+repackage_to_this_format
690
+ if File.exist? new_location
691
+ set_the_new_file_is_at(new_location)
692
+ cd @internal_hash[:original_directory_where_the_archive_was_kept]
693
+ move_this_package_to(
694
+ new_location,
695
+ @internal_hash[:original_directory_where_the_archive_was_kept]
696
+ )
697
+ cd start_dir?
698
+ if shall_we_delete_the_old_archive?
699
+ remove_the_old_archive
700
+ remove_extracted_data
701
+ end
702
+ end
703
+ else
704
+ e tomato('Unhandled format type: ')+
705
+ steelblue(repackage_to_this_format)
706
+ end
707
+ end; alias repackage_data do_repackage_everything # === repackage_data
708
+
709
+ # ========================================================================= #
710
+ # === set_shall_we_delete_the_old_archive
711
+ # ========================================================================= #
712
+ def set_shall_we_delete_the_old_archive(
713
+ i = :default
714
+ )
715
+ case i
716
+ # ======================================================================= #
717
+ # === :default
718
+ # ======================================================================= #
719
+ when :default,
720
+ nil
721
+ i = SHALL_WE_DELETE_THE_OLD_ARCHIVE
722
+ if is_on_roebe?
723
+ i = true
724
+ end
725
+ end
726
+ @internal_hash[:shall_we_delete_the_old_archive] = i
727
+ end; alias set_shall_we_delete_old_source set_shall_we_delete_the_old_archive # === set_shall_we_delete_old_source
728
+
729
+ # ========================================================================= #
730
+ # === remove_the_old_archive
731
+ #
732
+ # Only call this when we are sure to remove the old source. I recommend
733
+ # to delete the old source. Of course we must make sure to delete the
734
+ # right package.
735
+ # ========================================================================= #
736
+ def remove_the_old_archive(
737
+ i = dir_where_the_archive_resides?+filename?
738
+ )
739
+ opn; e "Removing the old archive at #{sfile(i)} next, as requested."
740
+ remove(i)
741
+ end
742
+
743
+ # ========================================================================= #
744
+ # === run (run tag)
745
+ # ========================================================================= #
746
+ def run
747
+ determine_relevant_entries
748
+ cd_to_the_extract_to_directory_then_set_it_as_the_start_dir
749
+ opn; e 'Working from the directory '+sdir(start_dir?)+'.'
750
+ do_repackage_everything
751
+ end
752
+
753
+ end
754
+
755
+ if __FILE__ == $PROGRAM_NAME
756
+ Repackage.new(ARGV)
757
+ end
758
+ # =========================================================================== #
759
+ # Usage examples with full syntax:
760
+ #
761
+ # rer filename.tar.gz format_type
762
+ # rer xpdf-3.00.tar.gz gzip
763
+ # rer AUD_MusicBox-020.tgz
764
+ # rer AUD_MusicBox-020.tgz
765
+ # rer
766
+ # repackagerb zlib-1.2.11.tar.gz
767
+ #
768
+ # =========================================================================== #
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/ruby -w
2
+ # Encoding: UTF-8
3
+ # frozen_string_literal: true
4
+ # =========================================================================== #
5
+ # require 'repackage/requires/embeddable_interface.rb'
6
+ # =========================================================================== #
7
+ require 'repackage/www/embeddable_interface.rb'
@@ -0,0 +1,19 @@
1
+ #!/usr/bin/ruby -w
2
+ # Encoding: UTF-8
3
+ # frozen_string_literal: true
4
+ # =========================================================================== #
5
+ # require 'repackage/version/version.rb'
6
+ # =========================================================================== #
7
+ class Repackage
8
+
9
+ # =========================================================================== #
10
+ # === VERSION
11
+ # =========================================================================== #
12
+ VERSION = '1.0.30'
13
+
14
+ # =========================================================================== #
15
+ # === LAST_UPDATE
16
+ # =========================================================================== #
17
+ LAST_UPDATE = '01.04.2022'
18
+
19
+ end
@@ -0,0 +1,2 @@
1
+ The code in this directory can be used to make the repackage functionality
2
+ available via the www, such as through sinatra.
@@ -0,0 +1,66 @@
1
+ #!/usr/bin/ruby -w
2
+ # Encoding: UTF-8
3
+ # frozen_string_literal: true
4
+ # =========================================================================== #
5
+ # require 'repackage/www/embeddable_interface.rb'
6
+ # =========================================================================== #
7
+ class Repackage
8
+
9
+ module EmbeddableInterface
10
+
11
+ # ========================================================================= #
12
+ # === Repackage::EmbeddableInterface.routes?
13
+ #
14
+ # Define all legal routes via this Array. This Array will then be used
15
+ # to add more routes to any sinatra-application that needs it.
16
+ # ========================================================================= #
17
+ def self.routes?
18
+ [
19
+ 'repackage',
20
+ 'repackage/*'
21
+ ]
22
+ end
23
+
24
+ # ========================================================================= #
25
+ # === return_sinatra_repackage
26
+ # ========================================================================= #
27
+ def return_sinatra_repackage
28
+ 'Please provide the name of the target archive that is to be repackaged.'
29
+ end
30
+
31
+ # ========================================================================= #
32
+ # === return_sinatra_repackage_with_arguments
33
+ # ========================================================================= #
34
+ def return_sinatra_repackage_with_arguments(
35
+ i = web_params_as_string?
36
+ )
37
+ i = i.dup if i.frozen?
38
+ _ = ''.dup
39
+ _ << 'The parameters given were: <b style="darkblue">'+i+'</b><br>'
40
+ i.prepend('/') unless i.start_with? '/'
41
+ if File.exist? i
42
+ _ << 'Repackaging this file next.<br>'
43
+ result = Repackage.new(i) {
44
+ :do_not_delete_the_old_source
45
+ }
46
+ _ << 'The archive is now available at: <b>'+
47
+ result.the_final_location_is_at?.to_s+
48
+ '</b>'
49
+ else
50
+ _ << 'No file exists at '+i
51
+ end
52
+ return _
53
+ end
54
+
55
+ end
56
+
57
+ # =========================================================================== #
58
+ # === Repackage.embeddable_interface
59
+ # =========================================================================== #
60
+ def self.embeddable_interface
61
+ object = Object.new
62
+ object.extend(Repackage::EmbeddableInterface)
63
+ return object
64
+ end
65
+
66
+ end
data/lib/repackage.rb ADDED
@@ -0,0 +1,2 @@
1
+ require 'repackage/class/repackage.rb'
2
+ require 'repackage/www/embeddable_interface.rb'
data/repackage.gemspec ADDED
@@ -0,0 +1,55 @@
1
+ # =========================================================================== #
2
+ # Gemspec for Project Repackage.
3
+ # =========================================================================== #
4
+ require 'repackage/version/version.rb'
5
+ require 'roebe'
6
+
7
+ Gem::Specification.new { |s|
8
+
9
+ s.name = 'repackage'
10
+ s.version = Repackage::VERSION
11
+ s.date = Time.now.strftime('%Y-%m-%d')
12
+
13
+ s.summary = <<-EOF
14
+
15
+ This library is called repackage. It allows you to
16
+ repackage an archive, i.e. .tar.gz to .tar.xz format.
17
+
18
+ If the target (the input you give to this class) can
19
+ not be found, we will try a glob before giving up
20
+ first, since version 1.0.2.
21
+
22
+ EOF
23
+
24
+ s.description = <<-EOF
25
+
26
+ This library is called repackage. It allows you to
27
+ repackage an archive, i.e. .tar.gz to .tar.xz format.
28
+
29
+ Since as of April 2021 (not an april joke), the
30
+ licence is now LGPL-2.1 rather than GPL-2.x. It
31
+ was considered to simplify integrating LGPL
32
+ into other projects rather than GPL.
33
+
34
+ EOF
35
+
36
+ s.extra_rdoc_files = %w()
37
+
38
+ s.authors = ['Robert A. Heiler']
39
+ s.email = Roebe.email?
40
+ s.files = Dir['**/*']
41
+ s.licenses = 'MIT'
42
+
43
+ s.homepage = 'https://rubygems.org/gems/repackage'
44
+ s.executables = Dir['bin/*'].map { |f| File.basename(f) }
45
+
46
+ s.required_ruby_version = '>= '+Roebe.third_most_stable_version_of_ruby
47
+ s.required_rubygems_version = '>= '+Gem::VERSION
48
+ s.rubygems_version = '>= '+Gem::VERSION
49
+
50
+ s.add_dependency 'colours'
51
+ s.add_dependency 'extracter'
52
+ s.add_dependency 'esystem'
53
+ s.add_dependency 'opn'
54
+
55
+ }
metadata ADDED
@@ -0,0 +1,112 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: repackage
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.30
5
+ platform: ruby
6
+ authors:
7
+ - Robert A. Heiler
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2022-04-01 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: extracter
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
+ - !ruby/object:Gem::Dependency
42
+ name: esystem
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: opn
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ description: "\nThis library is called repackage. It allows you to \nrepackage an
70
+ archive, i.e. .tar.gz to .tar.xz format.\n\nSince as of April 2021 (not an april
71
+ joke), the\nlicence is now LGPL-2.1 rather than GPL-2.x. It\nwas considered to simplify
72
+ integrating LGPL\ninto other projects rather than GPL.\n\n"
73
+ email: shevy@inbox.lt
74
+ executables:
75
+ - repackager
76
+ extensions: []
77
+ extra_rdoc_files: []
78
+ files:
79
+ - bin/repackager
80
+ - lib/repackage.rb
81
+ - lib/repackage/class/repackage.rb
82
+ - lib/repackage/requires/require_the_sinatra_interface.rb
83
+ - lib/repackage/version/version.rb
84
+ - lib/repackage/www/README.md
85
+ - lib/repackage/www/embeddable_interface.rb
86
+ - repackage.gemspec
87
+ homepage: https://rubygems.org/gems/repackage
88
+ licenses:
89
+ - MIT
90
+ metadata: {}
91
+ post_install_message:
92
+ rdoc_options: []
93
+ require_paths:
94
+ - lib
95
+ required_ruby_version: !ruby/object:Gem::Requirement
96
+ requirements:
97
+ - - ">="
98
+ - !ruby/object:Gem::Version
99
+ version: 2.5.8
100
+ required_rubygems_version: !ruby/object:Gem::Requirement
101
+ requirements:
102
+ - - ">="
103
+ - !ruby/object:Gem::Version
104
+ version: 3.3.7
105
+ requirements: []
106
+ rubygems_version: 3.3.7
107
+ signing_key:
108
+ specification_version: 4
109
+ summary: This library is called repackage. It allows you to repackage an archive,
110
+ i.e. .tar.gz to .tar.xz format. If the target (the input you give to this class)
111
+ can not be found, we will try a glob before giving up first, since version 1.0.2.
112
+ test_files: []