bin/sekka-server in sekka-1.7.0 vs bin/sekka-server in sekka-1.7.1
- old
+ new
@@ -5,10 +5,11 @@
require 'fileutils'
require 'rack'
require 'uri'
require 'sekkaconfig'
require 'sekka/sekkaversion'
+require 'sekka/downloader'
DICTDIR = File.expand_path( "~/.sekka-server" )
DICTURL = "https://raw.githubusercontent.com/kiyoka/sekka/master/public_dict/" + SekkaVersion.dictVersion
@@ -19,18 +20,22 @@
TC_FILE = sprintf( "%s/SEKKA-JISYO-%s.N.tch%s", DICTDIR, SekkaVersion.dictVersion, TC_OPTS )
TSV_FILE = sprintf( "%s/SEKKA-JISYO-%s.N.tsv", DICTDIR, SekkaVersion.dictVersion )
TSV_SUMFILE = sprintf( "%s/SEKKA-JISYO-%s.N.md5", DICTDIR, SekkaVersion.dictVersion )
LDB_FILE = sprintf( "%s/SEKKA-JISYO-%s.N.ldb.tar.gz", DICTDIR, SekkaVersion.dictVersion )
LDB_SUMFILE = sprintf( "%s/SEKKA-JISYO-%s.N.ldb.tar.gz.md5", DICTDIR, SekkaVersion.dictVersion )
+MAPDB_FILE = sprintf( "%s/SEKKA-JISYO-%s.N.mapdb", DICTDIR, SekkaVersion.dictVersion )
+MAPDB_SUMFILE = sprintf( "%s/SEKKA-JISYO-%s.N.mapdb.md5", DICTDIR, SekkaVersion.dictVersion )
-GDBM_FILE = sprintf( "%s/SEKKA-JISYO-%s.N.db", DICTDIR, SekkaVersion.dictVersion )
-LEVELDB_FILE = sprintf( "%s/SEKKA-JISYO-%s.N.ldb", DICTDIR, SekkaVersion.dictVersion )
+GDBM_FILE = sprintf( "%s/SEKKA-JISYO-%s.N.db", DICTDIR, SekkaVersion.dictVersion )
+LEVELDB_FILE = sprintf( "%s/SEKKA-JISYO-%s.N.ldb", DICTDIR, SekkaVersion.dictVersion )
TSV_URLURL = sprintf( "%s/SEKKA-JISYO-%s.N.url", DICTURL, SekkaVersion.dictVersion )
TSV_SUMURL = sprintf( "%s/SEKKA-JISYO-%s.N.md5", DICTURL, SekkaVersion.dictVersion )
LDB_URLURL = sprintf( "%s/SEKKA-JISYO-%s.N.ldb.tar.gz.url", DICTURL, SekkaVersion.dictVersion )
LDB_SUMURL = sprintf( "%s/SEKKA-JISYO-%s.N.ldb.tar.gz.md5", DICTURL, SekkaVersion.dictVersion )
+MAPDB_URLURL = sprintf( "%s/SEKKA-JISYO-%s.N.mapdb.url", DICTURL, SekkaVersion.dictVersion )
+MAPDB_SUMURL = sprintf( "%s/SEKKA-JISYO-%s.N.mapdb.md5", DICTURL, SekkaVersion.dictVersion )
MEMCACHED = "localhost:11211" # memcahced
def getSekkaDbInfo( env )
if env.has_key?( 'SEKKA_DB' )
@@ -46,15 +51,21 @@
[ :tokyocabinet, nil ]
elsif m = ENV['SEKKA_DB'].match( /^gdbm$/i )
[ :gdbm, nil ]
elsif m = ENV['SEKKA_DB'].match( /^level[a-z]+$/i )
[ :leveldb, nil ]
+ elsif m = ENV['SEKKA_DB'].match( /^map[a-z]+$/i )
+ [ :mapdb, nil ]
else
- raise RuntimeError, "Error: env var SEKKA_DB requires [redis:hostname] or [redis:] or [tokyocabinet] or [leveldb]"
+ raise RuntimeError, "Error: env var SEKKA_DB requires [redis:hostname] or [redis:] or [tokyocabinet] or [leveldb] or [mapdb]"
end
else
- [ :tokyocabinet, nil ]
+ if RUBY_PLATFORM == 'java'
+ [ :mapdb, nil ]
+ else
+ [ :tokyocabinet, nil ]
+ end
end
end
def checkJisyoIsInstalled( dictType, dictSource )
key = "SEKKA:VERSION"
@@ -81,10 +92,17 @@
kvs = Kvs.new( :tokyocabinet )
kvs.open( dictSource )
ret = kvs.get( key )
kvs.close()
ret
+ when :mapdb
+ require 'sekka/kvs'
+ kvs = Kvs.new( :mapdb )
+ kvs.open( dictSource )
+ ret = kvs.get( key )
+ kvs.close()
+ ret
when :redis
begin
require 'redis'
require 'sekka/kvs'
redis = Kvs.new( :redis )
@@ -101,42 +119,42 @@
end
def downloadFile( targetfile, sumfile, urlurl, sumurl )
if not File.exist?( targetfile )
STDERR.printf( "Info: Downloading SEKKA-JISYO\n" )
- # 辞書をダウンロードする
- cmd = sprintf( "curl %s", urlurl )
- STDERR.printf( "Command : %s\n", cmd )
- targeturl = open( "|" + cmd ) { |f|
- f.read
- }
- STDERR.printf( " download URL of target file : %s\n", targeturl );
- cmd = sprintf( "curl -o %s %s", targetfile, targeturl )
- STDERR.printf( "Command : %s\n", cmd )
- system( cmd )
- cmd = sprintf( "curl -o %s %s", sumfile, sumurl )
- STDERR.printf( "Command : %s\n", cmd )
- system( cmd )
+ # 辞書のURLをダウンロードする
+ dl = Downloader.new( urlurl )
+ dl.download()
+ targeturl = dl.getBody().chomp
+ dl.clearBody()
+ # md5記載ファイルをダウンロード
+ dl = Downloader.new( sumurl )
+ dl.download()
+ md5body = dl.getBody()
+ correctSum = md5body.chomp.split[0]
+ dl.clearBody()
+
+ # 辞書ファイル本体をダウンロード
+ STDERR.printf( " downloading URL : %s ...\n", targeturl );
+ dl = Downloader.new( targeturl )
+ dl.downloadToFile( targetfile )
+ dl.clearBody()
+
# チェックサムを確認する
- downloadSum = ""
- open( targetfile ) { |f|
- dataBody = f.read
- downloadSum = Digest::MD5.hexdigest( dataBody )
- }
- open( sumfile ) { |f|
- correctSum = f.readline.chomp.split[0]
- STDERR.printf( " downloaded file's MD5 : %s\n", downloadSum )
- STDERR.printf( " correct MD5 : %s\n", correctSum )
- if downloadSum == correctSum
- STDERR.printf( "Info: downloaded file [%s] verify OK.\n", targetfile )
- else
- STDERR.printf( "Error: downloaded file [%s] verify NG.\n", targetfile )
- File.unlink( targetfile )
- exit( 1 )
- end
- }
+ md5 = Digest::MD5.file( targetfile )
+ downloadSum = md5.hexdigest
+
+ STDERR.printf( " downloaded file's MD5 : %s\n", downloadSum )
+ STDERR.printf( " correct MD5 : %s\n", correctSum )
+ if downloadSum == correctSum
+ STDERR.printf( "Info: downloaded file [%s] verify OK.\n", targetfile )
+ else
+ STDERR.printf( "Error: downloaded file [%s] verify NG.\n", targetfile )
+ File.unlink( targetfile )
+ exit( 1 )
+ end
end
end
def main
if not File.directory?( DICTDIR )
@@ -163,10 +181,12 @@
# 必要なファイルをダウンロードする
case dictType
when :leveldb
downloadFile( LDB_FILE, LDB_SUMFILE, LDB_URLURL, LDB_SUMURL )
+ when :mapdb
+ downloadFile( MAPDB_FILE, MAPDB_SUMFILE, MAPDB_URLURL, MAPDB_SUMURL )
else
downloadFile( TSV_FILE, TSV_SUMFILE, TSV_URLURL, TSV_SUMURL )
end
case dictType
@@ -206,9 +226,20 @@
STDERR.printf( "Command : %s\n", cmd )
system( cmd )
end
STDERR.printf( "Info: [OK]\n" )
dictSource = TC_FILE
+
+ when :mapdb
+ # MapDBに辞書が投入済みか確認する
+ ok = checkJisyoIsInstalled( dictType, MAPDB_FILE )
+ unless ok
+ # tsvファイルをuploadする
+ STDERR.printf( "Error: mapdb file is not installed.\n" )
+ exit(1)
+ end
+ STDERR.printf( "Info: [OK]\n" )
+ dictSource = MAPDB_FILE
when :redis
# redisサーバーに辞書が投入済みか確認する
ok = checkJisyoIsInstalled( dictType, dictSource )
unless ok