hikiutils 0.1.0 → 0.1.1
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/README.md +43 -25
- data/Rakefile +1 -2
- data/docs/{README.ja.md → README.hiki} +21 -20
- data/docs/README.ja.hiki +11 -11
- data/hikiutils.gemspec +2 -2
- data/lib/#hikiutils.rb# +278 -0
- data/lib/.#hikiutils.rb +1 -0
- data/lib/hikiutils/{cleandb.rb → infodb.rb} +33 -3
- data/lib/hikiutils/version.rb +1 -1
- data/lib/hikiutils.rb +52 -49
- metadata +7 -6
- data/docs/README.en.md +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 98e94f886226df5e6dbf7972f48d5bc49aa5a43e
|
4
|
+
data.tar.gz: abfa5748c2135c2f5b5db18450b21bc85cae26fc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 169a79cc8844092d95bbcdfc3e3e77239872c263f468aeb628952db79721ec1c273619f3a8a9c233f322ee18fcae404c4158e0833c416826b7dc10770641291b
|
7
|
+
data.tar.gz: 86246ddc6ed0caf021840246168e0013dbec29f9c5f75953ee85c513c2a5a3326672e5943754aec14de9af6b81b1ac038416da2250f8b651297bc3ab6148fe72
|
data/README.md
CHANGED
@@ -1,41 +1,59 @@
|
|
1
|
-
#
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
1
|
+
# hikiutils
|
2
|
+
Utilities for helping hiki editing.
|
3
|
+
|
4
|
+
# Discriptions
|
5
|
+
Direct file handling utility for hiki text, cache and rsync of local ang global hiki sites.
|
6
|
+
|
7
|
+
|
8
|
+
# Operation
|
9
|
+
"hiki" is the command name.
|
10
|
+
|
11
|
+
```tcsh
|
12
|
+
bob% hiki
|
13
|
+
hiki says 'Hello world'.
|
14
|
+
Usage: hiki [options]
|
15
|
+
-v, --version show program Version.
|
16
|
+
-s, --show show sources
|
17
|
+
-a, --add add sources info
|
18
|
+
-t, --target [VAL] set target number
|
19
|
+
-o, --open [FILE] open file
|
20
|
+
-l, --list [FILE] list files
|
21
|
+
-u, --update [FILE] update file
|
22
|
+
-r, --rsync rsync files
|
23
|
+
```
|
6
24
|
|
7
25
|
## Installation
|
8
|
-
|
9
|
-
Add this line to your application's Gemfile:
|
10
|
-
|
11
|
-
```ruby
|
12
|
-
gem 'hikiutils'
|
26
|
+
Installed by
|
13
27
|
```
|
28
|
+
$ gem install hikimode
|
29
|
+
```
|
30
|
+
At the first time of hiki operation, hikirc file is created at home dir.
|
31
|
+
```
|
32
|
+
bob% cat ~/.hikirc
|
33
|
+
---
|
34
|
+
:target: 0
|
35
|
+
:editor_command: emacs
|
36
|
+
:srcs:
|
37
|
+
- :nick_name: hoge
|
38
|
+
:local_dir: hogehoge
|
39
|
+
:local_uri: http://localhost/~hoge
|
40
|
+
:global_dir: hoge@global_host:/hoge
|
41
|
+
:global_uri: http://hoge
|
42
|
+
```
|
43
|
+
The directly editing of hikirc file is much easier than using -a option.
|
44
|
+
Each hiki utility option runs, assuming the editing files lacating locally.
|
14
45
|
|
15
|
-
|
16
|
-
|
17
|
-
$ bundle
|
18
|
-
|
19
|
-
Or install it yourself as:
|
20
|
-
|
21
|
-
$ gem install hikiutils
|
22
|
-
|
23
|
-
## Usage
|
24
|
-
|
25
|
-
TODO: Write usage instructions here
|
46
|
+
Enjoy hiki world!!
|
26
47
|
|
27
48
|
## Development
|
28
49
|
|
29
|
-
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment. Run `bundle exec hikiutils` to use the gem in this directory, ignoring other installed copies of this gem.
|
30
|
-
|
31
50
|
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
32
51
|
|
33
52
|
## Contributing
|
34
53
|
|
35
|
-
Bug reports and pull requests are welcome on GitHub at https://github.com/
|
54
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/daddygongon/shunkuntype. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](contributor-covenant.org) code of conduct.
|
36
55
|
|
37
56
|
|
38
57
|
## License
|
39
58
|
|
40
59
|
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
41
|
-
|
data/Rakefile
CHANGED
@@ -10,8 +10,7 @@ end
|
|
10
10
|
|
11
11
|
desc "make documents by yard"
|
12
12
|
task :yard do
|
13
|
-
system "hiki2md docs/
|
14
|
-
system "hiki2md docs/readme.ja.hiki > docs/README.ja.md"
|
13
|
+
system "hiki2md docs/README.hiki > README.md"
|
15
14
|
YARD::Rake::YardocTask.new
|
16
15
|
end
|
17
16
|
|
@@ -1,14 +1,14 @@
|
|
1
|
-
|
2
|
-
hiki
|
1
|
+
!hikiutils
|
2
|
+
Utilities for helping hiki editing.
|
3
3
|
|
4
|
-
|
5
|
-
hiki
|
4
|
+
!Discriptions
|
5
|
+
Direct file handling utility for hiki text, cache and rsync of local ang global hiki sites.
|
6
6
|
|
7
7
|
|
8
|
-
|
9
|
-
|
8
|
+
!Operation
|
9
|
+
"hiki" is the command name.
|
10
10
|
|
11
|
-
|
11
|
+
<<< tcsh
|
12
12
|
bob% hiki
|
13
13
|
hiki says 'Hello world'.
|
14
14
|
Usage: hiki [options]
|
@@ -20,15 +20,15 @@ Usage: hiki [options]
|
|
20
20
|
-l, --list [FILE] list files
|
21
21
|
-u, --update [FILE] update file
|
22
22
|
-r, --rsync rsync files
|
23
|
-
|
23
|
+
>>>
|
24
24
|
|
25
|
-
|
26
|
-
|
27
|
-
|
25
|
+
!! Installation
|
26
|
+
Installed by
|
27
|
+
<<<
|
28
28
|
$ gem install hikimode
|
29
|
-
|
30
|
-
|
31
|
-
|
29
|
+
>>>
|
30
|
+
At the first time of hiki operation, hikirc file is created at home dir.
|
31
|
+
<<<
|
32
32
|
bob% cat ~/.hikirc
|
33
33
|
---
|
34
34
|
:target: 0
|
@@ -39,21 +39,22 @@ bob% cat ~/.hikirc
|
|
39
39
|
:local_uri: http://localhost/~hoge
|
40
40
|
:global_dir: hoge@global_host:/hoge
|
41
41
|
:global_uri: http://hoge
|
42
|
-
|
43
|
-
|
44
|
-
|
42
|
+
>>>D
|
43
|
+
The directly editing of hikirc file is much easier than using -a option.
|
44
|
+
Each hiki utility option runs, assuming the editing files lacating locally.
|
45
45
|
|
46
46
|
Enjoy hiki world!!
|
47
47
|
|
48
|
-
|
48
|
+
!! Development
|
49
49
|
|
50
50
|
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
51
51
|
|
52
|
-
|
52
|
+
!! Contributing
|
53
53
|
|
54
54
|
Bug reports and pull requests are welcome on GitHub at https://github.com/daddygongon/shunkuntype. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](contributor-covenant.org) code of conduct.
|
55
55
|
|
56
56
|
|
57
|
-
|
57
|
+
!! License
|
58
58
|
|
59
59
|
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
60
|
+
|
data/docs/README.ja.hiki
CHANGED
@@ -1,12 +1,12 @@
|
|
1
|
-
!
|
2
|
-
hiki
|
1
|
+
!hikiutils
|
2
|
+
Utilities for helping hiki editing.
|
3
3
|
|
4
|
-
|
5
|
-
hiki
|
4
|
+
!Features
|
5
|
+
Direct file handling utility for hiki text, cache and rsync of local ang global hiki sites.
|
6
6
|
|
7
7
|
|
8
|
-
|
9
|
-
|
8
|
+
!Operation
|
9
|
+
"hiki" is the command name.
|
10
10
|
|
11
11
|
<<< tcsh
|
12
12
|
bob% hiki
|
@@ -23,11 +23,11 @@ Usage: hiki [options]
|
|
23
23
|
>>>
|
24
24
|
|
25
25
|
!! Installation
|
26
|
-
|
26
|
+
Installed by
|
27
27
|
<<<
|
28
28
|
$ gem install hikimode
|
29
29
|
>>>
|
30
|
-
|
30
|
+
At the first time of hiki operation, hikirc file is created at home dir.
|
31
31
|
<<<
|
32
32
|
bob% cat ~/.hikirc
|
33
33
|
---
|
@@ -39,9 +39,9 @@ bob% cat ~/.hikirc
|
|
39
39
|
:local_uri: http://localhost/~hoge
|
40
40
|
:global_dir: hoge@global_host:/hoge
|
41
41
|
:global_uri: http://hoge
|
42
|
-
>>>
|
43
|
-
|
44
|
-
|
42
|
+
>>>D
|
43
|
+
The directly editing of hikirc file is much easier than using -a option.
|
44
|
+
Each hiki utility option runs, assuming the editing files lacating locally.
|
45
45
|
|
46
46
|
Enjoy hiki world!!
|
47
47
|
|
data/hikiutils.gemspec
CHANGED
@@ -27,6 +27,7 @@ Gem::Specification.new do |spec|
|
|
27
27
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
28
28
|
spec.require_paths = ["lib"]
|
29
29
|
|
30
|
+
spec.required_ruby_version = ">= 2.0.0"
|
30
31
|
spec.add_development_dependency "bundler", "~> 1.11"
|
31
32
|
spec.add_development_dependency "rake", "~> 10.0"
|
32
33
|
spec.add_development_dependency "minitest", "~> 5.0"
|
@@ -34,6 +35,5 @@ Gem::Specification.new do |spec|
|
|
34
35
|
spec.add_development_dependency "yard", "~> 0.8"
|
35
36
|
spec.add_development_dependency "hiki2md"
|
36
37
|
spec.add_runtime_dependency "systemu"
|
37
|
-
spec.add_runtime_dependency "hikidoc","~>0.1.0"
|
38
|
-
|
38
|
+
spec.add_runtime_dependency "hikidoc", "~> 0.1.0"
|
39
39
|
end
|
data/lib/#hikiutils.rb#
ADDED
@@ -0,0 +1,278 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
require 'nkf'
|
3
|
+
require "hikiutils/version"
|
4
|
+
require "hikiutils/tmarshal"
|
5
|
+
require "hikiutils/infodb"
|
6
|
+
require 'systemu'
|
7
|
+
require 'optparse'
|
8
|
+
require 'fileutils'
|
9
|
+
require 'yaml'
|
10
|
+
require 'pp'
|
11
|
+
|
12
|
+
module HikiUtils
|
13
|
+
DATA_FILE=File.join(ENV['HOME'],'.hikirc')
|
14
|
+
attr_accessor :src, :target, :data_name, :l_dir
|
15
|
+
|
16
|
+
class Command
|
17
|
+
def self.run(argv=[])
|
18
|
+
print "hiki says 'Hello world'.\n"
|
19
|
+
new(argv).execute
|
20
|
+
end
|
21
|
+
|
22
|
+
def initialize(argv=[])
|
23
|
+
@argv = argv
|
24
|
+
@data_name=['nick_name','local_dir','local_uri','global_dir','global_uri']
|
25
|
+
data_path = File.join(ENV['HOME'], '.hikirc')
|
26
|
+
DataFiles.prepare(data_path)
|
27
|
+
read_sources
|
28
|
+
end
|
29
|
+
|
30
|
+
def execute
|
31
|
+
@argv << '--help' if @argv.size==0
|
32
|
+
command_parser = OptionParser.new do |opt|
|
33
|
+
opt.on('-v', '--version','show program Version.') { |v|
|
34
|
+
opt.version = HikiUtils::VERSION
|
35
|
+
puts opt.ver
|
36
|
+
}
|
37
|
+
opt.on('-s', '--show','show sources') {show_sources}
|
38
|
+
opt.on('-a', '--add','add sources info') {add_sources }
|
39
|
+
opt.on('-t', '--target VAL','set target id') {|val| set_target(val) }
|
40
|
+
opt.on('-e', '--edit FILE','open file') {|file| edit_file(file) }
|
41
|
+
opt.on('-l', '--list [FILE]','list files') {|file| list_files(file) }
|
42
|
+
opt.on('-u', '--update FILE','update file') {|file| update_file(file) }
|
43
|
+
opt.on('-r', '--rsync','rsync files') {rsync_files}
|
44
|
+
opt.on('-d', '--database FILE','read database file') {|file| db_file(file)}
|
45
|
+
opt.on('-c', '--checkdb','check database file') {check_db}
|
46
|
+
opt.on('--remove FILE','remove file') {|file| remove_file(file)}
|
47
|
+
opt.on('--move FILES','move file1,file2',Array) {|files| move_file(files)}
|
48
|
+
end
|
49
|
+
command_parser.parse!(@argv)
|
50
|
+
dump_sources
|
51
|
+
exit
|
52
|
+
end
|
53
|
+
|
54
|
+
def move_file(files)
|
55
|
+
begin
|
56
|
+
p file1_path = File.join(@l_dir,'text',files[0])
|
57
|
+
p file2_path = File.join(@l_dir,'text',files[1])
|
58
|
+
rescue => evar
|
59
|
+
puts evar.to_s
|
60
|
+
puts "error on move_files, check the input format, especially comma separation."
|
61
|
+
exit
|
62
|
+
end
|
63
|
+
return if file1_path==file2_path
|
64
|
+
if File.exist?(file2_path) then
|
65
|
+
print ("moving target #{files[1]} exists.\n")
|
66
|
+
print ("first remove #{files[1]}.\n")
|
67
|
+
return
|
68
|
+
else
|
69
|
+
File.rename(file1_path,file2_path)
|
70
|
+
end
|
71
|
+
|
72
|
+
info=InfoDB.new(@l_dir)
|
73
|
+
|
74
|
+
db = info.db
|
75
|
+
|
76
|
+
# pp file0=db[files[0]]
|
77
|
+
# db.delete(files[0])
|
78
|
+
# db[files[1]]=file0
|
79
|
+
# db[files[1]][:title]=files[1] if db[files[1]][:title]==files[0]
|
80
|
+
# pp db[files[1]]
|
81
|
+
|
82
|
+
db.each{|ele|
|
83
|
+
ref = ele[1][:references]
|
84
|
+
if ref.include?(files[0]) then
|
85
|
+
p link_file=ele[0]
|
86
|
+
link_path = File.join(@l_dir,'text',link_file)
|
87
|
+
|
88
|
+
target=File.open(link_path,'r')
|
89
|
+
cont = target.read
|
90
|
+
target.close
|
91
|
+
if NKF.guess(cont)==NKF::EUC then
|
92
|
+
print "Don\'t support EUC-JP, change link manually.\n"
|
93
|
+
else
|
94
|
+
|
95
|
+
cont.gsub!(/\[\[#{files[0]}\]\]/,"\[\[#{files[1]}\]\]")
|
96
|
+
target=File.open(link_path,'w')
|
97
|
+
target.print cont
|
98
|
+
target.close
|
99
|
+
|
100
|
+
ref.delete(files[0])
|
101
|
+
ref << files[1]
|
102
|
+
|
103
|
+
p cache_path = File.join(@l_dir,'cache/parser',link_file)
|
104
|
+
begin
|
105
|
+
File.delete(cache_path)
|
106
|
+
rescue => evar
|
107
|
+
puts evar.to_s
|
108
|
+
end
|
109
|
+
end
|
110
|
+
end
|
111
|
+
}
|
112
|
+
|
113
|
+
info.dump
|
114
|
+
end
|
115
|
+
|
116
|
+
def remove_file(file_name)
|
117
|
+
p text_path = File.join(@l_dir,'text',file_name)
|
118
|
+
p attach_path = File.join(@l_dir,'cache/attach',file_name)
|
119
|
+
begin
|
120
|
+
File.delete(text_path)
|
121
|
+
rescue => evar
|
122
|
+
puts evar.to_s
|
123
|
+
end
|
124
|
+
begin
|
125
|
+
Dir.rmdir(attach_path)
|
126
|
+
rescue => evar
|
127
|
+
puts evar.to_s
|
128
|
+
end
|
129
|
+
|
130
|
+
info=InfoDB.new(@l_dir)
|
131
|
+
p "delete "
|
132
|
+
del_file=info.delete(file_name)
|
133
|
+
|
134
|
+
info.dump
|
135
|
+
end
|
136
|
+
|
137
|
+
def check_db
|
138
|
+
result= InfoDB.new(@l_dir).show_inconsist
|
139
|
+
print (result=='') ? "db agrees with text dir.\n" : result
|
140
|
+
end
|
141
|
+
|
142
|
+
def db_file(file_name)
|
143
|
+
info=InfoDB.new(@l_dir)
|
144
|
+
p info.show(file_name)
|
145
|
+
end
|
146
|
+
|
147
|
+
def rsync_files
|
148
|
+
p local = @l_dir
|
149
|
+
p global = @src[:srcs][@target][:global_dir]
|
150
|
+
p command="rsync -auvz --delete -e ssh #{local}/ #{global}"
|
151
|
+
system command
|
152
|
+
end
|
153
|
+
|
154
|
+
def update_file(file0)
|
155
|
+
file = (file0==nil) ? 'FrontPage' : file0
|
156
|
+
#rm cache file
|
157
|
+
t_file=File.join(@l_dir,'cache/parser',file)
|
158
|
+
p command="rm #{t_file}"
|
159
|
+
system command
|
160
|
+
|
161
|
+
#update info file
|
162
|
+
info=InfoDB.new(@l_dir)
|
163
|
+
info.update(file0)
|
164
|
+
|
165
|
+
#open file on browser
|
166
|
+
l_path = @src[:srcs][@target][:local_uri]
|
167
|
+
l_file=l_path+"/?"+file
|
168
|
+
p command="open \'#{l_file}\'"
|
169
|
+
system command
|
170
|
+
end
|
171
|
+
|
172
|
+
def list_files(file)
|
173
|
+
file ='' if file==nil
|
174
|
+
t_file=File.join(@l_dir,'text')
|
175
|
+
print "target_dir : "+t_file+"\n"
|
176
|
+
print `cd #{t_file} ; ls -lt #{file}*`
|
177
|
+
end
|
178
|
+
|
179
|
+
def edit_file(file)
|
180
|
+
t_file=File.join(@l_dir,'text',file)
|
181
|
+
if !File.exist?(t_file) then
|
182
|
+
file=File.open(t_file,'w')
|
183
|
+
file.close
|
184
|
+
File.chmod(0777,t_file)
|
185
|
+
end
|
186
|
+
p command="open -a mi #{t_file}"
|
187
|
+
system command
|
188
|
+
end
|
189
|
+
|
190
|
+
def dump_sources
|
191
|
+
file = File.open(DATA_FILE,'w')
|
192
|
+
YAML.dump(@src, file)
|
193
|
+
file.close
|
194
|
+
end
|
195
|
+
|
196
|
+
def set_target(val)
|
197
|
+
@src[:target] = val.to_i
|
198
|
+
show_sources
|
199
|
+
end
|
200
|
+
|
201
|
+
def show_sources()
|
202
|
+
printf("target_no:%i\n",@src[:target])
|
203
|
+
printf("editor_command:%s\n",@src[:editor_command])
|
204
|
+
header = display_format('id','nick name','local directory','global uri')
|
205
|
+
|
206
|
+
puts header
|
207
|
+
puts '-' * header.size
|
208
|
+
|
209
|
+
@src[:srcs].each_with_index{|src,i|
|
210
|
+
target = i==@src[:target] ? '*':' '
|
211
|
+
id = target+i.to_s
|
212
|
+
name=src[:nick_name]
|
213
|
+
local=src[:local_dir]
|
214
|
+
global=src[:global_uri]
|
215
|
+
puts display_format(id,name,local,global)
|
216
|
+
}
|
217
|
+
|
218
|
+
end
|
219
|
+
|
220
|
+
def display_format(id, name, local, global)
|
221
|
+
name_length = 10-full_width_count(name)
|
222
|
+
local_length = 40-full_width_count(local)
|
223
|
+
[id.to_s.rjust(3), name.ljust(name_length),local.ljust(local_length), global.center(10)].join(' | ')
|
224
|
+
end
|
225
|
+
|
226
|
+
def full_width_count(string)
|
227
|
+
string.each_char.select{|char| !(/[ -~��-��]/.match(char))}.count
|
228
|
+
end
|
229
|
+
|
230
|
+
def add_sources
|
231
|
+
cont = {}
|
232
|
+
@data_name.each{|name|
|
233
|
+
printf("%s ? ", name)
|
234
|
+
tmp = gets.chomp
|
235
|
+
cont[name.to_sym] = tmp
|
236
|
+
}
|
237
|
+
@src[:srcs] << cont
|
238
|
+
show_sources
|
239
|
+
end
|
240
|
+
|
241
|
+
def read_sources
|
242
|
+
file = File.open(DATA_FILE,'r')
|
243
|
+
@src = YAML.load(file.read)
|
244
|
+
file.close
|
245
|
+
@target = @src[:target]
|
246
|
+
@l_dir=@src[:srcs][@target][:local_dir]
|
247
|
+
end
|
248
|
+
end
|
249
|
+
end
|
250
|
+
|
251
|
+
module DataFiles
|
252
|
+
def self.prepare(data_path)
|
253
|
+
create_file_if_not_exists(data_path)
|
254
|
+
end
|
255
|
+
|
256
|
+
def self.create_file_if_not_exists(data_path)
|
257
|
+
return if File::exists?(data_path)
|
258
|
+
create_data_file(data_path)
|
259
|
+
end
|
260
|
+
|
261
|
+
def self.create_data_file(data_path)
|
262
|
+
print "make #{data_path}\n"
|
263
|
+
init_data_file(data_path)
|
264
|
+
end
|
265
|
+
|
266
|
+
# initialize source file by dummy data
|
267
|
+
def self.init_data_file(data_path)
|
268
|
+
@src = {:target => 0, :editor_command => 'open -a mi',
|
269
|
+
:srcs=>[{:nick_name => 'hoge', :local_dir => 'hogehoge', :local_uri => 'http://localhost/~hoge',
|
270
|
+
:global_dir => 'hoge@global_host:/hoge', :global_uri => 'http://hoge'}]}
|
271
|
+
file = File.open(data_path,'w')
|
272
|
+
YAML.dump(@src,file)
|
273
|
+
file.close
|
274
|
+
end
|
275
|
+
private_class_method :create_file_if_not_exists, :create_data_file, :init_data_file
|
276
|
+
end
|
277
|
+
|
278
|
+
|
data/lib/.#hikiutils.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
bob@bob.local.8100
|
@@ -1,13 +1,43 @@
|
|
1
|
-
|
1
|
+
require 'nkf'
|
2
|
+
|
3
|
+
class InfoDB
|
2
4
|
attr_accessor :file_path, :db, :text_dir
|
3
5
|
def initialize(file_path)
|
6
|
+
@file_path=File.join(file_path,"info.db")
|
4
7
|
@db = Hash.new
|
5
|
-
file = File.read(
|
8
|
+
file = File.read(@file_path)
|
9
|
+
if NKF.guess(file)==NKF::EUC then
|
10
|
+
print "Don\'t support EUC-JP for info.db.\n"
|
11
|
+
exit
|
12
|
+
end
|
6
13
|
@db = TMarshal::load(file)
|
7
|
-
|
14
|
+
end
|
15
|
+
|
16
|
+
def show(name)
|
17
|
+
@db[name]
|
18
|
+
end
|
19
|
+
|
20
|
+
def delete(name)
|
21
|
+
p @db.delete(name)
|
22
|
+
end
|
23
|
+
|
24
|
+
def update(name)
|
25
|
+
if @db[name]==nil then
|
26
|
+
puts "no info"
|
27
|
+
exit
|
28
|
+
end
|
29
|
+
p @db[name][:last_modified] = Time.now
|
30
|
+
self.dump
|
31
|
+
end
|
32
|
+
|
33
|
+
def dump
|
34
|
+
dump_file = File.open(@file_path,'w')
|
35
|
+
TMarshal::dump(@db,dump_file)
|
36
|
+
dump_file.close
|
8
37
|
end
|
9
38
|
|
10
39
|
def show_inconsist
|
40
|
+
@text_dir = Dir::entries(File.join(file_path,"text"))[3..-1]
|
11
41
|
cont = ""
|
12
42
|
@text_dir.each { |ent|
|
13
43
|
if @db[ent]==nil then
|
data/lib/hikiutils/version.rb
CHANGED
data/lib/hikiutils.rb
CHANGED
@@ -1,7 +1,8 @@
|
|
1
1
|
# -*- coding: utf-8 -*-
|
2
|
+
require 'nkf'
|
2
3
|
require "hikiutils/version"
|
3
4
|
require "hikiutils/tmarshal"
|
4
|
-
require "hikiutils/
|
5
|
+
require "hikiutils/infodb"
|
5
6
|
require 'systemu'
|
6
7
|
require 'optparse'
|
7
8
|
require 'fileutils'
|
@@ -49,9 +50,16 @@ module HikiUtils
|
|
49
50
|
dump_sources
|
50
51
|
exit
|
51
52
|
end
|
53
|
+
|
52
54
|
def move_file(files)
|
53
|
-
|
54
|
-
|
55
|
+
begin
|
56
|
+
p file1_path = File.join(@l_dir,'text',files[0])
|
57
|
+
p file2_path = File.join(@l_dir,'text',files[1])
|
58
|
+
rescue => evar
|
59
|
+
puts evar.to_s
|
60
|
+
puts "error on move_files, check the input format, especially comma separation."
|
61
|
+
exit
|
62
|
+
end
|
55
63
|
return if file1_path==file2_path
|
56
64
|
if File.exist?(file2_path) then
|
57
65
|
print ("moving target #{files[1]} exists.\n")
|
@@ -61,18 +69,15 @@ module HikiUtils
|
|
61
69
|
File.rename(file1_path,file2_path)
|
62
70
|
end
|
63
71
|
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
cont = file.read
|
68
|
-
db = TMarshal::load(cont)
|
69
|
-
file.close
|
72
|
+
info=InfoDB.new(@l_dir)
|
73
|
+
|
74
|
+
db = info.db
|
70
75
|
|
71
|
-
pp file0=db[files[0]]
|
72
|
-
db.delete(files[0])
|
73
|
-
db[files[1]]=file0
|
74
|
-
db[files[1]][:title]=files[1] if db[files[1]][:title]==files[0]
|
75
|
-
pp db[files[1]]
|
76
|
+
# pp file0=db[files[0]]
|
77
|
+
# db.delete(files[0])
|
78
|
+
# db[files[1]]=file0
|
79
|
+
# db[files[1]][:title]=files[1] if db[files[1]][:title]==files[0]
|
80
|
+
# pp db[files[1]]
|
76
81
|
|
77
82
|
db.each{|ele|
|
78
83
|
ref = ele[1][:references]
|
@@ -83,27 +88,29 @@ module HikiUtils
|
|
83
88
|
target=File.open(link_path,'r')
|
84
89
|
cont = target.read
|
85
90
|
target.close
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
91
|
+
if NKF.guess(cont)==NKF::EUC then
|
92
|
+
print "Don\'t support EUC-JP, change link manually.\n"
|
93
|
+
else
|
94
|
+
|
95
|
+
cont.gsub!(/\[\[#{files[0]}\]\]/,"\[\[#{files[1]}\]\]")
|
96
|
+
target=File.open(link_path,'w')
|
97
|
+
target.print cont
|
98
|
+
target.close
|
99
|
+
|
100
|
+
ref.delete(files[0])
|
101
|
+
ref << files[1]
|
102
|
+
|
103
|
+
p cache_path = File.join(@l_dir,'cache/parser',link_file)
|
104
|
+
begin
|
105
|
+
File.delete(cache_path)
|
106
|
+
rescue => evar
|
107
|
+
puts evar.to_s
|
108
|
+
end
|
99
109
|
end
|
100
|
-
|
101
110
|
end
|
102
111
|
}
|
103
112
|
|
104
|
-
|
105
|
-
TMarshal::dump(db,file)
|
106
|
-
file.close
|
113
|
+
info.dump
|
107
114
|
end
|
108
115
|
|
109
116
|
def remove_file(file_name)
|
@@ -120,32 +127,21 @@ module HikiUtils
|
|
120
127
|
puts evar.to_s
|
121
128
|
end
|
122
129
|
|
123
|
-
|
124
|
-
p
|
125
|
-
|
126
|
-
cont = file.read
|
127
|
-
db = TMarshal::load(cont)
|
128
|
-
file.close
|
129
|
-
|
130
|
-
db.delete(file_name)
|
131
|
-
|
132
|
-
file = File.open(db_path,'w')
|
133
|
-
TMarshal::dump(db,file)
|
134
|
-
file.close
|
130
|
+
info=InfoDB.new(@l_dir)
|
131
|
+
p "delete "
|
132
|
+
del_file=info.delete(file_name)
|
135
133
|
|
134
|
+
info.dump
|
136
135
|
end
|
137
136
|
|
138
137
|
def check_db
|
139
|
-
result=
|
138
|
+
result= InfoDB.new(@l_dir).show_inconsist
|
140
139
|
print (result=='') ? "db agrees with text dir.\n" : result
|
141
140
|
end
|
142
141
|
|
143
142
|
def db_file(file_name)
|
144
|
-
|
145
|
-
p
|
146
|
-
cont = File.read(file_path)
|
147
|
-
db = TMarshal::load(cont)
|
148
|
-
p db[file_name]
|
143
|
+
info=InfoDB.new(@l_dir)
|
144
|
+
p info.show(file_name)
|
149
145
|
end
|
150
146
|
|
151
147
|
def rsync_files
|
@@ -157,9 +153,16 @@ module HikiUtils
|
|
157
153
|
|
158
154
|
def update_file(file0)
|
159
155
|
file = (file0==nil) ? 'FrontPage' : file0
|
156
|
+
#rm cache file
|
160
157
|
t_file=File.join(@l_dir,'cache/parser',file)
|
161
158
|
p command="rm #{t_file}"
|
162
159
|
system command
|
160
|
+
|
161
|
+
#update info file
|
162
|
+
info=InfoDB.new(@l_dir)
|
163
|
+
info.update(file0)
|
164
|
+
|
165
|
+
#open file on browser
|
163
166
|
l_path = @src[:srcs][@target][:local_uri]
|
164
167
|
l_file=l_path+"/?"+file
|
165
168
|
p command="open \'#{l_file}\'"
|
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.1.
|
4
|
+
version: 0.1.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: 2016-04-
|
11
|
+
date: 2016-04-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -140,13 +140,14 @@ files:
|
|
140
140
|
- Rakefile
|
141
141
|
- bin/console
|
142
142
|
- bin/setup
|
143
|
-
- docs/README.
|
143
|
+
- docs/README.hiki
|
144
144
|
- docs/README.ja.hiki
|
145
|
-
- docs/README.ja.md
|
146
145
|
- exe/hiki
|
147
146
|
- hikiutils.gemspec
|
147
|
+
- lib/#hikiutils.rb#
|
148
|
+
- lib/.#hikiutils.rb
|
148
149
|
- lib/hikiutils.rb
|
149
|
-
- lib/hikiutils/
|
150
|
+
- lib/hikiutils/infodb.rb
|
150
151
|
- lib/hikiutils/tmarshal.rb
|
151
152
|
- lib/hikiutils/version.rb
|
152
153
|
homepage: http://github.org/daddygongon/hikiutils.
|
@@ -161,7 +162,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
161
162
|
requirements:
|
162
163
|
- - ">="
|
163
164
|
- !ruby/object:Gem::Version
|
164
|
-
version:
|
165
|
+
version: 2.0.0
|
165
166
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
166
167
|
requirements:
|
167
168
|
- - ">="
|
data/docs/README.en.md
DELETED
File without changes
|