ofocus_sync 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,4 @@
1
+ == 0.0.1 2008-05-27
2
+
3
+ * 1 major enhancement:
4
+ * Initial release
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2008 Quirkey NYC, LLC
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,15 @@
1
+ History.txt
2
+ License.txt
3
+ Manifest.txt
4
+ PostInstall.txt
5
+ README.txt
6
+ Rakefile
7
+ bin/ofocus_sync
8
+ config/hoe.rb
9
+ config/requirements.rb
10
+ lib/ofocus_sync.rb
11
+ lib/ofocus_sync/ofocus_cli.rb
12
+ lib/ofocus_sync/ofocus_sync.rb
13
+ lib/ofocus_sync/version.rb
14
+ test/test_helper.rb
15
+ test/test_ofocus_sync.rb
@@ -0,0 +1,3 @@
1
+ For more information on ofocus_sync, see http://quirkey.rubyforge.org/ofocus_sync
2
+
3
+
@@ -0,0 +1,66 @@
1
+ = ofocus_sync
2
+
3
+ http://quirkey.rubyforge.com/ofocus_sync
4
+
5
+ == DESCRIPTION:
6
+
7
+ Until OmniFocus provides a good syncing mechanism this will do:
8
+ ofocus_sync will gzip and upload your .ofocus file (that holds all your GTD data) to an FTP server of your choosing.
9
+ On the other side you can download the gziped file and ofocus_sync will unzip it and put it in the right place.
10
+ This is great for syncing between two computers (home/work) with an FTP as a bridge.
11
+
12
+ == FEATURES/PROBLEMS:
13
+
14
+ TODO: s3 syncing/backup
15
+ TODO: timestamp syncing
16
+
17
+ == SYNOPSIS:
18
+
19
+ Run
20
+ $ ofocus_sync setup
21
+
22
+ And follow the instructions to set up your configuration
23
+ When you're leaving your computer, quit OmniFocus, then run
24
+ $ ofocus_sync up
25
+
26
+ When you're at the other side (OmniFocus should not be running):
27
+ $ ofocus_sync down
28
+
29
+ == REQUIREMENTS:
30
+
31
+ OmniFocus (duh)
32
+ highline gem
33
+ An FTP account
34
+
35
+ == INSTALL:
36
+
37
+ $ sudo gem install ofocus_sync
38
+
39
+ Then run:
40
+ $ ofocus_sync setup
41
+ and follow the guided instructions
42
+
43
+ == LICENSE:
44
+
45
+ (The MIT License)
46
+
47
+ Copyright (c) 2008 Quirkey NYC, LLC
48
+
49
+ Permission is hereby granted, free of charge, to any person obtaining
50
+ a copy of this software and associated documentation files (the
51
+ 'Software'), to deal in the Software without restriction, including
52
+ without limitation the rights to use, copy, modify, merge, publish,
53
+ distribute, sublicense, and/or sell copies of the Software, and to
54
+ permit persons to whom the Software is furnished to do so, subject to
55
+ the following conditions:
56
+
57
+ The above copyright notice and this permission notice shall be
58
+ included in all copies or substantial portions of the Software.
59
+
60
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
61
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
62
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
63
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
64
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
65
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
66
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,4 @@
1
+ require 'config/requirements'
2
+ require 'config/hoe' # setup Hoe + all gem configuration
3
+
4
+ Dir['tasks/**/*.rake'].each { |rake| load rake }
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require File.join(File.dirname(__FILE__), "../lib/ofocus_sync.rb")
4
+
5
+ OfocusSync::Cli.new(ARGV.shift)
@@ -0,0 +1,75 @@
1
+ require 'ofocus_sync/version'
2
+
3
+ AUTHOR = 'Aaron Quint' # can also be an array of Authors
4
+ EMAIL = "aaron@quirkey.com"
5
+ DESCRIPTION = "A simple sync tool for OmniFocus"
6
+ GEM_NAME = 'ofocus_sync' # what ppl will type to install your gem
7
+ RUBYFORGE_PROJECT = 'quirkey' # The unix name for your project
8
+ HOMEPATH = "http://#{RUBYFORGE_PROJECT}.rubyforge.org"
9
+ DOWNLOAD_PATH = "http://rubyforge.org/projects/#{RUBYFORGE_PROJECT}"
10
+ EXTRA_DEPENDENCIES = [
11
+ ['highline','>= 1.4.0',
12
+ 'net-ssh', '>= 2.0.1',
13
+ 'net-sftp','>= 2.0.0']
14
+ ] # An array of rubygem dependencies [name, version]
15
+
16
+ @config_file = "~/.rubyforge/user-config.yml"
17
+ @config = nil
18
+ RUBYFORGE_USERNAME = "quirkey"
19
+ def rubyforge_username
20
+ unless @config
21
+ begin
22
+ @config = YAML.load(File.read(File.expand_path(@config_file)))
23
+ rescue
24
+ puts <<-EOS
25
+ ERROR: No rubyforge config file found: #{@config_file}
26
+ Run 'rubyforge setup' to prepare your env for access to Rubyforge
27
+ - See http://newgem.rubyforge.org/rubyforge.html for more details
28
+ EOS
29
+ exit
30
+ end
31
+ end
32
+ RUBYFORGE_USERNAME.replace @config["username"]
33
+ end
34
+
35
+
36
+ REV = nil
37
+ # UNCOMMENT IF REQUIRED:
38
+ # REV = YAML.load(`svn info`)['Revision']
39
+ VERS = OfocusSync::VERSION::STRING + (REV ? ".#{REV}" : "")
40
+ RDOC_OPTS = ['--quiet', '--title', 'ofocus_sync documentation',
41
+ "--opname", "index.html",
42
+ "--line-numbers",
43
+ "--main", "README",
44
+ "--inline-source"]
45
+
46
+ class Hoe
47
+ def extra_deps
48
+ @extra_deps.reject! { |x| Array(x).first == 'hoe' }
49
+ @extra_deps
50
+ end
51
+ end
52
+
53
+ # Generate all the Rake tasks
54
+ # Run 'rake -T' to see list of generated tasks (from gem root directory)
55
+ $hoe = Hoe.new(GEM_NAME, VERS) do |p|
56
+ p.developer(AUTHOR, EMAIL)
57
+ p.description = DESCRIPTION
58
+ p.summary = DESCRIPTION
59
+ p.url = HOMEPATH
60
+ p.rubyforge_name = RUBYFORGE_PROJECT if RUBYFORGE_PROJECT
61
+ p.test_globs = ["test/**/test_*.rb"]
62
+ p.clean_globs |= ['**/.*.sw?', '*.gem', '.config', '**/.DS_Store'] #An array of file patterns to delete on clean.
63
+
64
+ # == Optional
65
+ p.changes = p.paragraphs_of("History.txt", 0..1).join("\n\n")
66
+ #p.extra_deps = EXTRA_DEPENDENCIES
67
+
68
+ #p.spec_extras = {} # A hash of extra values to set in the gemspec.
69
+ end
70
+
71
+ CHANGES = $hoe.paragraphs_of('History.txt', 0..1).join("\\n\\n")
72
+ PATH = (RUBYFORGE_PROJECT == GEM_NAME) ? RUBYFORGE_PROJECT : "#{RUBYFORGE_PROJECT}/#{GEM_NAME}"
73
+ $hoe.remote_rdoc_dir = File.join(PATH.gsub(/^#{RUBYFORGE_PROJECT}\/?/,''), 'rdoc')
74
+ $hoe.rsync_args = '-av --delete --ignore-errors'
75
+ $hoe.spec.post_install_message = File.open(File.dirname(__FILE__) + "/../PostInstall.txt").read rescue ""
@@ -0,0 +1,15 @@
1
+ require 'fileutils'
2
+ include FileUtils
3
+
4
+ require 'rubygems'
5
+ %w[rake hoe newgem rubigen].each do |req_gem|
6
+ begin
7
+ require req_gem
8
+ rescue LoadError
9
+ puts "This Rakefile requires the '#{req_gem}' RubyGem."
10
+ puts "Installation: gem install #{req_gem} -y"
11
+ exit
12
+ end
13
+ end
14
+
15
+ $:.unshift(File.join(File.dirname(__FILE__), %w[.. lib]))
@@ -0,0 +1,5 @@
1
+ $:.unshift(File.dirname(__FILE__)) unless
2
+ $:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
3
+
4
+ require 'ofocus_sync/ofocus_sync'
5
+ require 'ofocus_sync/ofocus_cli'
@@ -0,0 +1,76 @@
1
+ require 'highline/import'
2
+ require 'yaml'
3
+
4
+ module OfocusSync
5
+ class Cli
6
+
7
+ ACTIONS =%w{up upload down download setup}
8
+ SETTINGS_YML = '~/.ofocus'
9
+
10
+ def initialize(action)
11
+ if ACTIONS.include?(action)
12
+ h1("OfocusSync", :blue)
13
+ hr
14
+ self.send(action)
15
+ else
16
+ usage
17
+ exit
18
+ end
19
+ end
20
+
21
+ def setup
22
+ h1 "SETUP"
23
+ hr
24
+ say "Please follow the instructions that follow to set up OfocusSync\n"
25
+ settings = OfocusSync::Sync::DEFAULT_OPTIONS.dup
26
+ yml_path = ask("Where would you like to store your settings? ") {|q| q.default = SETTINGS_YML }
27
+ h1 "FTP Settings"
28
+ settings[:host] = ask("FTP Host? ") {|q| q.default = settings[:host] }
29
+ settings[:username] = ask("Username? ")
30
+ settings[:password] = ask("Password? ") {|q| q.echo = false }
31
+ settings[:remote_path] = ask("Remote Path? ") {|q| q.default = settings[:remote_path] }
32
+ hr
33
+ h1 "Local Settings"
34
+ settings[:local_path] = ask("Your OmniFocus support directory? ") {|q| q.default = settings[:local_path] }
35
+ settings[:ofocus_dir] = ask("Your OmniFocus OmniFocus file? ") {|q| q.default = settings[:ofocus_dir] }
36
+ hr
37
+ say("Dumping to your YAML file: #{yml_path}.")
38
+ yml = YAML.dump(settings)
39
+ File.open(File.expand_path(yml_path), 'w+') {|f| f << yml }
40
+ say("Done")
41
+ hr
42
+ end
43
+
44
+ def download
45
+ OfocusSync::Sync.new(load_settings).download
46
+ end
47
+ alias :down :download
48
+
49
+ def upload
50
+ OfocusSync::Sync.new(load_settings).upload
51
+ end
52
+ alias :up :upload
53
+
54
+ def usage
55
+ say("USAGE: <%= color(' ofocus_sync [setup|upload|download]', :blue) %>")
56
+ end
57
+
58
+ protected
59
+
60
+ def h1(text, color = :red)
61
+ say("<%= color('#{text}', :#{color}) %>")
62
+ end
63
+
64
+ def hr
65
+ say("<%= color('#' * 40, :magenta) %>")
66
+ end
67
+
68
+ def load_settings
69
+ if File.readable?(File.expand_path(SETTINGS_YML))
70
+ File.open(File.expand_path(SETTINGS_YML)) {|f| YAML.load(f) }
71
+ else
72
+ say "You must run setup before using upload."
73
+ end
74
+ end
75
+ end
76
+ end
@@ -0,0 +1,132 @@
1
+ require 'net/ssh'
2
+ require 'net/sftp'
3
+ require 'ftools'
4
+
5
+ module OfocusSync
6
+
7
+ class Sync
8
+ DEFAULT_OPTIONS =
9
+ {
10
+ :host => 'localhost',
11
+ :username => '',
12
+ :password => '',
13
+ :ofocus_dir => 'OmniFocus.ofocus',
14
+ :local_path => '~/Library/Application Support/OmniFocus',
15
+ :tmpfile => 'ofocus.tar.gz',
16
+ :remote_path => 'omnifocus/',
17
+ :keep_backups => 3
18
+ }.freeze
19
+
20
+ def initialize(options = {})
21
+ @options = DEFAULT_OPTIONS.dup.merge(options)
22
+ end
23
+
24
+ def download
25
+ begin
26
+ rename_ofocus_file
27
+ download_zip_file
28
+ extract_zip_file
29
+ rescue => e
30
+ announce("Error: #{e}")
31
+ end
32
+ end
33
+
34
+ def upload
35
+ begin
36
+ announce("Starting upload sync")
37
+ zip_ofocus_file
38
+ upload_zip_file
39
+ announce("Finished upload sync")
40
+ rescue => e
41
+ announce("Error: #{e}")
42
+ end
43
+ end
44
+
45
+ def options
46
+ #spit out options but clean the password
47
+ end
48
+
49
+ protected
50
+
51
+ def upload_zip_file
52
+ get_connection do |ftp|
53
+ announce("Sending Ofocus Zip to Remote Host")
54
+ ftp.upload!(zip_file_path, remote_file_path)
55
+ end
56
+ # upload_file_with_progress(zip_file_path, remote_file_path)
57
+ end
58
+
59
+ def download_zip_file
60
+ get_connection do |ftp|
61
+ announce("Getting Ofocus Zip from Remote Host")
62
+ ftp.download!(remote_file_path, zip_file_path)
63
+ end
64
+ end
65
+
66
+ def zip_ofocus_file
67
+ announce("Packing OmniFocus dir")
68
+ tar = "tar -z --create -C #{cli_clean_path(@options[:local_path])} --file=#{cli_clean_path(zip_file_path)} #{@options[:ofocus_dir]}"
69
+ puts tar
70
+ `#{tar}`
71
+ end
72
+
73
+ def extract_zip_file
74
+ announce("Unpacking OmniFocus dir")
75
+ tar = "cd #{cli_clean_path(@options[:local_path])} && tar -xzvf #{cli_clean_path(zip_file_path)}"
76
+ puts tar
77
+ `#{tar}`
78
+ end
79
+
80
+ def rename_ofocus_file
81
+ announce("Renaming current OmniFocus directory")
82
+ File.mv(local_file_path,backup_file_path)
83
+ rescue => e
84
+ warn e
85
+ end
86
+
87
+ def cli_clean_path(path)
88
+ path.gsub(/ /,"\\ ")
89
+ end
90
+
91
+ def zip_file_path
92
+ File.join(File.expand_path(@options[:local_path]),@options[:tmpfile])
93
+ end
94
+
95
+ def local_file_path
96
+ File.join(File.expand_path(@options[:local_path]),@options[:ofocus_dir])
97
+ end
98
+
99
+ def remote_file_path
100
+ File.join(@options[:remote_path],@options[:tmpfile])
101
+ end
102
+
103
+ def backup_file_path
104
+ File.join(File.expand_path(@options[:local_path]),"Previous OmniFocus (#{Time.now.strftime('%Y-%m-%d')}).ofocus")
105
+ end
106
+
107
+ # gzip a file
108
+ # def tar(from, to, options = "")
109
+ # command = "tar #{options} '#{from}'"
110
+ # command << " '#{to}'" if to
111
+ # `#{command}`
112
+ # end
113
+
114
+ # get an sftp connection with the options provided
115
+ def get_connection
116
+ announce("Connecting to #{@options[:username]}@#{@options[:host]}")
117
+ Net::SFTP.start(@options[:host], @options[:username], :password => @options[:password]) do |sftp|
118
+ yield sftp
119
+ end
120
+ end
121
+
122
+ # use STDOUT to announce current step
123
+ def announce(what)
124
+ puts "[#{Time.now}] #{what}"
125
+ end
126
+
127
+ def progress
128
+ print "#"
129
+ end
130
+
131
+ end
132
+ end
@@ -0,0 +1,9 @@
1
+ module OfocusSync #:nodoc:
2
+ module VERSION #:nodoc:
3
+ MAJOR = 0
4
+ MINOR = 1
5
+ TINY = 0
6
+
7
+ STRING = [MAJOR, MINOR, TINY].join('.')
8
+ end
9
+ end
@@ -0,0 +1,2 @@
1
+ require 'test/unit'
2
+ require File.dirname(__FILE__) + '/../lib/ofocus_sync'
@@ -0,0 +1,11 @@
1
+ require File.dirname(__FILE__) + '/test_helper.rb'
2
+
3
+ class TestOfocusSync < Test::Unit::TestCase
4
+
5
+ def setup
6
+ end
7
+
8
+ def test_truth
9
+ assert true
10
+ end
11
+ end
metadata ADDED
@@ -0,0 +1,77 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ofocus_sync
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Aaron Quint
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2008-05-27 00:00:00 -04:00
13
+ default_executable:
14
+ dependencies: []
15
+
16
+ description: A simple sync tool for OmniFocus
17
+ email:
18
+ - aaron@quirkey.com
19
+ executables:
20
+ - ofocus_sync
21
+ extensions: []
22
+
23
+ extra_rdoc_files:
24
+ - History.txt
25
+ - License.txt
26
+ - Manifest.txt
27
+ - PostInstall.txt
28
+ - README.txt
29
+ files:
30
+ - History.txt
31
+ - License.txt
32
+ - Manifest.txt
33
+ - PostInstall.txt
34
+ - README.txt
35
+ - Rakefile
36
+ - bin/ofocus_sync
37
+ - config/hoe.rb
38
+ - config/requirements.rb
39
+ - lib/ofocus_sync.rb
40
+ - lib/ofocus_sync/ofocus_cli.rb
41
+ - lib/ofocus_sync/ofocus_sync.rb
42
+ - lib/ofocus_sync/version.rb
43
+ - test/test_helper.rb
44
+ - test/test_ofocus_sync.rb
45
+ has_rdoc: true
46
+ homepage: http://quirkey.rubyforge.org
47
+ post_install_message: |+
48
+ For more information on ofocus_sync, see http://quirkey.rubyforge.org/ofocus_sync
49
+
50
+
51
+ rdoc_options:
52
+ - --main
53
+ - README.txt
54
+ require_paths:
55
+ - lib
56
+ required_ruby_version: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ version: "0"
61
+ version:
62
+ required_rubygems_version: !ruby/object:Gem::Requirement
63
+ requirements:
64
+ - - ">="
65
+ - !ruby/object:Gem::Version
66
+ version: "0"
67
+ version:
68
+ requirements: []
69
+
70
+ rubyforge_project: quirkey
71
+ rubygems_version: 1.1.1
72
+ signing_key:
73
+ specification_version: 2
74
+ summary: A simple sync tool for OmniFocus
75
+ test_files:
76
+ - test/test_helper.rb
77
+ - test/test_ofocus_sync.rb