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

#actions, #append_this_onto_that_file, #append_what_into, #be_silent, #be_verbose?, #beautiful_url, #burlywood, #call_next, #chdir, #cheerful_guy, #cliner, #complex_esystem, #convert_global_env, #copy_directory, #copy_file, #cornflowerblue, #create_directory, #crimson, #current_month?, #current_time?, #current_year?, #cyan, #darkcyan, #darkgreen, #darkkhaki, #darkslateblue, #deeppink, #delete_symlink, #do_not_use_the_base_colours, #do_use_the_base_colours, #e, #ecomment, #editor_to_use?, #efancy, #eimp, #emphasis, #ensure_main_encoding, #ensure_utf_encoding, #eparse, #erev, #esteelblue, #etomato, #ewarn, #exit_program, #firebrick, #get_current_day, #get_current_month, #get_files_and_directories, #get_files_from, #get_german_name_for_this_weekday, #gold, #green, #grey, #hh_mm_ss, #hh_mm_ss_day_month_year, #home_dir?, #home_directory_of_user_x?, #infer_the_namespace, #internal_hash?, #is_a_directory?, #is_a_file?, #is_a_jpg_file?, #is_an_image_file?, #is_archive?, #is_audio_file?, #is_in_studium_dir?, #is_multimedia_file?, #is_on_roebe?, #is_on_windows?, #is_studium_available?, #is_symlink?, #is_this_a_ruby_file?, #is_video_file?, #iso_encoding?, #le, #left_colour, #lightblue, #lightgreen, #lightseagreen, #lightsteelblue, #lime, #limegreen, #localhost_to_data, #log_directory?, #main_encoding?, #mediumorchid, #mediumpurple, #mediumseagreen, #mediumslateblue, #mediumspringgreen, #mediumturquoise, #mkdir_p, #mv, #n_days_in_this_month, #n_pages_in_this_pdf_file?, #namespace?, #no_file_exists_at, #ogrey, #olive, #olivedrab, #open_in_browser, #opne, #opnesystem, #opnn, #orange, #orchid, #orev, #palegoldenrod, #palevioletred, #pink, #powderblue, #programs_dir?, #project_base_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, #require_rescue, #reset_the_internal_hash, #return_all_directories_from_this_directory, #return_all_files_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, #roebe_log_directory?, #rosybrown, #royalblue, #ruby_base_directory?, #run_in_background, #run_rcfiles_then_run_ata_via_qdbus, #sandybrown, #sdir, #seagreen, #set_be_verbose, #set_xorg_buffer, #sfancy, #sfile, #silent_redirection?, #simp, #simple_esystem, #skyblue, #slateblue, #slategray, #springgreen, #steelblue, #string_italic, #swarn, #symlink, #teal, #temp_dir?, #to_camelcase, #to_counted_hash, #tomato, #touch, #try_to_require_the_beautiful_url_gem, #try_to_require_the_html_template, #try_to_require_the_open_gem, #try_to_require_the_program_information_gem, #try_to_require_the_xorg_buffer, #use_colours?, #verbose_truth, #weekday?, #word_wrap, #write_what_into, #yellow

Methods included from Roebe::Base::CommandlineArguments

#append_onto_the_commandline_arguments, #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?, #remove_hyphened_arguments_from_the_commandline_arguments, #return_commandline_arguments_with_leading_hyphens, #second_argument?, #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

#

_

#


124
125
126
# File 'lib/roebe/classes/burn_iso/burn_iso.rb', line 124

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

#assembleObject

#

assemble

Wrapper method over two other methods.

#


202
203
204
205
# File 'lib/roebe/classes/burn_iso/burn_iso.rb', line 202

def assemble
  set_burn_program
  assemble_main_string
end

#assemble_main_stringObject

#

assemble_main_string

#


166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
# File 'lib/roebe/classes/burn_iso/burn_iso.rb', line 166

def assemble_main_string # This assembles the main string.
  reset
  _ @burn_program # Append to @cmd.
  case @burn_what
  # === :cdrskin
  when :cdrskin
    Cdrskin.new() # Use ruby wrapper here. Libburn.
  # === :dvd
  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

#


145
146
147
# File 'lib/roebe/classes/burn_iso/burn_iso.rb', line 145

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

#


159
160
161
# File 'lib/roebe/classes/burn_iso/burn_iso.rb', line 159

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)


131
132
133
# File 'lib/roebe/classes/burn_iso/burn_iso.rb', line 131

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

#parse_commandline(array) ⇒ Object

#

parse_commandline

#


226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
# File 'lib/roebe/classes/burn_iso/burn_iso.rb', line 226

def parse_commandline(array)
  _ = array.join(' ')
  case _ # case tag
  # ======================================================================== #
  # === burniso --help
  # ======================================================================== #
  when /-?-?help$/i
    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

#


250
251
252
253
254
# File 'lib/roebe/classes/burn_iso/burn_iso.rb', line 250

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

#


210
211
212
213
214
215
216
217
218
219
220
221
# File 'lib/roebe/classes/burn_iso/burn_iso.rb', line 210

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_burn_program(i = DEFAULT_BURN_PROGRAM) ⇒ Object Also known as: burn_program=

#

set_burn_program

#


138
139
140
# File 'lib/roebe/classes/burn_iso/burn_iso.rb', line 138

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)

#


115
116
117
118
119
# File 'lib/roebe/classes/burn_iso/burn_iso.rb', line 115

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

#stringObject

#

string

#


152
153
154
# File 'lib/roebe/classes/burn_iso/burn_iso.rb', line 152

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