Class: Roebe::MakeGem

Inherits:
Base show all
Defined in:
lib/roebe/classes/make_gem.rb

Overview

Roebe::MakeGem

Constant Summary collapse

EIGHTY_MB =
#

EIGHTY_MB

#
1096 * 1024 * 80
HOME_OF_THE_USER_CALLED_X+
'programming/ruby/src/bioroebe/lib/bioroebe/gui/gtk'

Constants inherited from Base

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

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, #show_help, #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 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(run_already = true) ⇒ MakeGem

#

initialize

#


57
58
59
60
61
62
# File 'lib/roebe/classes/make_gem.rb', line 57

def initialize(
    run_already = true
  )
  reset
  run if run_already
end

Instance Method Details

#build_the_gemObject

#

build_the_gem

Issue the “gem build” command to build a new gem.

#


211
212
213
# File 'lib/roebe/classes/make_gem.rb', line 211

def build_the_gem
  esystem 'gem build *.gemspec'
end

#check_for_readme_genObject

#

check_for_readme_gen

Some directories have files such as doc/README.gen. We will check for that, and then delegate towards class ReadmeGenerator in these cases.

To open that file, do:

bl $ROEBE/classes/readme_generator/readme_generator.rb
#


226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
# File 'lib/roebe/classes/make_gem.rb', line 226

def check_for_readme_gen
  this_file = 'doc/README.gen'
  if File.exist? this_file
    begin
      require 'roebe/classes/readme_generator/readme_generator.rb'
      opne "#{rev}Found file `#{sfile(this_file)}#{rev}`. Now "\
           "autogenerating the file"
      opne "#{sfile('README.md')} #{rev}here in #{sdir(return_pwd)}"
      Roebe::ReadmeGenerator.new { :do_not_open_in_the_browser }
    rescue LoadError
      e "#{rev}No file called roebe/classes/readme_generator/readme_generator.rb "\
        "is available"
    end
  end
end

#check_if_we_are_in_a_special_directoryObject

#

check_if_we_are_in_a_special_directory

#


112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
# File 'lib/roebe/classes/make_gem.rb', line 112

def check_if_we_are_in_a_special_directory
  _ = return_pwd
  # ======================================================================= #
  # === Handle the situation when we create a .gem for the bioroebe project
  # ======================================================================= #
  if in_a_bioroebe_directory?(_)
    if is_on_roebe?
      rename_kde_konsole_tab('Updating the bioroebe-gem', :be_quiet)
    end
    if File.symlink? BIOROEBE_GTK_SYMLINK
      delete_file(BIOROEBE_GTK_SYMLINK)
    end
  # ======================================================================= #
  # === Handle the situation when we are in the rbt project directory
  #
  # bl $rbt/toplevel_methods/generate_programs_version_yaml_file.rb
  # ======================================================================= #
  elsif _.include? "#{HOME_OF_THE_USER_CALLED_X}programming/ruby/src/rbt"
    prepare_the_gem_for_the_rbt_project
  elsif _.include? 'ruby/src/studium/'
    require 'studium'
    # ===================================================================== #
    # We will have to run some methods next, in order to upload
    # only useful data here.
    # ===================================================================== #
    # (1) Do a backup of the old 'lecture_information.yml' file.
    # ===================================================================== #
    Studium.backup_the_old_file_lecture_information
    # ===================================================================== #
    # (2) Generate a new file 'lecture_information.yml'.
    # ===================================================================== #
    target_file = Studium.log_dir?+'lecture_information/lecture_information.yml'
    mkdir(
      File.dirname(target_file)
    ) { :be_verbose }
    Studium.generate_a_new_file_lecture_information
    copy_file(
      target_file, RUBY_SRC_DIR+'studium/lib/studium/yaml/lecture_information/'
    )
    Roebe.rinstall2
    # ===================================================================== #
    # (3) The gem will be built at once.
    # ===================================================================== #
    build_the_gem
    # ===================================================================== #
    # (4) We will also publish the gem at once next.
    # ===================================================================== #
    e "#{rev}We will also automatically publish this gem at once."
    e "#{rev}This is "+orange('necessary')+"#{rev} so that we can "\
      "restore the old file called"
    e "#{sfile('lecture_information')} #{rev}again."
    require 'roebe/classes/publish_gem.rb'
    Roebe.publish_gem
    old_file = "#{Studium.log_dir?}backups/lecture_information.yml"
    opne "#{rev}Copying from `#{sfile(old_file)}#{rev}`."
    copy_file(
      old_file,
      RUBY_SRC_DIR+'studium/lib/studium/yaml/'
    )
    Roebe.rinstall2
    exit
  end
end

#check_size_of_the_created_gemObject

#

check_size_of_the_created_gem

#


188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
# File 'lib/roebe/classes/make_gem.rb', line 188

def check_size_of_the_created_gem
  _ = Dir['*.gem'].first
  if _
    size = File.size(_)
    if size > EIGHTY_MB # Check for too-big .gem files.
      ewarn ('NOTICE: The size is more than ')+
            steelblue('80 MB')+swarn('.')
      ewarn 'Have a look whether this is correct.'
      esystem 'xmessage "Have a look whether the size of the .gem is ok."'
    end
  else
    opne "#{rev}No .gem file was found here (#{sdir(return_pwd)})#{rev}. "\
         "This means that something must have went wrong."
    opne 'Thus, we will exit now.'
    exit
  end
end

#do_post_gem_creation_tasksObject

#

do_post_gem_creation_tasks (post tag)

This method can do some post-gem creation tasks, such as re-creating symlinks and what not.

#


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

def do_post_gem_creation_tasks
  if are_we_in_a_bioroebe_directory?
    opne "#{rev}Re-creating a symlink (#{BIOROEBE_GTK_SYMLINK})"
    unless File.exist? BIOROEBE_GTK_SYMLINK
      begin
        target = File.dirname(BIOROEBE_GTK_SYMLINK)+'/gtk2'
        if File.exist? BIOROEBE_GTK_SYMLINK
          File.symlink(
            BIOROEBE_GTK_SYMLINK,
            target # Is aliased to gtk2 for now.
          )
        else
          e "#{rev}No file exists at #{steelblue(target)}#{rev} - "\
            "thus, no symlink"
          e 'can be created.'
        end
      rescue Errno::EEXIST => error
        e "The file already exists (#{BIOROEBE_GTK_SYMLINK})"
        pp error
      end
    end
  end
end

#in_a_bioroebe_directory?(this_directory = return_pwd) ⇒ Boolean Also known as: are_we_in_a_bioroebe_directory?

#

in_a_bioroebe_directory?

#

Returns:

  • (Boolean)


179
180
181
182
183
# File 'lib/roebe/classes/make_gem.rb', line 179

def in_a_bioroebe_directory?(
    this_directory = return_pwd
  )
  this_directory.include? RUBY_SRC_DIR+'bioroebe'
end

#prepare_the_gem_for_the_rbt_projectObject

#

prepare_the_gem_for_the_rbt_project

This method will publish the rbt project.

#


247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
# File 'lib/roebe/classes/make_gem.rb', line 247

def prepare_the_gem_for_the_rbt_project
  return unless @may_we_prepare_the_gem_for_the_rbt_project
  if is_on_roebe?
    require 'rbt/requires/require_actions.rb'
    require 'rbt/version/version.rb'
    rename_kde_konsole_tab(
      "Updating RBT to Version #{RBT.version?}",
      :be_quiet
    )
  end
  require 'rbt'
  RBT.action(:save_available_programs)
  e orange('(1) RBT.save_the_available_programs_versions:')
  if RBT.respond_to? :save_the_available_programs_versions
    RBT.save_the_available_programs_versions
  else
    e "#{rev}RBT.save_the_available_programs_versions does not work."
  end
  if is_on_roebe?
   rename_kde_konsole_tab('', :be_quiet)
  end
end

#resetObject

#

reset (reset tag)

#


67
68
69
70
71
72
73
74
75
76
77
# File 'lib/roebe/classes/make_gem.rb', line 67

def reset
  super()
  infer_the_namespace
  # ======================================================================= #
  # === @may_we_prepare_the_gem_for_the_rbt_project
  #
  # Set the next variable to true if you wish to enable easy uploading
  # of the RBT project.
  # ======================================================================= #
  @may_we_prepare_the_gem_for_the_rbt_project = true
end

#runObject

#

run (run tag)

#


273
274
275
276
277
278
279
# File 'lib/roebe/classes/make_gem.rb', line 273

def run
  check_for_readme_gen # First, autogenerate if we can find README.gen files.
  check_if_we_are_in_a_special_directory
  build_the_gem
  check_size_of_the_created_gem
  do_post_gem_creation_tasks
end