Wiki2Go 1.15.1 → 1.16.0
Sign up to get free protection for your applications and to get access to all the features.
- data/bin/DebugWiki2GoServer.rb +10 -0
- data/bin/{Wiki2Go_make_repository.rb → Wiki2Go_make_cvs_repository.rb} +1 -1
- data/lib/Web2Go/WebrickRequest.rb +1 -1
- data/lib/Web2Go/WebrickResponse.rb +3 -3
- data/lib/Wiki2Go/BlackList.rb +24 -11
- data/lib/Wiki2Go/DotGraphics.rb +45 -5
- data/lib/Wiki2Go/FileStorage.rb +8 -2
- data/lib/Wiki2Go/GreyList.rb +38 -22
- data/lib/Wiki2Go/Install/make_repository.rb +351 -36
- data/lib/Wiki2Go/Install/make_site.rb +17 -8
- data/lib/Wiki2Go/Install/site/ruby.css +18 -0
- data/lib/Wiki2Go/Install/templates/admin.htm +11 -0
- data/lib/Wiki2Go/Install/templates/admin_pages/commit_site.txt +21 -0
- data/lib/Wiki2Go/Install/templates/admin_pages/edit.txt +33 -0
- data/lib/Wiki2Go/Install/templates/admin_pages/editfiles.txt +33 -0
- data/lib/Wiki2Go/Install/templates/admin_pages/greylist.txt +19 -37
- data/lib/Wiki2Go/Install/templates/admin_pages/show_log.txt +21 -0
- data/lib/Wiki2Go/Install/templates/admin_pages/update_conflicts.txt +38 -0
- data/lib/Wiki2Go/Install/templates/admin_pages/update_site.txt +49 -0
- data/lib/Wiki2Go/Install/wiki/ruby.css +18 -0
- data/lib/Wiki2Go/LineFormatter.rb +504 -0
- data/lib/Wiki2Go/Page.rb +50 -18
- data/lib/Wiki2Go/PublicWikiConfig.rb +34 -11
- data/lib/Wiki2Go/Server.rb +13 -2
- data/lib/Wiki2Go/SpamFilter.rb +27 -8
- data/lib/Wiki2Go/SyntaxHighlighter.rb +41 -0
- data/lib/Wiki2Go/Web.rb +0 -3
- data/lib/Wiki2Go/WebrickServlet.rb +2 -0
- data/lib/Wiki2Go/Wiki2Go.rb +19 -8
- data/lib/Wiki2Go/Wiki2GoConfig.rb +125 -18
- data/lib/Wiki2Go/Wiki2GoServlet.rb +32 -21
- data/lib/Wiki2Go/WikiFormatter.rb +55 -468
- data/lib/Wiki2Go/cgi/secure/log_rss +21 -0
- data/test/All.rb +21 -0
- data/test/TestBlackList.rb +82 -0
- data/test/TestConfig.rb +205 -0
- data/test/TestDot.rb +109 -0
- data/test/TestFormatter.rb +491 -0
- data/test/TestInstall.rb +120 -0
- data/test/TestLineFormatter.rb +553 -0
- data/test/TestMail.rb +29 -0
- data/test/TestRSS.rb +183 -0
- data/test/TestRepositoryMaker.rb +101 -0
- data/test/TestServer.rb +65 -0
- data/test/TestSpamFilter.rb +130 -0
- data/test/TestStorage.rb +212 -0
- data/test/TestSyntaxHighlighter.rb +41 -0
- data/test/TestUnitTestFiles.rb +27 -0
- data/test/TestUrlFinder.rb +39 -0
- data/test/TestWeb.rb +197 -0
- data/test/TestWeb2Go.rb +90 -0
- data/test/TestWiki2Go.rb +184 -0
- data/test/TestWiki2GoServlet.rb +747 -0
- data/test/UnitTestFiles.rb +102 -0
- data/test/Wiki2GoConfigForTest.rb +93 -0
- data/test/checksite.rb +56 -0
- data/test/testdata/changes.txt +4 -0
- data/test/testdata/expected_changes.html +93 -0
- data/test/testdata/expected_edit.html +105 -0
- data/test/testdata/expected_full_rss.xml +29 -0
- data/test/testdata/expected_header_rss.xml +13 -0
- data/test/testdata/expected_out.html +97 -0
- data/test/testdata/expected_put.html +99 -0
- data/test/testdata/expected_save.html +66 -0
- data/test/testdata/expected_savehtml.html +66 -0
- data/test/testdata/expected_search.html +67 -0
- data/test/testdata/expected_upload.html +69 -0
- data/test/testdata/expected_versions.html +85 -0
- data/test/testdata/expected_view.html +97 -0
- data/test/testdata/site/html/Xpday/rss.xml +103 -0
- data/test/testdata/templates/Test/child.htm +2 -0
- data/test/testdata/templates/Test/grandchild.htm +1 -0
- data/test/testdata/templates/Test/master.htm +3 -0
- data/test/testdata/texts/Test/FrontPage.txt +7 -0
- data/test/testdata/texts/Test/NewPage.txt +3 -0
- data/test/testdata/texts/Test/Subdir/Subpage.txt +1 -0
- data/test/testdata/texts/Test/empty.txt +3 -0
- data/test/testdata/texts/Test/test.txt +3 -0
- data/test/testdata/texts/Xpday/FrontPage.txt +36 -0
- data/test/testdata/texts/Xpday/Page.txt +3 -0
- data/test/testdata/texts/Xpday/VersionedPage.log +14 -0
- data/test/testdata/texts/Xpday/VersionedPage.txt +3 -0
- data/test/testdata/texts/Xpday/empty.log +3482 -0
- data/test/testdata/texts/Xpday/empty.txt +4 -0
- data/test/testdata/texts/Xpday/test.log +9425 -0
- data/test/testdata/texts/Xpday/test.txt +5 -0
- data/test/testdata/texts/whitelist.txt +1 -0
- metadata +85 -5
- data/lib/Wiki2Go/Install/templates/admin_pages/update.txt +0 -13
@@ -1,5 +1,5 @@
|
|
1
|
-
require '
|
2
|
-
require '
|
1
|
+
require 'webrick/httputils'
|
2
|
+
require 'webrick/cookie'
|
3
3
|
|
4
4
|
module Web2Go
|
5
5
|
|
@@ -34,7 +34,7 @@ module Web2Go
|
|
34
34
|
cookie = WEBrick::Cookie.new(name,value)
|
35
35
|
cookie.expires = expires unless expires.nil?
|
36
36
|
cookie.domain = domain unless domain.nil?
|
37
|
-
cookie.path = path
|
37
|
+
cookie.path = path.nil? ? '/' : path
|
38
38
|
set_cookie(cookie)
|
39
39
|
end
|
40
40
|
|
data/lib/Wiki2Go/BlackList.rb
CHANGED
@@ -1,38 +1,42 @@
|
|
1
1
|
|
2
2
|
module Wiki2Go
|
3
|
-
|
3
|
+
|
4
4
|
class BlackList
|
5
|
-
|
5
|
+
|
6
6
|
attr_reader :name
|
7
|
-
|
7
|
+
|
8
8
|
def initialize(name,items)
|
9
9
|
@name = name
|
10
|
+
@banned = []
|
10
11
|
items = items.collect {|line|
|
11
12
|
line.strip!
|
12
13
|
(line.empty? || line[0] == '#' ? nil : line)
|
13
14
|
}
|
14
15
|
@banned = items.compact
|
15
16
|
end
|
16
|
-
|
17
|
+
|
17
18
|
def all
|
18
19
|
return @banned
|
19
20
|
end
|
20
|
-
|
21
|
+
|
21
22
|
def add(item)
|
23
|
+
if item =~ /(:\/\/[^\/:]+)/ then
|
24
|
+
item = $1
|
25
|
+
end
|
22
26
|
item = escape_regex(item)
|
23
27
|
@banned << item
|
24
28
|
@banned = @banned.sort.uniq
|
25
29
|
end
|
26
|
-
|
30
|
+
|
27
31
|
def length
|
28
32
|
return @banned.length
|
29
33
|
end
|
30
|
-
|
34
|
+
|
31
35
|
def contains(user)
|
32
36
|
match = @banned.find { |ban| user =~ Regexp.new(ban,Regexp::IGNORECASE) }
|
33
37
|
! match.nil?
|
34
38
|
end
|
35
|
-
|
39
|
+
|
36
40
|
def found_in(lines)
|
37
41
|
lines = lines.join(' ') if lines.kind_of? Array
|
38
42
|
@banned.each do | pattern |
|
@@ -41,12 +45,21 @@ module Wiki2Go
|
|
41
45
|
end
|
42
46
|
return false
|
43
47
|
end
|
44
|
-
|
48
|
+
|
45
49
|
private
|
46
|
-
|
50
|
+
|
47
51
|
def escape_regex(item)
|
48
52
|
item.gsub(/\./,'\.')
|
49
53
|
end
|
54
|
+
|
55
|
+
def add_line(item)
|
56
|
+
if item =~ /(:\/\/[^\/:]+)/ then
|
57
|
+
item = $1
|
58
|
+
end
|
59
|
+
@banned << item
|
60
|
+
@banned = @banned.sort.uniq
|
61
|
+
end
|
62
|
+
|
50
63
|
end
|
51
|
-
|
64
|
+
|
52
65
|
end
|
data/lib/Wiki2Go/DotGraphics.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
#!/usr/bin/ruby
|
2
2
|
|
3
3
|
require 'English'
|
4
|
+
require 'Wiki2Go/LineFormatter'
|
4
5
|
|
5
6
|
module Wiki2Go
|
6
7
|
|
@@ -9,7 +10,7 @@ module Wiki2Go
|
|
9
10
|
|
10
11
|
class DotGraphics
|
11
12
|
|
12
|
-
def initialize(path)
|
13
|
+
def initialize(path='')
|
13
14
|
@path = path
|
14
15
|
end
|
15
16
|
|
@@ -28,7 +29,7 @@ module Wiki2Go
|
|
28
29
|
def save_if_necessary(config,web,content,force)
|
29
30
|
image = content
|
30
31
|
result = ''
|
31
|
-
if image =~ /^([^\s]
|
32
|
+
if image =~ /^([^\s,]+)\s/ then
|
32
33
|
filename = $1
|
33
34
|
image = $POSTMATCH
|
34
35
|
image = image.gsub('\n',' ').gsub('\r',' ')
|
@@ -46,12 +47,39 @@ module Wiki2Go
|
|
46
47
|
config.log("Writing image file to #{fullname}")
|
47
48
|
write(image,type,fullname)
|
48
49
|
end
|
49
|
-
|
50
|
+
if image =~ /url\s*=\s*\"([^\"]+)"/i then
|
51
|
+
mapname = File.basename(filename,'.*')
|
52
|
+
maptype = 'cmapx'
|
53
|
+
image = rewrite_urls(config,web,image)
|
54
|
+
map = generate(image,maptype)
|
55
|
+
map = map.gsub(/id="[^"]*"/,"id=\"#{mapname}\"").gsub(/name="[^"]*"/,"name=\"#{mapname}\"")
|
56
|
+
return "<img src=\"#{web.name}/graphics/#{filename}\" border=0 alt=\"#{filename}\" usemap=\"##{mapname}\">" + $/ + map
|
57
|
+
else
|
58
|
+
return "<img src=\"#{web.name}/graphics/#{filename}\" border=0 alt=\"#{filename}\">"
|
59
|
+
end
|
50
60
|
end
|
51
61
|
|
62
|
+
def rewrite_urls(config,web,image)
|
63
|
+
formatter = Wiki2Go::LineFormatter.new(web,config.storage,config,true,false)
|
64
|
+
|
65
|
+
image = image.gsub(/url\s*=\s*\"([^\"]+)"/i) { rewrite_url(config,web,formatter,$1) }
|
66
|
+
image
|
67
|
+
end
|
68
|
+
|
69
|
+
def rewrite_url(config,web,formatter,url)
|
70
|
+
if url =~ /:\/\// then
|
71
|
+
if config.redirect_url?(web,url) then
|
72
|
+
url = web.base_url + formatter.redirect_url(url)
|
73
|
+
end
|
74
|
+
else
|
75
|
+
url = formatter.absolute_url_of_topic(url)
|
76
|
+
end
|
77
|
+
"URL=\"#{url}\""
|
78
|
+
end
|
52
79
|
|
53
80
|
def write(graph,format,output)
|
54
|
-
|
81
|
+
command = @path.empty? ? 'dot' : File.join(@path,'dot')
|
82
|
+
cmdline = "#{command} -T#{format} -o#{output}"
|
55
83
|
IO.popen(cmdline,"w+") do |f|
|
56
84
|
f.puts graph
|
57
85
|
f.close_write
|
@@ -59,9 +87,21 @@ module Wiki2Go
|
|
59
87
|
end
|
60
88
|
end
|
61
89
|
|
90
|
+
def generate(graph,format)
|
91
|
+
command = @path.empty? ? 'dot' : File.join(@path,'dot')
|
92
|
+
cmdline = "#{command} -T#{format}"
|
93
|
+
result =""
|
94
|
+
IO.popen(cmdline,"w+") do |f|
|
95
|
+
f.puts graph
|
96
|
+
f.close_write
|
97
|
+
result = f.read
|
98
|
+
end
|
99
|
+
result
|
100
|
+
end
|
101
|
+
|
62
102
|
|
63
103
|
def ensure_directory_exists(path)
|
64
|
-
dir
|
104
|
+
dir = File.dirname(path)
|
65
105
|
FileUtils.makedirs(dir) unless File.directory?(dir)
|
66
106
|
end
|
67
107
|
end
|
data/lib/Wiki2Go/FileStorage.rb
CHANGED
@@ -38,8 +38,8 @@ module Wiki2Go
|
|
38
38
|
end
|
39
39
|
|
40
40
|
def save_page(subwiki,page)
|
41
|
-
path = text_filename(subwiki,page.
|
42
|
-
logfile = text_filename(subwiki,page.
|
41
|
+
path = text_filename(subwiki,page.filename,"txt")
|
42
|
+
logfile = text_filename(subwiki,page.filename,"log")
|
43
43
|
ensure_directory_exists(path)
|
44
44
|
append_current_text_to_logfile(path,logfile,page.author)
|
45
45
|
File.open(path,File::CREAT|File::TRUNC|File::RDWR) do |file|
|
@@ -58,6 +58,12 @@ module Wiki2Go
|
|
58
58
|
end
|
59
59
|
end
|
60
60
|
|
61
|
+
def delete_spam(subwiki,page)
|
62
|
+
text = text_filename(subwiki,page.filename,"txt")
|
63
|
+
spam_path = text_filename(subwiki,page.filename,"spam")
|
64
|
+
FileUtils::mv text,spam,:force => true
|
65
|
+
end
|
66
|
+
|
61
67
|
def save_html(subwiki,page, content)
|
62
68
|
path = File.join(@html,subwiki,page + ".html")
|
63
69
|
ensure_directory_exists(path)
|
data/lib/Wiki2Go/GreyList.rb
CHANGED
@@ -1,74 +1,82 @@
|
|
1
1
|
|
2
2
|
module Wiki2Go
|
3
|
-
|
3
|
+
|
4
4
|
class GreyList
|
5
|
-
|
5
|
+
|
6
6
|
class Suspect
|
7
7
|
include Comparable
|
8
|
-
|
8
|
+
|
9
9
|
attr_reader :url
|
10
10
|
attr_reader :user
|
11
|
-
|
11
|
+
|
12
12
|
def initialize(user,url)
|
13
13
|
@user = user
|
14
14
|
@url = url
|
15
15
|
end
|
16
|
-
|
16
|
+
|
17
17
|
def to_s
|
18
18
|
@user + ' ' + @url
|
19
19
|
end
|
20
|
-
|
20
|
+
|
21
21
|
def hash
|
22
22
|
self.to_s.hash
|
23
23
|
end
|
24
|
-
|
24
|
+
|
25
25
|
def <=>(other)
|
26
26
|
return false if other.nil?
|
27
27
|
self.to_s <=> other.to_s
|
28
28
|
end
|
29
|
-
|
29
|
+
|
30
30
|
def eql?(other)
|
31
31
|
return false if other.nil?
|
32
32
|
self.to_s == other.to_s
|
33
33
|
end
|
34
|
-
|
34
|
+
|
35
35
|
end
|
36
|
-
|
36
|
+
|
37
37
|
attr_reader :name
|
38
|
-
|
38
|
+
|
39
39
|
def initialize(name,items)
|
40
40
|
@name = name
|
41
41
|
items = items.collect {|line|
|
42
42
|
user, url = line.strip.split
|
43
|
-
|
43
|
+
(user.nil? || url.nil? ? nil : Suspect.new(user,url))
|
44
44
|
}
|
45
45
|
@banned = items.compact
|
46
46
|
end
|
47
|
-
|
47
|
+
|
48
|
+
def suspects
|
49
|
+
return @banned
|
50
|
+
end
|
51
|
+
|
48
52
|
def all
|
49
53
|
return @banned.collect { |suspect| suspect.to_s }
|
50
54
|
end
|
51
|
-
|
55
|
+
|
52
56
|
def add(user,url)
|
57
|
+
if url =~ /(:\/\/[^\/:]+)/ then
|
58
|
+
url = $1
|
59
|
+
end
|
60
|
+
|
53
61
|
url = escape_regex(url)
|
54
62
|
@banned << Suspect.new(user,url)
|
55
63
|
@banned = @banned.sort.uniq
|
56
64
|
end
|
57
|
-
|
65
|
+
|
58
66
|
def length
|
59
67
|
return @banned.length
|
60
68
|
end
|
61
|
-
|
62
|
-
def contains_user(user)
|
69
|
+
|
70
|
+
def contains_user?(user)
|
63
71
|
match = @banned.find { |ban| user =~ Regexp.new(ban.user,Regexp::IGNORECASE) }
|
64
72
|
! match.nil?
|
65
73
|
end
|
66
74
|
|
67
|
-
def contains_url(url)
|
75
|
+
def contains_url?(url)
|
68
76
|
match = @banned.find { |ban| url =~ Regexp.new(ban.url,Regexp::IGNORECASE) }
|
69
77
|
! match.nil?
|
70
78
|
end
|
71
|
-
|
79
|
+
|
72
80
|
def url_found_in(lines)
|
73
81
|
lines = lines.join(' ') if lines.kind_of? Array
|
74
82
|
@banned.each do | pattern |
|
@@ -77,12 +85,20 @@ module Wiki2Go
|
|
77
85
|
end
|
78
86
|
return false
|
79
87
|
end
|
80
|
-
|
88
|
+
|
89
|
+
def remove(author,url)
|
90
|
+
if url =~ /(:\/\/[^\/:]+)/ then
|
91
|
+
url = $1
|
92
|
+
end
|
93
|
+
url = escape_regex(url)
|
94
|
+
@banned = @banned.reject { |suspect| suspect.user == author && suspect.url == url }
|
95
|
+
end
|
96
|
+
|
81
97
|
private
|
82
|
-
|
98
|
+
|
83
99
|
def escape_regex(item)
|
84
100
|
item.gsub(/\./,'\.')
|
85
101
|
end
|
86
102
|
end
|
87
|
-
|
103
|
+
|
88
104
|
end
|
@@ -2,9 +2,65 @@ require 'tmpdir'
|
|
2
2
|
require 'fileutils'
|
3
3
|
require 'optparse'
|
4
4
|
require 'etc'
|
5
|
+
require 'logger'
|
5
6
|
|
6
7
|
require 'rubygems'
|
7
8
|
require_gem 'rscm'
|
9
|
+
require 'rscm/logging'
|
10
|
+
require 'rscm/better'
|
11
|
+
|
12
|
+
#Patch the RSCM 0.3 module
|
13
|
+
|
14
|
+
module RSCM
|
15
|
+
class Better
|
16
|
+
def Better.use_logger(logger)
|
17
|
+
@@logger = logger
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
class Cvs
|
22
|
+
# The extra simulate parameter is not in accordance with the AbstractSCM API,
|
23
|
+
# but it's optional and is only being used from within this class (uptodate? method).
|
24
|
+
def checkout(to_identifier=nil, simulate=false)
|
25
|
+
checked_out_files = []
|
26
|
+
if(checked_out?)
|
27
|
+
path_regex = /^([U|P|C]) (.*)/
|
28
|
+
cvs(@checkout_dir, update_command(to_identifier), simulate) do |line|
|
29
|
+
if(line =~ path_regex)
|
30
|
+
event = $1
|
31
|
+
path = $2.chomp
|
32
|
+
yield event,path if block_given?
|
33
|
+
checked_out_files << path
|
34
|
+
end
|
35
|
+
end
|
36
|
+
else
|
37
|
+
prefix = File.basename(@checkout_dir)
|
38
|
+
path_regex = /^([U|P|C]) #{prefix}\/(.*)/
|
39
|
+
# This is a workaround for the fact that -d . doesn't work - must be an existing sub folder.
|
40
|
+
mkdir_p(@checkout_dir) unless File.exist?(@checkout_dir)
|
41
|
+
target_dir = File.basename(@checkout_dir)
|
42
|
+
run_checkout_command_dir = File.dirname(@checkout_dir)
|
43
|
+
# -D is sticky, but subsequent updates will reset stickiness with -A
|
44
|
+
cvs(run_checkout_command_dir, checkout_command(target_dir, to_identifier), simulate) do |line|
|
45
|
+
if(line =~ path_regex)
|
46
|
+
event = $1
|
47
|
+
path = $2.chomp
|
48
|
+
yield event,path if block_given?
|
49
|
+
checked_out_files << path
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
checked_out_files
|
54
|
+
end
|
55
|
+
|
56
|
+
# def command_line(cmd, password=nil, simulate=false)
|
57
|
+
# cvs_options = simulate ? "-n" : ""
|
58
|
+
# dev_null = WIN32 ? "nul" : "/dev/null"
|
59
|
+
# "cvs -f \"-d#{root_with_password(password)}\" #{cvs_options} -q #{cmd} 2> c:\\temp\\out.log"
|
60
|
+
# end
|
61
|
+
|
62
|
+
end
|
63
|
+
end
|
8
64
|
|
9
65
|
module Wiki2Go
|
10
66
|
class RepositoryMaker
|
@@ -12,64 +68,299 @@ module Wiki2Go
|
|
12
68
|
def RepositoryMaker.create(args)
|
13
69
|
opts = OptionParser.new
|
14
70
|
|
15
|
-
directory
|
16
|
-
user
|
17
|
-
group
|
18
|
-
|
71
|
+
directory = ''
|
72
|
+
user = ''
|
73
|
+
group = ''
|
74
|
+
modulename = ''
|
75
|
+
opts.on("-d",'--directory dir',String) { |val| directory = expand_cvsroot(val) }
|
19
76
|
opts.on("-u",'--user username',String) { |val| user = val }
|
20
77
|
opts.on("-g",'--group groupname',String) { |val| group = val }
|
78
|
+
opts.on("-m",'--module name ',String) { |val| modulename = val }
|
21
79
|
opts.on_tail("-h", "--help", "Show this message") do
|
22
80
|
puts opts
|
23
81
|
exit
|
24
82
|
end
|
25
83
|
opts.parse(args)
|
26
84
|
|
27
|
-
puts "Directory = #{directory}"
|
28
85
|
if directory.empty? then
|
29
86
|
puts opts
|
30
87
|
else
|
31
88
|
puts "Creating CVS in directory #{directory}"
|
89
|
+
oldmask = File.umask(02)
|
32
90
|
cvs = RepositoryMaker.new(directory)
|
33
91
|
cvs.make_empty_repository(user,group)
|
34
|
-
cvs.
|
92
|
+
cvs.add_module(modulename,user,group)
|
93
|
+
File.umask(oldmask)
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
def RepositoryMaker.addwiki(args)
|
98
|
+
opts = OptionParser.new
|
99
|
+
|
100
|
+
directory = ''
|
101
|
+
wikidir = ''
|
102
|
+
modulename = ''
|
103
|
+
comment = 'Store wiki'
|
104
|
+
opts.on("-d",'--directory dir',String) { |val| directory = expand_cvsroot(val) }
|
105
|
+
opts.on("-w",'--wikidirectory dir',String) { |val| wikidir = File.expand_path(val) }
|
106
|
+
opts.on("-m",'--module name',String) { |val| modulename = val }
|
107
|
+
opts.on("-c",'--comment string',String) { |val| comment = val }
|
108
|
+
opts.on_tail("-h", "--help", "Show this message") do
|
109
|
+
puts opts
|
110
|
+
exit
|
111
|
+
end
|
112
|
+
opts.parse(args)
|
113
|
+
|
114
|
+
if directory.empty? || wikidir.empty? || modulename.empty? then
|
115
|
+
puts opts
|
116
|
+
return []
|
117
|
+
else
|
118
|
+
puts "Adding wiki #{wikidir} as module '#{modulename}' in CVS #{directory}"
|
119
|
+
oldmask = File.umask(02)
|
120
|
+
cvs = RepositoryMaker.new(directory)
|
121
|
+
added = cvs.add_wiki(wikidir,modulename,comment)
|
122
|
+
File.umask(oldmask)
|
123
|
+
return added
|
124
|
+
end
|
125
|
+
end
|
126
|
+
|
127
|
+
def RepositoryMaker.updatewiki(args)
|
128
|
+
opts = OptionParser.new
|
129
|
+
|
130
|
+
wikidir = ''
|
131
|
+
directory = ''
|
132
|
+
modulename = ''
|
133
|
+
opts.on("-d",'--directory dir',String) { |val| directory = expand_cvsroot(val) }
|
134
|
+
opts.on("-w",'--wikidirectory dir',String) { |val| wikidir = File.expand_path(val) }
|
135
|
+
opts.on("-m",'--module name ',String) { |val| modulename = val }
|
136
|
+
opts.on_tail("-h", "--help", "Show this message") do
|
137
|
+
puts opts
|
138
|
+
exit
|
139
|
+
end
|
140
|
+
opts.parse(args)
|
141
|
+
|
142
|
+
if wikidir.empty? then
|
143
|
+
puts opts
|
144
|
+
else
|
145
|
+
puts "Updating wiki #{wikidir}"
|
146
|
+
oldmask = File.umask(02)
|
147
|
+
cvs = RepositoryMaker.new(directory)
|
148
|
+
cvs.update(wikidir,modulename)
|
149
|
+
File.umask(oldmask)
|
35
150
|
end
|
36
151
|
end
|
37
152
|
|
38
|
-
def initialize(dir)
|
153
|
+
def initialize(dir,logger=nil)
|
39
154
|
@dir = dir
|
40
|
-
@
|
155
|
+
@logger = logger || Logger.new(STDERR)
|
156
|
+
RSCM::Better.use_logger @logger
|
41
157
|
end
|
42
158
|
|
43
159
|
def make_empty_repository(user,group)
|
44
|
-
|
45
|
-
|
160
|
+
if !File.exists?(File.join(@dir,'CVSROOT')) then
|
161
|
+
repository = RSCM::Cvs.new(@dir)
|
162
|
+
FileUtils::mkdir_p @dir
|
46
163
|
|
47
|
-
|
48
|
-
FileUtils::mkdir_p lockdir
|
49
|
-
FileUtils::chmod 02775,lockdir
|
164
|
+
repository.create_central
|
50
165
|
|
51
|
-
|
52
|
-
|
166
|
+
lockdir = File.join(@dir,'locks')
|
167
|
+
FileUtils::mkdir_p lockdir
|
168
|
+
|
169
|
+
set_owner(@dir,user,group)
|
170
|
+
end
|
171
|
+
update_configuration
|
172
|
+
|
173
|
+
end
|
174
|
+
|
175
|
+
def add_module(modulename,user,group)
|
176
|
+
if !modulename.nil? && !modulename.empty? then
|
177
|
+
moduledir = File.join(@dir,modulename)
|
178
|
+
FileUtils::mkdir_p moduledir
|
179
|
+
set_owner(moduledir,user,group)
|
180
|
+
end
|
53
181
|
|
54
182
|
end
|
55
183
|
|
184
|
+
def update(wikidir,modulename)
|
185
|
+
repository = RSCM::Cvs.new(@dir,modulename)
|
186
|
+
repository.checkout_dir = wikidir
|
187
|
+
updated = []
|
188
|
+
clashed = []
|
189
|
+
begin
|
190
|
+
repository.checkout do |event,path|
|
191
|
+
updated << path if event == 'U' || event == 'P'
|
192
|
+
clashed << path if event == 'C'
|
193
|
+
end
|
194
|
+
rescue Exception => e
|
195
|
+
clashed = [ e.to_s ]
|
196
|
+
end
|
197
|
+
return updated,clashed
|
198
|
+
end
|
199
|
+
|
200
|
+
def add_wiki(wikidir,modulename,comment='No Comment')
|
201
|
+
repository = RSCM::Cvs.new(@dir,modulename)
|
202
|
+
repository.checkout_dir = wikidir
|
203
|
+
repository.checkout unless repository.checked_out?
|
204
|
+
|
205
|
+
output = []
|
206
|
+
added_files = []
|
207
|
+
|
208
|
+
added_files += add_contents_of(modulename,wikidir,'texts') { |dir,name|
|
209
|
+
checkin = ((name =~ /^\./) ? false : true)
|
210
|
+
# output << "Add #{name.inspect} in #{dir} ? => #{checkin}"
|
211
|
+
checkin
|
212
|
+
}
|
213
|
+
added_files += add_contents_of(modulename,wikidir,'templates') { |dir,name|
|
214
|
+
checkin = ((name =~ /^\./) ? false : true)
|
215
|
+
# output << "Add #{name} in #{dir} ? => #{checkin}"
|
216
|
+
checkin
|
217
|
+
}
|
218
|
+
added_files += add_contents_of(modulename,File.join(wikidir,'site'),'html') { |dir,name|
|
219
|
+
checkin = ((name == 'rss.xml' || (name =~ /^\./)) ? false : true)
|
220
|
+
output << "Add #{name} in #{dir} ? => #{checkin}"
|
221
|
+
checkin
|
222
|
+
}
|
223
|
+
|
224
|
+
sitedir = File.join(wikidir,'site')
|
225
|
+
if File.exists?(sitedir) then
|
226
|
+
add_directory modulename,wikidir,'site'
|
227
|
+
scriptdir = File.join(sitedir,'scripts')
|
228
|
+
if File.exists?(scriptdir) then
|
229
|
+
add_directory modulename,sitedir,'scripts'
|
230
|
+
added_files += add_files modulename,scriptdir,[ 'CgiOptions.rb']
|
231
|
+
end
|
232
|
+
end
|
233
|
+
|
234
|
+
added_files += add_contents_of(modulename,wikidir,'config') { |dir,name|
|
235
|
+
checkin = ((name == 'chonqed_blacklist.txt' || (name =~ /^\./)) ? false : true)
|
236
|
+
# output << "Add #{name} in #{dir} ? => #{checkin}"
|
237
|
+
checkin
|
238
|
+
}
|
239
|
+
begin
|
240
|
+
repository.commit comment do |line|
|
241
|
+
output << line
|
242
|
+
end
|
243
|
+
rescue Exception => e
|
244
|
+
output << e.to_s
|
245
|
+
end
|
246
|
+
output
|
247
|
+
end
|
248
|
+
|
249
|
+
def is_local?(wikidir,modulename)
|
250
|
+
repository = RSCM::Cvs.new(@dir,modulename)
|
251
|
+
repository.checkout_dir = wikidir
|
252
|
+
repository.can_create_central?
|
253
|
+
end
|
254
|
+
|
255
|
+
private
|
256
|
+
|
257
|
+
def files_checked_in(dir)
|
258
|
+
files = []
|
259
|
+
entries = File.join(dir,'CVS','Entries')
|
260
|
+
pattern = Regexp.new("^/([^\/]+)/")
|
261
|
+
if File.exists?(entries) then
|
262
|
+
File.open(entries,File::RDONLY) do |f|
|
263
|
+
lines = f.readlines
|
264
|
+
lines.each do |line|
|
265
|
+
if line =~ pattern
|
266
|
+
files << $1
|
267
|
+
end
|
268
|
+
end
|
269
|
+
end
|
270
|
+
end
|
271
|
+
files
|
272
|
+
end
|
273
|
+
|
274
|
+
def not_checked_in(dir,filenames)
|
275
|
+
checked_in = files_checked_in(dir)
|
276
|
+
new_files = filenames - checked_in
|
277
|
+
new_files
|
278
|
+
end
|
279
|
+
|
280
|
+
|
281
|
+
def add_directory(modulename,dir,subdir)
|
282
|
+
repository = RSCM::Cvs.new(@dir,modulename)
|
283
|
+
repository.checkout_dir = dir
|
284
|
+
|
285
|
+
repository.add subdir unless dir_in_repository?(File.join(dir,subdir))
|
286
|
+
end
|
287
|
+
|
288
|
+
def add_files(modulename,dir,files)
|
289
|
+
added = []
|
290
|
+
if files.length > 0 then
|
291
|
+
files = not_checked_in(dir,files)
|
292
|
+
if files.length > 0 then
|
293
|
+
repository = RSCM::Cvs.new(@dir,modulename)
|
294
|
+
repository.checkout_dir = dir
|
295
|
+
repository.add files.join(' ')
|
296
|
+
added = files
|
297
|
+
end
|
298
|
+
end
|
299
|
+
return added
|
300
|
+
end
|
301
|
+
|
302
|
+
def dir_in_repository?(dir)
|
303
|
+
repository = RSCM::Cvs.new
|
304
|
+
repository.checkout_dir = dir
|
305
|
+
result = repository.checked_out?
|
306
|
+
result
|
307
|
+
end
|
308
|
+
|
309
|
+
def add_contents_of(modulename,dir,subdir,&proc)
|
310
|
+
return [] if !File.exists?(dir)
|
311
|
+
|
312
|
+
cvs = RSCM::Cvs.new(@dir,modulename)
|
313
|
+
cvs.checkout_dir = dir
|
314
|
+
|
315
|
+
added = []
|
316
|
+
|
317
|
+
current_dir = File.join(dir,subdir)
|
318
|
+
if File.exists?(current_dir) then
|
319
|
+
do_add = (block_given? ? yield(dir,subdir) : true)
|
320
|
+
if do_add then
|
321
|
+
add_directory(modulename,dir,subdir)
|
322
|
+
added << subdir
|
323
|
+
end
|
324
|
+
names = []
|
325
|
+
Dir.entries(current_dir).each do |name|
|
326
|
+
if name != '.' && name != '..' && name != 'CVS' then
|
327
|
+
if File.directory?(File.join(current_dir,name)) then
|
328
|
+
added += add_contents_of(modulename,current_dir,name,&proc)
|
329
|
+
else
|
330
|
+
do_add = (block_given? ? yield(current_dir,name) : true)
|
331
|
+
if do_add then
|
332
|
+
names << name
|
333
|
+
end
|
334
|
+
end
|
335
|
+
end
|
336
|
+
end
|
337
|
+
if names.length > 0 then
|
338
|
+
added += add_files(modulename,current_dir,names)
|
339
|
+
end
|
340
|
+
end
|
341
|
+
added
|
342
|
+
end
|
343
|
+
|
56
344
|
def update_configuration
|
57
345
|
checkout_to = File.join(Dir.tmpdir,'cvs_config')
|
58
346
|
FileUtils::rm_r checkout_to if File.exists?(checkout_to)
|
59
347
|
cvsroot = RSCM::Cvs.new(@dir,'CVSROOT')
|
60
|
-
cvsroot.
|
348
|
+
cvsroot.checkout_dir = checkout_to
|
349
|
+
cvsroot.checkout
|
61
350
|
|
62
351
|
update_cvswrappers(checkout_to)
|
63
352
|
update_config(checkout_to)
|
64
353
|
|
65
|
-
cvsroot.commit(
|
354
|
+
cvsroot.commit('update cvswrappers for binary files')
|
66
355
|
FileUtils::rm_r(checkout_to)
|
67
356
|
end
|
68
357
|
|
69
|
-
|
358
|
+
def self.expand_cvsroot(path)
|
359
|
+
path.include?(':') ? path : File.expand_path(path)
|
360
|
+
end
|
70
361
|
|
71
362
|
def update_cvswrappers(dir)
|
72
|
-
File.open(File.join(dir,'cvswrappers'),File::
|
363
|
+
File.open(File.join(dir,'cvswrappers'),File::CREAT|File::WRONLY) do |file|
|
73
364
|
file.write cvswrappers_content
|
74
365
|
end
|
75
366
|
end
|
@@ -106,6 +397,25 @@ module Wiki2Go
|
|
106
397
|
|
107
398
|
def cvswrappers_content
|
108
399
|
return <<-END_CVS_WRAPPERS
|
400
|
+
# This file affects handling of files based on their names.
|
401
|
+
#
|
402
|
+
# The -m option specifies whether CVS attempts to merge files.
|
403
|
+
#
|
404
|
+
# The -k option specifies keyword expansion (e.g. -kb for binary).
|
405
|
+
#
|
406
|
+
# Format of wrapper file ($CVSROOT/CVSROOT/cvswrappers or .cvswrappers)
|
407
|
+
#
|
408
|
+
# wildcard [option value][option value]...
|
409
|
+
#
|
410
|
+
# where option is one of
|
411
|
+
# -f from cvs filter value: path to filter
|
412
|
+
# -t to cvs filter value: path to filter
|
413
|
+
# -m update methodology value: MERGE or COPY
|
414
|
+
# -k expansion mode value: b, o, kkv, &c
|
415
|
+
#
|
416
|
+
# and value is a single-quote delimited value.
|
417
|
+
# For example:
|
418
|
+
#*.gif -k 'b'
|
109
419
|
*.gif -k 'b'
|
110
420
|
*.jpg -k 'b'
|
111
421
|
*.jpeg -k 'b'
|
@@ -113,28 +423,33 @@ module Wiki2Go
|
|
113
423
|
|
114
424
|
*.doc -k 'b'
|
115
425
|
*.pdf -k 'b'
|
426
|
+
*.xls -k 'b'
|
427
|
+
*.ppt -k 'b'
|
116
428
|
END_CVS_WRAPPERS
|
117
429
|
end
|
118
430
|
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
431
|
+
def set_owner(dir,username,groupname)
|
432
|
+
info = Etc.getpwnam(username)
|
433
|
+
if !info.nil? then
|
434
|
+
user_id = info.uid
|
435
|
+
group_id = info.gid
|
436
|
+
if !groupname.nil? then
|
437
|
+
group_id = Etc.getgrnam(groupname).gid
|
438
|
+
end
|
439
|
+
mode = File.stat(dir).mode | 02775
|
440
|
+
File.chmod(mode,dir)
|
441
|
+
File.chown(user_id,group_id,dir)
|
442
|
+
Dir.glob(File.join(dir,'**/*')).each do |file|
|
443
|
+
if file[0] != '.' then
|
444
|
+
mode = File.stat(file).mode | 02775
|
445
|
+
File.chmod(mode,file)
|
446
|
+
File.chown(user_id,group_id,file)
|
134
447
|
end
|
135
448
|
end
|
136
449
|
end
|
137
|
-
|
138
450
|
end
|
139
451
|
|
140
|
-
end
|
452
|
+
end
|
453
|
+
|
454
|
+
end
|
455
|
+
|