-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patht2c_import_attachments.rb
39 lines (34 loc) · 1.06 KB
/
t2c_import_attachments.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
require "find"
require "filemagic"
require "uri"
if not ARGV[0] then
puts("エラー:第一引数にtrac名を指定して下さい")
exit(1)
end
PRJNAME = ARGV[0].to_s
if not ARGV[1] then
puts("エラー:第一引数にスペース名を指定して下さい")
exit(1)
end
CONFNAME = ARGV[1].to_s
ATTDIR = "./#{PRJNAME}/attachments/wiki/**"
dirs = Dir.glob("#{ATTDIR}")
dirs.each {|d|
puts "==== #{d} ===="
dirname = d.split("/").last
Find.find("#{d}") {|f|
next unless FileTest.file?(f)
puts f
contenttype = FileMagic.new(FileMagic::MAGIC_MIME_TYPE).file(File.join("#{f}"))
if File.extname(f) == ".xlsx"
contenttype = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
elsif File.extname(f) == ".pptx"
contenttype = "application/vnd.openxmlformats-officedocument.presentationml.presentation"
elsif File.extname(f) == ".pdf"
contenttype = "application/pdf"
end
command = "python ./wikiFileAttachments.py #{CONFNAME} \"#{dirname}\" #{contenttype} \"#{f}\""
puts command
system(command)
}
}