technomancy-gitjour 6.3.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.
data/History.txt ADDED
@@ -0,0 +1,4 @@
1
+ == 0.0.1 2008-05-29
2
+
3
+ * 1 major enhancement:
4
+ * Initial release
data/License.txt ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2008 Chad Fowler, Evan Phoenix, Rich Kilmer
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.
data/Manifest.txt ADDED
@@ -0,0 +1,25 @@
1
+ bin/gitjour
2
+ History.txt
3
+ License.txt
4
+ Manifest.txt
5
+ README.txt
6
+ Rakefile
7
+ config/hoe.rb
8
+ config/requirements.rb
9
+ lib/gitjour.rb
10
+ lib/gitjour/application.rb
11
+ lib/gitjour/version.rb
12
+ script/destroy
13
+ script/generate
14
+ script/txt2html
15
+ setup.rb
16
+ tasks/deployment.rake
17
+ tasks/environment.rake
18
+ tasks/website.rake
19
+ test/test_gitjour.rb
20
+ test/test_helper.rb
21
+ website/index.html
22
+ website/index.txt
23
+ website/javascripts/rounded_corners_lite.inc.js
24
+ website/stylesheets/screen.css
25
+ website/template.rhtml
data/README.txt ADDED
@@ -0,0 +1,8 @@
1
+ README
2
+
3
+ DEVELOPMENT
4
+
5
+ How to test from the console:
6
+
7
+ irb -r 'lib/gitjour/application'
8
+ > Gitjour::Application.run "list"
data/Rakefile ADDED
@@ -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 }
data/bin/gitjour ADDED
@@ -0,0 +1,9 @@
1
+ #!/usr/bin/env ruby
2
+ require 'rubygems'
3
+ require 'gitjour'
4
+
5
+ trap "INT" do
6
+ exit!
7
+ end
8
+
9
+ Gitjour::Application.run(*ARGV)
data/config/hoe.rb ADDED
@@ -0,0 +1,71 @@
1
+ require 'gitjour/version'
2
+
3
+ AUTHOR = ['Chad Fowler', 'Rich Kilmer', 'Evan Phoenix'] # can also be an array of Authors
4
+ EMAIL = "chad@chadfowler.com"
5
+ DESCRIPTION = "Automates DNSSD-powered serving and cloning of git repositories."
6
+ GEM_NAME = 'gitjour' # what ppl will type to install your gem
7
+ RUBYFORGE_PROJECT = 'gitjour' # The unix name for your project
8
+ HOMEPATH = "http://#{RUBYFORGE_PROJECT}.rubyforge.org"
9
+ DOWNLOAD_PATH = "http://rubyforge.org/projects/#{RUBYFORGE_PROJECT}"
10
+
11
+ @config_file = "~/.rubyforge/user-config.yml"
12
+ @config = nil
13
+ RUBYFORGE_USERNAME = "chadfowler"
14
+ def rubyforge_username
15
+ unless @config
16
+ begin
17
+ @config = YAML.load(File.read(File.expand_path(@config_file)))
18
+ rescue
19
+ puts <<-EOS
20
+ ERROR: No rubyforge config file found: #{@config_file}
21
+ Run 'rubyforge setup' to prepare your env for access to Rubyforge
22
+ - See http://newgem.rubyforge.org/rubyforge.html for more details
23
+ EOS
24
+ exit
25
+ end
26
+ end
27
+ RUBYFORGE_USERNAME.replace @config["username"]
28
+ end
29
+
30
+
31
+ REV = nil
32
+ # UNCOMMENT IF REQUIRED:
33
+ # REV = `svn info`.each {|line| if line =~ /^Revision:/ then k,v = line.split(': '); break v.chomp; else next; end} rescue nil
34
+ VERS = Gitjour::VERSION::STRING + (REV ? ".#{REV}" : "")
35
+ RDOC_OPTS = ['--quiet', '--title', 'gitjour documentation',
36
+ "--opname", "index.html",
37
+ "--line-numbers",
38
+ "--main", "README",
39
+ "--inline-source"]
40
+
41
+ class Hoe
42
+ def extra_deps
43
+ @extra_deps.reject! { |x| Array(x).first == 'hoe' }
44
+ @extra_deps
45
+ end
46
+ end
47
+
48
+ # Generate all the Rake tasks
49
+ # Run 'rake -T' to see list of generated tasks (from gem root directory)
50
+ hoe = Hoe.new(GEM_NAME, VERS) do |p|
51
+ p.author = AUTHOR
52
+ p.description = DESCRIPTION
53
+ p.email = EMAIL
54
+ p.summary = DESCRIPTION
55
+ p.url = HOMEPATH
56
+ p.rubyforge_name = RUBYFORGE_PROJECT if RUBYFORGE_PROJECT
57
+ p.test_globs = ["test/**/test_*.rb"]
58
+ p.clean_globs |= ['**/.*.sw?', '*.gem', '.config', '**/.DS_Store'] #An array of file patterns to delete on clean.
59
+ p.extra_deps = ['dnssd']
60
+ # == Optional
61
+ p.changes = p.paragraphs_of("History.txt", 0..1).join("\n\n")
62
+ #p.extra_deps = [] # An array of rubygem dependencies [name, version], e.g. [ ['active_support', '>= 1.3.1'] ]
63
+
64
+ #p.spec_extras = {} # A hash of extra values to set in the gemspec.
65
+ p.extra_dev_deps = ['newgem']
66
+ end
67
+
68
+ CHANGES = hoe.paragraphs_of('History.txt', 0..1).join("\\n\\n")
69
+ PATH = (RUBYFORGE_PROJECT == GEM_NAME) ? RUBYFORGE_PROJECT : "#{RUBYFORGE_PROJECT}/#{GEM_NAME}"
70
+ hoe.remote_rdoc_dir = File.join(PATH.gsub(/^#{RUBYFORGE_PROJECT}\/?/,''), 'rdoc')
71
+ hoe.rsync_args = '-av --delete --ignore-errors'
@@ -0,0 +1,17 @@
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]))
16
+
17
+ require 'gitjour'
@@ -0,0 +1,183 @@
1
+ require 'rubygems'
2
+ require 'dnssd'
3
+ require 'set'
4
+ require 'gitjour/version'
5
+
6
+ Thread.abort_on_exception = true
7
+
8
+ module Gitjour
9
+ GitService = Struct.new(:name, :host, :port, :description)
10
+
11
+ class Application
12
+
13
+ class << self
14
+ def run(*args)
15
+ case args.shift
16
+ when "list"
17
+ list
18
+ when "clone"
19
+ clone(*args)
20
+ when "serve"
21
+ serve(*args)
22
+ when "remote"
23
+ remote(*args)
24
+ else
25
+ help
26
+ end
27
+ end
28
+
29
+ private
30
+ def list
31
+ service_list.each do |service|
32
+ puts "=== #{service.name} on #{service.host}:#{service.port} ==="
33
+ puts " gitjour clone #{service.name}"
34
+ if service.description != '' && service.description !~ /^Unnamed repository/
35
+ puts " #{service.description}"
36
+ end
37
+ puts
38
+ end
39
+ end
40
+
41
+ def clone(repository_name, *rest)
42
+ dir = rest.shift || repository_name
43
+ if File.exists?(dir)
44
+ exit_with! "ERROR: Clone directory '#{dir}' already exists."
45
+ end
46
+
47
+ puts "Cloning '#{repository_name}' into directory '#{dir}'..."
48
+
49
+ unless service = locate_repo(repository_name)
50
+ exit_with! "ERROR: Unable to find project named '#{repository_name}'"
51
+ end
52
+
53
+ puts "Connecting to #{service.host}:#{service.port}"
54
+
55
+ system "git clone git://#{service.host}:#{service.port}/ #{dir}"
56
+ end
57
+
58
+ def remote(repository_name, *rest)
59
+ dir = rest.shift || repository_name
60
+ service = locate_repo repository_name
61
+ system "git remote add #{dir} git://#{service.host}:#{service.port}/"
62
+ end
63
+
64
+ def serve(path=Dir.pwd, *rest)
65
+ path = File.expand_path(path)
66
+ name = rest.shift || File.basename(path)
67
+ port = rest.shift || 9418
68
+
69
+ # If the name starts with ^, then don't apply the prefix
70
+ if name[0] == ?^
71
+ name = name[1..-1]
72
+ else
73
+ prefix = `git config --get gitjour.prefix`.chomp
74
+ prefix = ENV["USER"] if prefix.empty?
75
+ name = [prefix, name].compact.join("-")
76
+ end
77
+
78
+ if File.exists?("#{path}/.git")
79
+ announce_repo(path, name, port.to_i)
80
+ else
81
+ Dir["#{path}/*"].each do |dir|
82
+ if File.directory?(dir)
83
+ name = File.basename(dir)
84
+ announce_repo(dir, name, 9418)
85
+ end
86
+ end
87
+ end
88
+
89
+ `git-daemon --verbose --export-all --port=#{port} --base-path=#{path} --base-path-relaxed`
90
+ end
91
+
92
+ def help
93
+ puts "Gitjour #{Gitjour::VERSION::STRING}"
94
+ puts "Serve up and use git repositories via Bonjour/DNSSD."
95
+ puts "\nUsage: gitjour <command> [args]"
96
+ puts
97
+ puts " list"
98
+ puts " Lists available repositories."
99
+ puts
100
+ puts " clone <project> [<directory>]"
101
+ puts " Clone a gitjour served repository."
102
+ puts
103
+ puts " serve <path_to_project> [<name_of_project>] [<port>] or"
104
+ puts " <path_to_projects>"
105
+ puts " Serve up the current directory or projects via gitjour."
106
+ puts
107
+ puts " The name of your project is automatically prefixed with"
108
+ puts " `git config --get gitjour.prefix` or your username (preference"
109
+ puts " in that order). If you don't want a prefix, put a ^ on the front"
110
+ puts " of the name_of_project (the ^ is removed before announcing)."
111
+ puts
112
+ puts " remote <project> [<name>]"
113
+ puts " Add a Bonjour remote into your current repository."
114
+ puts " Optionally pass name to not use pwd."
115
+ puts
116
+ end
117
+
118
+ def exit_with!(message)
119
+ STDERR.puts message
120
+ exit!
121
+ end
122
+
123
+ class Done < RuntimeError; end
124
+
125
+ def discover(timeout=5)
126
+ waiting_thread = Thread.current
127
+
128
+ dns = DNSSD.browse "_git._tcp" do |reply|
129
+ DNSSD.resolve reply.name, reply.type, reply.domain do |resolve_reply|
130
+ service = GitService.new(reply.name,
131
+ resolve_reply.target,
132
+ resolve_reply.port,
133
+ resolve_reply.text_record['description'].to_s)
134
+ begin
135
+ yield service
136
+ rescue Done
137
+ waiting_thread.run
138
+ end
139
+ end
140
+ end
141
+
142
+ puts "Gathering for up to #{timeout} seconds..."
143
+ sleep timeout
144
+ dns.stop
145
+ end
146
+
147
+ def locate_repo(name)
148
+ found = nil
149
+
150
+ discover do |obj|
151
+ if obj.name == name
152
+ found = obj
153
+ raise Done
154
+ end
155
+ end
156
+
157
+ return found
158
+ end
159
+
160
+ def service_list
161
+ list = Set.new
162
+ discover { |obj| list << obj }
163
+
164
+ return list
165
+ end
166
+
167
+ def announce_repo(path, name, port)
168
+ return unless File.exists?("#{path}/.git")
169
+
170
+ tr = DNSSD::TextRecord.new
171
+ tr['description'] = File.read("#{path}/.git/description") rescue "a git project"
172
+
173
+ DNSSD.register(name, "_git._tcp", 'local', port, tr.encode) do |rr|
174
+ puts "Registered #{name} on port #{port}. Starting service."
175
+ end
176
+ end
177
+
178
+ end
179
+ end
180
+ end
181
+
182
+
183
+
@@ -0,0 +1,9 @@
1
+ module Gitjour #:nodoc:
2
+ module VERSION #:nodoc:
3
+ MAJOR = 6
4
+ MINOR = 3
5
+ TINY = 0
6
+
7
+ STRING = [MAJOR, MINOR, TINY].join('.')
8
+ end
9
+ end
data/lib/gitjour.rb ADDED
@@ -0,0 +1 @@
1
+ require File.dirname(__FILE__) + '/gitjour/application'
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,74 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'rubygems'
4
+ begin
5
+ require 'newgem'
6
+ rescue LoadError
7
+ puts "\n\nGenerating the website requires the newgem RubyGem"
8
+ puts "Install: gem install newgem\n\n"
9
+ exit(1)
10
+ end
11
+ require 'redcloth'
12
+ require 'syntax/convertors/html'
13
+ require 'erb'
14
+ require File.dirname(__FILE__) + '/../lib/gitjour/version.rb'
15
+
16
+ version = Gitjour::VERSION::STRING
17
+ download = 'http://rubyforge.org/projects/gitjour'
18
+
19
+ class Fixnum
20
+ def ordinal
21
+ # teens
22
+ return 'th' if (10..19).include?(self % 100)
23
+ # others
24
+ case self % 10
25
+ when 1: return 'st'
26
+ when 2: return 'nd'
27
+ when 3: return 'rd'
28
+ else return 'th'
29
+ end
30
+ end
31
+ end
32
+
33
+ class Time
34
+ def pretty
35
+ return "#{mday}#{mday.ordinal} #{strftime('%B')} #{year}"
36
+ end
37
+ end
38
+
39
+ def convert_syntax(syntax, source)
40
+ return Syntax::Convertors::HTML.for_syntax(syntax).convert(source).gsub(%r!^<pre>|</pre>$!,'')
41
+ end
42
+
43
+ if ARGV.length >= 1
44
+ src, template = ARGV
45
+ template ||= File.join(File.dirname(__FILE__), '/../website/template.rhtml')
46
+
47
+ else
48
+ puts("Usage: #{File.split($0).last} source.txt [template.rhtml] > output.html")
49
+ exit!
50
+ end
51
+
52
+ template = ERB.new(File.open(template).read)
53
+
54
+ title = nil
55
+ body = nil
56
+ File.open(src) do |fsrc|
57
+ title_text = fsrc.readline
58
+ body_text = fsrc.read
59
+ syntax_items = []
60
+ body_text.gsub!(%r!<(pre|code)[^>]*?syntax=['"]([^'"]+)[^>]*>(.*?)</\1>!m){
61
+ ident = syntax_items.length
62
+ element, syntax, source = $1, $2, $3
63
+ syntax_items << "<#{element} class='syntax'>#{convert_syntax(syntax, source)}</#{element}>"
64
+ "syntax-temp-#{ident}"
65
+ }
66
+ title = RedCloth.new(title_text).to_html.gsub(%r!<.*?>!,'').strip
67
+ body = RedCloth.new(body_text).to_html
68
+ body.gsub!(%r!(?:<pre><code>)?syntax-temp-(\d+)(?:</code></pre>)?!){ syntax_items[$1.to_i] }
69
+ end
70
+ stat = File.stat(src)
71
+ created = stat.ctime
72
+ modified = stat.mtime
73
+
74
+ $stdout << template.result(binding)