Module: Insup::Console
- Defined in:
- lib/insup/console.rb
Defined Under Namespace
Classes: UploadObserver
Class Method Summary collapse
- .commit(args) ⇒ Object
- .init(directory = nil) ⇒ Object
- .init_log(settings) ⇒ Object
- .insales_download_theme(force = false, theme_id = nil) ⇒ Object
- .insales_list_themes ⇒ Object
- .list_files(options = {}) ⇒ Object
- .list_locations ⇒ Object
- .listen ⇒ Object
- .print_config ⇒ Object
- .process_error(exception) ⇒ Object
- .start(settings_file = nil, verbose = false, debug = false) ⇒ Object
- .status ⇒ Object
Class Method Details
.commit(args) ⇒ Object
132 133 134 135 |
# File 'lib/insup/console.rb', line 132 def self.commit(args) @insup.uploader.add_observer(Insup::Console::UploadObserver.new) @insup.commit(args) end |
.init(directory = nil) ⇒ Object
50 51 52 53 |
# File 'lib/insup/console.rb', line 50 def self.init(directory = nil) directory ||= Dir.getwd Insup.create_insup_file(directory) end |
.init_log(settings) ⇒ Object
18 19 20 21 22 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 |
# File 'lib/insup/console.rb', line 18 def self.init_log(settings) if settings.log_file.nil? || settings.log_file.empty? @logger = Logger.new($stdout) else log_dir = File.dirname(settings.log_file) FileUtils.mkdir_p(log_dir) if !Dir.exist?(log_dir) @logger = Logger.new(settings.log_file) end @logger.level = @debug ? Logger::DEBUG : settings.log_level @logger.formatter = proc do |severity, datetime, progname, msg| format_string = settings.log_pattern values_hash = { level: severity, timestamp: datetime } if msg.is_a? Exception values_hash[:message] = msg. values_hash[:backtrace] = "\n#{msg.backtrace.join("\n")}" else values_hash[:message] = msg.to_s values_hash[:backtrace] = nil end format_string % values_hash end Insup.logger = @logger end |
.insales_download_theme(force = false, theme_id = nil) ⇒ Object
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/insup/console.rb', line 75 def self.insales_download_theme(force = false, theme_id = nil) theme_id ||= @settings.uploader['theme_id'] puts "Downloading theme #{theme_id}" @insup.insales.download_theme(theme_id, Dir.getwd) do |asset, exists| if exists && !force puts "#{asset.path} already exists" false else if exists puts "Overwriting #{asset.path}" else puts "Downloading #{asset.path}" end true end end end |
.insales_list_themes ⇒ Object
67 68 69 70 71 72 73 |
# File 'lib/insup/console.rb', line 67 def self.insales_list_themes theme_id = @settings.uploader['theme_id'] @insup.insales.themes.each do |theme| prefix = theme.id == theme_id ? '=>' : ' ' puts "#{prefix} #{theme.id}\t#{theme.title}" end end |
.list_files(options = {}) ⇒ Object
61 62 63 64 65 |
# File 'lib/insup/console.rb', line 61 def self.list_files( = {}) @insup.files().each do |f| puts f end end |
.list_locations ⇒ Object
55 56 57 58 59 |
# File 'lib/insup/console.rb', line 55 def self.list_locations @insup.tracked_locations.each do |loc| puts loc end end |
.listen ⇒ Object
116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 |
# File 'lib/insup/console.rb', line 116 def self.listen @insup.uploader.add_observer(Insup::Console::UploadObserver.new) puts 'Listening...' @insup.listen exit_requested = false Kernel.trap( "INT" ) { exit_requested = true } while !exit_requested do sleep(0.1) end puts 'Stopping listener...' @insup.stop_listening puts 'Terminated by user' end |
.print_config ⇒ Object
107 108 109 110 111 112 113 114 |
# File 'lib/insup/console.rb', line 107 def self.print_config puts "Tracker: #{@settings.tracker['class']}" puts "Uploader: #{@settings.uploader['class']}" puts 'Tracked locations:' puts @settings.tracked_locations.map{|loc| "\t#{loc}"} puts 'Ignore patterns:' puts @settings.ignore_patterns.map{|ip| "\t#{ip}"} end |
.process_error(exception) ⇒ Object
137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 |
# File 'lib/insup/console.rb', line 137 def self.process_error(exception) if exception.is_a? Insup::Exceptions::UploaderError $stderr.puts "UploaderError: #{exception.}".red else $stderr.puts "Error: #{exception.}".red end if @debug $stderr.puts exception.backtrace end begin @logger.error(exception) if @logger rescue $stderr.puts "Unable to log error because the logger is not properly configured" end end |
.start(settings_file = nil, verbose = false, debug = false) ⇒ Object
8 9 10 11 12 13 14 15 16 |
# File 'lib/insup/console.rb', line 8 def self.start(settings_file = nil, verbose = false, debug = false) settings_file ||= '.insup' @settings = Insup::Settings.new(settings_file) @insup = Insup.new(Dir.getwd, @settings) @verbose = verbose @debug = debug self.init_log(@settings) true end |
.status ⇒ Object
94 95 96 97 98 99 100 101 102 103 104 105 |
# File 'lib/insup/console.rb', line 94 def self.status @insup.changes.each do |x| case x.state when Insup::TrackedFile::NEW puts "New: #{x.path}".green when Insup::TrackedFile::MODIFIED puts "Modified: #{x.path}".yellow when Insup::TrackedFile::DELETED puts "Deleted: #{x.path}".red end end end |