Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

file manager handles new documents. autosave calls file manager corre…

…ctly
  • Loading branch information...
commit 8d3c809e5339f07cc3d3ae6f7061841c5919978c 1 parent ce34586
Greg Borenstein authored
Showing with 19 additions and 9 deletions.
  1. +8 −5 autosave.rb
  2. +11 −4 script/file_manager.rb
View
13 autosave.rb
@@ -1,10 +1,10 @@
-dirname = ARGV[0]
-dbname = ARGV[1]
+dbname = ARGV[0]
-PROJECT_ROOT = "#{File.dirname(__FILE__)}/.." unless defined?(PROJECT_ROOT)
+PROJECT_ROOT = "#{File.expand_path(File.dirname(__FILE__))}/.." unless defined?(PROJECT_ROOT)
begin
+ puts "beginning autosave"
require 'osx/foundation'
OSX.require_framework '/System/Library/Frameworks/CoreServices.framework/Frameworks/CarbonCore.framework'
@@ -14,9 +14,12 @@
numEvents.times { |i| rpaths << paths[i] }
- if rpaths.any?{|p|/#{dirname}/.match(p)}
- puts `script/couchdir #{dirname} #{dbname}`
+ ["public", "controllers", "views"].each do |dir|
+ if rpaths.any?{|p| Regexp.new(dir).match(p)}
+ puts `ruby #{PROJECT_ROOT}/script/file_manager.rb #{dir}`
+ end
end
+
end
allocator = OSX::KCFAllocatorDefault
View
15 script/file_manager.rb
@@ -6,6 +6,7 @@
todo = ARGV
todo = ["views", "public", "controllers"] if ARGV.include? "all"
+
PROJECT_ROOT = "#{File.dirname(__FILE__)}/.." unless defined?(PROJECT_ROOT)
DBNAME = JSON.load( open("#{PROJECT_ROOT}/config.json").read )["db"]
@@ -63,6 +64,8 @@
props["views"].delete("#{name}-reduce") unless props["views"]["#{name}-reduce"].keys.include?("reduce")
end
+# puts couch.to_yaml
+
# parsing done, begin posting
# connect to couchdb
@@ -130,7 +133,9 @@ def handle_errors(&block)
if todo.include? "public"
puts "posting public docs into CouchDB"
- puts "no docs in public"; exit if !couch["public"].empty?
+ if couch["public"].empty?
+ puts "no docs in public"; exit
+ end
@content_types = {
"html" => "text/html",
@@ -143,7 +148,7 @@ def handle_errors(&block)
def md5 string
Digest::MD5.hexdigest(string)
end
-
+
@attachments = {}
@signatures = {}
couch["public"].each do |doc|
@@ -156,14 +161,15 @@ def md5 string
end
doc = get("public")
+
unless doc
puts "creating public"
@db.save({"_id" => "public", "_attachments" => @attachments, "signatures" => @signatures})
exit
end
-
+
doc["signatures"].each do |path, sig|
- if @signatures[path] == sig
+ if (@signatures[path] == sig) && doc["signatures"].keys.include?(path)
puts "no change to #{path}. skipping..."
else
puts "replacing #{path}"
@@ -179,5 +185,6 @@ def md5 string
end
end
end
+
puts
end
Please sign in to comment.
Something went wrong with that request. Please try again.