tendersync 1.0.2

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.
@@ -0,0 +1,102 @@
1
+
2
+ class Tendersync::Session
3
+ attr_reader :agent
4
+ def initialize(site, user, pass)
5
+ @username = user
6
+ @password = pass
7
+ @agent = WWW::Mechanize.new { |a| }
8
+ @site = site
9
+ @login_site = "#{site}/login"
10
+ end
11
+
12
+ def login
13
+ return if @logged_in
14
+ puts "logging in as #{@username}..."
15
+ page = @agent.get(@login_site)
16
+ f = page.form_with(:action => '/login') do | login_form |
17
+ login_form['email'] = @username
18
+ login_form['password'] = @password
19
+ end
20
+ result = f.submit
21
+ if result =~ /unable to login/i
22
+ raise Tendersync::Runner::Error, "login failed--bad credentials"
23
+ end
24
+ # TODO Check the result for a valid login.
25
+ @logged_in = true
26
+ end
27
+
28
+ def get(url)
29
+ login
30
+ page = @agent.get(url)
31
+ def page.links_like(r)
32
+ result = []
33
+ links.each { |l| result << l.href if l.href =~ r }
34
+ result
35
+ end
36
+ page
37
+ end
38
+ # Get the URL's of documents in the given section.
39
+ def documents(section)
40
+ login
41
+ index = get("#{@site}/faqs/#{section}")
42
+ index.links_like(%r{faqs/#{section}/.+}).collect { |url|"#{@site}#{url}" }
43
+ end
44
+ def edit_page_for(doc_url)
45
+ login
46
+ get "#{@site}#{get(doc_url).links_like(%r{faqs/\d+/edit}).first}"
47
+ end
48
+
49
+ # Return a hash of section id to section name.
50
+ def all_sections
51
+ sections = {}
52
+ get("#{@site}/dashboard/sections").links.each do | link |
53
+ if link.href =~ %r{/dashboard/sections/(.*)/edit$}
54
+ name = $1
55
+ sections[name] = link.text
56
+ end
57
+ end
58
+ sections
59
+ end
60
+
61
+ def pull_from_tender(*sections)
62
+ sections = all_sections.keys if sections.empty?
63
+ for section in sections do
64
+ documents(section).collect do |doc_url|
65
+ doc = Tendersync::Document.from_form(section,edit_page_for(doc_url).form_with(:action => /edit/))
66
+ puts " #{doc.permalink}"
67
+ doc.save unless $dry_run
68
+ end
69
+ end
70
+ end
71
+ # Print out a list of all documents
72
+ def ls(*sections)
73
+ sections = all_sections.keys if sections.empty?
74
+ sections.each do | section |
75
+ puts "Section #{section}"
76
+ documents(section).map {|url| url =~ %r{/([^/]*)$} && $1 }.each do |link|
77
+ puts " #{link}"
78
+ end
79
+ end
80
+ end
81
+ def post(document)
82
+ login
83
+ form = edit_page_for("#{@site}/faqs/#{document.section}/#{document.permalink}").form_with(:action => /edit/)
84
+ document.to_form(form)
85
+ form.submit unless $dry_run
86
+ end
87
+ def create_document(section,permalink,body)
88
+ login
89
+ form = get("#{@site}/faq/new").form_with(:action => "/faqs")
90
+ document = Tendersync::Document.new(
91
+ :section => section,
92
+ :title => "New Tendersync::Document",
93
+ :permalink => permalink,
94
+ :body => body
95
+ )
96
+ document.to_form(form)
97
+ return if $dry_run
98
+ form.radiobuttons_with(:value => Tender_id_for_section[section]).first.click
99
+ form.submit
100
+ Tendersync::Document.from_form(section,edit_page_for("#{@site}/faqs/#{section}/#{permalink}").form_with(:action => /edit/))
101
+ end
102
+ end
@@ -0,0 +1,7 @@
1
+ $:.unshift(File.dirname(__FILE__)) unless
2
+ $:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
3
+
4
+ module Tendersync
5
+ VERSION = '1.0.1'
6
+ end
7
+ require 'tendersync/runner'
data/lib/tendersync.rb ADDED
@@ -0,0 +1,6 @@
1
+ $:.unshift(File.dirname(__FILE__)) unless
2
+ $:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
3
+
4
+ module Tendersync
5
+ VERSION = '1.0.2'
6
+ end
data/script/console ADDED
@@ -0,0 +1,10 @@
1
+ #!/usr/bin/env ruby
2
+ # File: script/console
3
+ irb = RUBY_PLATFORM =~ /(:?mswin|mingw)/ ? 'irb.bat' : 'irb'
4
+
5
+ libs = " -r irb/completion"
6
+ # Perhaps use a console_lib to store any extra methods I may want available in the cosole
7
+ # libs << " -r #{File.dirname(__FILE__) + '/../lib/console_lib/console_logger.rb'}"
8
+ libs << " -r #{File.dirname(__FILE__) + '/../lib/tendersync.rb'}"
9
+ puts "Loading tendersync gem"
10
+ exec "#{irb} #{libs} --simple-prompt"
data/script/destroy ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+ APP_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..'))
3
+
4
+ begin
5
+ require 'rubigen'
6
+ rescue LoadError
7
+ require 'rubygems'
8
+ require 'rubigen'
9
+ end
10
+ require 'rubigen/scripts/destroy'
11
+
12
+ ARGV.shift if ['--help', '-h'].include?(ARGV[0])
13
+ RubiGen::Base.use_component_sources! [:rubygems, :newgem, :newgem_theme, :test_unit]
14
+ RubiGen::Scripts::Destroy.new.run(ARGV)
data/script/generate ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+ APP_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..'))
3
+
4
+ begin
5
+ require 'rubigen'
6
+ rescue LoadError
7
+ require 'rubygems'
8
+ require 'rubigen'
9
+ end
10
+ require 'rubigen/scripts/generate'
11
+
12
+ ARGV.shift if ['--help', '-h'].include?(ARGV[0])
13
+ RubiGen::Base.use_component_sources! [:rubygems, :newgem, :newgem_theme, :test_unit]
14
+ RubiGen::Scripts::Generate.new.run(ARGV)
data/script/txt2html ADDED
@@ -0,0 +1,71 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ load File.dirname(__FILE__) + "/../Rakefile"
4
+ require 'rubyforge'
5
+ require 'redcloth'
6
+ require 'syntax/convertors/html'
7
+ require 'erb'
8
+
9
+ download = "http://rubyforge.org/projects/#{$hoe.rubyforge_name}"
10
+ version = $hoe.version
11
+
12
+ def rubyforge_project_id
13
+ RubyForge.new.configure.autoconfig["group_ids"][$hoe.rubyforge_name]
14
+ end
15
+
16
+ class Fixnum
17
+ def ordinal
18
+ # teens
19
+ return 'th' if (10..19).include?(self % 100)
20
+ # others
21
+ case self % 10
22
+ when 1: return 'st'
23
+ when 2: return 'nd'
24
+ when 3: return 'rd'
25
+ else return 'th'
26
+ end
27
+ end
28
+ end
29
+
30
+ class Time
31
+ def pretty
32
+ return "#{mday}#{mday.ordinal} #{strftime('%B')} #{year}"
33
+ end
34
+ end
35
+
36
+ def convert_syntax(syntax, source)
37
+ return Syntax::Convertors::HTML.for_syntax(syntax).convert(source).gsub(%r!^<pre>|</pre>$!,'')
38
+ end
39
+
40
+ if ARGV.length >= 1
41
+ src, template = ARGV
42
+ template ||= File.join(File.dirname(__FILE__), '/../website/template.html.erb')
43
+ else
44
+ puts("Usage: #{File.split($0).last} source.txt [template.html.erb] > output.html")
45
+ exit!
46
+ end
47
+
48
+ template = ERB.new(File.open(template).read)
49
+
50
+ title = nil
51
+ body = nil
52
+ File.open(src) do |fsrc|
53
+ title_text = fsrc.readline
54
+ body_text_template = fsrc.read
55
+ body_text = ERB.new(body_text_template).result(binding)
56
+ syntax_items = []
57
+ body_text.gsub!(%r!<(pre|code)[^>]*?syntax=['"]([^'"]+)[^>]*>(.*?)</\1>!m){
58
+ ident = syntax_items.length
59
+ element, syntax, source = $1, $2, $3
60
+ syntax_items << "<#{element} class='syntax'>#{convert_syntax(syntax, source)}</#{element}>"
61
+ "syntax-temp-#{ident}"
62
+ }
63
+ title = RedCloth.new(title_text).to_html.gsub(%r!<.*?>!,'').strip
64
+ body = RedCloth.new(body_text).to_html
65
+ body.gsub!(%r!(?:<pre><code>)?syntax-temp-(\d+)(?:</code></pre>)?!){ syntax_items[$1.to_i] }
66
+ end
67
+ stat = File.stat(src)
68
+ created = stat.ctime
69
+ modified = stat.mtime
70
+
71
+ $stdout << template.result(binding)
@@ -0,0 +1,31 @@
1
+ ---------------------------- document_id ----------------------------
2
+ 1967
3
+ ---------------------------- title ----------------------------
4
+ I updated the agent and restarted Passenger but it didn't pick up the new agent.
5
+ ---------------------------- permalink ----------------------------
6
+ passenger_restart_issues
7
+ ---------------------------- keywords ----------------------------
8
+ passenger restart
9
+ ---------------------------- body ----------------------------
10
+
11
+ # Summary of Problem
12
+
13
+ When you update the agent it's not enough to touch the Passenger `tmp/restart.txt` file.
14
+ You need to do a hard restart of apache for the change to take effect.
15
+
16
+ # How to Fix it
17
+
18
+ Follow these detailed steps.
19
+
20
+ ## Shell
21
+
22
+ Open a shell. No brainer
23
+
24
+ ## Execute touch
25
+
26
+ Do touch tmp/restart.txt
27
+
28
+ # Conclusion
29
+
30
+ Hope this helps. If not, then I probably have no idea what I'm talking about and it's best just to move along and forget this ever happened.
31
+
data/spec/spec.opts ADDED
@@ -0,0 +1 @@
1
+ --colour
@@ -0,0 +1,17 @@
1
+ begin
2
+ require 'spec'
3
+ rescue LoadError
4
+ require 'rubygems' unless ENV['NO_RUBYGEMS']
5
+ gem 'rspec'
6
+ require 'spec'
7
+ end
8
+
9
+ $:.unshift(File.dirname(__FILE__) + '/../lib')
10
+ require 'tendersync'
11
+
12
+ Spec::Runner.configure do |config|
13
+
14
+ config.mock_with :mocha
15
+
16
+ end
17
+
@@ -0,0 +1,58 @@
1
+ require File.dirname(__FILE__) + '/spec_helper.rb'
2
+
3
+ describe Tendersync::Document do
4
+
5
+
6
+ before do
7
+ @doc_source = File.read("spec/fixtures/passenger_restart_issues")
8
+ end
9
+
10
+ it "should generate an index" do
11
+ index = Tendersync::Document.new
12
+ doc = Tendersync::Document.load("doc", StringIO.new(@doc_source))
13
+ Tendersync::Document.stubs(:each).yields(doc)
14
+ index.refresh_index
15
+ puts index.to_s
16
+ index.body.should =~ /baba/
17
+ end
18
+
19
+ it "should load from a file" do
20
+ doc = Tendersync::Document.load("doc", StringIO.new(@doc_source))
21
+ doc.title.should == "I updated the agent and restarted Passenger but it didn't pick up the new agent."
22
+ doc.permalink.should == 'passenger_restart_issues'
23
+ doc.keywords.should == 'passenger restart'
24
+ doc.body.should =~ /^When you update/
25
+ end
26
+ it "should print with fields" do
27
+ doc = Tendersync::Document.new :title => 'Title!', :body => "body!\nbody!"
28
+ doc.to_s.should == <<-DOC.gsub(/^\s+/,'')
29
+ ---------------------------- title ----------------------------
30
+ Title!
31
+ ---------------------------- body ----------------------------
32
+ body!\nbody!
33
+ DOC
34
+ end
35
+
36
+ it "should load from a form" do
37
+ fields = { 'faq[title]' => 'title!', 'faq[body]' => "body by\nbill"}.collect do | key, value |
38
+ WWW::Mechanize::Form::Field.new(key, value)
39
+ end
40
+ form = stub(:action => '/faqs/123/edit', :fields => fields)
41
+ doc = Tendersync::Document.from_form("doc", form)
42
+ doc.title.should == "title!"
43
+ doc.document_id.should == '123'
44
+ doc.body.should == "body by\nbill"
45
+ doc.to_s.should == <<EOF.gsub(/^ */,'')
46
+ ---------------------------- section ----------------------------
47
+ doc
48
+ ---------------------------- document_id ----------------------------
49
+ 123
50
+ ---------------------------- title ----------------------------
51
+ title!
52
+ ---------------------------- body ----------------------------
53
+ body by
54
+ bill
55
+ EOF
56
+ end
57
+ end
58
+
@@ -0,0 +1,26 @@
1
+ require File.dirname(__FILE__) + '/spec_helper.rb'
2
+
3
+ describe Tendersync::Runner do
4
+
5
+ before do
6
+ Tendersync::Runner.any_instance.stubs(:save_config_file)
7
+ end
8
+
9
+ it "should process no args" do
10
+ begin
11
+ Tendersync::Runner.new []
12
+ rescue Tendersync::Runner::Error => e
13
+ e.message.should match(/Please enter a/)
14
+ end
15
+ end
16
+
17
+ it "should process no args" do
18
+ begin
19
+ Tendersync::Runner.new []
20
+ rescue Tendersync::Runner::Error => e
21
+ e.message.should match(/Please enter a/)
22
+ end
23
+ end
24
+
25
+
26
+ end
@@ -0,0 +1,12 @@
1
+ require File.dirname(__FILE__) + '/spec_helper.rb'
2
+
3
+ describe Tendersync::Session do
4
+
5
+ before do
6
+
7
+ end
8
+
9
+ it "should login"
10
+ it "should get all sections"
11
+
12
+ end
data/tasks/rspec.rake ADDED
@@ -0,0 +1,21 @@
1
+ begin
2
+ require 'spec'
3
+ rescue LoadError
4
+ require 'rubygems' unless ENV['NO_RUBYGEMS']
5
+ require 'spec'
6
+ end
7
+ begin
8
+ require 'spec/rake/spectask'
9
+ rescue LoadError
10
+ puts <<-EOS
11
+ To use rspec for testing you must install rspec gem:
12
+ gem install rspec
13
+ EOS
14
+ exit(0)
15
+ end
16
+
17
+ desc "Run the specs under spec/models"
18
+ Spec::Rake::SpecTask.new do |t|
19
+ t.spec_opts = ['--options', "spec/spec.opts"]
20
+ t.spec_files = FileList['spec/**/*_spec.rb']
21
+ end
@@ -0,0 +1,39 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = %q{tendersync}
5
+ s.version = "1.0.2"
6
+
7
+ s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
8
+ s.authors = ["Bill Kayser"]
9
+ s.date = %q{2009-08-15}
10
+ s.default_executable = %q{tendersync}
11
+ s.description = %q{Tendersync is a utility for syncing files from ENTP's Tender site for managing customer facing documentation. It can be used to pull and push documents to a local repository as well as create indexes for each documentation section.
12
+ }
13
+ s.email = %q{bkayser@newrelic.com}
14
+ s.executables = ["tendersync"]
15
+ s.extra_rdoc_files = ["bin/tendersync", "lib/tendersync/document.rb", "lib/tendersync/runner.rb", "lib/tendersync/session.rb", "lib/tendersync/tendersync.rb", "lib/tendersync.rb", "README.md", "tasks/rspec.rake"]
16
+ s.files = ["bin/tendersync", "config/website.yml.sample", "History.txt", "lib/tendersync/document.rb", "lib/tendersync/runner.rb", "lib/tendersync/session.rb", "lib/tendersync/tendersync.rb", "lib/tendersync.rb", "Manifest", "Rakefile", "README.md", "script/console", "script/destroy", "script/generate", "script/txt2html", "spec/fixtures/passenger_restart_issues", "spec/spec.opts", "spec/spec_helper.rb", "spec/tendersync_document_spec.rb", "spec/tendersync_session_spec.rb", "spec/tendersync_spec.rb", "tasks/rspec.rake", "website/index.html", "website/index.txt", "website/javascripts/rounded_corners_lite.inc.js", "website/stylesheets/screen.css", "website/template.html.erb", "tendersync.gemspec"]
17
+ s.homepage = %q{http://www.github.com/newrelic/tendersync}
18
+ s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Tendersync", "--main", "README.md"]
19
+ s.require_paths = ["lib"]
20
+ s.rubyforge_project = %q{newrelic}
21
+ s.rubygems_version = %q{1.3.4}
22
+ s.summary = %q{Utility for syncing and indexing files from ENTP's Tender site.}
23
+
24
+ if s.respond_to? :specification_version then
25
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
26
+ s.specification_version = 3
27
+
28
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
29
+ s.add_runtime_dependency(%q<mechanize>, [">= 0.9.3"])
30
+ s.add_development_dependency(%q<newgem>, [">= 1.4.1"])
31
+ else
32
+ s.add_dependency(%q<mechanize>, [">= 0.9.3"])
33
+ s.add_dependency(%q<newgem>, [">= 1.4.1"])
34
+ end
35
+ else
36
+ s.add_dependency(%q<mechanize>, [">= 0.9.3"])
37
+ s.add_dependency(%q<newgem>, [">= 1.4.1"])
38
+ end
39
+ end
@@ -0,0 +1,11 @@
1
+ <html>
2
+ <head>
3
+ <meta http-equiv="Content-type" content="text/html; charset=utf-8">
4
+ <title>tendersync</title>
5
+
6
+ </head>
7
+ <body id="body">
8
+ <p>This page has not yet been created for RubyGem <code>tendersync</code></p>
9
+ <p>To the developer: To generate it, update website/index.txt and run the rake task <code>website</code> to generate this <code>index.html</code> file.</p>
10
+ </body>
11
+ </html>
data/website/index.txt ADDED
@@ -0,0 +1,81 @@
1
+ h1. tendersync
2
+
3
+
4
+ h2. What
5
+
6
+
7
+ h2. Installing
8
+
9
+ <pre syntax="ruby">sudo gem install tendersync</pre>
10
+
11
+ h2. The basics
12
+
13
+
14
+ h2. Demonstration of usage
15
+
16
+
17
+
18
+ h2. Forum
19
+
20
+ "http://groups.google.com/group/tendersync":http://groups.google.com/group/tendersync
21
+
22
+ TODO - create Google Group - tendersync
23
+
24
+ h2. How to submit patches
25
+
26
+ Read the "8 steps for fixing other people's code":http://drnicwilliams.com/2007/06/01/8-steps-for-fixing-other-peoples-code/ and for section "8b: Submit patch to Google Groups":http://drnicwilliams.com/2007/06/01/8-steps-for-fixing-other-peoples-code/#8b-google-groups, use the Google Group above.
27
+
28
+ TODO - pick SVN or Git instructions
29
+
30
+ The trunk repository is <code>svn://rubyforge.org/var/svn/tendersync/trunk</code> for anonymous access.
31
+
32
+ OOOORRRR
33
+
34
+ You can fetch the source from either:
35
+
36
+ <% if rubyforge_project_id %>
37
+
38
+ * rubyforge: "http://rubyforge.org/scm/?group_id=<%= rubyforge_project_id %>":http://rubyforge.org/scm/?group_id=<%= rubyforge_project_id %>
39
+
40
+ <pre>git clone git://rubyforge.org/tendersync.git</pre>
41
+
42
+ <% else %>
43
+
44
+ * rubyforge: MISSING IN ACTION
45
+
46
+ TODO - You can not created a RubyForge project, OR have not run <code>rubyforge config</code>
47
+ yet to refresh your local rubyforge data with this projects' id information.
48
+
49
+ When you do this, this message will magically disappear!
50
+
51
+ Or you can hack website/index.txt and make it all go away!!
52
+
53
+ <% end %>
54
+
55
+ * github: "http://github.com/GITHUB_USERNAME/tendersync/tree/master":http://github.com/GITHUB_USERNAME/tendersync/tree/master
56
+
57
+ <pre>git clone git://github.com/GITHUB_USERNAME/tendersync.git</pre>
58
+
59
+
60
+ TODO - add "github_username: username" to ~/.rubyforge/user-config.yml and newgem will reuse it for future projects.
61
+
62
+
63
+ * gitorious: "git://gitorious.org/tendersync/mainline.git":git://gitorious.org/tendersync/mainline.git
64
+
65
+ <pre>git clone git://gitorious.org/tendersync/mainline.git</pre>
66
+
67
+ h3. Build and test instructions
68
+
69
+ <pre>cd tendersync
70
+ rake test
71
+ rake install_gem</pre>
72
+
73
+
74
+ h2. License
75
+
76
+ This code is free to use under the terms of the MIT license.
77
+
78
+ h2. Contact
79
+
80
+ Comments are welcome. Send an email to "FIXME full name":mailto:bkayser@newrelic.com via the "forum":http://groups.google.com/group/tendersync
81
+