bitclust-core 0.6.0 → 0.7.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (34) hide show
  1. checksums.yaml +7 -0
  2. data/ChangeLog +7 -0
  3. data/Gemfile +1 -0
  4. data/bitclust.gemspec +1 -0
  5. data/data/bitclust/template.offline/class +1 -1
  6. data/lib/bitclust/crossrubyutils.rb +2 -2
  7. data/lib/bitclust/methodentry.rb +1 -2
  8. data/lib/bitclust/progress_bar.rb +7 -0
  9. data/lib/bitclust/rdcompiler.rb +1 -1
  10. data/lib/bitclust/runner.rb +46 -32
  11. data/lib/bitclust/searcher.rb +14 -13
  12. data/lib/bitclust/silent_progress_bar.rb +17 -0
  13. data/lib/bitclust/subcommand.rb +27 -0
  14. data/lib/bitclust/subcommands/ancestors_command.rb +145 -0
  15. data/lib/bitclust/subcommands/chm_command.rb +268 -0
  16. data/lib/bitclust/subcommands/classes_command.rb +73 -0
  17. data/lib/bitclust/subcommands/extract_command.rb +55 -0
  18. data/lib/bitclust/subcommands/htmlfile_command.rb +105 -0
  19. data/lib/bitclust/subcommands/init_command.rb +29 -30
  20. data/lib/bitclust/subcommands/list_command.rb +39 -41
  21. data/lib/bitclust/subcommands/lookup_command.rb +71 -73
  22. data/lib/bitclust/subcommands/methods_command.rb +159 -0
  23. data/lib/bitclust/subcommands/preproc_command.rb +35 -0
  24. data/lib/bitclust/subcommands/property_command.rb +47 -48
  25. data/lib/bitclust/subcommands/query_command.rb +12 -18
  26. data/lib/bitclust/subcommands/server_command.rb +180 -182
  27. data/lib/bitclust/subcommands/setup_command.rb +85 -89
  28. data/lib/bitclust/subcommands/statichtml_command.rb +276 -0
  29. data/lib/bitclust/subcommands/update_command.rb +39 -41
  30. data/lib/bitclust/version.rb +1 -1
  31. data/test/test_bitclust.rb +1 -1
  32. data/test/test_rdcompiler.rb +1 -1
  33. data/test/test_runner.rb +7 -14
  34. metadata +120 -114
@@ -0,0 +1,35 @@
1
+ require 'pathname'
2
+ require 'optparse'
3
+
4
+ require 'bitclust/rrdparser'
5
+
6
+ module BitClust
7
+ module Subcommands
8
+ class PreprocCommand < Subcommand
9
+
10
+ def initialize
11
+ super
12
+ @params = { "version" => "2.0.0" }
13
+ @parser.banner = "Usage: #{File.basename($0, '.*')} <file>..."
14
+ @parser.on('--param=KVPAIR', 'Set parameter by key/value pair.') {|pair|
15
+ key, value = pair.split('=', 2)
16
+ params[key] = value
17
+ }
18
+ end
19
+
20
+ def exec(argv, options)
21
+ argv.each do |path|
22
+ File.open(path) {|file|
23
+ Preprocessor.wrap(file, @params).each do |line|
24
+ puts line
25
+ end
26
+ }
27
+ end
28
+ rescue WriterError => err
29
+ $stderr.puts err.message
30
+ exit 1
31
+ end
32
+
33
+ end
34
+ end
35
+ end
@@ -8,66 +8,65 @@ require 'yaml'
8
8
  require 'bitclust'
9
9
  require 'bitclust/subcommand'
10
10
 
11
- module BitClust::Subcommands
12
- class PropertyCommand < BitClust::Subcommand
13
- def initialize
14
- @mode = nil
15
- @parser = OptionParser.new {|opt|
16
- opt.banner = "Usage: #{File.basename($0, '.*')} property [options]"
17
- opt.on('--list', 'List all properties.') {
11
+ module BitClust
12
+ module Subcommands
13
+ class PropertyCommand < Subcommand
14
+ def initialize
15
+ super
16
+ @mode = nil
17
+ @parser.banner = "Usage: #{File.basename($0, '.*')} property [options]"
18
+ @parser.on('--list', 'List all properties.') {
18
19
  @mode = :list
19
20
  }
20
- opt.on('--get', 'Get property value.') {
21
+ @parser.on('--get', 'Get property value.') {
21
22
  @mode = :get
22
23
  }
23
- opt.on('--set', 'Set property value.') {
24
+ @parser.on('--set', 'Set property value.') {
24
25
  @mode = :set
25
26
  }
26
- opt.on('--help', 'Prints this message and quit.') {
27
- puts opt.help
28
- exit 0
29
- }
30
- }
31
- end
32
-
33
- def parse(argv)
34
- super
35
- unless @mode
36
- error "one of (--list|--get|--set) is required"
37
27
  end
38
- case @mode
39
- when :list
40
- unless argv.empty?
41
- error "--list requires no argument"
28
+
29
+ def parse(argv)
30
+ super
31
+ unless @mode
32
+ error "one of (--list|--get|--set) is required"
42
33
  end
43
- when :get
44
- ;
45
- when :set
46
- unless argv.size == 2
47
- error "--set requires just 2 arguments"
34
+ case @mode
35
+ when :list
36
+ unless argv.empty?
37
+ error "--list requires no argument"
38
+ end
39
+ when :get
40
+ ;
41
+ when :set
42
+ unless argv.size == 2
43
+ error "--set requires just 2 arguments"
44
+ end
45
+ else
46
+ raise "must not happen: #{@mode}"
48
47
  end
49
- else
50
- raise "must not happen: #{@mode}"
51
48
  end
52
- end
53
49
 
54
- def exec(db, argv)
55
- case @mode
56
- when :list
57
- db.properties.each do |key, val|
58
- puts "#{key}=#{val}"
59
- end
60
- when :get
61
- argv.each do |key|
62
- puts db.propget(key)
50
+ def exec(argv, options)
51
+ prefix = options[:prefix]
52
+ db = MethodDatabase.new(prefix)
53
+ case @mode
54
+ when :list
55
+ db.properties.each do |key, val|
56
+ puts "#{key}=#{val}"
57
+ end
58
+ when :get
59
+ argv.each do |key|
60
+ puts db.propget(key)
61
+ end
62
+ when :set
63
+ key, val = *argv
64
+ db.transaction {
65
+ db.propset key, val
66
+ }
67
+ else
68
+ raise "must not happen: #{@mode}"
63
69
  end
64
- when :set
65
- key, val = *argv
66
- db.transaction {
67
- db.propset key, val
68
- }
69
- else
70
- raise "must not happen: #{@mode}"
71
70
  end
72
71
  end
73
72
  end
@@ -8,26 +8,20 @@ require 'yaml'
8
8
  require 'bitclust'
9
9
  require 'bitclust/subcommand'
10
10
 
11
- module BitClust::Subcommands
12
- class QueryCommand < BitClust::Subcommand
11
+ module BitClust
12
+ module Subcommands
13
+ class QueryCommand < Subcommand
13
14
 
14
- def initialize
15
- @parser = OptionParser.new {|opt|
16
- opt.banner = "Usage: #{File.basename($0, '.*')} query <ruby-script>"
17
- opt.on('--help', 'Prints this message and quit.') {
18
- puts opt.help
19
- exit 0
20
- }
21
- }
22
- end
23
-
24
- def parse(argv)
25
- end
15
+ def initialize
16
+ super
17
+ @parser.banner = "Usage: #{File.basename($0, '.*')} query <ruby-script>"
18
+ end
26
19
 
27
- def exec(db, argv)
28
- argv.each do |query|
29
- #pp eval(query) # FIXME: causes ArgumentError
30
- p eval(query)
20
+ def exec(argv, options)
21
+ argv.each do |query|
22
+ # pp eval(query) # FIXME: causes ArgumentError
23
+ p eval(query)
24
+ end
31
25
  end
32
26
  end
33
27
  end
@@ -10,208 +10,206 @@ require 'uri'
10
10
  require 'bitclust'
11
11
  require 'bitclust/subcommand'
12
12
 
13
- module BitClust::Subcommands
14
- class ServerCommand < BitClust::Subcommand
15
- def initialize
16
- require 'webrick'
17
- require 'uri'
13
+ module BitClust
14
+ module Subcommands
15
+ class ServerCommand < Subcommand
16
+ def initialize
17
+ super
18
+ require 'webrick'
19
+ require 'uri'
18
20
 
19
- @params = {
20
- :BindAddress => "0.0.0.0",
21
- :Port => 10080
22
- }
23
- @baseurl = nil
24
- @dbpath = nil
25
- @srcdir = @datadir = @themedir = @theme = @templatedir = nil
26
- @encoding = 'utf-8' # encoding of view
27
- if Object.const_defined?(:Encoding)
28
- Encoding.default_external = @encoding
29
- end
21
+ @params = {
22
+ :BindAddress => "0.0.0.0",
23
+ :Port => 10080
24
+ }
25
+ @baseurl = nil
26
+ @dbpath = nil
27
+ @srcdir = @datadir = @themedir = @theme = @templatedir = nil
28
+ @encoding = 'utf-8' # encoding of view
29
+ if Object.const_defined?(:Encoding)
30
+ Encoding.default_external = @encoding
31
+ end
30
32
 
31
- @debugp = false
32
- @autop = false
33
- @browser = nil
34
- @pid_file = nil
35
- @capi = false
33
+ @debugp = false
34
+ @autop = false
35
+ @browser = nil
36
+ @pid_file = nil
37
+ @capi = false
36
38
 
37
- @parser = OptionParser.new
38
- @parser.banner = "#{$0} [--bind-address=ADDR] [--port=NUM] --baseurl=URL --database=PATH [--srcdir=PATH] [--datadir=PATH] [--themedir=PATH] [--debug] [--auto] [--browser=BROWSER] [--pid-file=PATH] [--capi]"
39
- @parser.on('--bind-address=ADDR', 'Bind address') {|addr|
40
- @params[:BindAddress] = addr
41
- }
42
- @parser.on('--port=NUM', 'Listening port number') {|num|
43
- @params[:Port] = num.to_i
44
- }
45
- @parser.on('--baseurl=URL', 'The base URL to host.') {|url|
46
- @baseurl = url
47
- }
48
- @parser.on('--database=PATH', 'MethodDatabase root directory.') {|path|
49
- @dbpath = path
50
- }
51
- @parser.on('--srcdir=PATH', 'BitClust source directory.') {|path|
52
- set_srcdir(path)
53
- }
54
- @parser.on('--datadir=PATH', 'BitClust data directory.') {|path|
55
- @datadir = path
56
- }
57
- @parser.on('--templatedir=PATH', 'Template directory.') {|path|
58
- @templatedir = path
59
- }
60
- @parser.on('--themedir=PATH', 'BitClust theme directory.') {|path|
61
- @themedir = path
62
- }
63
- @parser.on('--theme=THEME', 'BitClust theme.') {|th|
64
- @theme = th
65
- }
66
- @parser.on('--[no-]debug', 'Debug mode.') {|flag|
67
- @debugp = flag
68
- }
69
- @parser.on('--[no-]auto', 'Auto mode.') {|flag|
70
- @autop = flag
71
- }
72
- @parser.on('--browser=BROWSER', 'Open with the browser.') {|path|
73
- @browser = path
74
- }
75
- @parser.on('--pid-file=PATH', 'Write pid of the daemon to the specified file.') {|path|
76
- @pid_file = path
77
- }
78
- @parser.on('--help', 'Prints this message and quit.') {
79
- puts @parser.help
80
- exit 0
81
- }
82
- @parser.on('--capi', 'see also FunctionDatabase.') {|path|
83
- @capi = true
84
- }
85
- end
39
+ @parser.banner = "#{$0} [--bind-address=ADDR] [--port=NUM] --baseurl=URL --database=PATH [--srcdir=PATH] [--datadir=PATH] [--themedir=PATH] [--debug] [--auto] [--browser=BROWSER] [--pid-file=PATH] [--capi]"
40
+ @parser.on('--bind-address=ADDR', 'Bind address') {|addr|
41
+ @params[:BindAddress] = addr
42
+ }
43
+ @parser.on('--port=NUM', 'Listening port number') {|num|
44
+ @params[:Port] = num.to_i
45
+ }
46
+ @parser.on('--baseurl=URL', 'The base URL to host.') {|url|
47
+ @baseurl = url
48
+ }
49
+ @parser.on('--database=PATH', 'MethodDatabase root directory.') {|path|
50
+ @dbpath = path
51
+ }
52
+ @parser.on('--srcdir=PATH', 'BitClust source directory.') {|path|
53
+ set_srcdir(path)
54
+ }
55
+ @parser.on('--datadir=PATH', 'BitClust data directory.') {|path|
56
+ @datadir = path
57
+ }
58
+ @parser.on('--templatedir=PATH', 'Template directory.') {|path|
59
+ @templatedir = path
60
+ }
61
+ @parser.on('--themedir=PATH', 'BitClust theme directory.') {|path|
62
+ @themedir = path
63
+ }
64
+ @parser.on('--theme=THEME', 'BitClust theme.') {|th|
65
+ @theme = th
66
+ }
67
+ @parser.on('--[no-]debug', 'Debug mode.') {|flag|
68
+ @debugp = flag
69
+ }
70
+ @parser.on('--[no-]auto', 'Auto mode.') {|flag|
71
+ @autop = flag
72
+ }
73
+ @parser.on('--browser=BROWSER', 'Open with the browser.') {|path|
74
+ @browser = path
75
+ }
76
+ @parser.on('--pid-file=PATH', 'Write pid of the daemon to the specified file.') {|path|
77
+ @pid_file = path
78
+ }
79
+ @parser.on('--capi', 'see also FunctionDatabase.') {|path|
80
+ @capi = true
81
+ }
82
+ end
86
83
 
87
- def parse(argv)
88
- super
89
- load_config_file
90
- set_srcdir(srcdir_root) unless @srcdir
84
+ def parse(argv)
85
+ super
86
+ load_config_file
87
+ set_srcdir(srcdir_root) unless @srcdir
91
88
 
92
- unless @baseurl
93
- $stderr.puts "missing base URL. Use --baseurl or check ~/.bitclust/config"
94
- exit 1
95
- end
96
- unless @dbpath || @autop
97
- $stderr.puts "missing database path. Use --database"
98
- exit 1
99
- end
100
- unless @datadir
101
- $stderr.puts "missing datadir. Use --datadir"
102
- exit 1
103
- end
104
- unless @themedir
105
- $stderr.puts "missing themedir. Use --themedir"
106
- exit 1
107
- end
108
- if @pid_file
109
- if File.exist?(@pid_file)
110
- $stderr.puts "There is still #{@pid_file}. Is another process running?"
89
+ unless @baseurl
90
+ $stderr.puts "missing base URL. Use --baseurl or check ~/.bitclust/config"
111
91
  exit 1
112
92
  end
113
- @pid_file = File.expand_path(@pid_file)
114
- end
115
- end
116
-
117
- def exec(db, argv)
118
- require 'bitclust/app'
119
- if @debugp
120
- @params[:Logger] = WEBrick::Log.new($stderr, WEBrick::Log::DEBUG)
121
- @params[:AccessLog] = [
122
- [ $stderr, WEBrick::AccessLog::COMMON_LOG_FORMAT ],
123
- [ $stderr, WEBrick::AccessLog::REFERER_LOG_FORMAT ],
124
- [ $stderr, WEBrick::AccessLog::AGENT_LOG_FORMAT ],
125
- ]
126
- else
127
- @params[:Logger] = WEBrick::Log.new($stderr, WEBrick::Log::INFO)
128
- @params[:AccessLog] = []
93
+ unless @dbpath || @autop
94
+ $stderr.puts "missing database path. Use --database"
95
+ exit 1
96
+ end
97
+ unless @datadir
98
+ $stderr.puts "missing datadir. Use --datadir"
99
+ exit 1
100
+ end
101
+ unless @themedir
102
+ $stderr.puts "missing themedir. Use --themedir"
103
+ exit 1
104
+ end
105
+ if @pid_file
106
+ if File.exist?(@pid_file)
107
+ $stderr.puts "There is still #{@pid_file}. Is another process running?"
108
+ exit 1
109
+ end
110
+ @pid_file = File.expand_path(@pid_file)
111
+ end
129
112
  end
130
- basepath = URI.parse(@baseurl).path
131
- server = WEBrick::HTTPServer.new(@params)
132
113
 
133
- if @autop
134
- app = BitClust::App.new(
135
- :dbpath => Dir.glob("#{@database_prefix}-*"),
136
- :baseurl => @baseurl,
137
- :datadir => @datadir,
138
- :templatedir => @templatedir,
139
- :theme => @theme,
140
- :encoding => @encoding,
141
- :capi => @capi
142
- )
143
- app.interfaces.each do |version, interface|
144
- server.mount(File.join(basepath, version), interface)
114
+ def exec(argv, options)
115
+ require 'bitclust/app'
116
+ if @debugp
117
+ @params[:Logger] = WEBrick::Log.new($stderr, WEBrick::Log::DEBUG)
118
+ @params[:AccessLog] = [
119
+ [ $stderr, WEBrick::AccessLog::COMMON_LOG_FORMAT ],
120
+ [ $stderr, WEBrick::AccessLog::REFERER_LOG_FORMAT ],
121
+ [ $stderr, WEBrick::AccessLog::AGENT_LOG_FORMAT ],
122
+ ]
123
+ else
124
+ @params[:Logger] = WEBrick::Log.new($stderr, WEBrick::Log::INFO)
125
+ @params[:AccessLog] = []
145
126
  end
146
- server.mount(File.join(basepath, '/'), app)
147
- else
148
- viewpath = File.join(basepath, 'view')
149
- app = BitClust::App.new(
150
- :viewpath => viewpath,
151
- :dbpath => @dbpath,
152
- :baseurl => @baseurl,
153
- :datadir => @datadir,
154
- :templatedir => @templatedir,
155
- :theme => @theme,
156
- :encoding => @encoding,
157
- :capi => @capi
158
- )
159
- app.interfaces.each do |viewpath, interface|
160
- server.mount viewpath, interface
127
+ basepath = URI.parse(@baseurl).path
128
+ server = WEBrick::HTTPServer.new(@params)
129
+
130
+ if @autop
131
+ app = App.new(
132
+ :dbpath => Dir.glob("#{@database_prefix}-*"),
133
+ :baseurl => @baseurl,
134
+ :datadir => @datadir,
135
+ :templatedir => @templatedir,
136
+ :theme => @theme,
137
+ :encoding => @encoding,
138
+ :capi => @capi
139
+ )
140
+ app.interfaces.each do |version, interface|
141
+ server.mount(File.join(basepath, version), interface)
142
+ end
143
+ server.mount(File.join(basepath, '/'), app)
144
+ else
145
+ viewpath = File.join(basepath, 'view')
146
+ app = App.new(
147
+ :viewpath => viewpath,
148
+ :dbpath => @dbpath,
149
+ :baseurl => @baseurl,
150
+ :datadir => @datadir,
151
+ :templatedir => @templatedir,
152
+ :theme => @theme,
153
+ :encoding => @encoding,
154
+ :capi => @capi
155
+ )
156
+ app.interfaces.each do |viewpath, interface|
157
+ server.mount viewpath, interface
158
+ end
159
+ # Redirect from '/' to "#{viewpath}/"
160
+ server.mount('/', app)
161
161
  end
162
- # Redirect from '/' to "#{viewpath}/"
163
- server.mount('/', app)
164
- end
165
162
 
166
- server.mount File.join(basepath, 'theme/'), WEBrick::HTTPServlet::FileHandler, @themedir
163
+ server.mount File.join(basepath, 'theme/'), WEBrick::HTTPServlet::FileHandler, @themedir
167
164
 
168
- if @debugp
169
- trap(:INT) { server.shutdown }
170
- else
171
- WEBrick::Daemon.start do
172
- trap(:TERM) {
173
- server.shutdown
174
- begin
175
- File.unlink @pid_file if @pid_file
176
- rescue Errno::ENOENT
177
- end
178
- }
179
- File.open(@pid_file, 'w') {|f| f.write Process.pid } if @pid_file
165
+ if @debugp
166
+ trap(:INT) { server.shutdown }
167
+ else
168
+ WEBrick::Daemon.start do
169
+ trap(:TERM) {
170
+ server.shutdown
171
+ begin
172
+ File.unlink @pid_file if @pid_file
173
+ rescue Errno::ENOENT
174
+ end
175
+ }
176
+ File.open(@pid_file, 'w') {|f| f.write Process.pid } if @pid_file
177
+ end
180
178
  end
181
- end
182
- exit if $".include?("exerb/mkexy.rb")
183
- if @autop && !@browser
184
- case RUBY_PLATFORM
185
- when /mswin/
186
- @browser = "start"
179
+ exit if $".include?("exerb/mkexy.rb")
180
+ if @autop && !@browser
181
+ case RUBY_PLATFORM
182
+ when /mswin/
183
+ @browser = "start"
184
+ end
187
185
  end
186
+ system("#{@browser} http://localhost:#{@params[:Port]}/") if @browser
187
+ server.start
188
188
  end
189
- system("#{@browser} http://localhost:#{@params[:Port]}/") if @browser
190
- server.start
191
- end
192
189
 
193
- private
190
+ private
194
191
 
195
- def srcdir_root
196
- Pathname.new(__FILE__).realpath.dirname.parent.parent.parent.cleanpath
197
- end
192
+ def srcdir_root
193
+ Pathname.new(__FILE__).realpath.dirname.parent.parent.parent.cleanpath
194
+ end
198
195
 
199
- def set_srcdir(dir)
200
- @srcdir ||= dir
201
- @datadir ||= "#{@srcdir}/data/bitclust"
202
- @themedir ||= "#{@srcdir}/theme"
203
- end
196
+ def set_srcdir(dir)
197
+ @srcdir ||= dir
198
+ @datadir ||= "#{@srcdir}/data/bitclust"
199
+ @themedir ||= "#{@srcdir}/theme"
200
+ end
204
201
 
205
- def load_config_file
206
- home_directory = Pathname(ENV['HOME'])
207
- config_path = home_directory + ".bitclust/config"
208
- if config_path.exist?
209
- config = YAML.load_file(config_path)
210
- @baseurl ||= config[:baseurl]
211
- @dbpath ||= "#{config[:database_prefix]}-#{config[:default_version]}"
212
- @port ||= config[:port]
213
- @pid_file ||= config[:pid_file]
214
- @database_prefix ||= config[:database_prefix]
202
+ def load_config_file
203
+ home_directory = Pathname(ENV['HOME'])
204
+ config_path = home_directory + ".bitclust/config"
205
+ if config_path.exist?
206
+ config = YAML.load_file(config_path)
207
+ @baseurl ||= config[:baseurl]
208
+ @dbpath ||= "#{config[:database_prefix]}-#{config[:default_version]}"
209
+ @port ||= config[:port]
210
+ @pid_file ||= config[:pid_file]
211
+ @database_prefix ||= config[:database_prefix]
212
+ end
215
213
  end
216
214
  end
217
215
  end