X-Git-Url: https://git.cworth.org/git?a=blobdiff_plain;f=lib%2Fsup.rb;h=43daa7e7be19b0ba12c83bec1d67c5f50d0b6d94;hb=aa5608229171a78694c64d0a30375e765ffe86e0;hp=4f59eaaf13caf6f1c5187af73bc7f4b26201a24b;hpb=5057149d9c3b57c6b5c4d0964a0aae9d490aaa38;p=sup diff --git a/lib/sup.rb b/lib/sup.rb index 4f59eaa..43daa7e 100644 --- a/lib/sup.rb +++ b/lib/sup.rb @@ -5,6 +5,10 @@ require 'thread' require 'fileutils' require 'gettext' require 'curses' +begin + require 'fastthread' +rescue LoadError +end class Object ## this is for debugging purposes because i keep calling #id on the @@ -20,7 +24,7 @@ class Module vars = props.map { |p| "@#{p}" } klass = self path = klass.name.gsub(/::/, "/") - + klass.instance_eval do define_method(:to_yaml_properties) { vars } define_method(:to_yaml_type) { "!#{Redwood::YAML_DOMAIN},#{Redwood::YAML_DATE}/#{path}" } @@ -50,6 +54,8 @@ module Redwood YAML_DOMAIN = "masanjin.net" YAML_DATE = "2006-10-01" + DEFAULT_INDEX = 'ferret' + ## record exceptions thrown in threads nicely @exceptions = [] @exception_mutex = Mutex.new @@ -79,38 +85,51 @@ module Redwood module_function :reporting_thread, :record_exception, :exceptions ## one-stop shop for yamliciousness - def save_yaml_obj object, fn, safe=false + def save_yaml_obj o, fn, safe=false + o = if o.is_a?(Array) + o.map { |x| (x.respond_to?(:before_marshal) && x.before_marshal) || x } + else + o.respond_to?(:before_marshal) && o.before_marshal + end + if safe safe_fn = "#{File.dirname fn}/safe_#{File.basename fn}" mode = File.stat(fn).mode if File.exists? fn - File.open(safe_fn, "w", mode) { |f| f.puts object.to_yaml } + File.open(safe_fn, "w", mode) { |f| f.puts o.to_yaml } FileUtils.mv safe_fn, fn else - File.open(fn, "w") { |f| f.puts object.to_yaml } + File.open(fn, "w") { |f| f.puts o.to_yaml } end end def load_yaml_obj fn, compress=false - if File.exists? fn + o = if File.exists? fn if compress Zlib::GzipReader.open(fn) { |f| YAML::load f } else YAML::load_file fn end end + if o.is_a?(Array) + o.each { |x| x.after_unmarshal! if x.respond_to?(:after_unmarshal!) } + else + o.after_unmarshal! if o.respond_to?(:after_unmarshal!) + end + o 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::SuicideManager.new Redwood::SUICIDE_FN - Redwood::CryptoManager.new - Redwood::UndoManager.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 @@ -126,7 +145,7 @@ module Redwood def report_broken_sources opts={} return unless BufferManager.instantiated? - broken_sources = Index.sources.select { |s| s.error.is_a? FatalSourceError } + broken_sources = SourceManager.sources.select { |s| s.error.is_a? FatalSourceError } unless broken_sources.empty? BufferManager.spawn_unless_exists("Broken source notification for #{broken_sources.join(',')}", opts) do TextMode.new(<