require 'zlib'
require 'thread'
require 'fileutils'
-require 'lockfile'
-
-## time for some monkeypatching!
-class Lockfile
- def gen_lock_id
- Hash[
- 'host' => "#{ Socket.gethostname }",
- 'pid' => "#{ Process.pid }",
- 'ppid' => "#{ Process.ppid }",
- 'time' => timestamp,
- 'user' => ENV["USER"]
- ]
- end
-
- def dump_lock_id lock_id = @lock_id
- "host: %s\npid: %s\nppid: %s\ntime: %s\nuser: %s\n" %
- lock_id.values_at('host','pid','ppid','time','user')
- end
-
- def lockinfo_on_disk
- load_lock_id IO.read(path)
- end
-end
+require 'curses'
class Object
## this is for debugging purposes because i keep calling #id on the
end
end
-class LockError < StandardError
- def initialize h
- super ""
- @h = h
- end
-
- def method_missing m; @h[m.to_s] end
-end
-
class Module
def yaml_properties *props
props = props.map { |p| p.to_s }
end
module Redwood
- VERSION = "0.0.8"
+ VERSION = "0.2"
BASE_DIR = ENV["SUP_BASE"] || File.join(ENV["HOME"], ".sup")
CONFIG_FN = File.join(BASE_DIR, "config.yaml")
SENT_FN = File.join(BASE_DIR, "sent.mbox")
LOCK_FN = File.join(BASE_DIR, "lock")
SUICIDE_FN = File.join(BASE_DIR, "please-kill-yourself")
+ HOOK_DIR = File.join(BASE_DIR, "hooks")
YAML_DOMAIN = "masanjin.net"
YAML_DATE = "2006-10-01"
+## determine encoding and character set
+## probably a better way to do this
+ $ctype = ENV["LC_CTYPE"] || ENV["LANG"] || "en-US.utf-8"
+ $encoding =
+ if $ctype =~ /\.(.*)?/
+ $1
+ else
+ "utf-8"
+ end
+
## record exceptions thrown in threads nicely
$exception = nil
def reporting_thread
File.open("sup-exception-log.txt", "w") do |f|
f.puts "--- #{e.class.name} at #{Time.now}"
f.puts e.message, e.backtrace
- end unless e.is_a? SuicideException
+ end
$exception ||= e
raise
end
module_function :reporting_thread
## one-stop shop for yamliciousness
- def save_yaml_obj object, fn, compress=false
- if compress
- Zlib::GzipWriter.open(fn) { |f| f.puts object.to_yaml }
+ def save_yaml_obj object, fn, safe=false
+ if safe
+ safe_fn = "#{File.dirname fn}/safe_#{File.basename fn}"
+ mode = File.stat(fn) if File.exists? fn
+ File.open(safe_fn, "w", mode) { |f| f.puts object.to_yaml }
+ FileUtils.mv safe_fn, fn
else
File.open(fn, "w") { |f| f.puts object.to_yaml }
end
Redwood::UpdateManager.new
Redwood::PollManager.new
Redwood::SuicideManager.new Redwood::SUICIDE_FN
+ Redwood::CryptoManager.new
end
def finish
- Redwood::LabelManager.save
- Redwood::ContactManager.save
- Redwood::PersonManager.save
- Redwood::BufferManager.deinstantiate!
- end
-
- def lock
- FileUtils.rm_f SUICIDE_FN
-
- Redwood::log "locking #{LOCK_FN}..."
- $lock = Lockfile.new LOCK_FN, :retries => 0
- begin
- $lock.lock
- rescue Lockfile::MaxTriesLockError
- raise LockError, $lock.lockinfo_on_disk
- end
- end
-
- def unlock
- Redwood::log "unlocking #{LOCK_FN}..."
- $lock.unlock if $lock
+ Redwood::LabelManager.save if Redwood::LabelManager.instantiated?
+ Redwood::ContactManager.save if Redwood::ContactManager.instantiated?
+ Redwood::PersonManager.save if Redwood::PersonManager.instantiated?
+ Redwood::BufferManager.deinstantiate! if Redwood::BufferManager.instantiated?
end
## not really a good place for this, so I'll just dump it here.
end
module_function :save_yaml_obj, :load_yaml_obj, :start, :finish,
- :lock, :unlock, :report_broken_sources
+ :report_broken_sources
end
## set up default configuration file
},
:editor => ENV["EDITOR"] || "/usr/bin/vim -f -c 'setlocal spell spelllang=en_us' -c 'set filetype=mail'",
:thread_by_subject => false,
+ :edit_signature => false,
+ :ask_for_cc => true,
+ :ask_for_bcc => false,
+ :confirm_no_attachments => true,
+ :confirm_top_posting => true,
}
begin
FileUtils.mkdir_p Redwood::BASE_DIR
end
require "sup/util"
+require "sup/hook"
+
+## we have to initialize this guy first, because other classes must
+## reference it in order to register hooks, and they do that at parse
+## time.
+Redwood::HookManager.new Redwood::HOOK_DIR
+
require "sup/update"
require "sup/suicide"
+require "sup/message-chunks"
require "sup/message"
require "sup/source"
require "sup/mbox"
require "sup/tagger"
require "sup/draft"
require "sup/poll"
+require "sup/crypto"
require "sup/modes/scroll-mode"
require "sup/modes/text-mode"
require "sup/modes/line-cursor-mode"
require "sup/modes/buffer-list-mode"
require "sup/modes/log-mode"
require "sup/modes/poll-mode"
+require "sup/modes/file-browser-mode"
+require "sup/modes/completion-mode"
require "sup/logger"
require "sup/sent"