Class: Mortar::Generators::CharacterizeGenerator

Inherits:
Base
  • Object
show all
Defined in:
lib/mortar/generators/characterize_generator.rb

Instance Method Summary collapse

Methods inherited from Base

#copy_file, #generate_file, #initialize, #inside, #mkdir

Methods included from Helpers

#action, #ask, #confirm, #copy_if_not_present_at_dest, #default_host, #deprecate, #display, #display_header, #display_object, #display_row, #display_table, #display_with_indent, #download_to_file, #ensure_dir_exists, #error, error_with_failure, error_with_failure=, extended, extended_into, #format_bytes, #format_date, #format_with_bang, #full_host, #get_terminal_environment, #home_directory, #host, #hprint, #hputs, included, included_into, #installed_with_omnibus?, #json_decode, #json_encode, #line_formatter, #longest, #output_with_bang, #pending_github_team_state_message, #quantify, #redisplay, #retry_on_exception, #running_on_a_mac?, #running_on_windows?, #set_buffer, #shell, #spinner, #status, #string_distance, #styled_array, #styled_error, #styled_hash, #styled_header, #suggestion, #test_name, #ticking, #time_ago, #truncate, #warning, #with_tty, #write_to_file

Constructor Details

This class inherits a constructor from Mortar::Generators::Base

Instance Method Details

#cleanup_characterize(project_root) ⇒ Object



52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/mortar/generators/characterize_generator.rb', line 52

def cleanup_characterize(project_root)
  @src_path = project_root
  begin
    inside "pigscripts" do
      remove_file "characterize.pig"
    end

    inside "controlscripts" do
      inside "lib" do
        remove_file "characterize_control.py"
      end
    end

    inside "macros" do
      remove_file "characterize_macro.pig"
    end

    inside "udfs" do
      inside "jython" do
        remove_file "top_5_tuple.py"
      end
    end

  # how best to handle exceptions, here?
  rescue => e 
    display("\nCharacterize script cleanup failed.\n\n")
    raise e
  end
end

#copy_file_char(src_file, dest_file, options = { :recursive => false }) ⇒ Object



91
92
93
94
95
96
97
98
99
100
101
# File 'lib/mortar/generators/characterize_generator.rb', line 91

def copy_file_char(src_file, dest_file, options={ :recursive => false })
  src_path = File.join(@src_path, @rel_path, src_file)
  dest_path = File.join(@dest_path, @rel_path, dest_file)
  msg = File.join(@rel_path, dest_file)[1..-1]

  unless File.exists?(dest_path) and 
      FileUtils.compare_file(src_path, dest_path)
    FileUtils.mkdir_p(File.dirname(dest_path)) if options[:recursive]
    FileUtils.cp(src_path, dest_path)
  end
end

#generate_characterizeObject



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/mortar/generators/characterize_generator.rb', line 23

def generate_characterize
  begin
    inside "pigscripts" do
      copy_file_char "characterize.pig", "characterize.pig"
    end

    inside "controlscripts" do
      inside "lib" do
        copy_file_char "characterize_control.py", "characterize_control.py"
      end
    end

    inside "macros" do
      copy_file_char "characterize_macro.pig", "characterize_macro.pig"
    end

    inside "udfs" do
      inside "jython" do
        copy_file_char "top_5_tuple.py", "top_5_tuple.py"
      end
    end

  # how best to handle exceptions, here?
  rescue => e 
    display("\nCharacterize script generation failed.\n\n")
    raise e
  end
end

#remove_file(target_file, options = { :recursive => false }) ⇒ Object



82
83
84
85
86
87
88
89
# File 'lib/mortar/generators/characterize_generator.rb', line 82

def remove_file(target_file, options={ :recursive => false })
  target_path = File.join(@src_path, @rel_path, target_file)
  msg = File.join(@rel_path, target_file)[1..-1]

  if File.exists?(target_path)
    FileUtils.rm(target_path)
  end
end