vigetlabs-amazon-ec2 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (9) hide show
  1. data/LICENSE +20 -0
  2. data/Manifest +19 -0
  3. data/README +39 -0
  4. data/Rakefile +51 -0
  5. data/TODO +6 -0
  6. data/bin/dockit +17 -0
  7. data/lib/dockit.rb +42 -0
  8. data/lib/export.rb +104 -0
  9. metadata +87 -0
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2007 Viget Labs
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,19 @@
1
+ config
2
+ config/users.yml
3
+ lib
4
+ lib/dockit.rb
5
+ lib/export.rb
6
+ lib/tony.pitale.ics
7
+ LICENSE
8
+ pkg
9
+ Rakefile
10
+ rawresponse.txt
11
+ README
12
+ script
13
+ script/destroy
14
+ script/generate
15
+ spec
16
+ spec/dockit_spec.rb
17
+ spec/spec_helper.rb
18
+ TODO
19
+ Manifest
data/README ADDED
@@ -0,0 +1,39 @@
1
+ dockit
2
+ =================
3
+
4
+ A rack application daemon that creates an iCal subscription file from exchange calendars.
5
+
6
+ Install
7
+ -----------------
8
+ sudo gem install dockit # if you've cloned from github
9
+
10
+ # else
11
+
12
+ sudo gem install vigetlabs-dockit -s http://gems.github.com
13
+
14
+ Configure
15
+ -----------------
16
+
17
+ Simply set up a file, .dockit, in your home directory with your username, domain, and the
18
+ url of your exchange server. Leave the domain blank if your login for exchange is NOT your
19
+ email address. If you leave domain blank, change the resulting url to simply reflect your
20
+ username, with the @domain.com. The port too, if not 2000, should be changed.
21
+
22
+ Example .dockit Configuration
23
+ -----------------
24
+
25
+ default:
26
+ username: john.doe
27
+ domain: example.com
28
+ password: password
29
+ remote_uri: http://mail.example.com/exchange/john.doe@example.com/
30
+ local_port: 2000
31
+
32
+ The resulting url for subscribing in iCal when running this daemon on the localhost would be:
33
+ http://localhost:2000/john.doe.ics
34
+
35
+ Starting the Daemon
36
+ -----------------
37
+ Given the yaml file defined example, the command would be:
38
+
39
+ dockit default (or in the case of default, just dockit)
@@ -0,0 +1,51 @@
1
+ require 'rubygems'
2
+ require 'rake/gempackagetask'
3
+
4
+ GEM = "dockit"
5
+ VERSION = "0.1"
6
+ AUTHOR = "Tony Pitale @ Viget Labs"
7
+ EMAIL = "tony.pitale@viget.com"
8
+ HOMEPAGE = "http://www.viget.com/extend/"
9
+ SUMMARY = "A rack application daemon that creates an iCal subscription file from exchange calendars."
10
+
11
+ # spec = Gem::Specification.new do |s|
12
+ # s.name = GEM
13
+ # s.version = VERSION
14
+ # s.platform = Gem::Platform::RUBY
15
+ # s.has_rdoc = true
16
+ # s.extra_rdoc_files = ["README", "LICENSE", 'TODO']
17
+ # s.summary = SUMMARY
18
+ # s.description = s.summary
19
+ # s.author = AUTHOR
20
+ # s.email = EMAIL
21
+ # s.homepage = HOMEPAGE
22
+ #
23
+ # # Uncomment this to add a dependency
24
+ # # s.add_dependency "foo"
25
+ # s.add_dependency "rexchange", ">= 0.3.4"
26
+ # s.add_dependency "rack", ">= 0.3.0"
27
+ # s.add_dependency "chronic", ">= 0.2.3"
28
+ #
29
+ # s.executables = ['dockit']
30
+ #
31
+ # s.require_path = 'lib'
32
+ # s.autorequire = GEM
33
+ # s.files = %w(LICENSE README Rakefile TODO Manifest ) + Dir.glob("{lib,specs}/**/*")
34
+ # end
35
+
36
+ spec_file = ""
37
+ File.open("dockit.gemspec", "r") do |f|
38
+ while line = f.gets
39
+ spec_file << line
40
+ end
41
+ end
42
+
43
+ spec = eval(spec_file)
44
+
45
+ Rake::GemPackageTask.new(spec) do |pkg|
46
+ pkg.gem_spec = spec
47
+ end
48
+
49
+ task :install => [:package] do
50
+ sh %{sudo gem install pkg/#{GEM}-#{VERSION}}
51
+ end
data/TODO ADDED
@@ -0,0 +1,6 @@
1
+ TODO
2
+ -----------------
3
+ Start/Stop/Restart scripting
4
+ User selection from url
5
+ Include and configure todos, journals, free/busy time
6
+ Failed connection error handling
@@ -0,0 +1,17 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # This file was generated by RubyGems.
4
+ #
5
+ # The application 'dockit' is installed as part of a gem, and
6
+ # this file is here to facilitate running it.
7
+ #
8
+
9
+ require 'rubygems'
10
+ require 'dockit'
11
+ # require "optparse"
12
+
13
+ config = ARGV.first || 'default'
14
+
15
+ Dockit.new(config).run
16
+
17
+ # TODO start/stop daemon
@@ -0,0 +1,42 @@
1
+ require 'rubygems'
2
+ require 'rack'
3
+ require 'yaml'
4
+
5
+ require "export"
6
+
7
+ class String
8
+ def blank?
9
+ self.nil? || self.strip.empty?
10
+ end
11
+ end
12
+
13
+ class NilClass
14
+ def blank?
15
+ true
16
+ end
17
+ end
18
+
19
+ class Dockit
20
+ include Export
21
+
22
+ def initialize(config)
23
+ # Get configuration information
24
+ config_file = YAML.load_file(File.join(ENV['HOME'], ".dockit"))
25
+ @user = config_file && config_file.has_key?(config) ?
26
+ config_file[config] : config_file['default']
27
+
28
+ raise "No users.yml found for user #{ARGV.first}!" unless @user
29
+ end
30
+
31
+ def run
32
+ local_port = @user.fetch("local_port", 2000)
33
+
34
+ pid = fork do
35
+ Rack::Handler::Mongrel.run(rack_process(@user), :Port => local_port)
36
+ end
37
+
38
+ Process.detach(pid)
39
+
40
+ puts "Use sudo kill #{pid} to stop this process."
41
+ end
42
+ end
@@ -0,0 +1,104 @@
1
+ require 'rexchange'
2
+ require 'chronic'
3
+
4
+ module Export
5
+ def rack_process(user)
6
+ lambda do |env|
7
+ # puts user.inspect
8
+ exchange(user)
9
+
10
+ Rack::File.new('.').call(env)
11
+ end
12
+ end
13
+
14
+ def exchange(user)
15
+ username = user.fetch("username", ENV['USER'])
16
+ domain = user.fetch("domain", 'localhost')
17
+ email = "#{username}@#{domain}"
18
+ password = user.fetch("password", 'password')
19
+ remote_uri = user.fetch("remote_uri", "http://localhost/#{email}/")
20
+
21
+ # puts "User: #{username}@#{domain}, #{password}, #{remote_uri}"
22
+
23
+ RExchange::open(remote_uri, email, password) do |mailbox|
24
+
25
+ # create ics file, clearing any old one
26
+ file = File.new("#{username}.ics", "w")
27
+ raise "Failed to create file #{username}.ics" unless file
28
+
29
+ file.puts "BEGIN:VCALENDAR"
30
+ file.puts "CALSCALE:GREGORIAN"
31
+ file.puts "PRODID:-//Apple Computer\, Inc//iCal 2.0//EN"
32
+ file.puts "VERSION:2.0"
33
+ file.puts "X-WR-CALNAME:#{username}"
34
+
35
+ # itemcount = 0
36
+
37
+ # Loop through all calendar events, making VEVENTS
38
+ mailbox.calendar.each do |event|
39
+
40
+ file.puts "BEGIN:VEVENT"
41
+
42
+ # Set some properties for this event
43
+ file.puts "DTSTAMP:#{dformat(event.created_at)}"
44
+ file.puts "DTSTART:#{dformat(event.start_at)}"
45
+ file.puts "DTEND:#{dformat(event.end_at)}"
46
+ file.puts "LAST-MODIFIED:#{dformat(event.modified_at)}"
47
+
48
+ file.puts "SUMMARY:" + (event.subject.blank? ? "Unknown Subject" : event.subject)
49
+
50
+ description = event.body.blank? ? "" : event.body.gsub!("\n","\\n").gsub("^\n","")
51
+ # ?? add event.href+"?Cmd=accept" or "decline" or "tentative"
52
+ # description += event.href+"?Cmd=accept"
53
+ # description += event.href+"?Cmd=decline"
54
+ # description += event.href+"?Cmd=tentative"
55
+
56
+ file.puts "DESCRIPTION:" + description
57
+
58
+ file.puts "UID:" + event.uid if event.uid
59
+
60
+ if event.reminder_offset && event.reminder_offset.to_i > 60
61
+ # ouput valarm details. reminder_offset is in seconds
62
+ ro_min = event.reminder_offset.to_i / 60
63
+ file.puts "BEGIN:VALARM"
64
+ file.puts "TRIGGER:-PT#{ro_min}M"
65
+ # item.puts "DESCRIPTION:Påminnelse om aktivitet"
66
+ file.puts "ACTION:DISPLAY"
67
+ file.puts "END:VALARM"
68
+ end
69
+
70
+ #add event to calendar
71
+ file.puts "END:VEVENT"
72
+
73
+ # itemcount += 1
74
+ end
75
+
76
+ # puts mailbox.inspect
77
+ # puts
78
+ # puts mailbox.methods
79
+
80
+ # Loop through all todos, creating VTODOS
81
+ # Loop through all journals, creating VJOURNAL
82
+ # Loop through all free/busy time, creating VFREEBUSY
83
+ # event.busy_status
84
+
85
+ #close ical file
86
+ file.puts "END:VCALENDAR"
87
+ file.close
88
+
89
+ # p "Done! Wrote #{itemcount} appointment items"
90
+
91
+ end
92
+ end
93
+
94
+ def dformat(t)
95
+ # month = s[4..6]
96
+ # day = s[8..9].to_i
97
+ # hour = s[11..12].to_i
98
+ # minute = s[14..15].to_i
99
+ # second = s[17..18].to_i
100
+ # year = s[23..27].to_i
101
+ # Time.local(year, month, day, hour, minute, second).strftime('%Y%m%dT%H%M%S')
102
+ t.strftime('%Y%m%dT%H%M%S')
103
+ end
104
+ end
metadata ADDED
@@ -0,0 +1,87 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: vigetlabs-amazon-ec2
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ platform: ruby
6
+ authors:
7
+ - Glenn Rempe
8
+ autorequire: amazon-ec2
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2008-05-14 00:00:00 -07:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: rexchange
17
+ version_requirement:
18
+ version_requirements: !ruby/object:Gem::Requirement
19
+ requirements:
20
+ - - ">="
21
+ - !ruby/object:Gem::Version
22
+ version: 0.3.4
23
+ version:
24
+ - !ruby/object:Gem::Dependency
25
+ name: rack
26
+ version_requirement:
27
+ version_requirements: !ruby/object:Gem::Requirement
28
+ requirements:
29
+ - - ">="
30
+ - !ruby/object:Gem::Version
31
+ version: 0.3.0
32
+ version:
33
+ - !ruby/object:Gem::Dependency
34
+ name: chronic
35
+ version_requirement:
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: 0.2.3
41
+ version:
42
+ description: An interface library that allows Ruby applications to easily connect to the HTTP 'Query API' for the Amazon Web Services Elastic Compute Cloud (EC2) and manipulate cloud servers.
43
+ email: glenn.rempe@gmail.com
44
+ executables:
45
+ - dockit
46
+ extensions: []
47
+
48
+ extra_rdoc_files:
49
+ - README
50
+ - LICENSE
51
+ - TODO
52
+ files:
53
+ - LICENSE
54
+ - README
55
+ - Rakefile
56
+ - TODO
57
+ - Manifest
58
+ - lib/dockit.rb
59
+ - lib/export.rb
60
+ has_rdoc: true
61
+ homepage: http://github.com/grempe/amazon-ec2/
62
+ post_install_message:
63
+ rdoc_options: []
64
+
65
+ require_paths:
66
+ - lib
67
+ required_ruby_version: !ruby/object:Gem::Requirement
68
+ requirements:
69
+ - - ">="
70
+ - !ruby/object:Gem::Version
71
+ version: "0"
72
+ version:
73
+ required_rubygems_version: !ruby/object:Gem::Requirement
74
+ requirements:
75
+ - - ">="
76
+ - !ruby/object:Gem::Version
77
+ version: "0"
78
+ version:
79
+ requirements: []
80
+
81
+ rubyforge_project:
82
+ rubygems_version: 1.0.1
83
+ signing_key:
84
+ specification_version: 2
85
+ summary: An interface library that allows Ruby applications to easily connect to the HTTP 'Query API' for the Amazon Web Services Elastic Compute Cloud (EC2) and manipulate cloud servers.
86
+ test_files: []
87
+