Class: BackupParadise::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/backup_paradise/base/tab.rb,
lib/backup_paradise/base/base.rb,
lib/backup_paradise/base/colours.rb,
lib/backup_paradise/base/namespace.rb

Constant Summary collapse

NAMESPACE =
#

NAMESPACE

#
inspect

Instance Method Summary collapse

Instance Method Details

#all_important_directories?Boolean

#

all_important_directories?

Feedback which directories are the most important ones.

#

Returns:

  • (Boolean)


476
477
478
479
480
481
482
483
484
# File 'lib/backup_paradise/base/base.rb', line 476

def all_important_directories?
  CONFIG['backup_these_directories'].map {|entry|
    unless entry.end_with?('/')
      entry = entry.dup if entry.frozen?
      entry << '/' # Keep a trailing /; it looks better that way.
    end
    entry
  }
end

#append_what_into(what, into) ⇒ Object

#

append_what_into

#


281
282
283
# File 'lib/backup_paradise/base/base.rb', line 281

def append_what_into(what, into)
  ::Roebe.append_what_into(what, into)
end

#are_we_on_windows?Boolean

#

are_we_on_windows?

Query whether the underlying operating system is windows or whether it is not.

#

Returns:

  • (Boolean)


467
468
469
# File 'lib/backup_paradise/base/base.rb', line 467

def are_we_on_windows?
  ::BackupParadise.send(__method__)
end

#cd_to_the_mounted_deviceObject

#

cd_to_the_mounted_device

#


215
216
217
# File 'lib/backup_paradise/base/base.rb', line 215

def cd_to_the_mounted_device
  cd target_mountpoint?
end

#chdir(i) ⇒ Object Also known as: cd, change_directory

#

chdir (cd tag)

Change directory via this method here.

#


341
342
343
# File 'lib/backup_paradise/base/base.rb', line 341

def chdir(i)
  BackupParadise.change_directory(i)
end

#clinerObject

#

cliner

#


117
118
119
# File 'lib/backup_paradise/base/base.rb', line 117

def cliner
  BackupParadise.cliner
end

#copy_file(from, to) ⇒ Object Also known as: copy_this_file

#

copy_file

#


267
268
269
# File 'lib/backup_paradise/base/base.rb', line 267

def copy_file(from, to)
  BackupParadise.copy_file(from, to)
end

#copy_recursively(this_directory, backup_to_this_target, be_verbose = :be_verbose) ⇒ Object Also known as: cpr, backup_this_directory_if_it_exists

#

copy_recursively

This method can be used to copy the source to the target in a recursive manner.

The third argument to this method, called ‘be_verbose`, will feedback what is done, to the user, if it has a value of true. Symbols such as :be_verbose can be used as an “alias” to true. If it is set to false, or :be_silent, then no output will be issued to the user.

#


440
441
442
443
444
445
446
447
448
449
450
# File 'lib/backup_paradise/base/base.rb', line 440

def copy_recursively(
    this_directory,        # from (also called source)
    backup_to_this_target, # to   (also called target)
    be_verbose = :be_verbose
  )
  ::BackupParadise.copy_recursively(
    this_directory,
    backup_to_this_target,
    be_verbose
  )
end

#create_directory(i, options = { mode_to_use: 0755 }) ⇒ Object Also known as: mkdir

#

create_directory (mkdir tag)

The first argument to this method should be the name of the directory that has to be created, such as ‘foobar/’.

#


206
207
208
209
210
# File 'lib/backup_paradise/base/base.rb', line 206

def create_directory(
    i, options = { mode_to_use: 0755 }
  )
  BackupParadise.create_directory(i, options)
end

#cyanObject

#

cyan

#


133
134
135
# File 'lib/backup_paradise/base/colours.rb', line 133

def cyan
  Colours::CYAN
end

#data_directory?Boolean Also known as: data_dir?

#

data_directory?

#

Returns:

  • (Boolean)


288
289
290
# File 'lib/backup_paradise/base/base.rb', line 288

def data_directory?
  DATA_DIRECTORY
end

#dd_mm_yyyyObject

#

dd_mm_yyyy

This method will return a String such as “25.12.2018”.

#


144
145
146
147
148
149
150
# File 'lib/backup_paradise/base/base.rb', line 144

def dd_mm_yyyy
  if Object.const_defined? :Roebe
    ::Roebe::Time.dd_mm_yyyy # Tap into the Roebe namespace for this.
  else
    Time.now.strftime('%d.%m.%Y')
  end
end

#delete_files(i, be_verbose = false) ⇒ Object Also known as: delete_file, remove_these_files

#

delete_files

#


235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
# File 'lib/backup_paradise/base/base.rb', line 235

def delete_files(
    i, be_verbose = false
  )
  case be_verbose
  when :be_verbose
    be_verbose = true
  end
  if i.is_a? Array
    i.each {|entry| delete_files(entry, be_verbose) }
  else
    if File.file? i
      if be_verbose
        opnn; e "Now deleting the file `#{sfile(i)}`."
      end
      File.delete(i)
    else
      e sfancy(i)+' is not not a file - we thus can not delete it.'
    end
  end
end
#
#


503
504
505
506
507
# File 'lib/backup_paradise/base/base.rb', line 503

def delete_symlink(i)
  if File.symlink? i
    File.delete(i)
  end
end
#
#


222
223
224
225
226
227
228
229
230
# File 'lib/backup_paradise/base/base.rb', line 222

def do_symlink(
    from_this_target, create_a_symlink_here
  )
  if File.exist? create_a_symlink_here
    no_target_at(create_a_symlink_here)
  else
    File.symlink(from_this_target, create_a_symlink_here)
  end
end

#e(i = '') ⇒ Object

#

BackupParadise.e

#


43
44
45
# File 'lib/backup_paradise/base/base.rb', line 43

def e(i = '')
  BackupParadise.e(i)
end

#esystem(i) ⇒ Object

#

esystem

#


182
183
184
185
# File 'lib/backup_paradise/base/base.rb', line 182

def esystem(i)
  e i
  system i
end

#exit_program(be_verbose = false) ⇒ Object

#

exit_program (exit tag)

This method should be used when we have to exit from the backup_paradise project.

The reason why a separate exit-method has been added is so that we can change this at a later time possibly, if we wish to do further checks before exiting.

#


95
96
97
98
99
100
101
102
103
# File 'lib/backup_paradise/base/base.rb', line 95

def exit_program(be_verbose = false)
  if be_verbose
    e 'Quit was called, thus we exit now.'
  end
  if @use_this_program_to_rename_tabs
   rename_tab(@use_this_program_to_rename_tabs)
  end
  exit
end

#has_superuser_abilities?Boolean

#

has_superuser_abilities?

#

Returns:

  • (Boolean)


332
333
334
# File 'lib/backup_paradise/base/base.rb', line 332

def has_superuser_abilities?
  Process.uid.zero?
end

#hh_mm_ssObject Also known as: current_time

#

hh_mm_ss

#


321
322
323
324
325
326
327
# File 'lib/backup_paradise/base/base.rb', line 321

def hh_mm_ss
  if Object.const_defined? :Roebe
    ::Roebe::Time.hh_mm_ss # This will yield something like: "03:53:55"
  else
    Time.now.strftime('%H:%M:%S')
  end
end

#home_dir_of_user_x?Boolean

#

home_dir_of_user_x?

This method is only relevant on my home system.

#

Returns:

  • (Boolean)


110
111
112
# File 'lib/backup_paradise/base/base.rb', line 110

def home_dir_of_user_x?
  '/home/x/'
end

#is_on_roebe?Boolean

#

is_on_roebe?

#

Returns:

  • (Boolean)


489
490
491
# File 'lib/backup_paradise/base/base.rb', line 489

def is_on_roebe?
  BackupParadise.is_on_roebe?
end

#is_symlink?(i) ⇒ Boolean

#
#

Returns:

  • (Boolean)


496
497
498
# File 'lib/backup_paradise/base/base.rb', line 496

def is_symlink?(i)
  File.symlink?(i)
end

#lightcoral(i) ⇒ Object

#

lightcoral

#


105
106
107
108
109
110
# File 'lib/backup_paradise/base/colours.rb', line 105

def lightcoral(i)
  if use_colours?
    return ::Colours.lightcoral(i)
  end
  return i
end

#n_files_in?(i) ⇒ Boolean

#

n_files_in?

This method will return how many files are in the given directory.

#

Returns:

  • (Boolean)


192
193
194
195
196
197
198
# File 'lib/backup_paradise/base/base.rb', line 192

def n_files_in?(i)
  _ = 0
  if File.directory? i
    _ = Dir["#{i}*"].size
  end
  _
end

#no_file_exists_at(i) ⇒ Object

#

no_file_exists_at

#


81
82
83
# File 'lib/backup_paradise/base/base.rb', line 81

def no_file_exists_at(i)
  e "No file exists at `#{sfile(i)}`."
end

#no_such_directory_exists_at(i) ⇒ Object Also known as: no_directory_at

#

no_such_directory_exists_at

#


67
68
69
# File 'lib/backup_paradise/base/base.rb', line 67

def no_such_directory_exists_at(i)
  e "No such directory exists at `#{sdir(i)}`."
end

#no_target_at(i) ⇒ Object

#

no_target_at

#


74
75
76
# File 'lib/backup_paradise/base/base.rb', line 74

def no_target_at(i)
  e "No target at #{sfile(i)} could be found."
end

#opne(i = '') ⇒ Object

#

opne

#


525
526
527
# File 'lib/backup_paradise/base/base.rb', line 525

def opne(i = '')
  opnn; e i
end

#opnn(i = NAMESPACE) ⇒ Object

#

opnn

#


169
170
171
172
173
174
175
176
177
# File 'lib/backup_paradise/base/base.rb', line 169

def opnn(i = NAMESPACE)
  if i.is_a? String
    i = {
      namespace: i,
      use_colours: use_colours?
    }
  end
  BackupParadise.opnn(i)
end

#orangered(i) ⇒ Object

#

orangered

#


95
96
97
98
99
100
# File 'lib/backup_paradise/base/colours.rb', line 95

def orangered(i)
  if use_colours?
    return ::Colours.orangered(i)
  end
  return i
end
#

print_rev

#


126
127
128
# File 'lib/backup_paradise/base/colours.rb', line 126

def print_rev
  print rev
end

#rds(i) ⇒ Object

#

rds

#


60
61
62
# File 'lib/backup_paradise/base/base.rb', line 60

def rds(i)
  BackupParadise.rds(i)
end

#register_sigintObject

#

register_sigint

#


124
125
126
# File 'lib/backup_paradise/base/base.rb', line 124

def register_sigint
  Signal.trap('SIGINT') { exit_program }
end

#remove(i) ⇒ Object

#

remove

#


368
369
370
# File 'lib/backup_paradise/base/base.rb', line 368

def remove(i)
  BackupParadise.remove(i)
end

#remove_directory(i) ⇒ Object

#

remove_directory

#


260
261
262
# File 'lib/backup_paradise/base/base.rb', line 260

def remove_directory(i)
  BackupParadise.remove_directory(i)
end

#remove_file(i) ⇒ Object

#

remove_file

#


375
376
377
# File 'lib/backup_paradise/base/base.rb', line 375

def remove_file(i)
  File.delete(i) if File.file?(i)
end

#rename(a, b) ⇒ Object

#

rename

#


131
132
133
134
135
136
137
# File 'lib/backup_paradise/base/base.rb', line 131

def rename(a, b)
  if File.exist? b
    e "Can not rename to #{sfancy(b)} as that target already exists."
  else
    FileUtils.mv(a, b)
  end
end

#rename_tab(use_this_terminal = use_this_program_to_rename_tabs?, , use_this_as_new_title = 'Hello world!') ⇒ Object

#

rename_tab

This method can be used to rename the tab of e. g. mrxvt or KDE konsole.

#


26
27
28
29
30
31
32
33
34
# File 'lib/backup_paradise/base/tab.rb', line 26

def rename_tab(
    use_this_terminal     = use_this_program_to_rename_tabs?, # or :mrxvt
    use_this_as_new_title = 'Hello world!'
  )
  BackupParadise::Tab.rename_tab(
    use_this_terminal,
    use_this_as_new_title
  )
end

#report_total_size_of(i) ⇒ Object Also known as: report_file_size_of

#

report_total_size_of

Use this method to report the total size of a specific directory. We expect the input to this method thus be a (local) directory.

#


352
353
354
355
356
357
358
359
360
361
362
363
# File 'lib/backup_paradise/base/base.rb', line 352

def report_total_size_of(i)
  size_result = size?(i)
  kb_size     = (size_result.to_f / 1000.0).round(2)
  mb_size     = (kb_size.to_f / 1000.0).round(2)
  gb_size     = (mb_size.to_f / 1000.0).round(2)
  e "#{rev}Total size of files in bytes at #{sdir(i)}: "\
    "#{seagreen(size_result)} bytes."
  e 'This corresponds to '+
    orangered(kb_size.to_s)+lightcoral(' KB ')+
    orangered(mb_size.to_s)+lightcoral(' MB ')+
    orangered(gb_size.to_s)+lightcoral(' GB')+'.'
end

#resetObject

#

reset (reset tag)

#


50
51
52
53
54
55
# File 'lib/backup_paradise/base/base.rb', line 50

def reset
  # ======================================================================= #
  # === @use_this_program_to_rename_tabs
  # ======================================================================= #
  @use_this_program_to_rename_tabs = nil
end
#

This method can be used to return all symlinks from a given directory.

Naturally this method expects a directory as its given input argument.

#


516
517
518
519
520
# File 'lib/backup_paradise/base/base.rb', line 516

def return_all_symlinks_from_this_directory(i)
  Dir["#{i}**/**"].select {|entry|
    is_symlink?(entry)
  }
end

#return_current_date_and_timeObject Also known as: return_full_date, date_and_time?

#

return_current_date_and_time

This method will return a String such as:

"24.05.2018-03:48:50"
#


160
161
162
# File 'lib/backup_paradise/base/base.rb', line 160

def return_current_date_and_time
  "#{dd_mm_yyyy}-#{hh_mm_ss}"
end

#revObject

#

rev

#


115
116
117
118
119
120
121
# File 'lib/backup_paradise/base/colours.rb', line 115

def rev
  if Object.const_defined? :Colours
    Colours.rev
  else
    ''
  end
end

#rosybrown(i) ⇒ Object

#

rosybrown

#


65
66
67
68
69
70
# File 'lib/backup_paradise/base/colours.rb', line 65

def rosybrown(i)
  if use_colours?
    return ::Colours.rosybrown(i)
  end
  return i
end

#royalblue(i) ⇒ Object

#

royalblue

#


58
59
60
# File 'lib/backup_paradise/base/colours.rb', line 58

def royalblue(i)
  BackupParadise.royalblue(i)
end

#sdir(i = '') ⇒ Object

#

sdir

#


30
31
32
# File 'lib/backup_paradise/base/colours.rb', line 30

def sdir(i = '')
  BackupParadise.sdir(i)
end

#seagreen(i) ⇒ Object

#

seagreen

#


75
76
77
78
79
80
# File 'lib/backup_paradise/base/colours.rb', line 75

def seagreen(i)
  if use_colours?
    return ::Colours.seagreen(i)
  end
  return i
end

#set_target_mountpoint(i) ⇒ Object Also known as: set_target_device, set_backup_to_this_directory, set_target, set_main_target

#

set_target_mountpoint

#


382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
# File 'lib/backup_paradise/base/base.rb', line 382

def set_target_mountpoint(i)
  i = i.to_s
  case i
  when 'chroot'
    i = '/Depot/Chroot/' unless File.exist?('chroot')
  # ======================================================================= #
  # Specify some shortcuts to be used here.
  # ======================================================================= #
  when '1',
       '2',
       '3',
       '4',
       '5',
       '6',
       '7',
       '8',
       '9',
       'usb1',
       'usb2',
       'usb3',
       'usb4',
       'usb5',
       'usb6',
       'tousb1',
       'tousb2',
       'tousb3',
       'tousb4',
       'tousb5'
    i = i.dup if i.frozen?
    if BackupParadise.is_this_a_shortcut?(i)
      i = BackupParadise.return_the_assumed_mountpoint_from_this_input(i)
    else
      if i.start_with? 'usb'
        i.sub!(/^usb/,'')
      elsif i.start_with? 'to'
        i.sub!(/^to(-| |_)?usb/,'')
      end
      i = "/Mount/USB#{i}/"
    end
  end
  BackupParadise.target_mountpoint = i
end

#sfancy(i = '') ⇒ Object

#

sfancy

#


44
45
46
# File 'lib/backup_paradise/base/colours.rb', line 44

def sfancy(i = '')
  BackupParadise.sfancy(i)
end

#sfile(i = '') ⇒ Object

#

sfile

#


37
38
39
# File 'lib/backup_paradise/base/colours.rb', line 37

def sfile(i = '')
  BackupParadise.sfile(i)
end

#simp(i = '') ⇒ Object

#

simp

#


23
24
25
# File 'lib/backup_paradise/base/colours.rb', line 23

def simp(i = '')
  BackupParadise.simp(i)
end

#size?(i) ⇒ Boolean

#

size?

#

Returns:

  • (Boolean)


295
296
297
# File 'lib/backup_paradise/base/base.rb', line 295

def size?(i)
  BackupParadise.size?(i)
end

#steelblue(i) ⇒ Object

#

steelblue

#


85
86
87
88
89
90
# File 'lib/backup_paradise/base/colours.rb', line 85

def steelblue(i)
  if use_colours?
    return ::Colours.steelblue(i)
  end
  return i
end

#tab_title(i = '') ⇒ Object

#

tab_title

This is as above, but uses the default terminal.

#


41
42
43
44
45
# File 'lib/backup_paradise/base/tab.rb', line 41

def tab_title(
    i = ''
  )
  rename_tab(use_this_program_to_rename_tabs?, i)
end

#target_hdd_does_not_have_enough_space_left?Boolean

#

target_hdd_does_not_have_enough_space_left?

#

Returns:

  • (Boolean)


456
457
458
459
# File 'lib/backup_paradise/base/base.rb', line 456

def target_hdd_does_not_have_enough_space_left? # FIXME
  false # for now this is always false. stub
  # MINIMAL_FILESIZE
end

#target_mountpoint?Boolean Also known as: main_target?, backup_to_this_directory?, mount_point?, mount_target?

#

target_mountpoint?

Designate to which target we will backup.

#

Returns:

  • (Boolean)


304
305
306
# File 'lib/backup_paradise/base/base.rb', line 304

def target_mountpoint?
  BackupParadise.target_mountpoint?
end

#tomato(i) ⇒ Object

#

tomato

#


51
52
53
# File 'lib/backup_paradise/base/colours.rb', line 51

def tomato(i)
  BackupParadise.tomato(i)
end

#use_colours?Boolean

#

use_colours?

#

Returns:

  • (Boolean)


16
17
18
# File 'lib/backup_paradise/base/colours.rb', line 16

def use_colours?
  BackupParadise.use_colours?
end

#use_system_cp?Boolean

#

use_system_cp

#

Returns:

  • (Boolean)


314
315
316
# File 'lib/backup_paradise/base/base.rb', line 314

def use_system_cp?
  ::BackupParadise.use_system_cp?
end

#use_this_program_to_rename_tabs?Boolean

#

use_this_program_to_rename_tabs?

#

Returns:

  • (Boolean)


17
18
19
# File 'lib/backup_paradise/base/tab.rb', line 17

def use_this_program_to_rename_tabs?
  BackupParadise.use_this_program_to_rename_tabs?
end

#write_what_into(what, into) ⇒ Object

#

write_what_into

#


274
275
276
# File 'lib/backup_paradise/base/base.rb', line 274

def write_what_into(what, into)
  ::Roebe.write_what_into(what, into)
end