[logaling-commit] logaling/logaling-command [use-relative-spurce-path] Insert relative_source_path into glossary_source table

Back to archive index

SUZUKI Miho null+****@clear*****
Fri Oct 12 21:43:23 JST 2012


SUZUKI Miho	2012-10-12 21:43:23 +0900 (Fri, 12 Oct 2012)

  New Revision: eaeac2b831f07621ea09ed6d790e7052f9a3adde
  https://github.com/logaling/logaling-command/commit/eaeac2b831f07621ea09ed6d790e7052f9a3adde

  Log:
    Insert relative_source_path into glossary_source table

  Modified files:
    lib/logaling/glossary.rb
    lib/logaling/glossary_db.rb
    lib/logaling/glossary_sources/base.rb
    lib/logaling/project.rb
    lib/logaling/repository.rb

  Modified: lib/logaling/glossary.rb (+1 -1)
===================================================================
--- lib/logaling/glossary.rb    2012-10-12 19:06:13 +0900 (fbc9fa9)
+++ lib/logaling/glossary.rb    2012-10-12 21:43:23 +0900 (5ec9249)
@@ -19,7 +19,7 @@ module Logaling
     SUPPORTED_FILE_TYPE = %w(yml tsv csv)
     SUPPORTED_ANNOTATION = %w(wip)
 
-    attr_reader :name, :source_language, :target_language
+    attr_reader :name, :source_language, :target_language, :project
 
     def initialize(name, source_language, target_language, project=nil)
       @name = name

  Modified: lib/logaling/glossary_db.rb (+8 -8)
===================================================================
--- lib/logaling/glossary_db.rb    2012-10-12 19:06:13 +0900 (189dcb3)
+++ lib/logaling/glossary_db.rb    2012-10-12 21:43:23 +0900 (eb3ba85)
@@ -62,14 +62,14 @@ module Logaling
     end
 
     def deindex_glossary(glossary, glossary_source)
-      delete_translations_by_glossary_source(glossary_source.source_path)
+      delete_translations_by_glossary_source(glossary_source.relative_source_path)
       delete_glossary(glossary.name)
-      delete_glossary_source(glossary_source.source_path)
+      delete_glossary_source(glossary_source.relative_source_path)
     end
 
     def deindex_glossary_source(glossary_source)
-      delete_translations_by_glossary_source(glossary_source.source_path)
-      delete_glossary_source(glossary_source.source_path)
+      delete_translations_by_glossary_source(glossary_source.relative_source_path)
+      delete_glossary_source(glossary_source.relative_source_path)
     end
 
     def index_glossary_source(glossary_source)
@@ -83,7 +83,7 @@ module Logaling
         source_term = term['source_term']
         target_term = term['target_term']
         note = term['note']
-        add_translation(glossary.name, glossary_source.source_path, glossary.source_language, glossary.target_language, source_term, target_term, note)
+        add_translation(glossary.name, glossary_source.relative_source_path, glossary.source_language, glossary.target_language, source_term, target_term, note)
       end
 
       create_terms if offline_index?
@@ -100,7 +100,7 @@ module Logaling
         source_term = term['source_term']
         target_term = term['target_term']
         note = term['note']
-        add_translation(glossary.name, glossary_source.source_path, glossary.source_language, glossary.target_language, source_term, target_term, note)
+        add_translation(glossary.name, glossary_source.relative_source_path, glossary.source_language, glossary.target_language, source_term, target_term, note)
       end
 
       create_terms if offline_index?
@@ -217,7 +217,7 @@ module Logaling
     def glossary_source_exist?(glossary_source)
       glossary = Groonga["glossary_sources"].select do |record|
         [
-          record.key == glossary_source.source_path,
+          record.key == glossary_source.relative_source_path,
           record.indexed_at == glossary_source.mtime
         ]
       end
@@ -260,7 +260,7 @@ module Logaling
     end
 
     def add_glossary_source(glossary_source)
-      Groonga["glossary_sources"].add(glossary_source.source_path, :indexed_at => glossary_source.mtime)
+      Groonga["glossary_sources"].add(glossary_source.relative_source_path, :indexed_at => glossary_source.mtime)
     end
 
     def delete_glossary(glossary_name)

  Modified: lib/logaling/glossary_sources/base.rb (+14 -1)
===================================================================
--- lib/logaling/glossary_sources/base.rb    2012-10-12 19:06:13 +0900 (9dfced5)
+++ lib/logaling/glossary_sources/base.rb    2012-10-12 21:43:23 +0900 (a1b601f)
@@ -18,7 +18,7 @@
 module Logaling
   module GlossarySources
     class Base
-      attr_reader :source_path, :glossary
+      attr_accessor :source_path, :glossary
 
       def initialize(source_path, glossary)
         @source_path = source_path
@@ -37,6 +37,19 @@ module Logaling
       def mtime
         File.mtime(@source_path)
       end
+
+      def relative_source_path
+        if glossary.project
+          if glossary.project.repository
+            logaling_home = glossary.project.repository.path
+          else
+            logaling_home = glossary.project.logaling_home
+          end
+        else
+          logaling_home = ''
+        end
+        source_path.sub(logaling_home, '')
+      end
     end
   end
 end

  Modified: lib/logaling/project.rb (+14 -0)
===================================================================
--- lib/logaling/project.rb    2012-10-12 19:06:13 +0900 (dc181f5)
+++ lib/logaling/project.rb    2012-10-12 21:43:23 +0900 (9771eb7)
@@ -49,6 +49,12 @@ module Logaling
       Logaling::Glossary.new(name, source_language, target_language, self)
     end
 
+    def logaling_home
+      path = glossary_source_path
+      3.times { path = File.dirname(path) }
+      path
+    end
+
     def glossary_source_path
       File.join(@path, "glossary")
     end
@@ -96,6 +102,10 @@ module Logaling
       [GlossarySource.create(@path, glossary(source_language, target_language))]
     end
 
+    def logaling_home
+      File.dirname(glossary_source_path)
+    end
+
     def glossary_source_path
       File.dirname(@path)
     end
@@ -128,6 +138,10 @@ module Logaling
       File.basename(@path).split(/\./).first
     end
 
+    def logaling_home
+      File.dirname(glossary_source_path)
+    end
+
     def glossary_sources
       name, source_language, target_language, type = File.basename(@path).split(/\./)
       [GlossarySource.create(@path, glossary(source_language, target_language))]

  Modified: lib/logaling/repository.rb (+4 -0)
===================================================================
--- lib/logaling/repository.rb    2012-10-12 19:06:13 +0900 (d39b8e9)
+++ lib/logaling/repository.rb    2012-10-12 21:43:23 +0900 (11f1360)
@@ -21,6 +21,8 @@ require "logaling/project"
 
 module Logaling
   class Repository
+    attr_reader :path
+
     def initialize(path)
       @path = path
     end
@@ -121,6 +123,8 @@ module Logaling
             db.index_glossary(glossary, glossary_source)
           end
         end
+#puts db.get_all_glossary_sources.inspect
+#puts all_glossary_sources.inspect
         (db.get_all_glossary_sources - all_glossary_sources).each do |glossary_source|
           glossary = glossary_source.glossary
           puts "now deindex #{glossary.name}..."
-------------- next part --------------
An HTML attachment was scrubbed...
Download 



More information about the logaling-commit mailing list
Back to archive index