gonzui 1.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (116) hide show
  1. data/AUTHORS.txt +9 -0
  2. data/History.txt +5539 -0
  3. data/Manifest.txt +115 -0
  4. data/PostInstall.txt +17 -0
  5. data/README.rdoc +149 -0
  6. data/Rakefile +28 -0
  7. data/bin/gonzui-db +167 -0
  8. data/bin/gonzui-import +177 -0
  9. data/bin/gonzui-remove +58 -0
  10. data/bin/gonzui-search +68 -0
  11. data/bin/gonzui-server +176 -0
  12. data/bin/gonzui-update +53 -0
  13. data/data/gonzui/catalog/catalog.ja +80 -0
  14. data/data/gonzui/doc/favicon.ico +0 -0
  15. data/data/gonzui/doc/folder.png +0 -0
  16. data/data/gonzui/doc/gonzui.css +279 -0
  17. data/data/gonzui/doc/gonzui.js +111 -0
  18. data/data/gonzui/doc/text.png +0 -0
  19. data/data/gonzuirc.sample +29 -0
  20. data/ext/autopack/autopack.c +88 -0
  21. data/ext/autopack/extconf.rb +3 -0
  22. data/ext/delta/delta.c +147 -0
  23. data/ext/delta/extconf.rb +5 -0
  24. data/ext/texttokenizer/extconf.rb +5 -0
  25. data/ext/texttokenizer/texttokenizer.c +93 -0
  26. data/ext/xmlformatter/extconf.rb +5 -0
  27. data/ext/xmlformatter/xmlformatter.c +207 -0
  28. data/lib/gonzui.rb +59 -0
  29. data/lib/gonzui/apt.rb +193 -0
  30. data/lib/gonzui/bdbdbm.rb +118 -0
  31. data/lib/gonzui/cmdapp.rb +14 -0
  32. data/lib/gonzui/cmdapp/app.rb +175 -0
  33. data/lib/gonzui/cmdapp/search.rb +134 -0
  34. data/lib/gonzui/config.rb +117 -0
  35. data/lib/gonzui/content.rb +19 -0
  36. data/lib/gonzui/dbm.rb +673 -0
  37. data/lib/gonzui/deindexer.rb +162 -0
  38. data/lib/gonzui/delta.rb +49 -0
  39. data/lib/gonzui/extractor.rb +347 -0
  40. data/lib/gonzui/fetcher.rb +309 -0
  41. data/lib/gonzui/gettext.rb +144 -0
  42. data/lib/gonzui/importer.rb +84 -0
  43. data/lib/gonzui/indexer.rb +316 -0
  44. data/lib/gonzui/info.rb +80 -0
  45. data/lib/gonzui/license.rb +100 -0
  46. data/lib/gonzui/logger.rb +48 -0
  47. data/lib/gonzui/monitor.rb +177 -0
  48. data/lib/gonzui/progressbar.rb +235 -0
  49. data/lib/gonzui/remover.rb +38 -0
  50. data/lib/gonzui/searcher.rb +330 -0
  51. data/lib/gonzui/searchquery.rb +235 -0
  52. data/lib/gonzui/searchresult.rb +111 -0
  53. data/lib/gonzui/updater.rb +254 -0
  54. data/lib/gonzui/util.rb +415 -0
  55. data/lib/gonzui/vcs.rb +128 -0
  56. data/lib/gonzui/webapp.rb +25 -0
  57. data/lib/gonzui/webapp/advsearch.rb +123 -0
  58. data/lib/gonzui/webapp/filehandler.rb +24 -0
  59. data/lib/gonzui/webapp/jsfeed.rb +61 -0
  60. data/lib/gonzui/webapp/markup.rb +445 -0
  61. data/lib/gonzui/webapp/search.rb +269 -0
  62. data/lib/gonzui/webapp/servlet.rb +319 -0
  63. data/lib/gonzui/webapp/snippet.rb +155 -0
  64. data/lib/gonzui/webapp/source.rb +37 -0
  65. data/lib/gonzui/webapp/stat.rb +137 -0
  66. data/lib/gonzui/webapp/top.rb +63 -0
  67. data/lib/gonzui/webapp/uri.rb +140 -0
  68. data/lib/gonzui/webapp/webrick.rb +48 -0
  69. data/script/console +10 -0
  70. data/script/destroy +14 -0
  71. data/script/generate +14 -0
  72. data/script/makemanifest.rb +21 -0
  73. data/tasks/extconf.rake +13 -0
  74. data/tasks/extconf/autopack.rake +43 -0
  75. data/tasks/extconf/delta.rake +43 -0
  76. data/tasks/extconf/texttokenizer.rake +43 -0
  77. data/tasks/extconf/xmlformatter.rake +43 -0
  78. data/test/_external_tools.rb +13 -0
  79. data/test/_test-util.rb +142 -0
  80. data/test/foo/Makefile.foo +66 -0
  81. data/test/foo/bar.c +5 -0
  82. data/test/foo/bar.h +6 -0
  83. data/test/foo/foo.c +25 -0
  84. data/test/foo/foo.spec +33 -0
  85. data/test/test_apt.rb +42 -0
  86. data/test/test_autopack_extn.rb +7 -0
  87. data/test/test_bdbdbm.rb +79 -0
  88. data/test/test_cmdapp-app.rb +35 -0
  89. data/test/test_cmdapp-search.rb +99 -0
  90. data/test/test_config.rb +28 -0
  91. data/test/test_content.rb +15 -0
  92. data/test/test_dbm.rb +171 -0
  93. data/test/test_deindexer.rb +50 -0
  94. data/test/test_delta.rb +66 -0
  95. data/test/test_extractor.rb +78 -0
  96. data/test/test_fetcher.rb +75 -0
  97. data/test/test_gettext.rb +50 -0
  98. data/test/test_gonzui.rb +11 -0
  99. data/test/test_helper.rb +10 -0
  100. data/test/test_importer.rb +56 -0
  101. data/test/test_indexer.rb +37 -0
  102. data/test/test_info.rb +82 -0
  103. data/test/test_license.rb +49 -0
  104. data/test/test_logger.rb +60 -0
  105. data/test/test_monitor.rb +23 -0
  106. data/test/test_searcher.rb +37 -0
  107. data/test/test_searchquery.rb +27 -0
  108. data/test/test_searchresult.rb +43 -0
  109. data/test/test_texttokenizer.rb +47 -0
  110. data/test/test_updater.rb +95 -0
  111. data/test/test_util.rb +149 -0
  112. data/test/test_vcs.rb +61 -0
  113. data/test/test_webapp-markup.rb +42 -0
  114. data/test/test_webapp-util.rb +19 -0
  115. data/test/test_webapp-xmlformatter.rb +19 -0
  116. metadata +291 -0
@@ -0,0 +1,177 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # gonzui-import - a tool to import contents from a gonzui DB
4
+ #
5
+ # Copyright (C) 2004-2005 Satoru Takabayashi <satoru@namazu.org>
6
+ # All rights reserved.
7
+ # This is free software with ABSOLUTELY NO WARRANTY.
8
+ #
9
+ # You can redistribute it and/or modify it under the terms of
10
+ # the GNU General Public License version 2.
11
+ #
12
+
13
+ # %LOADPATH%
14
+ require 'getoptlong'
15
+ require 'gonzui'
16
+ require 'gonzui/cmdapp'
17
+
18
+ include Gonzui
19
+
20
+ class GonzuiImport < CommandLineApplication
21
+ def do_show_usage
22
+ puts "Usage: #{program_name} [OPTION] TARGET..."
23
+ puts " TARGET: directories, archives, packages (by apt)"
24
+ puts
25
+ puts " -a, --apt PACKAGE... use apt-get to get a source package"
26
+ puts " --cvs REPOSITORY MODULE use cvs to get a source tree"
27
+ puts " --git REPOSITORY use git to get a source tree"
28
+ puts " --svn REPOSITORY MODULE use svn to get a source tree"
29
+ puts " --exclude=PATTERN exclude files matching PATTERN"
30
+ puts " [#{@config.exclude_pattern.to_s}]"
31
+ puts " --no-utf8 don't convert files to UTF-8"
32
+ puts " --no-ABBREV don't index ABBREV files. (ex. --no-text)"
33
+ puts " try --list-formats to see abbrev. list"
34
+ puts " --list-archives list all supported archives"
35
+ end
36
+
37
+ def do_get_option_table
38
+ table = [
39
+ ['--apt', '-a', GetoptLong::NO_ARGUMENT],
40
+ ['--cvs', GetoptLong::NO_ARGUMENT],
41
+ ['--git', GetoptLong::NO_ARGUMENT],
42
+ ['--svn', GetoptLong::NO_ARGUMENT],
43
+ ['--no-utf8', GetoptLong::NO_ARGUMENT],
44
+ ['--exclude', GetoptLong::REQUIRED_ARGUMENT],
45
+ ['--list-archives', GetoptLong::NO_ARGUMENT],
46
+ ]
47
+ LangScan.modules.each {|m|
48
+ option = "--no-" + m.abbrev
49
+ table.push([option, GetoptLong::NO_ARGUMENT])
50
+ }
51
+ return table
52
+ end
53
+
54
+ def validate_combinations(options)
55
+ keys = ["apt", "cvs", "svn"]
56
+ used_keys = keys.find_all {|key| options[key] }
57
+ n = used_keys.length
58
+ if n >= 2
59
+ eprintf("%s cannot be combined",
60
+ used_keys.map {|key| "--" + key }.join(" "))
61
+ end
62
+ end
63
+
64
+ def show_list_archives
65
+ supported_archives = Extractor.extnames.sort
66
+ supported_archives.each {|extname|
67
+ printf("%s\n", extname)
68
+ }
69
+ exit
70
+ end
71
+
72
+ def do_process_options(options)
73
+ validate_combinations(options)
74
+ @use_apt = if options["apt"] then true else false end
75
+ @use_cvs = if options["cvs"] then true else false end
76
+ @use_git = if options["git"] then true else false end
77
+ @use_svn = if options["svn"] then true else false end
78
+
79
+ @config.utf8 = false if options["no-utf8"]
80
+ if options["exclude"]
81
+ @config.exclude_pattern = Regexp.new(options["exclude"])
82
+ end
83
+ options.each_key {|key|
84
+ if m = /^no-(.+)$/.match(key)
85
+ abbrev = m[1]
86
+ @config.noindex_formats.push(abbrev)
87
+ end
88
+ }
89
+ show_list_archives if options["list-archives"]
90
+ show_usage if ARGV.empty?
91
+ if @use_cvs
92
+ eprintf("--cvs REPOSITORY MODULE") if ARGV.length != 2
93
+ @target_names = [[ARGV.first, ARGV.last]]
94
+ elsif @use_git
95
+ eprintf("--git REPOSITORY") if ARGV.length != 1
96
+ @target_names = [[ARGV.first]]
97
+ elsif @use_svn
98
+ eprintf("--svn REPOSITORY MODULE") if ARGV.length != 2
99
+ @target_names = [[ARGV.first, ARGV.last]]
100
+ else
101
+ @target_names = ARGV
102
+ end
103
+ end
104
+
105
+ def make_uri_for_vcs(target_name)
106
+ repository = target_name.first
107
+ mozule = target_name.last
108
+ if @use_cvs
109
+ return URI.for_cvs(repository, mozule)
110
+ elsif @use_svn
111
+ return URI.for_svn(repository, mozule)
112
+ elsif @use_git
113
+ return URI.for_git(repository)
114
+ else
115
+ assert_not_reached
116
+ end
117
+ end
118
+
119
+ def make_uri(target_name)
120
+ if @use_apt
121
+ return URI.for_apt(target_name)
122
+ elsif @use_cvs or @use_svn or @use_git
123
+ return make_uri_for_vcs(target_name)
124
+ end
125
+
126
+ begin
127
+ uri = URI.parse(target_name)
128
+ return uri if uri.absolute?
129
+ return URI.from_path(target_name)
130
+ rescue URI::InvalidURIError => e
131
+ begin
132
+ # windows
133
+ return URI.from_path(target_name)
134
+ rescue => e
135
+ # ignore
136
+ end
137
+ raise GonzuiError.new("#{target_name}: malformed URI")
138
+ end
139
+ end
140
+
141
+ def import(importer, target_name)
142
+ begin
143
+ uri = make_uri(target_name)
144
+ importer.import(uri)
145
+ @logger.log("imported %s", importer.last_package_name)
146
+ rescue GonzuiError => e
147
+ wprintf("%s", e.message)
148
+ end
149
+ end
150
+
151
+ def lower_priority
152
+ begin
153
+ Process.setpriority(Process::PRIO_PROCESS, 0, 10)
154
+ rescue NoMethodError, Errno::EACCES, NameError => e
155
+ end
156
+ end
157
+
158
+ def do_start
159
+ parse_options()
160
+ init_logger
161
+ lower_priority
162
+
163
+ show_progress = if @config.quiet then false else true end
164
+ importer = Importer.new(@config,
165
+ :show_progress => show_progress)
166
+ begin
167
+ @target_names.each {|target_name|
168
+ import(importer, target_name)
169
+ }
170
+ print importer.summary
171
+ importer.finish
172
+ rescue Interrupt
173
+ end
174
+ end
175
+ end
176
+
177
+ GonzuiImport.start
@@ -0,0 +1,58 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # gonzui-remove - a tool to remove contents from a gonzui DB
4
+ #
5
+ # Copyright (C) 2004-2005 Satoru Takabayashi <satoru@namazu.org>
6
+ # All rights reserved.
7
+ # This is free software with ABSOLUTELY NO WARRANTY.
8
+ #
9
+ # You can redistribute it and/or modify it under the terms of
10
+ # the GNU General Public License version 2.
11
+ #
12
+
13
+ # %LOADPATH%
14
+ require 'getoptlong'
15
+ require 'gonzui'
16
+ require 'gonzui/cmdapp'
17
+
18
+ include Gonzui
19
+ include Gonzui::Util
20
+
21
+ class GonzuiRemove < Gonzui::CommandLineApplication
22
+ def do_show_usage
23
+ puts "Usage: #{program_name} [OPTION] PACKAGE..."
24
+ end
25
+
26
+ def do_get_option_table
27
+ []
28
+ end
29
+
30
+ def do_process_options(options)
31
+ show_usage if ARGV.empty?
32
+ @package_names = ARGV
33
+ end
34
+
35
+ def do_start
36
+ parse_options()
37
+ ensure_db_directory_available
38
+ init_logger
39
+
40
+ show_progress = if @config.quiet then false else true end
41
+ remover = Remover.new(@config, :show_progress => show_progress)
42
+ begin
43
+ @package_names.each {|package_name|
44
+ begin
45
+ remover.remove_package(package_name)
46
+ @logger.log("removed %s", package_name)
47
+ rescue GonzuiError => e
48
+ wprintf("%s", e.message)
49
+ end
50
+ }
51
+ print remover.summary
52
+ ensure
53
+ remover.finish
54
+ end
55
+ end
56
+ end
57
+
58
+ GonzuiRemove.start
@@ -0,0 +1,68 @@
1
+ #!/usr/bin/env ruby
2
+ # -*- ruby -*-
3
+ #
4
+ # gonzui-search - a tool to search a gonzui DB
5
+ #
6
+ # Copyright (C) 2004-2005 Satoru Takabayashi <satoru@namazu.org>
7
+ # All rights reserved.
8
+ # This is free software with ABSOLUTELY NO WARRANTY.
9
+ #
10
+ # You can redistribute it and/or modify it under the terms of
11
+ # the GNU General Public License version 2.
12
+ #
13
+
14
+ # %LOADPATH%
15
+ require 'getoptlong'
16
+ require 'gonzui'
17
+ require 'gonzui/cmdapp'
18
+
19
+ include Gonzui
20
+
21
+ class GonzuiSearch < CommandLineApplication
22
+ def do_show_usage
23
+ puts "Usage: #{program_name} PATTERN"
24
+ puts " -P, --package=PACKAGE search for PACKAGE"
25
+ puts " -p, --prefix perform prefix search"
26
+ puts " -e, --regexp perform regular expression search"
27
+ puts " -t, --type=TYPE search for TYPE"
28
+ puts " funcall, fundef, fundecl, others"
29
+ puts " -n, --line-number print line number with output lines"
30
+ puts " -c, --count only print a count of matching words"
31
+ puts " -C, --context=NUM print NUM lines of output context"
32
+ puts " --color use markers to highlight the matching string"
33
+ puts " -h, --no-filename suppress the prefixing filename on output"
34
+ end
35
+
36
+ def do_get_option_table
37
+ [
38
+ ['--color', GetoptLong::NO_ARGUMENT],
39
+ ['--context', '-C', GetoptLong::REQUIRED_ARGUMENT],
40
+ ['--count', '-c', GetoptLong::NO_ARGUMENT],
41
+ ['--line-number', '-n', GetoptLong::NO_ARGUMENT],
42
+ ['--no-filename', '-h', GetoptLong::NO_ARGUMENT],
43
+ ['--package', '-P', GetoptLong::REQUIRED_ARGUMENT],
44
+ ['--prefix', '-p', GetoptLong::NO_ARGUMENT],
45
+ ['--regexp', '-e', GetoptLong::NO_ARGUMENT],
46
+ ['--type', '-t', GetoptLong::REQUIRED_ARGUMENT],
47
+ ]
48
+ end
49
+
50
+ def do_process_options(options)
51
+ @options = options
52
+ show_usage if ARGV.length != 1
53
+ @pattern = ARGV.first
54
+ end
55
+
56
+ def do_start
57
+ parse_options
58
+ ensure_db_directory_available
59
+ searcher = CommandLineSearcher.new(@config, @options)
60
+ begin
61
+ searcher.search(@pattern)
62
+ ensure
63
+ searcher.finish
64
+ end
65
+ end
66
+ end
67
+
68
+ GonzuiSearch.start
@@ -0,0 +1,176 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # gonzui-server - a web-based search engine of gonzui
4
+ #
5
+ # Copyright (C) 2004-2005 Satoru Takabayashi <satoru@namazu.org>
6
+ # All rights reserved.
7
+ # This is free software with ABSOLUTELY NO WARRANTY.
8
+ #
9
+ # You can redistribute it and/or modify it under the terms of
10
+ # the GNU General Public License version 2.
11
+ #
12
+
13
+ # %LOADPATH%
14
+ require 'webrick'
15
+ require 'gonzui'
16
+ require 'gonzui/cmdapp'
17
+ require 'gonzui/webapp'
18
+ require 'ftools'
19
+ require 'fileutils'
20
+
21
+ include WEBrick
22
+ include Gonzui
23
+ include FileUtils
24
+
25
+ class NullWriter
26
+ def << (message)
27
+ end
28
+ end
29
+
30
+ class GonzuiServer < CommandLineApplication
31
+ include GetText
32
+
33
+ def be_secure
34
+ return unless Process.uid == 0
35
+ uid = Etc::getpwnam(@config.user).uid
36
+ gid = Etc::getgrnam(@config.group).gid
37
+ touch(@config.pid_file)
38
+ touch(@config.gonzui_log_file)
39
+ touch(@config.access_log_file)
40
+ File.chown(uid, gid, @config.pid_file)
41
+ File.chown(uid, gid, @config.gonzui_log_file)
42
+ File.chown(uid, gid, @config.access_log_file)
43
+ Process.uid = uid
44
+ Process.gid = gid
45
+ Process.euid = uid
46
+ end
47
+
48
+ def make_webrick_options
49
+ log_proc = lambda {@logger.log("server started [%d]", Process.pid) }
50
+ webrick_options = {}
51
+ if @config.bind_address != '*'
52
+ webrick_options[:BindAddress] = @config.bind_address
53
+ end
54
+ webrick_options[:Port] = @config.http_port
55
+ if @config.daemon
56
+ eprintf("daemon mode is not supported in Windows platform") if windows?
57
+ webrick_options[:StartCallback] = lambda {
58
+ log_proc.call
59
+ start_daemon
60
+ }
61
+ webrick_options[:Logger] = Log.new(NullWriter.new) # be quiet
62
+ else
63
+ webrick_options[:StartCallback] = log_proc
64
+ webrick_options[:Logger] = Log.new(STDOUT, Log::ERROR)
65
+ end
66
+ access_logger = File.open(@config.access_log_file, "a")
67
+ access_logger.sync = true
68
+ webrick_options[:AccessLog] =
69
+ [[ access_logger, AccessLog::COMBINED_LOG_FORMAT ]]
70
+ return webrick_options
71
+ end
72
+
73
+ def read_pid_file
74
+ File.read(@config.pid_file).chomp.to_i
75
+ end
76
+
77
+ def write_pid_file
78
+ begin
79
+ File.open(@config.pid_file, "w") {|f| f.puts Process.pid }
80
+ rescue
81
+ # FIXME: we need logging here.
82
+ end
83
+ end
84
+
85
+ def remove_pid_file
86
+ File.safe_unlink(@config.pid_file)
87
+ end
88
+
89
+ def start_daemon
90
+ Daemon.start
91
+ write_pid_file
92
+ be_secure
93
+ end
94
+
95
+ def stop_daemon
96
+ begin
97
+ pid = read_pid_file
98
+ Process.kill("TERM", pid)
99
+ rescue
100
+ wprintf("no processe to kill" )
101
+ end
102
+ remove_pid_file
103
+ exit
104
+ end
105
+
106
+ def do_show_usage
107
+ puts "Usage: #{program_name} [OPTION]"
108
+ puts " -p, --port=PORT listen on the specified PORT [#{@config.http_port}]"
109
+ puts " --bind=ADDRESS listen on the specified ADDRESS [#{@config.bind_address}]"
110
+ puts " --daemon run as a daemon"
111
+ puts " -u, --user=USER use USER's UID when daemonized [#{@config.user}]"
112
+ puts " -g, --group=GROUP use GROUP's GID when daemonized [#{@config.group}]"
113
+ puts " -t, --title=TITLE use TITLE for HTML contents [#{@config.site_title}]"
114
+ end
115
+
116
+ def do_get_option_table
117
+ [
118
+ ['--port', '-p', GetoptLong::REQUIRED_ARGUMENT],
119
+ ['--bind', GetoptLong::REQUIRED_ARGUMENT],
120
+ ['--user', '-u', GetoptLong::REQUIRED_ARGUMENT],
121
+ ['--group', '-g', GetoptLong::REQUIRED_ARGUMENT],
122
+ ['--title', '-t', GetoptLong::REQUIRED_ARGUMENT],
123
+ ['--daemon', GetoptLong::NO_ARGUMENT],
124
+ ['--stop', GetoptLong::NO_ARGUMENT],
125
+ ]
126
+ end
127
+
128
+ def do_process_options(options)
129
+ @config.http_port = options["port"].to_i if options["port"]
130
+ @config.bind_address = options["bind"] if options["bind"]
131
+ @config.user = options["user"] if options["user"]
132
+ @config.group = options["group"] if options["group"]
133
+ @config.site_title = options["title"] if options["title"]
134
+ @config.daemon = true if options["daemon"]
135
+ stop_daemon if options["stop"]
136
+ end
137
+
138
+ def start_server(dbm, catalog_repository)
139
+ server = HTTPServer.new(make_webrick_options)
140
+ trap("INT"){ server.shutdown }
141
+ GonzuiServlet.servlets.each {|klass|
142
+ absolute_mount_point = URI.path_join(@config.base_mount_point,
143
+ klass.mount_point)
144
+ server.mount(absolute_mount_point, klass,
145
+ @config, @logger, dbm, catalog_repository)
146
+ }
147
+ server.start
148
+ end
149
+
150
+ def do_start
151
+ parse_options()
152
+ ensure_db_directory_available
153
+ init_logger
154
+ @logger.monitor = STDOUT unless @config.daemon
155
+
156
+ catalog_repository = CatalogRepository.new(@config.catalog_directory)
157
+ if @config.bind_address != '*'
158
+ printf("http://%s:%d/\n", @config.bind_address, @config.http_port)
159
+ else
160
+ printf("http://%s:%d/\n", Socket.gethostname, @config.http_port)
161
+ end
162
+
163
+ dbm = Gonzui::DBM.open(@config, true)
164
+ begin
165
+ start_server(dbm, catalog_repository)
166
+ rescue => e
167
+ eprintf("%s", e.message)
168
+ ensure
169
+ @logger.log("server stopped [%d]", Process.pid)
170
+ dbm.close
171
+ remove_pid_file
172
+ end
173
+ end
174
+ end
175
+
176
+ GonzuiServer.start