marseditsync 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: d48c5cd4cf70c0dddff5ca4e8d6adce2d90eb72b
4
+ data.tar.gz: f4579971635d2fd5ad324520d60bc62c248067bc
5
+ SHA512:
6
+ metadata.gz: a743de8d855c54bee86a975c2e8f63e63a38a489f833609ce38cbe4f73f474e8c3365209f5e3fc2a7366e634132002ba1798322fbb681fbea3b6c1e15bb4cf85
7
+ data.tar.gz: e366c39b48095a911d5344eca9e57348156148cdb09cfebe8b9d16b696c334f45d66547596c06eed7ae5f6f3ad8b13683d21d4488b38c8056ac6ea1e2b3f1b3e
data/.gitignore ADDED
@@ -0,0 +1,10 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ /vendor/
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.3.1
5
+ before_install: gem install bundler -v 1.12.5
@@ -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 src@srcw.net. 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 marseditsync.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 src
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
+ # Marseditsync
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/marseditsync`. 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 'marseditsync'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install marseditsync
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.
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]/marseditsync. 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,10 @@
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+
4
+ Rake::TestTask.new(:test) do |t|
5
+ t.libs << "test"
6
+ t.libs << "lib"
7
+ t.test_files = FileList['test/**/*_test.rb']
8
+ end
9
+
10
+ task :default => :test
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "marseditsync"
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
@@ -0,0 +1 @@
1
+ originalhost: maroon
@@ -0,0 +1,3 @@
1
+ common:
2
+ original_host: maroon
3
+
data/exe/marseditsync ADDED
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "marseditsync"
4
+
5
+ Marseditsync::Command.run(ARGV)
@@ -0,0 +1,221 @@
1
+ # coding: utf-8
2
+ require "marseditsync/version"
3
+ require 'fileutils'
4
+ require 'optparse'
5
+ require 'yaml'
6
+
7
+ module Marseditsync
8
+ DROPBOX_DIR = File.expand_path("~/Dropbox/app/MarsEdit")
9
+ MARSEDIT_DIR = File.expand_path("~/Library/Application Support/MarsEdit")
10
+ LINK_DIRS = ['LocalDrafts', 'PendingUploads']
11
+
12
+ PREFERENCES_DIR = File.expand_path("~/Library/Preferences")
13
+ MAIN_PLIST_FILE = File.expand_path(File.join(PREFERENCES_DIR, 'com.red-sweater.marsedit.macappstore.plist'))
14
+ # DataSources.plistも必要?
15
+ DATASOURCES_PLIST_FILE = File.expand_path(File.join(MARSEDIT_DIR, 'DataSources.plist'))
16
+ PLIST_FILES = [MAIN_PLIST_FILE, DATASOURCES_PLIST_FILE]
17
+
18
+ class Config
19
+ def initialize(yaml)
20
+ @yaml = yaml
21
+ @common_original_host = config_value('common', 'original_host', true)
22
+ end
23
+ attr_reader :common_original_host
24
+
25
+ def config_value(section, key, require)
26
+ value = @yaml[section][key]
27
+ if require && (value.nil? || value.empty?)
28
+ raise RuntimeError, "#{section}:#{key}: is empty"
29
+ end
30
+ value
31
+ end
32
+ end
33
+
34
+ class Command
35
+ def self.run(argv)
36
+ STDOUT.sync = true
37
+ opts = {}
38
+ opt = OptionParser.new(argv)
39
+ opt.banner = "Usage: #{opt.program_name} [options] <backup|restore>"
40
+ opt.separator "options:"
41
+ opt.on('-h', '--help', 'Show this message') do |v|
42
+ puts opt.help
43
+ exit
44
+ end
45
+ # 冗長メッセージ
46
+ opt.on('-v', '--verbose', 'Verbose message') {|v| opts[:v] = v}
47
+ opt.on('-n', '--dry-run', 'Message only') {|v| opts[:n] = v}
48
+ opt.on('-c', '--config', 'Config file') {|v| opts[:c] = v}
49
+ opt.order!(argv)
50
+
51
+ # 最後の引数を:jに入れて送る
52
+ cmd = ARGV.shift
53
+ opts[:j] = cmd
54
+ yamlfile = opts[:c] || '~/.marseditsyncrc'
55
+ config = Config.new(YAML.load_file(File.expand_path(yamlfile)))
56
+ command = Command.new(config, opts)
57
+ command.run
58
+ end
59
+
60
+ def self.create_dir(dir)
61
+ # コピー先ディレクトリの確認
62
+ if FileTest.directory?(dir)
63
+ puts "dir already exists. #{dir}"
64
+ else
65
+ FileUtils.mkdir(dir)
66
+ end
67
+ unless FileTest.directory?(dir)
68
+ puts "dir is not directory. #{dir}"
69
+ return false
70
+ end
71
+ true
72
+ end
73
+
74
+ def self.cp_new(srcfile, dstfile, check_mtime = false)
75
+ return unless FileTest.file?(srcfile)
76
+
77
+ srcfile_mtime = File.mtime(srcfile)
78
+ dstfile_mtime = nil
79
+ if FileTest.file?(dstfile)
80
+ dstfile_mtime = File.mtime(dstfile)
81
+ end
82
+
83
+ new_file = dstfile_mtime.nil? || srcfile_mtime > dstfile_mtime
84
+
85
+ puts "cp #{srcfile}(#{srcfile_mtime}) #{dstfile}(#{dstfile_mtime})"
86
+ if !check_mtime || new_file
87
+ FileUtils.cp(srcfile, dstfile, :preserve => true)
88
+ else
89
+ puts "=>skip by mtime"
90
+ end
91
+ end
92
+
93
+ def initialize(config, opts)
94
+ @config = config
95
+ @opts = opts
96
+ end
97
+
98
+ def run
99
+ puts "##### marseditsync start #####"
100
+ result = false
101
+ if @opts[:j] == 'backup'
102
+ result = backup
103
+ elsif @opts[:j] == 'restore'
104
+ result = restore
105
+ end
106
+ puts "##### marseditsync end(#{result}) #####"
107
+ end
108
+
109
+ private
110
+ def hostname
111
+ `hostname`.strip
112
+ end
113
+
114
+ def original_host?
115
+ hostname == @config.common_original_host
116
+ end
117
+
118
+ def backup
119
+ # バックアップできるのはオリジナルホストだけ
120
+ unless original_host?
121
+ puts "This mac cannot use for backup. #{hostname}"
122
+ return false
123
+ end
124
+ unless backup_links
125
+ return false
126
+ end
127
+ unless backup_plists
128
+ return false
129
+ end
130
+ true
131
+ end
132
+
133
+ def backup_links
134
+ puts "# backup_links"
135
+
136
+ return false unless self.class.create_dir(DROPBOX_DIR)
137
+
138
+ # コピー実行
139
+ LINK_DIRS.each do |link_dir|
140
+ srcdir = File.join(MARSEDIT_DIR, link_dir)
141
+ dstdir = File.join(DROPBOX_DIR, link_dir)
142
+ timestamp = Time.now.strftime("%Y%m%d_%H%M%S")
143
+ if FileTest.directory?(srcdir) && !FileTest.symlink?(srcdir)
144
+ puts "cp #{srcdir} #{DROPBOX_DIR}"
145
+ # ファイルコピー実行
146
+ unless FileTest.directory?(dstdir)
147
+ FileUtils.cp_r(srcdir, DROPBOX_DIR)
148
+ end
149
+ # オリジナルはバックアップとして残す(なぜか他の親フォルダにmvできない?)
150
+ backupdir = File.join(MARSEDIT_DIR, link_dir + '_' + timestamp)
151
+ puts "mv #{srcdir} #{backupdir}"
152
+ FileUtils.mv(srcdir, backupdir)
153
+ puts "ln #{dstdir} #{srcdir}"
154
+ FileUtils.symlink(dstdir, srcdir)
155
+ end
156
+ end
157
+
158
+ true
159
+ end
160
+
161
+ def backup_plists
162
+ puts "# backup_plists"
163
+ return false unless self.class.create_dir(DROPBOX_DIR)
164
+ PLIST_FILES.each do |srcfile|
165
+ basename = File.basename(srcfile)
166
+ dstfile = File.join(DROPBOX_DIR, basename)
167
+ self.class.cp_new(srcfile, dstfile)
168
+ end
169
+ true
170
+ end
171
+
172
+ def restore
173
+ if original_host?
174
+ puts "This mac cannot use for restore. #{hostname}"
175
+ return false
176
+ end
177
+
178
+ unless restore_links
179
+ return false
180
+ end
181
+ unless restore_plists
182
+ return false
183
+ end
184
+ true
185
+ end
186
+
187
+ def restore_links
188
+ puts "# restore_links"
189
+ unless FileTest.directory?(MARSEDIT_DIR)
190
+ print "dir is not directory. #{MARSEDIT_DIR}"
191
+ return false
192
+ end
193
+ LINK_DIRS.each do |link_dir|
194
+ srcdir = File.join(DROPBOX_DIR, link_dir)
195
+ dstdir = File.join(MARSEDIT_DIR, link_dir)
196
+ timestamp = Time.now.strftime("%Y%m%d_%H%M%S")
197
+ if FileTest.directory?(srcdir)
198
+ if FileTest.directory?(dstdir)
199
+ # オリジナルはバックアップとして残す(なぜか他の親フォルダにmvできない?)
200
+ backupdir = File.join(MARSEDIT_DIR, link_dir + '_' + timestamp)
201
+ puts "mv #{dstdir} #{backupdir}"
202
+ FileUtils.mv(dstdir, backupdir)
203
+ end
204
+ puts "ln #{srcdir} #{dstdir}"
205
+ FileUtils.symlink(srcdir, dstdir)
206
+ end
207
+ end
208
+ true
209
+ end
210
+
211
+ def restore_plists
212
+ puts "# restore_plists"
213
+ PLIST_FILES.each do |dstfile|
214
+ basename = File.basename(dstfile)
215
+ srcfile = File.join(DROPBOX_DIR, basename)
216
+ self.class.cp_new(srcfile, dstfile)
217
+ end
218
+ true
219
+ end
220
+ end
221
+ end
@@ -0,0 +1,3 @@
1
+ module Marseditsync
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,32 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'marseditsync/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "marseditsync"
8
+ spec.version = Marseditsync::VERSION
9
+ spec.authors = ["src"]
10
+ spec.email = ["src@srcw.net"]
11
+
12
+ spec.summary = %q{MarsEdit sync utility}
13
+ spec.description = %q{MarsEdit sync utility}
14
+ spec.homepage = ""
15
+ spec.license = "MIT"
16
+
17
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
18
+ # to allow pushing to a single host or delete this section to allow pushing to any host.
19
+ # if spec.respond_to?(:metadata)
20
+ # spec.metadata['allowed_push_host'] = "TODO: Set to 'http://mygemserver.com'"
21
+ # else
22
+ # raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
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
+ spec.add_development_dependency "bundler", "~> 1.12"
30
+ spec.add_development_dependency "rake", "~> 10.0"
31
+ spec.add_development_dependency "minitest", "~> 5.0"
32
+ end
data/marseditsync.sh ADDED
@@ -0,0 +1,3 @@
1
+ #!/bin/sh
2
+ bundle exec ruby exe/marseditsync "$@"
3
+
metadata ADDED
@@ -0,0 +1,103 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: marseditsync
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - src
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-09-26 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.12'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.12'
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
+ description: MarsEdit sync utility
56
+ email:
57
+ - src@srcw.net
58
+ executables:
59
+ - marseditsync
60
+ extensions: []
61
+ extra_rdoc_files: []
62
+ files:
63
+ - ".gitignore"
64
+ - ".travis.yml"
65
+ - CODE_OF_CONDUCT.md
66
+ - Gemfile
67
+ - LICENSE.txt
68
+ - README.md
69
+ - Rakefile
70
+ - bin/console
71
+ - bin/setup
72
+ - config/.marseditsync.yml
73
+ - config/marseditsyncrc
74
+ - exe/marseditsync
75
+ - lib/marseditsync.rb
76
+ - lib/marseditsync/version.rb
77
+ - marseditsync.gemspec
78
+ - marseditsync.sh
79
+ homepage: ''
80
+ licenses:
81
+ - MIT
82
+ metadata: {}
83
+ post_install_message:
84
+ rdoc_options: []
85
+ require_paths:
86
+ - lib
87
+ required_ruby_version: !ruby/object:Gem::Requirement
88
+ requirements:
89
+ - - ">="
90
+ - !ruby/object:Gem::Version
91
+ version: '0'
92
+ required_rubygems_version: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ requirements: []
98
+ rubyforge_project:
99
+ rubygems_version: 2.5.1
100
+ signing_key:
101
+ specification_version: 4
102
+ summary: MarsEdit sync utility
103
+ test_files: []