hikiutils 0.2.3 → 0.2.3.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 820810ad85670c7d8df9779f1edb5aeb2fbedacf
4
- data.tar.gz: 143d10e7ff4d9682e6bceba891e4a0587587b886
3
+ metadata.gz: 81506266e388a01ba351b64fe66e457727ee7cd6
4
+ data.tar.gz: f78970f278ed761b7a00cee237710ecbec41bef6
5
5
  SHA512:
6
- metadata.gz: c4d4607ef5a7cba3b13b98dad2f13e37fb3ce595dfff9a820197ac30fad3ab63639556318d2792c65e16ad01ae09ee7ef69bf4f03726bb45d10b6df057e6f4d6
7
- data.tar.gz: 19af682ceb930e1f6a63c3d0ea59c8eb13113f1d049e05bfeeedafca397d77b7327cb83407ec551efc1fe283ef1540a3e0b852226868bc86574430f4987c2dd5
6
+ metadata.gz: c9c177e0cb6386e1bfcdba4419a053dc3543367edbd315c4fca8b89d08d0ef411fcb67701defa34f2b01b77eebedb9b8092662a03f9e21b3b50af53e15014d5e
7
+ data.tar.gz: 140726c03217b302d23d8d169eb4ce3b5c97cb29e7916460166ce3f89e98e09a92b396c22678b984fb77429a0f818811badb390fbf5f9847820a06f591dfc1d2
data/exe/hiki CHANGED
@@ -1,5 +1,8 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
3
  require "hikiutils"
4
+ #require "hikiutils_thor"
4
5
 
5
6
  HikiUtils::Command.run(ARGV)
7
+ #CLI::Command.run(ARGV)
8
+ #Hikithor::CLI.start(ARGV)
data/exe/hiki_thor ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ #require "hikiutils"
4
+ require "hikiutils_thor"
5
+
6
+ #HikiUtils::Command.run(ARGV)
7
+ #CLI::Command.run(ARGV)
8
+ Hikithor::CLI.start(ARGV)
data/hikiutils.gemspec CHANGED
@@ -38,4 +38,5 @@ Gem::Specification.new do |spec|
38
38
  spec.add_development_dependency "hiki2yard"
39
39
  spec.add_runtime_dependency "systemu"
40
40
  spec.add_runtime_dependency "hikidoc", "~> 0.1.0"
41
+ spec.add_runtime_dependency 'thor'
41
42
  end
@@ -0,0 +1 @@
1
+ .hikirc
@@ -0,0 +1,66 @@
1
+ begin
2
+ target_dir = File.readlines('./.hikirc')[0].chomp
3
+ rescue => e
4
+ puts e
5
+ exit
6
+ end
7
+ p target_dir
8
+
9
+ task :default do
10
+ system 'rake -T'
11
+ end
12
+
13
+ desc "convert fig size SCALE TARGET_DIR"
14
+ task :convert do
15
+ scale = ARGV[1]
16
+ target_dir=ARGV[2]
17
+ Dir.entries(target_dir)[2..-1].each{|file|
18
+ p file
19
+ source = File.join(target_dir,file)
20
+ target = File.join('figs',file)
21
+ p command = "convert #{source} -resize #{scale}\% #{target}"
22
+ system command
23
+ }
24
+ exit
25
+ end
26
+
27
+ desc "sync hikis and figs to hiki directory"
28
+ task :sync do
29
+ p dirnames=Dir.pwd.split('/')
30
+ p basename = (dirnames[-1]=='hikis')? dirnames[-2] : dirnames[-1]
31
+ p entries=Dir.entries('.')
32
+ entries[2..-1].each{|source| #cp *.hiki
33
+ next unless source.include?('.hiki')
34
+ next if source.include?('.hikirc')
35
+ p base = source.split('.')[0]
36
+ name = (base==basename)? base : basename+'_'+base
37
+ p target = File.join(target_dir,'text',name)
38
+ FileUtils.cp(source,target,:verbose=>true)
39
+ }
40
+ p entries=Dir.entries('./figs') #cp files in figs
41
+ p target = File.join(target_dir,'cache','attach',basename)
42
+ FileUtils.mkdir_p(target,:verbose=>true) unless File.exists?(target)
43
+ entries[2..-1].each{|file|
44
+ p source = File.join('./figs',file)
45
+ FileUtils.cp(source,target,:verbose=>true)
46
+ }
47
+ exit
48
+ end
49
+
50
+ desc "For hiki Errno::ENOENT, Errno::EACCES"
51
+ task :chenv do
52
+ p user = ENV['USER']
53
+ system("sudo chmod -R a+w #{target_dir}")
54
+ # system("sudo chown -R #{user} #{target_dir}")
55
+ end
56
+
57
+ desc "self copy to hikiutils template directory"
58
+ task :self_copy do
59
+ p cp_files=[['Rakefile','Rakefile_hiki_sync'],
60
+ [File.join(ENV['HOME'],'.my_help','hiki_help.yml'),'hiki_help.yml']]
61
+ cp_files.each{|files|
62
+ p source = File.join(Dir.pwd,'Rakefile')
63
+ p target = File.join('/Users/bob/Github/hikiutils/lib/templates/',files[1])
64
+ FileUtils.cp(source,target,:verbose=>true)
65
+ }
66
+ end
@@ -0,0 +1,66 @@
1
+ begin
2
+ target_dir = File.readlines('./.hikirc')[0].chomp
3
+ rescue => e
4
+ puts e
5
+ exit
6
+ end
7
+ p target_dir
8
+
9
+ task :default do
10
+ system 'rake -T'
11
+ end
12
+
13
+ desc "convert fig size SCALE TARGET_DIR"
14
+ task :convert do
15
+ scale = ARGV[1]
16
+ target_dir=ARGV[2]
17
+ Dir.entries(target_dir)[2..-1].each{|file|
18
+ p file
19
+ source = File.join(target_dir,file)
20
+ target = File.join('figs',file)
21
+ p command = "convert #{source} -resize #{scale}\% #{target}"
22
+ system command
23
+ }
24
+ exit
25
+ end
26
+
27
+ desc "sync hikis and figs to hiki directory"
28
+ task :sync do
29
+ p dirnames=Dir.pwd.split('/')
30
+ p basename = (dirnames[-1]=='hikis')? dirnames[-2] : dirnames[-1]
31
+ p entries=Dir.entries('.')
32
+ entries[2..-1].each{|source| #cp *.hiki
33
+ next unless source.include?('.hiki')
34
+ next if source.include?('.hikirc')
35
+ p base = source.split('.')[0]
36
+ name = (base==basename)? base : basename+'_'+base
37
+ p target = File.join(target_dir,'text',name)
38
+ FileUtils.cp(source,target,:verbose=>true)
39
+ }
40
+ p entries=Dir.entries('./figs') #cp files in figs
41
+ p target = File.join(target_dir,'cache','attach',basename)
42
+ FileUtils.mkdir(target,:verbose=>true) unless File.exists?(target)
43
+ entries[2..-1].each{|file|
44
+ p source = File.join('./figs',file)
45
+ FileUtils.cp(source,target,:verbose=>true)
46
+ }
47
+ exit
48
+ end
49
+
50
+ desc "For hiki Errno::ENOENT, Errno::EACCES"
51
+ task :chenv do
52
+ p user = ENV['USER']
53
+ system("sudo chmod -R a+w #{target_dir}")
54
+ # system("sudo chown -R #{user} #{target_dir}")
55
+ end
56
+
57
+ desc "self copy to hikiutils template directory"
58
+ task :self_copy do
59
+ p cp_files=[['Rakefile','Rakefile_hiki_sync'],
60
+ [File.join(ENV['HOME'],'.my_help','hiki_help.yml'),'hiki_help.yml']]
61
+ cp_files.each{|files|
62
+ p source = File.join(Dir.pwd,'Rakefile')
63
+ p target = File.join('/Users/bob/Github/hikiutils/lib/templates/',files[1])
64
+ FileUtils.cp(source,target,:verbose=>true)
65
+ }
66
+ end
@@ -0,0 +1 @@
1
+ !test
@@ -1,3 +1,3 @@
1
1
  module HikiUtils
2
- VERSION = "0.2.3"
2
+ VERSION = "0.2.3.1"
3
3
  end
@@ -0,0 +1,308 @@
1
+ # -*- coding: utf-8 -*-
2
+ require 'thor'
3
+ require 'kconv'
4
+ require 'hikidoc'
5
+ require 'erb'
6
+ require "hikiutils/tmarshal"
7
+ require "hikiutils/infodb"
8
+ #require "hikiutils/hiki1"
9
+ require 'systemu'
10
+ require 'fileutils'
11
+ require 'yaml'
12
+ require 'pp'
13
+
14
+ module Hikithor
15
+
16
+ DATA_FILE=File.join(ENV['HOME'],'.hikirc')
17
+ attr_accessor :src, :target, :editor_command, :browser, :data_name, :l_dir
18
+
19
+
20
+ class CLI < Thor
21
+ def initialize(*args)
22
+ super
23
+ @data_name=['nick_name','local_dir','local_uri','global_dir','global_uri']
24
+ data_path = File.join(ENV['HOME'], '.hikirc')
25
+ DataFiles.prepare(data_path)
26
+
27
+ file = File.open(DATA_FILE,'r')
28
+ @src = YAML.load(file.read)
29
+ file.close
30
+ @target = @src[:target]
31
+ @l_dir=@src[:srcs][@target][:local_dir]
32
+ browser = @src[:browser]
33
+ @browser = (browser==nil) ? 'firefox' : browser
34
+ p editor_command = @src[:editor_command]
35
+ @editor_command = (editor_command==nil) ? 'open -a mi' : editor_command
36
+ end
37
+ HTML_TEMPLATE = <<EOS
38
+ <!DOCTYPE html
39
+ PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
40
+ "http://www.w3.org/TR/html4/loose.dtd">
41
+ <html lang="ja">
42
+ <html>
43
+ <head>
44
+ <meta http-equiv="Content-Language" content="ja">
45
+ <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
46
+ <title><%= title %></title>
47
+ </head>
48
+ <body>
49
+ <%= body %>
50
+ </body>
51
+ </html>
52
+ EOS
53
+ =begin
54
+ def initialize(*args)
55
+ @data_name=['nick_name','local_dir','local_uri','global_dir','global_uri']
56
+ data_path = File.join(ENV['HOME'], '.hikirc')
57
+ DataFiles.prepare(data_path)
58
+
59
+ file = File.open(DATA_FILE,'r')
60
+ @src = YAML.load(file.read)
61
+ # p @src
62
+ file.close
63
+ @target = @src[:target]
64
+ # p @target
65
+ @l_dir=@src[:srcs][@target][:local_dir]
66
+ browser = @src[:browser]
67
+ # p browser
68
+ @browser = (browser==nil) ? 'firefox' : browser
69
+ p editor_command = @src[:editor_command]
70
+ @editor_command = (editor_command==nil) ? 'open -a mi' : editor_command
71
+ # p @l_dir
72
+ end
73
+ =end
74
+ =begin
75
+ desc 'show', 'show sources'
76
+ def show()
77
+ printf("target_no:%i\n",@src[:target])
78
+ printf("editor_command:%s\n",@src[:editor_command])
79
+ check_display_size()
80
+ header = display_format('id','name','local directory','global uri')
81
+
82
+ puts header
83
+ puts '-' * header.size
84
+
85
+ @src[:srcs].each_with_index{|src,i|
86
+ target = i==@src[:target] ? '*':' '
87
+ id = target+i.to_s
88
+ name=src[:nick_name]
89
+ local=src[:local_dir]
90
+ global=src[:global_uri]
91
+ puts display_format(id,name,local,global)
92
+ }
93
+ end
94
+ =end
95
+ desc 'version', 'show program version'
96
+ def version
97
+ puts Hikithor::VERSION
98
+ end
99
+ =begin
100
+ desc 'add', 'add sources info'
101
+ def add
102
+ cont = {}
103
+ # p @data_name
104
+ @data_name.each{|name|
105
+ printf("%s ? ", name)
106
+ tmp = gets.chomp
107
+ cont[name.to_sym] = tmp
108
+ }
109
+ @src[:srcs] << cont
110
+ show
111
+ end
112
+
113
+ desc 'target VAL', 'set target id'
114
+ def target(val)
115
+ @src[:target] = val.to_i
116
+ show
117
+ end
118
+ =end
119
+ desc 'edit FILE', 'open file'
120
+ def edit(file)
121
+ p @l_dir
122
+ t_file=File.join(@l_dir,'text',file)
123
+ if !File.exist?(t_file) then
124
+ file=File.open(t_file,'w')
125
+ file.close
126
+ File.chmod(0777,t_file)
127
+ end
128
+ p command="#{@editor_command} #{t_file}"
129
+ system command
130
+ end
131
+ =begin
132
+ desc 'list [FILE]', 'list files'
133
+ def list(file)
134
+ file ='' if file==nil
135
+ t_file=File.join(@l_dir,'text')
136
+ print "target_dir : "+t_file+"\n"
137
+ print `cd #{t_file} ; ls -lt #{file}*`
138
+ end
139
+
140
+ desc 'update FILE', 'update file'
141
+ def update(file0)
142
+ file = (file0==nil) ? 'FrontPage' : file0
143
+ t_file=File.join(@l_dir,'cache/parser',file)
144
+ FileUtils.rm(t_file,:verbose=>true)
145
+ info=InfoDB.new(@l_dir)
146
+ info.update(file0)
147
+ l_path = @src[:srcs][@target][:local_uri]
148
+ p command="open -a #{@browser} \'#{l_path}/?#{file}\'"
149
+ system command
150
+ p "If you get open error, try rackup from the src_dir."
151
+ p "If you get 整形式になっていません, try login as a valid user."
152
+ end
153
+
154
+ desc 'rsync', 'rsync files'
155
+ def rsync
156
+ p local = @l_dir
157
+ p global = @src[:srcs][@target][:global_dir]
158
+ p command="rsync -auvz -e ssh #{local}/ #{global}"
159
+ system command
160
+ end
161
+
162
+ desc 'datebase FILE', 'read datebase file'
163
+ def database(file_name)
164
+ info=InfoDB.new(@l_dir)
165
+ p info.show(file_name)
166
+ end
167
+
168
+ desc 'display FILE', 'display converted hikifile'
169
+ def display(file)
170
+ body = HikiDoc.to_html(File.read(file))
171
+ source = HTML_TEMPLATE
172
+ title = File.basename(file)
173
+ erb = ERB.new(source)
174
+ t = File.open(file+".html",'w')
175
+ t.puts(erb.result(binding))
176
+ t.close
177
+ system "open #{t.path}"
178
+ end
179
+
180
+ desc 'checkdb', 'check database file'
181
+ def checkdb
182
+ result= InfoDB.new(@l_dir).show_inconsist
183
+ print (result=='') ? "db agrees with text dir.\n" : result
184
+ end
185
+
186
+ desc 'remove [FILE]', 'remove files'
187
+ def remove(file_name)
188
+ p text_path = File.join(@l_dir,'text',file_name)
189
+ p attach_path = File.join(@l_dir,'cache/attach',file_name)
190
+ begin
191
+ File.delete(text_path)
192
+ rescue => evar
193
+ puts evar.to_s
194
+ end
195
+ begin
196
+ Dir.rmdir(attach_path)
197
+ rescue => evar
198
+ puts evar.to_s
199
+ end
200
+
201
+ info=InfoDB.new(@l_dir)
202
+ p "delete "
203
+ del_file=info.delete(file_name)
204
+ info.show_link(file_name)
205
+ info.dump
206
+ end
207
+
208
+ desc 'move [FILE]', 'move file'
209
+ def move(files)
210
+ begin
211
+ p file1_path = File.join(@l_dir,'text',files[0])
212
+ p file2_path = File.join(@l_dir,'text',files[1])
213
+ rescue => evar
214
+ puts evar.to_s
215
+ puts "error on move_files, check the input format, especially comma separation."
216
+ exit
217
+ end
218
+ return if file1_path==file2_path
219
+ if File.exist?(file2_path) then
220
+ print ("moving target #{files[1]} exists.\n")
221
+ print ("first remove#{files[1]}.\n")
222
+ return
223
+ else
224
+ File.rename(file1_path,file2_path)
225
+ end
226
+
227
+ info=InfoDB.new(@l_dir)
228
+
229
+ db = info.db
230
+
231
+ pp file0=db[files[0]]
232
+ db.delete(files[0])
233
+ db[files[1]]=file0
234
+ db[files[1]][:title]=files[1] if db[files[1]][:title]==files[0]
235
+ pp db[files[1]]
236
+
237
+ db.each{|ele|
238
+ ref = ele[1][:references]
239
+ if ref.include?(files[0]) then
240
+ p link_file=ele[0]
241
+ link_path = File.join(@l_dir,'text',link_file)
242
+
243
+ cont = File.read(link_path)
244
+ if Kconv.iseuc(cont) then
245
+ print "euc\n"
246
+ utf8_cont=cont.toutf8
247
+ utf8_cont.gsub!(/#{files[0]}/,"#{files[1]}")
248
+ cont = utf8_cont.toeuc
249
+ else
250
+ cont.gsub!(/#{files[0]}/,"#{files[1]}")
251
+ end
252
+
253
+ File.write(link_path,cont)
254
+
255
+ ref.delete(files[0])
256
+ ref << files[1]
257
+
258
+ p cache_path = File.join(@l_dir,'cache/parser',link_file)
259
+ begin
260
+ File.delete(cache_path)
261
+ rescue => evar
262
+ puts evar.to_s
263
+ end
264
+ end
265
+ }
266
+
267
+ info.dump
268
+ end
269
+
270
+ desc 'euc FILE', 'translate file to euc'
271
+ def euc(file)
272
+ p file_path = File.join(@l_dir,'text',file)
273
+ cont = File.readlines(file_path)
274
+ cont.each{|line| puts line.toeuc }
275
+ end
276
+ =end
277
+ end
278
+ end
279
+
280
+ module DataFiles
281
+ def self.prepare(data_path)
282
+ create_file_if_not_exists(data_path)
283
+ end
284
+
285
+ def self.create_file_if_not_exists(data_path)
286
+ return if File::exists?(data_path)
287
+ create_data_file(data_path)
288
+ end
289
+
290
+ def self.create_data_file(data_path)
291
+ print "make #{data_path}\n"
292
+ init_data_file(data_path)
293
+ end
294
+
295
+ # initialize source file by dummy data
296
+ def self.init_data_file(data_path)
297
+ @src = {:target => 0, :editor_command => 'open -a mi',
298
+ :srcs=>[{:nick_name => 'hoge', :local_dir => 'hogehoge',
299
+ :local_uri => 'http://localhost/~hoge',
300
+ :global_dir => 'hoge@global_host:/hoge',
301
+ :global_uri => 'http://hoge'}]}
302
+ file = File.open(data_path,'w')
303
+ YAML.dump(@src,file)
304
+ file.close
305
+ end
306
+ private_class_method :create_file_if_not_exists, :create_data_file, :init_data_file
307
+ end
308
+
@@ -10,6 +10,26 @@ task :default do
10
10
  system 'rake -T'
11
11
  end
12
12
 
13
+ desc "increment fig NUBERS in FILE"
14
+ task :increment do
15
+ number=ARGV[1]
16
+ file = ARGV[2]
17
+ dir = ARGV[3] || nil
18
+ lines = File.readlines(file)
19
+ cont = ""
20
+ lines.each{|line|
21
+ if m=line.match(/\{\{attach_view\((\w+|_).(\d+).jpeg\)\}\}/)
22
+ new_num=sprintf("%03d",m[2].to_i+number.to_i)
23
+ line="\{\{attach_view\(#{m[1]}.#{new_num}.jpeg,#{dir}\)\}\}\n"
24
+ cont << line
25
+ else
26
+ cont << line
27
+ end
28
+ }
29
+ print cont
30
+ exit
31
+ end
32
+
13
33
  desc "convert fig size SCALE TARGET_DIR"
14
34
  task :convert do
15
35
  scale = ARGV[1]
@@ -10,6 +10,26 @@ task :default do
10
10
  system 'rake -T'
11
11
  end
12
12
 
13
+ desc "increment fig NUBERS in FILE"
14
+ task :increment do
15
+ number=ARGV[1]
16
+ file = ARGV[2]
17
+ dir = ARGV[3] || nil
18
+ lines = File.readlines(file)
19
+ cont = ""
20
+ lines.each{|line|
21
+ if m=line.match(/\{\{attach_view\((\w+|_).(\d+).jpeg\)\}\}/)
22
+ new_num=sprintf("%03d",m[2].to_i+number.to_i)
23
+ line="\{\{attach_view\(#{m[1]}.#{new_num}.jpeg,#{dir}\)\}\}\n"
24
+ cont << line
25
+ else
26
+ cont << line
27
+ end
28
+ }
29
+ print cont
30
+ exit
31
+ end
32
+
13
33
  desc "convert fig size SCALE TARGET_DIR"
14
34
  task :convert do
15
35
  scale = ARGV[1]
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hikiutils
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.3
4
+ version: 0.2.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Shigeto R. Nishitani
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-01-13 00:00:00.000000000 Z
11
+ date: 2017-01-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -150,11 +150,26 @@ dependencies:
150
150
  - - "~>"
151
151
  - !ruby/object:Gem::Version
152
152
  version: 0.1.0
153
+ - !ruby/object:Gem::Dependency
154
+ name: thor
155
+ requirement: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - ">="
158
+ - !ruby/object:Gem::Version
159
+ version: '0'
160
+ type: :runtime
161
+ prerelease: false
162
+ version_requirements: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - ">="
165
+ - !ruby/object:Gem::Version
166
+ version: '0'
153
167
  description: "."
154
168
  email:
155
169
  - shigeto_nishitani@me.com
156
170
  executables:
157
171
  - hiki
172
+ - hiki_thor
158
173
  extensions: []
159
174
  extra_rdoc_files: []
160
175
  files:
@@ -220,6 +235,7 @@ files:
220
235
  - bin/console
221
236
  - bin/setup
222
237
  - exe/hiki
238
+ - exe/hiki_thor
223
239
  - hikis/README.hiki
224
240
  - hikis/README.hiki.html
225
241
  - hikis/README_ja.hiki
@@ -230,10 +246,15 @@ files:
230
246
  - hikiutils.wiki/README.md
231
247
  - hikiutils.wiki/README_ja.md
232
248
  - hikiutils.wiki/yamane.md
249
+ - hikiutils_yamane/.gitignore
250
+ - hikiutils_yamane/Rakefile
251
+ - hikiutils_yamane/hiki_help.yml
252
+ - hikiutils_yamane/hikiutils_yamane.hiki
233
253
  - lib/hikiutils.rb
234
254
  - lib/hikiutils/infodb.rb
235
255
  - lib/hikiutils/tmarshal.rb
236
256
  - lib/hikiutils/version.rb
257
+ - lib/hikiutils_thor.rb
237
258
  - lib/templates/Rakefile_hiki_sync
238
259
  - lib/templates/hiki_help.yml
239
260
  homepage: http://github.org/daddygongon/hikiutils