hikiutils 0.2.3.13 → 0.2.3.14
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/hikiutils.gemspec +2 -1
- data/hikiutils_bob/Rakefile +30 -16
- data/hikiutils_bob/code.hiki +9 -30
- data/hikiutils_bob/figs/hikiutils_bob.002.jpeg +0 -0
- data/hikiutils_bob/figs/hikiutils_bob.007.jpeg +0 -0
- data/hikiutils_bob/figs/hikiutils_bob.pdf +0 -0
- data/hikiutils_bob/hikiutils_bob/hikiutils_bob.002.jpeg +0 -0
- data/hikiutils_bob/hikiutils_bob/hikiutils_bob.007.jpeg +0 -0
- data/hikiutils_bob/hikiutils_bob.key +0 -0
- data/hikiutils_bob/latex_all.hiki +33 -8
- data/hikiutils_bob/latex_dir/code.aux +7 -14
- data/hikiutils_bob/latex_dir/code.log +28 -0
- data/hikiutils_bob/latex_dir/code.tex +13 -31
- data/hikiutils_bob/latex_dir/hikiutils_bob.log +59 -50
- data/hikiutils_bob/latex_dir/hikiutils_bob.pdf +0 -0
- data/hikiutils_bob/latex_dir/hikiutils_bob.synctex.gz +0 -0
- data/hikiutils_bob/latex_dir/hikiutils_bob.toc +29 -29
- data/hikiutils_bob/latex_dir/latex_all.aux +19 -16
- data/hikiutils_bob/latex_dir/latex_all.log +28 -0
- data/hikiutils_bob/latex_dir/latex_all.tex +34 -9
- data/hikiutils_bob/latex_dir/sync.aux +16 -16
- data/hikiutils_bob/latex_dir/sync.tex +4 -4
- data/hikiutils_yamane/Rakefile +14 -2
- data/hikiutils_yamane/abstract.hiki +3 -3
- data/hikiutils_yamane/discussion.hiki +9 -0
- data/hikiutils_yamane/hikiutils_yamane.hiki +8 -10
- data/hikiutils_yamane/introduction.hiki +1 -1
- data/hikiutils_yamane/latex_dir/abstract.tex +3 -3
- data/hikiutils_yamane/latex_dir/{%CA%FD/313/241.aux → discussion.aux} +8 -7
- data/hikiutils_yamane/latex_dir/discussion.tex +9 -0
- data/hikiutils_yamane/latex_dir/hikiutils_yamane.aux +3 -6
- data/hikiutils_yamane/latex_dir/hikiutils_yamane.log +50 -59
- data/hikiutils_yamane/latex_dir/hikiutils_yamane.pdf +0 -0
- data/hikiutils_yamane/latex_dir/hikiutils_yamane.synctex.gz +0 -0
- data/hikiutils_yamane/latex_dir/hikiutils_yamane.tex +4 -7
- data/hikiutils_yamane/latex_dir/hikiutils_yamane.toc +21 -21
- data/hikiutils_yamane/latex_dir/introduction.tex +1 -1
- data/hikiutils_yamane/latex_dir/method.aux +46 -0
- data/hikiutils_yamane/latex_dir/method.tex +247 -0
- data/hikiutils_yamane/latex_dir/results.aux +49 -0
- data/hikiutils_yamane/latex_dir/results.tex +249 -0
- data/hikiutils_yamane/method.hiki +234 -0
- data/hikiutils_yamane/results.hiki +225 -0
- data/hikiutils_yamane/toc.hiki +0 -1
- data/lib/hikiutils/version.rb +1 -1
- data/lib/hikiutils_thor.rb~ +37 -37
- data/lib/templates/Rakefile_hiki_sync +32 -17
- data/lib/templates/mi_key_bind_setting +1 -0
- metadata +33 -19
- data/hikiutils_yamane/Rakefile~ +0 -477
- data/hikiutils_yamane/command.hiki +0 -111
- data/hikiutils_yamane/compare.hiki +0 -116
- data/hikiutils_yamane/latex_dir/command.aux +0 -35
- data/hikiutils_yamane/latex_dir/command.log +0 -0
- data/hikiutils_yamane/latex_dir/command.tex +0 -123
- data/hikiutils_yamane/latex_dir/compare.aux +0 -30
- data/hikiutils_yamane/latex_dir/compare.tex +0 -123
- data/hikiutils_yamane/latex_dir/optparse.aux +0 -31
- data/hikiutils_yamane/latex_dir/optparse.tex +0 -119
- data/hikiutils_yamane/latex_dir/thor.aux +0 -32
- data/hikiutils_yamane/latex_dir/thor.tex +0 -110
- data/hikiutils_yamane/optparse.hiki +0 -114
- data/hikiutils_yamane/thor.hiki +0 -107
data/hikiutils_yamane/Rakefile~
DELETED
@@ -1,477 +0,0 @@
|
|
1
|
-
# -*- coding: utf-8 -*-
|
2
|
-
require 'systemu'
|
3
|
-
require 'tempfile'
|
4
|
-
require 'colorize'
|
5
|
-
# -*- coding: utf-8 -*-
|
6
|
-
begin
|
7
|
-
$hiki_dir = File.readlines('./.hikirc')[0].chomp
|
8
|
-
rescue => e
|
9
|
-
puts e
|
10
|
-
exit
|
11
|
-
end
|
12
|
-
dirnames=Dir.pwd.split('/')
|
13
|
-
$basename = (dirnames[-1]=='hikis')? dirnames[-2] : dirnames[-1]
|
14
|
-
$latex_dir= 'latex_dir'
|
15
|
-
$section_layer = {}
|
16
|
-
|
17
|
-
task :default do
|
18
|
-
system 'rake -T'
|
19
|
-
end
|
20
|
-
|
21
|
-
desc "Githubのdirをsafariでopen"
|
22
|
-
task :github do
|
23
|
-
status, stdout, stderr = systemu %q( git remote -v |grep origin )
|
24
|
-
github_dir=stdout.match(/(.+):(.+) \(push\)/)[2]
|
25
|
-
puts github_dir.blue
|
26
|
-
system "open https://github.com/#{github_dir}"
|
27
|
-
end
|
28
|
-
|
29
|
-
desc "hikiシステムにあるゴミファイルを掃除する"
|
30
|
-
task :reset_hiki do
|
31
|
-
status, stdout, stderr = systemu "hiki -l #{$basename}"
|
32
|
-
print stdout
|
33
|
-
files=[]
|
34
|
-
stdout.split("\n").each{|line|
|
35
|
-
files << line.split(/\s+/)[-1]
|
36
|
-
}
|
37
|
-
r_files = files.reverse[0..-4]
|
38
|
-
r_files.each{|file|
|
39
|
-
print "remove #{file}[ynqlA]? ".red
|
40
|
-
input=STDIN.gets.chomp
|
41
|
-
case input
|
42
|
-
when 'y'
|
43
|
-
p command="hiki --remove #{file}"
|
44
|
-
system command
|
45
|
-
when 'n'
|
46
|
-
when 'l'
|
47
|
-
p command="hiki -l #{$basename}"
|
48
|
-
system command
|
49
|
-
when 'q'
|
50
|
-
exit
|
51
|
-
when 'A'
|
52
|
-
print "\nAre you sure[Yn]? ".magenta
|
53
|
-
input2 = STDIN.gets.chomp
|
54
|
-
case input2
|
55
|
-
when 'Y'
|
56
|
-
r_files.each{|file| system "hiki --remove #{file}"}
|
57
|
-
p target = File.join($hiki_dir,'cache','attach',$basename)
|
58
|
-
exit
|
59
|
-
when 'n'
|
60
|
-
exit
|
61
|
-
end
|
62
|
-
end
|
63
|
-
}
|
64
|
-
end
|
65
|
-
|
66
|
-
desc "latex_dirのゴミを掃除"
|
67
|
-
task :reset_latex_dir do
|
68
|
-
system "mv latex_dir/head.tex ."
|
69
|
-
system "rm -rf latex_dir"
|
70
|
-
system "mkdir latex_dir"
|
71
|
-
system "mv head.tex latex_dir/"
|
72
|
-
system "rake latex_all"
|
73
|
-
end
|
74
|
-
|
75
|
-
desc "toc.hikiの作成"
|
76
|
-
task :mk_toc do
|
77
|
-
p target = $basename+'.toc'
|
78
|
-
cont=""
|
79
|
-
File.readlines(File.join('latex_dir',target)).each{|line|
|
80
|
-
if m=line.match(/\\contentsline \{(.+)\}\{\\numberline \{([\d|\.]+)\}(.+)\}\{\d+\}/)
|
81
|
-
layer,sec_no,title=m[1],m[2],m[3]
|
82
|
-
d = case m[1]
|
83
|
-
when 'section'; 1
|
84
|
-
when 'subsection'; 2
|
85
|
-
when 'subsubsection'; 3
|
86
|
-
else; 4
|
87
|
-
end
|
88
|
-
layer = "!"*d
|
89
|
-
title.gsub!('\_','_')
|
90
|
-
cont << "#{layer}#{sec_no}:#{title}\n"
|
91
|
-
end
|
92
|
-
}
|
93
|
-
print cont
|
94
|
-
File.open("toc.hiki",'w'){|file| file.print cont}
|
95
|
-
end
|
96
|
-
|
97
|
-
desc "FILE.hikiあるいはhikiファイルすべてを最新状態に更新"
|
98
|
-
task :touch do
|
99
|
-
if file=ARGV[1]
|
100
|
-
file_split=file.split(".")
|
101
|
-
p target = $basename==file_split[0] ? $basename : $basename+"_"+file_split[0]
|
102
|
-
system "hiki -u #{target}"
|
103
|
-
else
|
104
|
-
p target = File.join($hiki_dir,'cache','attach',$basename)
|
105
|
-
system "touch #{target}/*"
|
106
|
-
Dir.entries('.').each{|file|
|
107
|
-
file_split=file.split(".")
|
108
|
-
if file_split[1]=='hiki'
|
109
|
-
p target = $basename==file_split[0] ? $basename : $basename+"_"+file_split[0]
|
110
|
-
system "hiki -u #{target}"
|
111
|
-
end
|
112
|
-
}
|
113
|
-
end
|
114
|
-
exit
|
115
|
-
end
|
116
|
-
|
117
|
-
desc "FILE.hikiあるいはhikiファイルをedtiorで開く"
|
118
|
-
task :open do
|
119
|
-
if file=ARGV[1]
|
120
|
-
system "open -a mi #{file}"
|
121
|
-
else
|
122
|
-
Dir.entries('.').each{|file|
|
123
|
-
file_split=file.split(".")
|
124
|
-
if file_split[1]=='hiki'
|
125
|
-
p target = file_split[0]
|
126
|
-
system "open -a mi #{target}"
|
127
|
-
end
|
128
|
-
}
|
129
|
-
end
|
130
|
-
end
|
131
|
-
|
132
|
-
desc "FILE1をlatexに変換"
|
133
|
-
task :latex => [:latex_base] do
|
134
|
-
exit
|
135
|
-
end
|
136
|
-
|
137
|
-
desc "FILE1をwrap formatでlatexに変換"
|
138
|
-
task :latex_wrap => [:latex_base, :change_wrap] do
|
139
|
-
exit
|
140
|
-
end
|
141
|
-
|
142
|
-
def latex_loop(entries,opts={})
|
143
|
-
check_bounding_box
|
144
|
-
main_file=""
|
145
|
-
entries.each{|file|
|
146
|
-
options={:latex_all=>true}
|
147
|
-
next unless file.split('.')[1]=='hiki'
|
148
|
-
next if file=='toc.hiki'
|
149
|
-
next if file.include?('.hikirc')
|
150
|
-
f_name =File.basename(file,'.hiki')
|
151
|
-
if opts[:main]
|
152
|
-
if f_name==$basename
|
153
|
-
options[:latex]="--listings --head latex_dir/head.tex -p "
|
154
|
-
options[:main]=true
|
155
|
-
main_file=f_name
|
156
|
-
convert_to_latex(file, options)
|
157
|
-
end
|
158
|
-
else
|
159
|
-
if f_name!=$basename
|
160
|
-
p level = $section_layer[f_name] || 1
|
161
|
-
options[:latex]="-l #{level} --listings -b "
|
162
|
-
convert_to_latex(file, options)
|
163
|
-
end
|
164
|
-
end
|
165
|
-
}
|
166
|
-
return main_file
|
167
|
-
end
|
168
|
-
|
169
|
-
def check_section_layers(lines)
|
170
|
-
p reg_exp = Regexp.new("#{$basename}_(.+)")
|
171
|
-
lines.each{|line|
|
172
|
-
p line
|
173
|
-
if m=line.match(/(!+)\[\[(.+)\]\]/)
|
174
|
-
p count = m[1].count('!')
|
175
|
-
p file_name=m[2].match(reg_exp)[1]
|
176
|
-
$section_layer[file_name]=count
|
177
|
-
end
|
178
|
-
}
|
179
|
-
p $section_layer
|
180
|
-
end
|
181
|
-
|
182
|
-
def check_bounding_box
|
183
|
-
# $bounding_box="0 0 442 432"
|
184
|
-
$bounding_box=" 0 0 737 553"
|
185
|
-
end
|
186
|
-
|
187
|
-
desc "すべてのhikiファイルをlatex変換"
|
188
|
-
task :latex_all do
|
189
|
-
p entries=Dir.entries('.')
|
190
|
-
main_file = latex_loop(entries,opts={:main=>true})
|
191
|
-
latex_loop(entries)
|
192
|
-
cont=""
|
193
|
-
p reg_exp = Regexp.new("#{$basename}_(.+)")
|
194
|
-
toc = false
|
195
|
-
File.readlines(File.join($latex_dir,"#{main_file}.tex")).each{|line|
|
196
|
-
# line, toc = "", true if line.match(/\\tableofcontents/) and toc == true #only one
|
197
|
-
if line.match(/\\tableofcontents/)
|
198
|
-
if toc == false #only one
|
199
|
-
toc = true
|
200
|
-
else
|
201
|
-
line = ''
|
202
|
-
end
|
203
|
-
end
|
204
|
-
line ="\\usepackage{listings,jlisting}" if line.match(/\\usepackage{listings}/)
|
205
|
-
if line.match(/section{(.+)}/)
|
206
|
-
if m=line.match(/\\verb\|(.+)\((.+)\)\|/)
|
207
|
-
p m
|
208
|
-
p m_t=m[2].match(reg_exp)[1]
|
209
|
-
line = "\\include{#{m_t}}\n"
|
210
|
-
elsif m=line.match(/section{\\verb\|(.+)\|}/)
|
211
|
-
p m
|
212
|
-
p m_t=m[1].match(reg_exp)[1]
|
213
|
-
line = "\\include{#{m_t}}\n"
|
214
|
-
else
|
215
|
-
# line = ""
|
216
|
-
end
|
217
|
-
end
|
218
|
-
cont << line
|
219
|
-
}
|
220
|
-
File.open(File.join($latex_dir,"#{main_file}.tex"),'w'){|file| file.print cont}
|
221
|
-
system "open latex_dir/#{main_file}.tex"
|
222
|
-
exit
|
223
|
-
end
|
224
|
-
|
225
|
-
task :latex_base do
|
226
|
-
check_bounding_box
|
227
|
-
Dir.mkdir($latex_dir) unless Dir.exist?($latex_dir)
|
228
|
-
convert_to_latex(ARGV[1])
|
229
|
-
system("open #{$save_name}")
|
230
|
-
end
|
231
|
-
|
232
|
-
def convert_to_latex(file_name, options={})
|
233
|
-
p file_name = file_name.include?('.hiki')? file_name : file_name+'.hiki'
|
234
|
-
p tex_name = File.basename(file_name,'.hiki')+'.tex'
|
235
|
-
p $save_name = ARGV[2] || File.join($latex_dir,tex_name)
|
236
|
-
pre_name = File.join($latex_dir,'pre.tex')
|
237
|
-
p pre_command = File.exist?(pre_name) ? '--pre '+pre_name : nil
|
238
|
-
lines = File.readlines(file_name)
|
239
|
-
check_section_layers(lines) if options[:main]
|
240
|
-
cont = ""
|
241
|
-
lines.each_with_index{|line,i|
|
242
|
-
if m=line.match(/\{\{attach_view\((.*),(.*)\)\}\}/)
|
243
|
-
p line="\{\{attach_view\(#{m[1]}\)\}\}\n"
|
244
|
-
elsif options[:latex_all] and i<5
|
245
|
-
line="" if line.match(/^!title:|^!author:|^!date:/)
|
246
|
-
end
|
247
|
-
cont << line
|
248
|
-
}
|
249
|
-
tf1,tf2='tmp1.txt','tmp2.txt'
|
250
|
-
File.open(tf1,'w'){|file| file.print cont}
|
251
|
-
system "hiki2latex #{pre_command} #{options[:latex]} #{tf1} > #{tf2}"
|
252
|
-
lines = File.readlines(tf2)
|
253
|
-
system "rm #{tf1} #{tf2}"
|
254
|
-
in_bib,cont=false,""
|
255
|
-
lines.each{|line|
|
256
|
-
line=latex_cite_ref(line)
|
257
|
-
if m=line.match(/\\caption{\s*\((.+?)\)(.+)}/)
|
258
|
-
p m
|
259
|
-
puts line = "\\caption{#{m[2]}}\n\\label{#{m[1]}}\n"
|
260
|
-
end
|
261
|
-
if m=line.match(/\\section{reference:}(.+)/) and in_bib==false
|
262
|
-
in_bib=true
|
263
|
-
line = "\\begin{thebibliography}{99}\n"
|
264
|
-
puts line.blue
|
265
|
-
end
|
266
|
-
if m=line.match(/\\end{description}/) and in_bib==true
|
267
|
-
in_bib=false
|
268
|
-
line = "\\end{thebibliography}\n"
|
269
|
-
end
|
270
|
-
if m=line.match(/\\item\[(.+)\](.+)/) and in_bib==true
|
271
|
-
line ="\\bibitem{#{m[1]}} #{m[2]}"
|
272
|
-
end
|
273
|
-
if m=line.match(/\\includegraphics\[width=6cm\]\{(.+)\}/)
|
274
|
-
p line="\\includegraphics\[width=10cm,bb=#{$bounding_box}\]\{../figs/#{m[1]}\}\n"
|
275
|
-
cont << line
|
276
|
-
else
|
277
|
-
cont << line
|
278
|
-
end
|
279
|
-
}
|
280
|
-
File.open($save_name,'w'){|file| file.print cont }
|
281
|
-
end
|
282
|
-
|
283
|
-
def latex_cite_ref(line)
|
284
|
-
r_pair=[/\\verb\|{{cite\((.+?)\)}}\|/,/\\verb\|{{ref\((.+?)\)}}\|/]
|
285
|
-
while m=line.match(r_pair[0])
|
286
|
-
line.sub!(r_pair[0],"\\cite\{#{m[1]}\}")
|
287
|
-
end
|
288
|
-
while m=line.match(r_pair[1])
|
289
|
-
line.sub!(r_pair[1],"\\ref\{#{m[1]}\}")
|
290
|
-
end
|
291
|
-
# puts line.chomp.blue
|
292
|
-
return line
|
293
|
-
end
|
294
|
-
|
295
|
-
task :change_wrap do
|
296
|
-
lines = File.readlines($save_name)
|
297
|
-
|
298
|
-
cont = ""
|
299
|
-
lines.each{|line|
|
300
|
-
if line.include?('\begin{figure}[htbp]\begin{center}')
|
301
|
-
p line
|
302
|
-
cont << '\begin{wrapfigure}{r}{8cm}'+"\n"
|
303
|
-
cont << '\vspace{-2\baselineskip}'+"\n"
|
304
|
-
cont << '\begin{center}'+"\n"
|
305
|
-
elsif line.include?('\label{default}\end{center}\end{figure}')
|
306
|
-
p line
|
307
|
-
cont << '\end{center}'+"\n"
|
308
|
-
cont << '\vspace{2\baselineskip}'+"\n"
|
309
|
-
cont << '\end{wrapfigure}'+"\n"
|
310
|
-
else
|
311
|
-
cont << line
|
312
|
-
end
|
313
|
-
}
|
314
|
-
File.open($save_name,'w'){|file| file.print cont }
|
315
|
-
|
316
|
-
system("open #{$save_name}")
|
317
|
-
exit
|
318
|
-
end
|
319
|
-
|
320
|
-
|
321
|
-
desc "increment fig NUBERS in FILE"
|
322
|
-
task :increment do
|
323
|
-
number=ARGV[1]
|
324
|
-
file = ARGV[2]
|
325
|
-
dir = ARGV[3] || nil
|
326
|
-
lines = File.readlines(file)
|
327
|
-
cont = ""
|
328
|
-
lines.each{|line|
|
329
|
-
if m=line.match(/\{\{attach_view\((\w+|_).(\d+).jpeg\)\}\}/)
|
330
|
-
new_num=sprintf("%03d",m[2].to_i+number.to_i)
|
331
|
-
line="\{\{attach_view\(#{m[1]}.#{new_num}.jpeg,#{dir}\)\}\}\n"
|
332
|
-
cont << line
|
333
|
-
else
|
334
|
-
cont << line
|
335
|
-
end
|
336
|
-
}
|
337
|
-
print cont
|
338
|
-
exit
|
339
|
-
end
|
340
|
-
|
341
|
-
desc "numbering figs from the NUBER in FILE"
|
342
|
-
task :number do
|
343
|
-
number=ARGV[1].to_i
|
344
|
-
file = ARGV[2]
|
345
|
-
dir = ARGV[3] || nil
|
346
|
-
lines = File.readlines(file)
|
347
|
-
cont = ""
|
348
|
-
lines.each{|line|
|
349
|
-
if m=line.match(/\{\{attach_view\((\w+|_).(\d+).jpeg,(\w+)\)\}\}/)
|
350
|
-
new_num=sprintf("%03d",number)
|
351
|
-
line="\{\{attach_view\(#{m[1]}.#{new_num}.jpeg,#{m[3]}\)\}\}\n"
|
352
|
-
cont << line
|
353
|
-
number += 1
|
354
|
-
else
|
355
|
-
cont << line
|
356
|
-
end
|
357
|
-
}
|
358
|
-
print cont
|
359
|
-
exit
|
360
|
-
end
|
361
|
-
|
362
|
-
desc "convert fig size SCALE TARGET_DIR"
|
363
|
-
task :convert do
|
364
|
-
scale = ARGV[1]
|
365
|
-
target_dir=ARGV[2]
|
366
|
-
Dir.entries(target_dir)[2..-1].each{|file|
|
367
|
-
p file
|
368
|
-
source = File.join(target_dir,file)
|
369
|
-
target = File.join('figs',file)
|
370
|
-
p command = "convert #{source} -resize #{scale}\% #{target}"
|
371
|
-
system command
|
372
|
-
}
|
373
|
-
exit
|
374
|
-
end
|
375
|
-
|
376
|
-
desc "hikiの同期"
|
377
|
-
task :sync => [:check_previous,:sync0]
|
378
|
-
|
379
|
-
|
380
|
-
desc "hikiの強制同期"
|
381
|
-
task :force_sync => [:sync0]
|
382
|
-
|
383
|
-
def hiki_cite_ref(file)
|
384
|
-
tf1 = 'tmp1.txt'
|
385
|
-
lines = File.readlines(file)
|
386
|
-
inside_pre_form,cont = false,""
|
387
|
-
lines.each{|line|
|
388
|
-
inside_pre_form=true if line.match(/^<<</) and !inside_pre_form
|
389
|
-
inside_pre_form=false if line.match(/^>>>/) and inside_pre_form
|
390
|
-
tr_pair=[/\{\{cite\((.+?)\)\}\}/,/\{\{ref\((.+)\)\}\}/]
|
391
|
-
while m=line.match(tr_pair[0]) and !inside_pre_form
|
392
|
-
puts line.sub!(tr_pair[0], "\[[[#{m[1]}|#{$basename}_references]]\]").chomp.green
|
393
|
-
end
|
394
|
-
while m=line.match(tr_pair[1]) and !inside_pre_form
|
395
|
-
puts line.sub!(tr_pair[1],"#{m[1]}").chomp.green
|
396
|
-
end
|
397
|
-
cont << line
|
398
|
-
}
|
399
|
-
File.open(tf1,'w'){|file| file.print cont }
|
400
|
-
return tf1
|
401
|
-
end
|
402
|
-
|
403
|
-
task :sync0 do
|
404
|
-
entries=Dir.entries('.')
|
405
|
-
entries[2..-1].each{|source| #cp *.hiki
|
406
|
-
next unless source.split('.')[1]=='hiki'
|
407
|
-
next if source.include?('.hikirc')
|
408
|
-
p base = source.split('.')[0]
|
409
|
-
name = (base==$basename)? base : $basename+'_'+base
|
410
|
-
p target = File.join($hiki_dir,'text',name)
|
411
|
-
source = hiki_cite_ref(source)
|
412
|
-
FileUtils.cp(source,target,:verbose=>true)
|
413
|
-
}
|
414
|
-
p entries=Dir.entries('./figs') #cp files in figs
|
415
|
-
p target = File.join($hiki_dir,'cache','attach',$basename)
|
416
|
-
FileUtils.mkdir_p(target,:verbose=>true) unless File.exists?(target)
|
417
|
-
entries[2..-1].each{|file|
|
418
|
-
p source = File.join('./figs',file)
|
419
|
-
FileUtils.cp(source,target,:verbose=>true)
|
420
|
-
}
|
421
|
-
|
422
|
-
File.open('./.hikirc','w'){|file|
|
423
|
-
status, stdout, stderr =systemu "hiki -l #{$basename}*"
|
424
|
-
file.print($hiki_dir+"\n")
|
425
|
-
stdout.split("\n")[3..-1].each{|line|
|
426
|
-
file.print line+"\n"
|
427
|
-
}
|
428
|
-
}
|
429
|
-
exit
|
430
|
-
end
|
431
|
-
|
432
|
-
desc "For hiki Errno::ENOENT, Errno::EACCES"
|
433
|
-
task :chenv do
|
434
|
-
p user = ENV['USER']
|
435
|
-
system("sudo chmod -R a+w #{$hiki_dir}")
|
436
|
-
# system("sudo chown -R #{user} #{$hiki_dir}")
|
437
|
-
end
|
438
|
-
|
439
|
-
desc "self copy to hikiutils template directory"
|
440
|
-
task :self_copy do
|
441
|
-
p cp_files=[[File.join(Dir.pwd,'Rakefile'),'Rakefile_hiki_sync'],
|
442
|
-
[File.join(ENV['HOME'],'.my_help','hiki_help.yml'),'hiki_help.yml']]
|
443
|
-
cp_files.each{|files|
|
444
|
-
p source = files[0]
|
445
|
-
p target = File.join('/Users/bob/Github/hikiutils/lib/templates/',files[1])
|
446
|
-
FileUtils.cp(source,target,:verbose=>true)
|
447
|
-
}
|
448
|
-
end
|
449
|
-
|
450
|
-
task :check_previous do
|
451
|
-
current={}
|
452
|
-
print "current hiki dir\n"
|
453
|
-
status, stdout, stderr = systemu("hiki -l #{$basename}*")
|
454
|
-
stdout.split("\n")[3..-1].each{|line|
|
455
|
-
p line
|
456
|
-
file= line.split(/\s+/)[-1]
|
457
|
-
current[file]=line
|
458
|
-
}
|
459
|
-
previous={}
|
460
|
-
print "previous sync\n"
|
461
|
-
File.readlines('.hikirc')[1..-1].each{|line|
|
462
|
-
p line.chomp
|
463
|
-
file= line.split(/\s+/)[-1]
|
464
|
-
previous[file]=line.chomp
|
465
|
-
}
|
466
|
-
changed = []
|
467
|
-
current.each_pair{|key,val|
|
468
|
-
if !previous.include?(key) or previous[key]!=val
|
469
|
-
changed << val+"\n"
|
470
|
-
end
|
471
|
-
}
|
472
|
-
if changed.size != 0
|
473
|
-
print("hiki dirで変更が発生しています.\n")
|
474
|
-
changed.each{|line| print line+"\n"}
|
475
|
-
exit
|
476
|
-
end
|
477
|
-
end
|
@@ -1,111 +0,0 @@
|
|
1
|
-
{{toc}}
|
2
|
-
!コマンドの命名原則
|
3
|
-
|
4
|
-
機能ごとの動作はコマンドのオプションによって指定されます.
|
5
|
-
このオプションにどのような名前をつけるかは,どれだけコマンドを覚えやすいかという
|
6
|
-
意味で重要です.コマンドの振る舞いを的確に表す名称をつける必要があります.
|
7
|
-
|
8
|
-
この振る舞いとしてもっとも受け入れやすいのがshellで用意されているコマンドです.
|
9
|
-
pwd, ls, rm, touch, openなどはもっとも直感的に動作がわかるコマンドです.
|
10
|
-
hikiutilsの振る舞いを予測できるシェルコマンドと同じ名前でオプションを提供する
|
11
|
-
ようにします.
|
12
|
-
|
13
|
-
|
14
|
-
!!hikiutilsの想定利用形態
|
15
|
-
ここでhikiutilsがあらかじめ想定している利用形態を解説しておきます.
|
16
|
-
|
17
|
-
!!!caption:(fig:002)hikiutilsがあらかじめ想定している利用形態.
|
18
|
-
{{attach_view(hikiutils_yamane.002.jpg,hikiutils_yamane)}}
|
19
|
-
|
20
|
-
hikiutilsは,
|
21
|
-
*local PCとglobal serverとが用意されており,
|
22
|
-
*それらのデータをrsyncで同期する
|
23
|
-
ことで動作することを想定しています.これは,ネットに繋がっていないオフラインの状況でも
|
24
|
-
テキストなどの編集が可能で,さらに不用意な書き換えを防ぐための機構です.さらに,
|
25
|
-
どちらもが何かあった時のバックアップともなって,ミスによる手戻りを防いでいます.
|
26
|
-
|
27
|
-
これらの設定は,~/.hikircにyaml形式で記述・保存されています.
|
28
|
-
<<< yaml
|
29
|
-
bob% cat ~/.hikirc
|
30
|
-
:srcs:
|
31
|
-
- :nick_name: new_ist
|
32
|
-
:local_dir: "/Users/bob/Sites/new_ist_data/ist_data"
|
33
|
-
:local_uri: http://localhost/ist
|
34
|
-
:global_dir: nishitani@ist.ksc.kwansei.ac.jp:/home/nishitani/new_ist_data/ist_data
|
35
|
-
:global_uri: http://ist.ksc.kwansei.ac.jp/~nishitani/
|
36
|
-
- :nick_name: dmz0
|
37
|
-
:local_dir: "/Users/bob/Sites/nishitani0/Internal/data"
|
38
|
-
:local_uri: http://localhost/~bob/nishitani0/Internal
|
39
|
-
:global_dir: bob@dmz0:/Users/bob/Sites/nishitani0/Internal/data
|
40
|
-
:global_uri: http://nishitani0.kwansei.ac.jp/~bob/nishitani0/Internal
|
41
|
-
>>>
|
42
|
-
また,一般的に一人のユーザがいくつものまとまりとしてのlocal-globalペアを
|
43
|
-
保持して管理することが普通です.それぞれにnicke_nameをつけて管理しています.
|
44
|
-
<<< bash
|
45
|
-
bob% hiki -s
|
46
|
-
hikiutils: provide utilities for helping hiki editing.
|
47
|
-
"open -a mi"
|
48
|
-
target_no:1
|
49
|
-
editor_command:open -a mi
|
50
|
-
id | name | local directory | global uri
|
51
|
-
-----------------------------------------------------------------------------
|
52
|
-
0 | new_ist | /Users/bob/Sites/new_ist_data/ist_data | http://ist.ksc.k
|
53
|
-
*1 | dmz0 | /Users/bob/Sites/nishitani0/Internal/data | http://nishitani
|
54
|
-
2 | ist | /Users/bob/Sites/hiki-data/data | http://ist.ksc.k
|
55
|
-
3 | new_maple | /Users/bob/Sites/new_ist_data/maple_hiki_d| http://ist.ksc.k
|
56
|
-
>>>
|
57
|
-
とすると,それらの一覧と,いまtargetにしているnick_nameディレクリが表示されます.
|
58
|
-
|
59
|
-
!!コメンド名と振る舞いの詳細
|
60
|
-
|
61
|
-
検討の結果コマンドを以下のように書き換えることとします.
|
62
|
-
上部に記した,特によく使うコマンドに関しては,shellでよく使われるコマンド名と一致するにようにしました.
|
63
|
-
|
64
|
-
||変更前||変更後||動作の解説
|
65
|
-
||edit FILE ||open|| open file
|
66
|
-
||list [FILE] ||ls|| list files
|
67
|
-
||rsync ||rsync|| rsync files
|
68
|
-
||update FILE ||touch|| update file
|
69
|
-
||show ||pwd|| show nick_names
|
70
|
-
||target VAL ||cd|| targetを変える,cdとのメタファ
|
71
|
-
|| || ||
|
72
|
-
||move [FILE] ||mv|| move file
|
73
|
-
||remove [FILE] ||rm|| remove files
|
74
|
-
||add || || add sources info
|
75
|
-
||checkdb || || check database file
|
76
|
-
||datebase FILE ||db|| read datebase file
|
77
|
-
||display FILE ||show|| display converted hikifile
|
78
|
-
||euc FILE || || translate file to euc
|
79
|
-
||help [COMMAND] ||-h|| Describe available commands
|
80
|
-
||version ||-v|| show program version
|
81
|
-
|
82
|
-
それぞれの意図を動作の解説として記述しています.
|
83
|
-
|
84
|
-
!!! open FILE
|
85
|
-
ファイルを編集のためにeditorでopen.Editorは~/.hikircに
|
86
|
-
:editor_command: open -a mi
|
87
|
-
として保存されている.open -a miをemacsなどに適宜変更して使用.
|
88
|
-
|
89
|
-
!!! ls [FILE]
|
90
|
-
local_dirにあるファイル名を[FILE*]として表示.例えば,hikiutils_yamane以下の拡張子が
|
91
|
-
ついたファイルを表示.hikiシステムではtextディレクトリーは階層構造を取ることができない.
|
92
|
-
西谷研ではdirectoryの代わりにスネーク表記で階層構造を表している.
|
93
|
-
|
94
|
-
!!! rsync
|
95
|
-
local_dirの内容をglobal_dirにrsyncする.逆方向は同期に誤差が生じたり,permissionが
|
96
|
-
おかしくなるので,現在のところ一方向の同期のみとしている.したがって,作業手順としては
|
97
|
-
テキストの変更はlocal_dirで読み行うようにしている.
|
98
|
-
|
99
|
-
!!! touch FILE
|
100
|
-
loccal_dirで書き換えたFILEの内容をlocal_uriに反映させ,ブラウザで表示.シェルコマンドの
|
101
|
-
touchによって,変更時間を現在に変え,最新状態とするのに似せてコマンド名をtouchとしている.
|
102
|
-
|
103
|
-
!!! pwd
|
104
|
-
nick_nameの一覧とtargetを表示,current targetをcurrent dirとみなして,
|
105
|
-
コマンド名をpwdとした.
|
106
|
-
|
107
|
-
!!! cd VAL
|
108
|
-
targetを変える,change directoryとのメタファ.ただし,いまのところnick_nameでは
|
109
|
-
対応しておらず,nick_nameの番号をVAL入力することで変更する.
|
110
|
-
|
111
|
-
|
@@ -1,116 +0,0 @@
|
|
1
|
-
{{toc}}
|
2
|
-
!optparseとthorの比較
|
3
|
-
今回の既存システムであるhikiutilsはoptparseというコマンドライン解析ライブラリが用いられている.
|
4
|
-
本研究ではこの代替ライブラリとしてThorの採用を検討した.
|
5
|
-
本章の最初では,FizzBuzzという簡単なコードを例にoptparseとThorにより作成するコマンドライン解析コードの比較を行う.
|
6
|
-
|
7
|
-
!!optparse
|
8
|
-
optparseとは,getoptよりも簡便で,柔軟性に富み,かつ強力なコマンドライン解析ライブラリである.optparseでは,より宣言的なスタイルのコマンドライン解析手法,すなわちOptionParserのインスタンスでコマンドラインを解析するという手法をとっている.これを使うと,GNU/POSIX構文でオプションを指定できるだけでなく,使用法やヘルプメッセージの生成も行える[2].利用頻度はあまり高くないが古くから開発され,使用例が広く紹介されている.
|
9
|
-
|
10
|
-
optparseの基本的な流れとしては
|
11
|
-
#OptionParserオブジェクトoptを生成する
|
12
|
-
#オプションを取り扱うブロックをopt.onに登録する
|
13
|
-
#opt.parse(ARGV)でコマンドラインを実際にparseする
|
14
|
-
である.
|
15
|
-
|
16
|
-
OptionParserはコマンドラインのオプション取り扱うためのクラスであるためオブジェクトoptを生成されopt.onにコマンドを登録することができる.しかし,OptionParser\#onにはコマンドが登録されているだけであるため,OptionParser\#parseが呼ばれた時,コマンドラインにオプションが指定されていれば実行される.optparseにはデフォルトとして--helpと--versionオプションを認識する[3].
|
17
|
-
|
18
|
-
以下に示したコードがoptparseで記述されたfizzbuzzである.
|
19
|
-
|
20
|
-
<<< ruby
|
21
|
-
module Fizzbuzz
|
22
|
-
class Command
|
23
|
-
|
24
|
-
def self.run(argv)
|
25
|
-
new(argv).execute
|
26
|
-
end
|
27
|
-
|
28
|
-
def initialize(argv)
|
29
|
-
@argv = argv
|
30
|
-
end
|
31
|
-
|
32
|
-
def execute
|
33
|
-
options = Options.parse!(@argv)
|
34
|
-
sub_command = options.delete(:command)
|
35
|
-
case sub_command
|
36
|
-
when 'fizzbuzz'
|
37
|
-
fizzbuzz(options[:id])
|
38
|
-
when 'version'
|
39
|
-
version
|
40
|
-
end
|
41
|
-
end
|
42
|
-
|
43
|
-
def fizzbuzz(limit_number)
|
44
|
-
(0..limit_number).map do |num|
|
45
|
-
if (num % 15).zero? then print 'FizzBuzz'
|
46
|
-
elsif (num % 5).zero? then print 'Buzz'
|
47
|
-
elsif (num % 3).zero? then print 'Fizz'
|
48
|
-
else print num.to_s
|
49
|
-
end
|
50
|
-
print ' '
|
51
|
-
end
|
52
|
-
end
|
53
|
-
|
54
|
-
def version
|
55
|
-
puts Fizzbuzz::VERSION
|
56
|
-
exit
|
57
|
-
end
|
58
|
-
end
|
59
|
-
end
|
60
|
-
>>>
|
61
|
-
|
62
|
-
このコードはfizzbuzzとversionのコマンドを実行させる.
|
63
|
-
!!!runメソッド
|
64
|
-
コマンド実行を行うためのメソッドであり,argv配列を代入することでexecuteメソッドを実行する.
|
65
|
-
!!!initializeメソッド
|
66
|
-
初期化を行うメソッドである.
|
67
|
-
<<<
|
68
|
-
@argv = argv
|
69
|
-
>>>
|
70
|
-
こうすることでargvをクラス内で利用できるようにする.
|
71
|
-
!!!executeメソッド
|
72
|
-
上記でoptparseではopt.onにコマンドを登録する必要があると説明したが,opt.onで登録できるものはハイフンがついたコマンドだけであり,ハイフンなしのコマンドの登録はこのようになる.
|
73
|
-
|
74
|
-
argv配列の解析を行うOptions.parse!(@argv)をoptionsに代入して解析を行いsub_commandに代入する.sub_commandがfizzbuzzであればfizzbuzz(options[:id])メソッドを実行,versionであればversionメソッドを実行する.
|
75
|
-
!!!fizzbuzzメソッド
|
76
|
-
引数としてlimit_numberを受け取り,0〜limit_numberまでの数字を繰り返す.numが15であればFizzbuzzを表示,5であればBuzzを表示,3であればFizzを表示,それ以外は数字を表示し,その後に空白を表示する.
|
77
|
-
!!!versionメソッド
|
78
|
-
fizzbuzzのバージョンを表示する.
|
79
|
-
|
80
|
-
!!Thor
|
81
|
-
Thorとは,コマンドラインツールの作成を支援するライブラリのことである.gitやbundlerのようにサブコマンドを含むコマンドラインツールを簡単に作成することができる[4].
|
82
|
-
|
83
|
-
Thorの基本的な流れとしては
|
84
|
-
#Thorを継承したクラスのパブリックメソッドがコマンドになる
|
85
|
-
#クラス.start(ARGV)でコマンドラインの処理をスタートする
|
86
|
-
である[4].
|
87
|
-
|
88
|
-
startに渡す引数が空の場合,Thorはクラスのヘルプリストを出力する.また,Thorはサブコマンドやサブサブコマンドも容易に作ることができる.
|
89
|
-
|
90
|
-
以下に示したコードがThorで記述されたfizzbuzzである.
|
91
|
-
|
92
|
-
<<< ruby
|
93
|
-
module Fizzbuzz
|
94
|
-
class CLI < Thor
|
95
|
-
|
96
|
-
desc 'fizzbuzz', 'Get fizzbuzz result from limit number'
|
97
|
-
def fizzbuzz(limit)
|
98
|
-
print Fizzbuzz.fizzbuzz(limit).join(',')
|
99
|
-
exit
|
100
|
-
end
|
101
|
-
|
102
|
-
desc 'version', 'version'
|
103
|
-
def version
|
104
|
-
puts Fizzbuzz::VERSION
|
105
|
-
end
|
106
|
-
end
|
107
|
-
end
|
108
|
-
>>>
|
109
|
-
|
110
|
-
このコードもoptparseのfizzbuzzと同様fizzbuzzとversionのコマンドを実行させる.
|
111
|
-
!!!fizzbuzzメソッド,versionメソッド
|
112
|
-
descでコマンド一覧で表示させるコマンド名と説明を書く.
|
113
|
-
|
114
|
-
メソッド内ではそれぞれのコマンドの処理内容が書かれている.
|
115
|
-
|
116
|
-
|