forked from ryanjosephking/meshlint
-
Notifications
You must be signed in to change notification settings - Fork 10
/
mkblenderwiki
executable file
·87 lines (80 loc) · 2.03 KB
/
mkblenderwiki
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#!/usr/bin/env ruby
# A thing to automatically spew out text for BlenderWiki. (depends on pandoc)
require 'optparse'
options = {}
OptionParser.new do |opts|
opts.banner = "Usage: #{$0} [options]"
opts.on("-w", "--wiki-edit-url", "Output the Wiki link with Edit on") do |o|
options[:wiki_edit_url] = o
end
end.parse!
py_file_name = File.basename(Dir.pwd + '.py')
txt = File.open(py_file_name).read
txt =~ /bl_info\s*=\s*{(.*?)}/m or
raise "#{py_file_name} must have bl_info"
info_txt = $1
txt =~ /mkblenderwiki_info\s*=\s*{(.*?)}/m or
raise "#{py_file_name} must have mkblenderwiki_info"
info_txt += $1
info = {}
info_txt.split(/\n/).each do |line|
info[$1] = $2 if line =~ /['"]([^"']+)["']:\s*['"(](.+)[)"'],?$/
end
class Hash
def demand_keys dict_name, keys
keys.each do |e|
raise "#{dict_name} must have \"#{e}\"" unless has_key? e
end
end
end
info.demand_keys 'bl_info', %w(
name
author
version
blender
location
description
tracker_url
category
)
info.demand_keys 'mkblenderwiki_info', %w(
license
py_download
git_download
input_img_prefix
wiki_img_prefix
)
%w(version blender).each do |e| info[e].gsub! /,\s*/, '.' end
name, tooltip = info['name'].split ': '
if options.has_key? :wiki_edit_url
url = info['wiki_url'].sub /index.php\//, "index.php?title="
url += '&action=edit'
puts url
else
raise "No input file." unless ARGV.size
main_input_file = ARGV[0]
body = `pandoc -t mediawiki "#{main_input_file}"`
body.gsub! "Image:#{info['input_img_prefix']}",
"Image:#{info['wiki_img_prefix']}"
# a pandoc bug?:
body.gsub! '|caption ', '|'
puts <<EOT
{{ScriptInfo
|name=#{name}
|tooltip=#{tooltip}
|menu=#{info['location']}
|usage=#{info['description']}
|version=#{info['version']}
|blender=#{info['blender']}
|category=#{info['category']}
|author=#{info['author']}
|license=#{info['license']}
|exe=#{py_file_name}
|distribution=Extern
|note=
|download=#{info['py_download']} or <tt>git clone #{info['git_download']}</tt>
|link=
}}
#{body}
EOT
end