end
module_function :start_cursing, :stop_cursing
-Index.new
+Index.init
- begin
- Index.lock
- rescue Index::LockError => e
- require 'highline'
-
- h = HighLine.new
- h.wrap_at = :auto
- h.say Index.fancy_lock_error_message_for(e)
-
- case h.ask("Should I ask that process to kill itself? ")
- when /^\s*y(es)?\s*$/i
- h.say "Ok, suggesting seppuku..."
- FileUtils.touch Redwood::SUICIDE_FN
- sleep SuicideManager::DELAY * 2
- FileUtils.rm_f Redwood::SUICIDE_FN
- h.say "Let's try that again."
- retry
- else
- h.say <<EOS
- Ok, giving up. If the process crashed and left a stale lockfile, you
- can fix this by manually deleting #{Index.lockfile}.
- EOS
- exit
- end
- end
+ Index.lock_interactively or exit
begin
Redwood::start
Redwood::finish
stop_cursing
- Redwood::log "stopped cursing"
+ Redwood::Logger.remove_all_sinks!
+ Redwood::Logger.add_sink $stderr, false
+ debug "stopped cursing"
- if SuicideManager.instantiated? && SuicideManager.die?
+ if $die
- Redwood::log "I've been ordered to commit seppuku. I obey!"
+ info "I've been ordered to commit seppuku. I obey!"
end
if Redwood::exceptions.empty?
$terminal.wrap_at = :auto
Redwood::start
-index = Redwood::Index.new
+index = Redwood::Index.init
- index.lock_or_die
+ index.lock_interactively or exit
begin
Redwood::SourceManager.load_sources
op = [:asis, :restore, :discard].find { |x| opts[x] } || :asis
Redwood::start
-index = Redwood::Index.new
-
-restored_state =
- if opts[:restore]
- dump = {}
- $stderr.puts "Loading state dump from #{opts[:restore]}..."
- IO.foreach opts[:restore] do |l|
- l =~ /^(\S+) \((.*?)\)$/ or raise "Can't read dump line: #{l.inspect}"
- mid, labels = $1, $2
- dump[mid] = labels.symbolistize
- end
- $stderr.puts "Read #{dump.size} entries from dump file."
- dump
- else
- {}
+index = Redwood::Index.init
+
+restored_state = if opts[:restore]
+ dump = {}
+ $stderr.puts "Loading state dump from #{opts[:restore]}..."
+ IO.foreach opts[:restore] do |l|
+ l =~ /^(\S+) \((.*?)\)$/ or raise "Can't read dump line: #{l.inspect}"
+ mid, labels = $1, $2
+ dump[mid] = labels.to_set_of_symbols
end
+ $stderr.puts "Read #{dump.size} entries from dump file."
+ dump
+else
+ {}
+end
seen = {}
- index.lock_or_die
+ index.lock_interactively or exit
begin
index.load
end
Redwood::start
-index = Redwood::Index.new
+index = Redwood::Index.init
- index.lock_or_die
+ index.lock_interactively or exit
deleted_fp, spam_fp = nil
unless opts[:dry_run]
end
opts[:verbose] = true if opts[:very_verbose]
-add_labels = (opts[:add] || "").split(",").map { |l| l.intern }.uniq
-remove_labels = (opts[:remove] || "").split(",").map { |l| l.intern }.uniq
+add_labels = opts[:add].to_set_of_symbols ","
+remove_labels = opts[:remove].to_set_of_symbols ","
Trollop::die "nothing to do: no labels to add or remove" if add_labels.empty? && remove_labels.empty?
+ Trollop::die "no sources specified" if ARGV.empty?
Redwood::start
-index = Redwood::Index.new
++index = Redwood::Index.init
+ index.lock_interactively or exit
begin
- index = Redwood::Index.init
index.load
- source_ids =
- if opts[:all_sources]
- Redwood::SourceManager.sources
- else
- ARGV.map do |uri|
- Redwood::SourceManager.source_for uri or Trollop::die "Unknown source: #{uri}. Did you add it with sup-add first?"
- end
+ source_ids = if opts[:all_sources]
+ Redwood::SourceManager.sources
+ else
+ ARGV.map do |uri|
+ Redwood::SourceManager.source_for uri or Trollop::die "Unknown source: #{uri}. Did you add it with sup-add first?"
+ end
end.map { |s| s.id }
Trollop::die "nothing to do: no sources" if source_ids.empty?
end
def start
- Redwood::SentManager.new $config[:sent_source] || 'sup://sent'
- Redwood::ContactManager.new Redwood::CONTACT_FN
- Redwood::LabelManager.new Redwood::LABEL_FN
- Redwood::AccountManager.new $config[:accounts]
- Redwood::DraftManager.new Redwood::DRAFT_DIR
- Redwood::UpdateManager.new
- Redwood::PollManager.new
- Redwood::CryptoManager.new
- Redwood::UndoManager.new
- Redwood::SourceManager.new
+ Redwood::SentManager.init $config[:sent_source] || 'sup://sent'
+ Redwood::ContactManager.init Redwood::CONTACT_FN
+ Redwood::LabelManager.init Redwood::LABEL_FN
+ Redwood::AccountManager.init $config[:accounts]
+ Redwood::DraftManager.init Redwood::DRAFT_DIR
+ Redwood::UpdateManager.init
+ Redwood::PollManager.init
- Redwood::SuicideManager.init Redwood::SUICIDE_FN
+ Redwood::CryptoManager.init
+ Redwood::UndoManager.init
+ Redwood::SourceManager.init
end
def finish
$encoding = "UTF-8"
end
-## now everything else (which can feel free to call Redwood::log at load time)
+require "sup/buffer"
+require "sup/keymap"
+require "sup/mode"
+require "sup/modes/scroll-mode"
+require "sup/modes/text-mode"
+require "sup/modes/log-mode"
require "sup/update"
- require "sup/suicide"
require "sup/message-chunks"
require "sup/message"
require "sup/source"
@lock_update_thread = nil
end
- def possibly_pluralize number_of, kind
- "#{number_of} #{kind}" +
- if number_of == 1 then "" else "s" end
- end
-
- def fancy_lock_error_message_for e
- secs = (Time.now - e.mtime).to_i
- mins = secs / 60
- time =
- if mins == 0
- possibly_pluralize secs , "second"
- else
- possibly_pluralize mins, "minute"
- end
-
- <<EOS
- Error: the sup index is locked by another process! User '#{e.user}' on
- host '#{e.host}' is running #{e.pname} with pid #{e.pid}. The process was alive
- as of #{time} ago.
- EOS
- end
-
- def lock_or_die
- begin
- lock
- rescue LockError => e
- $stderr.puts fancy_lock_error_message_for(e)
- $stderr.puts <<EOS
-
- You can wait for the process to finish, or, if it crashed and left a
- stale lock file behind, you can manually delete #{@lock.path}.
- EOS
- exit
- end
- end
-
def unlock
if @lock && @lock.locked?
- Redwood::log "unlocking #{lockfile}..."
+ debug "unlocking #{lockfile}..."
@lock.unlock
end
end