tdiary-io-mongodb 4.1.0 → 4.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: cd626291a08fa158deffecdd80c5c7d97c155df6
4
- data.tar.gz: 6daee2e028071f83a88d8079efb2fdcc7f781e94
3
+ metadata.gz: 6548c0fd521b10af7a9eca195eadb3a09f626817
4
+ data.tar.gz: d5f7fb0a107de7832a947fbc3a6232e628279717
5
5
  SHA512:
6
- metadata.gz: f8a761e3561fce36d15c3e154e3c33305bd3d4a018e51ac303f4b30aeed143444dbe05e9f15f10d28e9b5f9f04f3c9776cf29e6905640159bf8d986c4ffb8dd0
7
- data.tar.gz: 57170406c2ede48bb2a61eaf38c13349b5f83a79195292f7c217655b45b554029a3de4aad52b2b7119b511f58dcaf3e659a7c286f748a68a20678308fe341092
6
+ metadata.gz: d9c6b4d82aa896d8d557c9182b4d121afb0f4664ce3a52e0313ca0fab42067d846b4da43ae19b03f5070e903e53187e956b504339815162c5316db16bb8c66f5
7
+ data.tar.gz: 4d1fa505079f8da704d38a5e744bb04977f77353f3d73a36f2e7c5a6e784d016a5f1f86977a04f8c43b0e9e79022bf6fa6d8cdd649849838439d34229b7be6e5
@@ -0,0 +1,88 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'optparse'
4
+ require 'erb'
5
+ require 'tdiary/view_helper'
6
+ require 'tdiary/base'
7
+ require 'tdiary/comment'
8
+ require 'tdiary/comment_manager'
9
+ require 'tdiary/referer_manager'
10
+ require 'tdiary/style'
11
+ require 'tdiary/cache/file'
12
+ require 'ostruct'
13
+
14
+ def load_diaries(data_path, style_path)
15
+ require 'tdiary/io/default'
16
+
17
+ options = {
18
+ 'style.path' => style_path
19
+ }
20
+ conf = OpenStruct.new({
21
+ data_path: "#{data_path}/",
22
+ options: options
23
+ })
24
+ tdiary = OpenStruct.new({conf: conf})
25
+ default_io = TDiary::IO::Default.new(tdiary)
26
+
27
+ default_io.calendar.each do |y, ms|
28
+ ms.each do |m|
29
+ puts "loading #{y}-#{m}"
30
+ month = Time.local(y.to_i, m.to_i)
31
+ default_io.transaction(month) do |diaries|
32
+ yield month, diaries
33
+ TDiary::TDiaryBase::DIRTY_NONE
34
+ end
35
+ end
36
+ end
37
+ end
38
+
39
+ def update_diaries(mongodb_io, month, new_diaries)
40
+ mongodb_io.transaction(month) do |diaries|
41
+ diaries.update(new_diaries)
42
+ TDiary::TDiaryBase::DIRTY_DIARY | TDiary::TDiaryBase::DIRTY_COMMENT
43
+ end
44
+ end
45
+
46
+ def store_diaries(data_path, style_path, mongo_url = nil)
47
+ require 'tdiary/io/mongodb'
48
+
49
+ options = {'style.path' => [style_path]}
50
+ conf = OpenStruct.new({options: options, database_url: mongo_url})
51
+ tdiary = OpenStruct.new({conf: conf})
52
+ TDiary::IO::MongoDB.load_cgi_conf(conf)
53
+ mongodb_io = TDiary::IO::MongoDB.new(tdiary)
54
+
55
+ load_diaries(data_path, style_path) do |month, diaries|
56
+ update_diaries(mongodb_io, month, diaries)
57
+ end
58
+ end
59
+
60
+ def store_conf(conf_path, mongo_url = nil)
61
+ require 'tdiary/io/mongodb'
62
+
63
+ conf = OpenStruct.new({options: {}, database_url: mongo_url})
64
+ tdiary = OpenStruct.new({conf: conf})
65
+
66
+ TDiary::IO::MongoDB.save_cgi_conf(conf, open(conf_path, &:read))
67
+ end
68
+
69
+ args = {}
70
+ OptionParser.new do |opts|
71
+ opts.banner = 'Usage: tdiary-mongodb-convert [options] <data_path>'
72
+ opts.on('-c CONF', '--conf=CONF', 'store only tdiary.conf'){|v| args[:conf] = v}
73
+ opts.on('-s PATH', '--style=STYLE', 'style path'){|v| args[:style] = v}
74
+ opts.on('-m URL', '--mongo=URL', 'URL of mongoDB'){|v| args[:mongo] = v}
75
+ opts.parse!(ARGV)
76
+
77
+ args[:data] = ARGV.shift
78
+ unless args[:data] || args[:conf]
79
+ $stderr.print opts.help
80
+ exit 1
81
+ end
82
+ end
83
+
84
+ if args[:conf]
85
+ store_conf(args[:conf], args[:mongo])
86
+ else
87
+ store_diaries(args[:data], args[:style], args[:mongo])
88
+ end
@@ -4,7 +4,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
4
 
5
5
  Gem::Specification.new do |spec|
6
6
  spec.name = "tdiary-io-mongodb"
7
- spec.version = "4.1.0"
7
+ spec.version = "4.1.1"
8
8
  spec.authors = ["TADA Tadashi"]
9
9
  spec.email = ["t@tdtds.jp"]
10
10
  spec.description = %q{MongoDB adapter for tDiary}
@@ -18,6 +18,7 @@ Gem::Specification.new do |spec|
18
18
  spec.require_paths = ["lib"]
19
19
 
20
20
  spec.add_dependency "mongoid"
21
+ spec.add_dependency "hikidoc"
21
22
 
22
23
  spec.add_development_dependency "bundler", "~> 1.3"
23
24
  spec.add_development_dependency "rake"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tdiary-io-mongodb
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.1.0
4
+ version: 4.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - TADA Tadashi
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-11-29 00:00:00.000000000 Z
11
+ date: 2015-01-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: mongoid
@@ -24,6 +24,20 @@ dependencies:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: hikidoc
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
27
41
  - !ruby/object:Gem::Dependency
28
42
  name: bundler
29
43
  requirement: !ruby/object:Gem::Requirement
@@ -83,7 +97,8 @@ dependencies:
83
97
  description: MongoDB adapter for tDiary
84
98
  email:
85
99
  - t@tdtds.jp
86
- executables: []
100
+ executables:
101
+ - tdiary-mongodb-convert
87
102
  extensions: []
88
103
  extra_rdoc_files: []
89
104
  files:
@@ -93,6 +108,7 @@ files:
93
108
  - LICENSE.txt
94
109
  - README.md
95
110
  - Rakefile
111
+ - bin/tdiary-mongodb-convert
96
112
  - lib/tdiary/io/mongodb.rb
97
113
  - spec/spec_helper.rb
98
114
  - spec/tdiary/io/mongodb_spec.rb
@@ -117,7 +133,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
117
133
  version: '0'
118
134
  requirements: []
119
135
  rubyforge_project:
120
- rubygems_version: 2.2.2
136
+ rubygems_version: 2.4.5
121
137
  signing_key:
122
138
  specification_version: 4
123
139
  summary: MongoDB adapter for tDiary