hikiutils 0.1.0

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 9492b7b31d9c2a5a7338eca035a0a7dd65b9af35
4
+ data.tar.gz: 00f1ddcb7217a5740ae632d223e2193fd80201ec
5
+ SHA512:
6
+ metadata.gz: d3a3f51153fbdaa283749051b9f06055902a9199ae1ab7375acda471f7f365fd71a194d1c54242998dce8d3b5ecc5a5e380196459a3f8c31564649d56f75f8a3
7
+ data.tar.gz: 0dbec68d969a50edba9f0bb4ca183f0466f3eb1404a78a6e84dd3384cc848bdd409459d50be4386db9962aa953bef0d24d51821878470cce59554bf6f075f40d
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.travis.yml ADDED
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.2.2
4
+ before_install: gem install bundler -v 1.11.2
data/.yardopts ADDED
@@ -0,0 +1,2 @@
1
+ -
2
+ docs/README.ja.md
@@ -0,0 +1,49 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, and in the interest of
4
+ fostering an open and welcoming community, we pledge to respect all people who
5
+ contribute through reporting issues, posting feature requests, updating
6
+ documentation, submitting pull requests or patches, and other activities.
7
+
8
+ We are committed to making participation in this project a harassment-free
9
+ experience for everyone, regardless of level of experience, gender, gender
10
+ identity and expression, sexual orientation, disability, personal appearance,
11
+ body size, race, ethnicity, age, religion, or nationality.
12
+
13
+ Examples of unacceptable behavior by participants include:
14
+
15
+ * The use of sexualized language or imagery
16
+ * Personal attacks
17
+ * Trolling or insulting/derogatory comments
18
+ * Public or private harassment
19
+ * Publishing other's private information, such as physical or electronic
20
+ addresses, without explicit permission
21
+ * Other unethical or unprofessional conduct
22
+
23
+ Project maintainers have the right and responsibility to remove, edit, or
24
+ reject comments, commits, code, wiki edits, issues, and other contributions
25
+ that are not aligned to this Code of Conduct, or to ban temporarily or
26
+ permanently any contributor for other behaviors that they deem inappropriate,
27
+ threatening, offensive, or harmful.
28
+
29
+ By adopting this Code of Conduct, project maintainers commit themselves to
30
+ fairly and consistently applying these principles to every aspect of managing
31
+ this project. Project maintainers who do not follow or enforce the Code of
32
+ Conduct may be permanently removed from the project team.
33
+
34
+ This code of conduct applies both within project spaces and in public spaces
35
+ when an individual is representing the project or its community.
36
+
37
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
38
+ reported by contacting a project maintainer at shigeto_nishitani@me.com. All
39
+ complaints will be reviewed and investigated and will result in a response that
40
+ is deemed necessary and appropriate to the circumstances. Maintainers are
41
+ obligated to maintain confidentiality with regard to the reporter of an
42
+ incident.
43
+
44
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage],
45
+ version 1.3.0, available at
46
+ [http://contributor-covenant.org/version/1/3/0/][version]
47
+
48
+ [homepage]: http://contributor-covenant.org
49
+ [version]: http://contributor-covenant.org/version/1/3/0/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in hikiutils.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Shigeto R. Nishitani
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,41 @@
1
+ # Hikiutils
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/hikiutils`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'hikiutils'
13
+ ```
14
+
15
+ And then execute:
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
26
+
27
+ ## Development
28
+
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
+ 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
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/hikiutils. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
36
+
37
+
38
+ ## License
39
+
40
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
41
+
data/Rakefile ADDED
@@ -0,0 +1,24 @@
1
+ require "bundler/gem_tasks"
2
+ require 'yard'
3
+ require "rake/testtask"
4
+
5
+ #task :default => :test
6
+ task :default do
7
+ system 'rake -T'
8
+ end
9
+
10
+
11
+ desc "make documents by yard"
12
+ task :yard do
13
+ system "hiki2md docs/readme.hiki > docs/README.en.md"
14
+ system "hiki2md docs/readme.ja.hiki > docs/README.ja.md"
15
+ YARD::Rake::YardocTask.new
16
+ end
17
+
18
+ Rake::TestTask.new(:test) do |t|
19
+ t.libs << "test"
20
+ t.libs << "lib"
21
+ t.test_files = FileList['test/**/*_test.rb']
22
+ end
23
+
24
+ #task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "hikiutils"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
data/docs/README.en.md ADDED
File without changes
@@ -0,0 +1,60 @@
1
+ !hikimode
2
+ hikiの編集を助けるhelper.
3
+
4
+ !!【特徴】
5
+ hiki-mode.elがうまく動かせなかったので,cliで自作してみた.
6
+
7
+
8
+ !!【操作法】
9
+ コマンド名が違うので注意.
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
+ >>>
24
+
25
+ !! Installation
26
+
27
+ <<<
28
+ $ gem install hikimode
29
+ >>>
30
+ でinstallされます.最初に起動した時に
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
+ というファイルがhome dirに作成されます.hikimodeはこのように,localでの編集・閲覧と,globalへの同期を前提に動作します.sourcesを追加するには-aで追加できますが,適当にいれてファイルを直接編集する方が
44
+ 間違いが少ないです.
45
+
46
+ Enjoy hiki world!!
47
+
48
+ !! Development
49
+
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
+
52
+ !! Contributing
53
+
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
+
56
+
57
+ !! License
58
+
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.md ADDED
@@ -0,0 +1,59 @@
1
+ # hikimode
2
+ hikiの編集を助けるhelper.
3
+
4
+ ## 【特徴】
5
+ hiki-mode.elがうまく動かせなかったので,cliで自作してみた.
6
+
7
+
8
+ ## 【操作法】
9
+ コマンド名が違うので注意.
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
+ ```
24
+
25
+ ## Installation
26
+
27
+ ```
28
+ $ gem install hikimode
29
+ ```
30
+ でinstallされます.最初に起動した時に
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
+ というファイルがhome dirに作成されます.hikimodeはこのように,localでの編集・閲覧と,globalへの同期を前提に動作します.sourcesを追加するには-aで追加できますが,適当にいれてファイルを直接編集する方が
44
+ 間違いが少ないです.
45
+
46
+ Enjoy hiki world!!
47
+
48
+ ## Development
49
+
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
+
52
+ ## Contributing
53
+
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
+
56
+
57
+ ## License
58
+
59
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
data/exe/hiki ADDED
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "hikiutils"
4
+
5
+ HikiUtils::Command.run(ARGV)
data/hikiutils.gemspec ADDED
@@ -0,0 +1,39 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'hikiutils/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "hikiutils"
8
+ spec.version = HikiUtils::VERSION
9
+ spec.authors = ["Shigeto R. Nishitani"]
10
+ spec.email = ["shigeto_nishitani@me.com"]
11
+
12
+ spec.summary = %q{helper of hiki editing.}
13
+ spec.description = %q{.}
14
+ spec.homepage = "http://github.org/daddygongon/hikiutils."
15
+ spec.license = "MIT"
16
+
17
+ # Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or
18
+ # delete this section to allow pushing this gem to any host.
19
+ # if spec.respond_to?(:metadata)
20
+ # spec.metadata['allowed_push_host'] = 'http://rubygems.org'
21
+ # else
22
+ # raise "use 'gem inabox -o pkg/hogehoge.gem' for releasing on the non-public server."
23
+ # end
24
+
25
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
26
+ spec.bindir = "exe"
27
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
28
+ spec.require_paths = ["lib"]
29
+
30
+ spec.add_development_dependency "bundler", "~> 1.11"
31
+ spec.add_development_dependency "rake", "~> 10.0"
32
+ spec.add_development_dependency "minitest", "~> 5.0"
33
+ spec.add_development_dependency "rspec"
34
+ spec.add_development_dependency "yard", "~> 0.8"
35
+ spec.add_development_dependency "hiki2md"
36
+ spec.add_runtime_dependency "systemu"
37
+ spec.add_runtime_dependency "hikidoc","~>0.1.0"
38
+
39
+ end
@@ -0,0 +1,28 @@
1
+ class CleanDB
2
+ attr_accessor :file_path, :db, :text_dir
3
+ def initialize(file_path)
4
+ @db = Hash.new
5
+ file = File.read(File.join(file_path,"info.db"))
6
+ @db = TMarshal::load(file)
7
+ @text_dir = Dir::entries(File.join(file_path,"text"))[3..-1]
8
+ end
9
+
10
+ def show_inconsist
11
+ cont = ""
12
+ @text_dir.each { |ent|
13
+ if @db[ent]==nil then
14
+ cont << "in text_dir but not in db:#{ent}\n"
15
+ next
16
+ end
17
+ # newdb.store(ent,db[ent])
18
+ }
19
+
20
+ @db.each { |ent|
21
+ name = ent[0]
22
+ if !(@text_dir.member? (name)) then
23
+ cont << "in db but not in text_dir:#{name}\n"
24
+ end
25
+ }
26
+ return cont
27
+ end
28
+ end
@@ -0,0 +1,51 @@
1
+ # Original Copyright (C) Rubikichi
2
+ # Modified by TAKEUCHI Hitoshi
3
+ # You can redistribute it and/or modify it under the terms of
4
+ # the Ruby's licence.
5
+
6
+ module TMarshal
7
+ module_function
8
+ def dump(obj, port = nil)
9
+ dumped = dump_text(obj)
10
+ if port
11
+ port.write dumped
12
+ end
13
+ dumped
14
+ end
15
+
16
+ def load(port)
17
+ case port
18
+ when String
19
+ eval port.untaint
20
+ when IO, StringIO
21
+ eval port.read.untaint
22
+ else
23
+ raise 'Wrong type!'
24
+ end
25
+ end
26
+
27
+ def restore(port)
28
+ load(port)
29
+ end
30
+
31
+ def dump_text(obj)
32
+ case obj
33
+ when String
34
+ obj.dump
35
+ when Array
36
+ "[\n"+obj.collect{|x| dump_text(x)+",\n"}.join+"]"
37
+ when Hash
38
+ "{\n"+obj.sort_by{|e| e[0].inspect}.collect{|k,v| "#{dump_text(k)} => #{dump_text(v)},\n"}.join+"}"
39
+ when Numeric, Module, Regexp, Symbol, TrueClass, FalseClass, NilClass, Range
40
+ obj.inspect
41
+ when Time
42
+ "Time.at(#{obj.to_i})"
43
+ else
44
+ raise 'Wrong type!'
45
+ end
46
+ end
47
+ end
48
+
49
+ if __FILE__ == $0
50
+ puts TMarshal.dump({:age => 22, :lang => 'Ruby', :man => true, :day => Time.now})
51
+ end
@@ -0,0 +1,3 @@
1
+ module HikiUtils
2
+ VERSION = "0.1.0"
3
+ end
data/lib/hikiutils.rb ADDED
@@ -0,0 +1,275 @@
1
+ # -*- coding: utf-8 -*-
2
+ require "hikiutils/version"
3
+ require "hikiutils/tmarshal"
4
+ require "hikiutils/cleandb"
5
+ require 'systemu'
6
+ require 'optparse'
7
+ require 'fileutils'
8
+ require 'yaml'
9
+ require 'pp'
10
+
11
+ module HikiUtils
12
+ DATA_FILE=File.join(ENV['HOME'],'.hikirc')
13
+ attr_accessor :src, :target, :data_name, :l_dir
14
+
15
+ class Command
16
+ def self.run(argv=[])
17
+ print "hiki says 'Hello world'.\n"
18
+ new(argv).execute
19
+ end
20
+
21
+ def initialize(argv=[])
22
+ @argv = argv
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
+ read_sources
27
+ end
28
+
29
+ def execute
30
+ @argv << '--help' if @argv.size==0
31
+ command_parser = OptionParser.new do |opt|
32
+ opt.on('-v', '--version','show program Version.') { |v|
33
+ opt.version = HikiUtils::VERSION
34
+ puts opt.ver
35
+ }
36
+ opt.on('-s', '--show','show sources') {show_sources}
37
+ opt.on('-a', '--add','add sources info') {add_sources }
38
+ opt.on('-t', '--target VAL','set target id') {|val| set_target(val) }
39
+ opt.on('-e', '--edit FILE','open file') {|file| edit_file(file) }
40
+ opt.on('-l', '--list [FILE]','list files') {|file| list_files(file) }
41
+ opt.on('-u', '--update FILE','update file') {|file| update_file(file) }
42
+ opt.on('-r', '--rsync','rsync files') {rsync_files}
43
+ opt.on('-d', '--database FILE','read database file') {|file| db_file(file)}
44
+ opt.on('-c', '--checkdb','check database file') {check_db}
45
+ opt.on('--remove FILE','remove file') {|file| remove_file(file)}
46
+ opt.on('--move FILES','move file1,file2',Array) {|files| move_file(files)}
47
+ end
48
+ command_parser.parse!(@argv)
49
+ dump_sources
50
+ exit
51
+ end
52
+ def move_file(files)
53
+ p file1_path = File.join(@l_dir,'text',files[0])
54
+ p file2_path = File.join(@l_dir,'text',files[1])
55
+ return if file1_path==file2_path
56
+ if File.exist?(file2_path) then
57
+ print ("moving target #{files[1]} exists.\n")
58
+ print ("first remove #{files[1]}.\n")
59
+ return
60
+ else
61
+ File.rename(file1_path,file2_path)
62
+ end
63
+
64
+ db = Hash.new
65
+ p db_path = File.join(@l_dir,'info.db')
66
+ file = File.open(db_path,'r')
67
+ cont = file.read
68
+ db = TMarshal::load(cont)
69
+ file.close
70
+
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
+
77
+ db.each{|ele|
78
+ ref = ele[1][:references]
79
+ if ref.include?(files[0]) then
80
+ p link_file=ele[0]
81
+ link_path = File.join(@l_dir,'text',link_file)
82
+
83
+ target=File.open(link_path,'r')
84
+ cont = target.read
85
+ target.close
86
+ cont.gsub!(/\[\[#{files[0]}\]\]/,"\[\[#{files[1]}\]\]")
87
+ target=File.open(link_path,'w')
88
+ target.print cont
89
+ target.close
90
+
91
+ ref.delete(files[0])
92
+ ref << files[1]
93
+
94
+ p cache_path = File.join(@l_dir,'cache/parser',link_file)
95
+ begin
96
+ File.delete(cache_path)
97
+ rescue => evar
98
+ puts evar.to_s
99
+ end
100
+
101
+ end
102
+ }
103
+
104
+ file = File.open(db_path,'w')
105
+ TMarshal::dump(db,file)
106
+ file.close
107
+ end
108
+
109
+ def remove_file(file_name)
110
+ p text_path = File.join(@l_dir,'text',file_name)
111
+ p attach_path = File.join(@l_dir,'cache/attach',file_name)
112
+ begin
113
+ File.delete(text_path)
114
+ rescue => evar
115
+ puts evar.to_s
116
+ end
117
+ begin
118
+ Dir.rmdir(attach_path)
119
+ rescue => evar
120
+ puts evar.to_s
121
+ end
122
+
123
+ db = Hash.new
124
+ p db_path = File.join(@l_dir,'info.db')
125
+ file = File.open(db_path,'r')
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
135
+
136
+ end
137
+
138
+ def check_db
139
+ result= CleanDB.new(@l_dir).show_inconsist
140
+ print (result=='') ? "db agrees with text dir.\n" : result
141
+ end
142
+
143
+ def db_file(file_name)
144
+ db = Hash.new
145
+ p file_path = File.join(@l_dir,'info.db')
146
+ cont = File.read(file_path)
147
+ db = TMarshal::load(cont)
148
+ p db[file_name]
149
+ end
150
+
151
+ def rsync_files
152
+ p local = @l_dir
153
+ p global = @src[:srcs][@target][:global_dir]
154
+ p command="rsync -auvz --delete -e ssh #{local}/ #{global}"
155
+ system command
156
+ end
157
+
158
+ def update_file(file0)
159
+ file = (file0==nil) ? 'FrontPage' : file0
160
+ t_file=File.join(@l_dir,'cache/parser',file)
161
+ p command="rm #{t_file}"
162
+ system command
163
+ l_path = @src[:srcs][@target][:local_uri]
164
+ l_file=l_path+"/?"+file
165
+ p command="open \'#{l_file}\'"
166
+ system command
167
+ end
168
+
169
+ def list_files(file)
170
+ file ='' if file==nil
171
+ t_file=File.join(@l_dir,'text')
172
+ print "target_dir : "+t_file+"\n"
173
+ print `cd #{t_file} ; ls -lt #{file}*`
174
+ end
175
+
176
+ def edit_file(file)
177
+ t_file=File.join(@l_dir,'text',file)
178
+ if !File.exist?(t_file) then
179
+ file=File.open(t_file,'w')
180
+ file.close
181
+ File.chmod(0777,t_file)
182
+ end
183
+ p command="open -a mi #{t_file}"
184
+ system command
185
+ end
186
+
187
+ def dump_sources
188
+ file = File.open(DATA_FILE,'w')
189
+ YAML.dump(@src, file)
190
+ file.close
191
+ end
192
+
193
+ def set_target(val)
194
+ @src[:target] = val.to_i
195
+ show_sources
196
+ end
197
+
198
+ def show_sources()
199
+ printf("target_no:%i\n",@src[:target])
200
+ printf("editor_command:%s\n",@src[:editor_command])
201
+ header = display_format('id','nick name','local directory','global uri')
202
+
203
+ puts header
204
+ puts '-' * header.size
205
+
206
+ @src[:srcs].each_with_index{|src,i|
207
+ target = i==@src[:target] ? '*':' '
208
+ id = target+i.to_s
209
+ name=src[:nick_name]
210
+ local=src[:local_dir]
211
+ global=src[:global_uri]
212
+ puts display_format(id,name,local,global)
213
+ }
214
+
215
+ end
216
+
217
+ def display_format(id, name, local, global)
218
+ name_length = 10-full_width_count(name)
219
+ local_length = 40-full_width_count(local)
220
+ [id.to_s.rjust(3), name.ljust(name_length),local.ljust(local_length), global.center(10)].join(' | ')
221
+ end
222
+
223
+ def full_width_count(string)
224
+ string.each_char.select{|char| !(/[ -~。-゚]/.match(char))}.count
225
+ end
226
+
227
+ def add_sources
228
+ cont = {}
229
+ @data_name.each{|name|
230
+ printf("%s ? ", name)
231
+ tmp = gets.chomp
232
+ cont[name.to_sym] = tmp
233
+ }
234
+ @src[:srcs] << cont
235
+ show_sources
236
+ end
237
+
238
+ def read_sources
239
+ file = File.open(DATA_FILE,'r')
240
+ @src = YAML.load(file.read)
241
+ file.close
242
+ @target = @src[:target]
243
+ @l_dir=@src[:srcs][@target][:local_dir]
244
+ end
245
+ end
246
+ end
247
+
248
+ module DataFiles
249
+ def self.prepare(data_path)
250
+ create_file_if_not_exists(data_path)
251
+ end
252
+
253
+ def self.create_file_if_not_exists(data_path)
254
+ return if File::exists?(data_path)
255
+ create_data_file(data_path)
256
+ end
257
+
258
+ def self.create_data_file(data_path)
259
+ print "make #{data_path}\n"
260
+ init_data_file(data_path)
261
+ end
262
+
263
+ # initialize source file by dummy data
264
+ def self.init_data_file(data_path)
265
+ @src = {:target => 0, :editor_command => 'open -a mi',
266
+ :srcs=>[{:nick_name => 'hoge', :local_dir => 'hogehoge', :local_uri => 'http://localhost/~hoge',
267
+ :global_dir => 'hoge@global_host:/hoge', :global_uri => 'http://hoge'}]}
268
+ file = File.open(data_path,'w')
269
+ YAML.dump(@src,file)
270
+ file.close
271
+ end
272
+ private_class_method :create_file_if_not_exists, :create_data_file, :init_data_file
273
+ end
274
+
275
+
metadata ADDED
@@ -0,0 +1,177 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: hikiutils
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Shigeto R. Nishitani
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-04-22 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.11'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.11'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: minitest
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '5.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '5.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: yard
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '0.8'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '0.8'
83
+ - !ruby/object:Gem::Dependency
84
+ name: hiki2md
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: systemu
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :runtime
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: hikidoc
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: 0.1.0
118
+ type: :runtime
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: 0.1.0
125
+ description: "."
126
+ email:
127
+ - shigeto_nishitani@me.com
128
+ executables:
129
+ - hiki
130
+ extensions: []
131
+ extra_rdoc_files: []
132
+ files:
133
+ - ".gitignore"
134
+ - ".travis.yml"
135
+ - ".yardopts"
136
+ - CODE_OF_CONDUCT.md
137
+ - Gemfile
138
+ - LICENSE.txt
139
+ - README.md
140
+ - Rakefile
141
+ - bin/console
142
+ - bin/setup
143
+ - docs/README.en.md
144
+ - docs/README.ja.hiki
145
+ - docs/README.ja.md
146
+ - exe/hiki
147
+ - hikiutils.gemspec
148
+ - lib/hikiutils.rb
149
+ - lib/hikiutils/cleandb.rb
150
+ - lib/hikiutils/tmarshal.rb
151
+ - lib/hikiutils/version.rb
152
+ homepage: http://github.org/daddygongon/hikiutils.
153
+ licenses:
154
+ - MIT
155
+ metadata: {}
156
+ post_install_message:
157
+ rdoc_options: []
158
+ require_paths:
159
+ - lib
160
+ required_ruby_version: !ruby/object:Gem::Requirement
161
+ requirements:
162
+ - - ">="
163
+ - !ruby/object:Gem::Version
164
+ version: '0'
165
+ required_rubygems_version: !ruby/object:Gem::Requirement
166
+ requirements:
167
+ - - ">="
168
+ - !ruby/object:Gem::Version
169
+ version: '0'
170
+ requirements: []
171
+ rubyforge_project:
172
+ rubygems_version: 2.5.1
173
+ signing_key:
174
+ specification_version: 4
175
+ summary: helper of hiki editing.
176
+ test_files: []
177
+ has_rdoc: