Class: Roebe::BurnISO

Inherits:
Base show all
Defined in:
lib/roebe/classes/burn_iso/burn_iso.rb,
lib/roebe/classes/burn_iso/constants.rb,
lib/roebe/classes/burn_iso/initialize.rb

Overview

Roebe::BurnISO

Constant Summary collapse

DEFAULT_FILE_TO_BURN =
#

DEFAULT_FILE_TO_BURN

#
'foobar.iso'
DEFAULT_BURN_PROGRAM =
#

DEFAULT_BURN_PROGRAM

#
'growisofs'
WHICH_SR_DEVICE =
#

WHICH_SR_DEVICE

#
'sr0'
USE_THIS_SPEED =
#

USE_THIS_SPEED

How fast to burn. A low number may lead to less errors in the long run.

#
'1'
REGEX_FOR_SPEED =
#

REGEX_FOR_SPEED

If you wish to modify the speed setting, then this regex is useful.

#
/-?-?speed=(\d+)/

Constants inherited from Base

Roebe::Base::COLOURS, Roebe::Base::HOME_DIRECTORY_OF_USER_X, Roebe::Base::N, Roebe::Base::NAMESPACE

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#append_this_onto_that_file, #append_what_into, #be_silent, #be_verbose?, #beautiful_url, #bold_blue, #burlywood, #call_next, #chdir, #cheerful_guy, #cliner, #convert_global_env, #copy_directory, #copy_file, #cornflowerblue, #create_directory, #crimson, #current_month?, #current_time?, #current_year?, #cyan, #darkcyan, #darkgreen, #darkslateblue, #deeppink, #delete_symlink, #disable_colours, #e, #ecomment, #editor_to_use?, #efancy, #eimp, #ensure_main_encoding, #ensure_utf_encoding, #eparse, #erev, #esystem, #esystem_colourized, #ewarn, #firebrick, #get_current_day, #get_current_month, #get_files_from, #get_german_name_for_this_weekday, #gold, #grey, #hh_mm_ss, #home_dir?, #home_directory_of_user_x?, #is_a_file?, #is_an_image_file?, #is_archive?, #is_audio_file?, #is_in_studium_dir?, #is_multimedia_file?, #is_on_roebe?, #is_on_windows?, #is_symlink?, #is_this_a_ruby_file?, #is_video_file?, #iso_encoding?, #left_colour, #lightblue, #lightgreen, #lightseagreen, #lime, #localhost_to_data, #log_directory?, #main_encoding?, #mediumorchid, #mediumpurple, #mediumseagreen, #mediumspringgreen, #mediumturquoise, #mkdir, #mv, #n_days_in_this_month, #no_file_exists_at, #olivedrab, #open_in_browser, #opne, #opnn, #orchid, #palegoldenrod, #palevioletred, #pink, #powderblue, #programs_dir?, #random_html_colour, #rds, #read_file_in_iso_encoding, #read_file_via_the_default_encoding, #read_lines_via_iso_encoding, #readlines_with_main_encoding, #red, #register_sigint, #remove, #remove_directory, #remove_file, #rename_kde_konsole_tab, #replace_localhost_with_data, #report_pwd, #return_all_directories_from_this_directory, #return_current_directory, #return_dd_mm_yyyy, #return_file_or_directory_of, #return_files_from_pwd, #return_last_part_of_the_current_directory, #return_utc, #rev, #right_arrow?, #right_colour, #rosybrown, #royalblue, #ruby_base_directory?, #run_in_background, #run_rcfiles_then_run_ata_via_qdbus, #sandybrown, #sdir, #seagreen, #set_xorg_buffer, #sfancy, #sfile, #silent_redirection?, #simp, #skyblue, #slateblue, #slategray, #springgreen, #steelblue, #swarn, #symlink, #teal, #to_camelcase, #tomato, #touch, #use_colours?, #verbose_truth, #weekday?, #write_what_into, #yellow

Methods included from Roebe::Base::CommandlineArguments

#clear_commandline_arguments, #commandline_arguments?, #commandline_arguments_as_string?, #commandline_arguments_without_leading_hyphens?, #first_argument?, #first_argument_without_leading_hyphens?, #has_an_argument_been_passed?, #return_commandline_arguments_with_leading_hyphens, #set_commandline_arguments

Constructor Details

#initialize(file_to_burn = 'foobar.iso', run_already = false, be_verbose = true) ⇒ BurnISO

#

initialize

The first argument, file_to_burn, is the file which we wish to burn.

#

18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/roebe/classes/burn_iso/initialize.rb', line 18

def initialize(
    file_to_burn = 'foobar.iso',
    run_already  = false,
    be_verbose   = true
  )
  reset
  set_be_verbose(be_verbose)
  set_file_to_burn(file_to_burn)
  case run_already
  when :dont_run_yet
    run_already = false
  end
  run if run_already
end

Instance Attribute Details

#run_simulationObject

If this is true, then we will simulate, rather than burn.


29
30
31
# File 'lib/roebe/classes/burn_iso/burn_iso.rb', line 29

def run_simulation
  @run_simulation
end

#use_usb_burnerObject

Whether to use the ISO Burner or not.


30
31
32
# File 'lib/roebe/classes/burn_iso/burn_iso.rb', line 30

def use_usb_burner
  @use_usb_burner
end

Instance Method Details

#_(i) ⇒ Object

#

_

#

148
149
150
# File 'lib/roebe/classes/burn_iso/burn_iso.rb', line 148

def _(i)
  @cmd << i.dup
end

#assembleObject

#

assemble

Wrapper method over two other methods.

#

231
232
233
234
# File 'lib/roebe/classes/burn_iso/burn_iso.rb', line 231

def assemble
  set_burn_program
  assemble_main_string
end

#assemble_main_stringObject

#

assemble_main_string

#

197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
# File 'lib/roebe/classes/burn_iso/burn_iso.rb', line 197

def assemble_main_string # This assembles the main string.
  reset
  _ @burn_program # Append to @cmd.
  case @burn_what
  when :cdrskin
    Cdrskin.new() # Use ruby wrapper here. Libburn.
  when :dvd
    _ '-dvd-compat '
    _ '-speed='+@use_this_speed+' '
    _ '-Z '
    if @use_usb_burner # Use the USB Burner here.
      target_dev = '/dev/'+WHICH_SR_DEVICE
      if File.exist? target_dev
        _ target_dev+'='
      else # else check for sr
        e 'File `'+sfile(target_dev)+'` does not exist.'
        _ check_for_proper_sr_target
      end
    else
      _ '/dev/dvd=' # Use some integral Burner.
    end
  when :cd
    _ ' -v -pad '
  else
    e 'Not allowed mode '+mode.to_s
  end
  _ @file_to_burn # Last but not least, append the file to the command string.
end

#burn(i = :dvd) ⇒ Object Also known as: set_burn_what

#

burn

#

176
177
178
# File 'lib/roebe/classes/burn_iso/burn_iso.rb', line 176

def burn(i = :dvd) # This method sets @burn_what.
  @burn_what = i
end

#burn_what=(i) ⇒ Object

#

burn_what=

#

55
56
57
# File 'lib/roebe/classes/burn_iso/burn_iso.rb', line 55

def burn_what=(i)
  @burn_what = i
end

#check_for_proper_sr_targetObject

#

check_for_proper_sr_target

#

190
191
192
# File 'lib/roebe/classes/burn_iso/burn_iso.rb', line 190

def check_for_proper_sr_target # This will check the proper sr link.
  return Dir.glob('/dev/sr*').first+'='
end

#cmd?Boolean Also known as: cmd

#

cmd?

#

Returns:

  • (Boolean)

155
156
157
# File 'lib/roebe/classes/burn_iso/burn_iso.rb', line 155

def cmd?
  @cmd
end

#is_there_at_the_least_one_iso_file_in_the_current_working_directory?Boolean

#

is_there_at_the_least_one_iso_file_in_the_current_working_directory?

#

Returns:

  • (Boolean)

79
80
81
# File 'lib/roebe/classes/burn_iso/burn_iso.rb', line 79

def is_there_at_the_least_one_iso_file_in_the_current_working_directory?
  !Dir['*.iso'].empty?
end

#orange(i) ⇒ Object

#

orange

#

239
240
241
# File 'lib/roebe/classes/burn_iso/burn_iso.rb', line 239

def orange(i)
  ::Colours.orange(i)
end

#parse_commandline(array) ⇒ Object

#

parse_commandline

#

115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
# File 'lib/roebe/classes/burn_iso/burn_iso.rb', line 115

def parse_commandline(array)
  _ = array.join(' ')
  case _ # case tag
  # ======================================================================== #
  # === burniso --help
  # ======================================================================== #
  when /-?-?help/
    show_help
    exit
  # ======================================================================== #
  # === burniso --speed=3
  # ======================================================================== #
  when REGEX_FOR_SPEED
    set_speed($1)
    array.reject! {|line|
      line.include? 'speed='
    }
  end
  return array
end

#resetObject

#

reset (reset tag)

This method can be used to reset the main variables of this class.

#

37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/roebe/classes/burn_iso/burn_iso.rb', line 37

def reset
  super()
  set_burn_program
  burn :dvd # may be either :dvd or cd. Defaults to :dvd
  # ======================================================================== #
  # === @use_usb_burner
  # ======================================================================== #
  @use_usb_burner = true
  # ======================================================================== #
  # === @cmd
  # ======================================================================== #
  @cmd = ''.dup
  set_use_this_speed
end

#runObject

#

run

#

262
263
264
265
266
# File 'lib/roebe/classes/burn_iso/burn_iso.rb', line 262

def run # This will also return a string, which can be used. (run tag)
  assemble
  run_sys_command
  return @cmd
end

#run_sys_commandObject

#

run_sys_command

#

246
247
248
249
250
251
252
253
254
255
256
257
# File 'lib/roebe/classes/burn_iso/burn_iso.rb', line 246

def run_sys_command
  e orange(@cmd) if @be_verbose
  if is_on_roebe?
    begin
      require 'roebe/requires/require_kde_konsole.rb'
      Roebe.rename_kde_konsole(@cmd)
    rescue LoadError
      e 'roebe/requires/require_kde_konsole.rb is not available.'
    end
  end
  system @cmd
end

#set_be_verbose(i = true) ⇒ Object Also known as: be_verbose

#

set_be_verbose

#

162
163
164
# File 'lib/roebe/classes/burn_iso/burn_iso.rb', line 162

def set_be_verbose(i = true)
  @be_verbose = i
end

#set_burn_program(i = DEFAULT_BURN_PROGRAM) ⇒ Object Also known as: burn_program=

#

set_burn_program

#

169
170
171
# File 'lib/roebe/classes/burn_iso/burn_iso.rb', line 169

def set_burn_program(i = DEFAULT_BURN_PROGRAM) # Called only from assemble()
  @burn_program = i+' '
end

#set_file_to_burn(i = DEFAULT_FILE_TO_BURN) ⇒ Object

#

set_file_to_burn

#

86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
# File 'lib/roebe/classes/burn_iso/burn_iso.rb', line 86

def set_file_to_burn(
    i = DEFAULT_FILE_TO_BURN
  )
  if i.is_a? Array
    if i.empty?
      # ==================================================================== #
      # Handle the situation where the user did not input anything
      # to this class, here.
      # ==================================================================== #
      if is_there_at_the_least_one_iso_file_in_the_current_working_directory?
        i = Dir['*.iso'].first # "Randomly" grab one entry - the first.
      end
    else
      # ==================================================================== #
      # Handle entries that contain the phrase '--speed' differently.
      # ==================================================================== #
      i = parse_commandline(i)
      i = i.first
    end
  end
  if i.nil?
    i = DEFAULT_FILE_TO_BURN
  end
  @file_to_burn = i
end

#set_use_this_speed(i = USE_THIS_SPEED) ⇒ Object Also known as: set_speed

#

set_use_this_speed

#

62
63
64
65
66
# File 'lib/roebe/classes/burn_iso/burn_iso.rb', line 62

def set_use_this_speed(
    i = USE_THIS_SPEED
  )
  @use_this_speed = i
end

#show_helpObject

#

show_help (help tag)

#

139
140
141
142
143
# File 'lib/roebe/classes/burn_iso/burn_iso.rb', line 139

def show_help
  e
  e ' --speed=1 # use speed 1 rather than '+default_speed?.to_s
  e
end

#stringObject

#

string

#

183
184
185
# File 'lib/roebe/classes/burn_iso/burn_iso.rb', line 183

def string
  @cmd
end

#use_this_speed?Boolean Also known as: speed?, default_speed?

#

use_this_speed?

#

Returns:

  • (Boolean)

71
72
73
# File 'lib/roebe/classes/burn_iso/burn_iso.rb', line 71

def use_this_speed?
  @use_this_speed
end