wtnabe-shlauncher 0.0.1

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/ChangeLog ADDED
@@ -0,0 +1,4 @@
1
+ == 0.0.1 / 2009-08-27
2
+
3
+ * initial release
4
+
data/README.doc ADDED
@@ -0,0 +1,62 @@
1
+
2
+ = Shlauncher - A shell script launcher
3
+
4
+ Scaffold your custom launcher. Launch from your shell script ( and also Ruby script ) collection.
5
+
6
+ == Installation
7
+
8
+ === Archive Installation
9
+
10
+ rake install
11
+
12
+ === Gem Installation
13
+
14
+ gem install wtnabe-shlauncher
15
+
16
+ == Features/Problems
17
+
18
+ * scaffold launcher ( by `tractor' command )
19
+ * collect scripts in script/ directory and list up as task
20
+ * exec all tasks in some scope
21
+ * generate gem
22
+
23
+ == Synopsis
24
+
25
+ Scaffold your launcher.
26
+
27
+ $ tractor LAUNCHER_NAME
28
+
29
+ Put your script into script/ directory and make executable.
30
+
31
+ $ cd LAUNCHER_NAME
32
+ $ ./bin/LAUNCHER_NAME
33
+ $ echo '# script sample' > script/sample
34
+ $ chmod a+x script/sample
35
+
36
+ Run your launcher.
37
+
38
+ $ ./bin/LAUNCHER_NAME
39
+
40
+ LAUNCHER_NAME sample # script sample
41
+
42
+ Generate gem from your launcher.
43
+
44
+ $ rake gem
45
+ $ ls pkg
46
+
47
+ LAUNCHER_NAME-0.0.1.gem
48
+
49
+ == Thanks
50
+
51
+ `Cutagem' inspires and be helpful to this product.
52
+
53
+ * http://github.com/genki/cutagem/tree/master
54
+ * http://cutagem.rubyforge.org/
55
+
56
+ Thank you, cho45 and genki !
57
+
58
+ == Copyright
59
+
60
+ Author:: wtnabe <wtnabe@gmail.com>
61
+ Copyright:: Copyright (c) 2009 wtnabe
62
+ License:: Two-claused BSD
data/Rakefile ADDED
@@ -0,0 +1,147 @@
1
+ # -*- mode: ruby -*-
2
+
3
+ require 'rubygems'
4
+ require 'rake'
5
+ require 'rake/clean'
6
+ require 'rake/testtask'
7
+ require 'rake/packagetask'
8
+ require 'rake/gempackagetask'
9
+ require 'rake/rdoctask'
10
+ require 'rake/contrib/rubyforgepublisher'
11
+ require 'rake/contrib/sshpublisher'
12
+ require 'fileutils'
13
+ require 'lib/tractor'
14
+ require 'template/lib/shlauncher'
15
+ include FileUtils
16
+
17
+ NAME = "shlauncher"
18
+ AUTHOR = "wtnabe"
19
+ EMAIL = "wtnabe@gmail.com"
20
+ DESCRIPTION = "A shell script launcher"
21
+ RUBYFORGE_PROJECT = ""
22
+ HOMEPATH = ""
23
+ BIN_FILES = %w( tractor )
24
+
25
+ VERS = Shlauncher_Tractor::VERSION
26
+ REV = File.read(".svn/entries")[/committed-rev="(d+)"/, 1] rescue nil
27
+ CLEAN.include ['**/.*.sw?', '*.gem', '.config']
28
+ RDOC_OPTS = [
29
+ '--title', "#{NAME} documentation",
30
+ "--charset", "utf-8",
31
+ "--opname", "index.html",
32
+ "--line-numbers",
33
+ "--main", "README.doc",
34
+ "--inline-source",
35
+ ]
36
+
37
+ task :default => [:test]
38
+ task :package => [:clean]
39
+
40
+ Rake::TestTask.new("test") do |t|
41
+ t.libs << "test"
42
+ t.pattern = "test/**/*_test.rb"
43
+ t.verbose = true
44
+ end
45
+
46
+ spec = Gem::Specification.new do |s|
47
+ s.name = NAME
48
+ s.version = VERS
49
+ s.platform = Gem::Platform::RUBY
50
+ s.has_rdoc = true
51
+ s.extra_rdoc_files = ["README.doc", "ChangeLog"]
52
+ s.rdoc_options += RDOC_OPTS + ['--exclude', '^(examples|extras)/']
53
+ s.summary = "Scaffold your custom launcher. Launch from your shell script ( and also Ruby script ) collection."
54
+ s.description = DESCRIPTION
55
+ s.author = AUTHOR
56
+ s.email = EMAIL
57
+ s.homepage = HOMEPATH
58
+ s.executables = BIN_FILES
59
+ s.rubyforge_project = RUBYFORGE_PROJECT
60
+ s.bindir = "bin"
61
+ s.require_path = "lib"
62
+ #s.autorequire = ""
63
+ s.test_files = Dir["test/*_test.rb"]
64
+
65
+ s.add_dependency('rake', '>= 0')
66
+ #s.required_ruby_version = '>= 1.8.2'
67
+
68
+ s.files = %w(README.doc ChangeLog Rakefile) +
69
+ Dir.glob("{bin,doc,test,lib,templates,generator,extras,website,script}/**/*") +
70
+ Dir.glob("ext/**/*.{h,c,rb}") +
71
+ Dir.glob("examples/**/*.rb") +
72
+ Dir.glob("tools/*.rb") +
73
+ Dir.glob("rails/*.rb")
74
+
75
+ s.extensions = FileList["ext/**/extconf.rb"].to_a
76
+ end
77
+
78
+ Rake::GemPackageTask.new(spec) do |p|
79
+ p.need_tar = true
80
+ p.gem_spec = spec
81
+ end
82
+
83
+ task :install do
84
+ name = "#{NAME}-#{VERS}.gem"
85
+ sh %{rake package}
86
+ sh %{sudo gem install pkg/#{name}}
87
+ end
88
+
89
+ task :uninstall => [:clean] do
90
+ sh %{sudo gem uninstall #{NAME}}
91
+ end
92
+
93
+
94
+ Rake::RDocTask.new do |rdoc|
95
+ rdoc.rdoc_dir = 'html'
96
+ rdoc.options += RDOC_OPTS
97
+ rdoc.template = "resh"
98
+ #rdoc.template = "#{ENV['template']}.rb" if ENV['template']
99
+ if ENV['DOC_FILES']
100
+ rdoc.rdoc_files.include(ENV['DOC_FILES'].split(/,\s*/))
101
+ else
102
+ rdoc.rdoc_files.include('README.doc', 'ChangeLog')
103
+ rdoc.rdoc_files.include('lib/**/*.rb')
104
+ rdoc.rdoc_files.include('ext/**/*.c')
105
+ end
106
+ end
107
+
108
+ desc "Publish to RubyForge"
109
+ task :rubyforge => [:rdoc, :package] do
110
+ require 'rubyforge'
111
+ Rake::RubyForgePublisher.new(RUBYFORGE_PROJECT, 'watanabe').upload
112
+ end
113
+
114
+ desc 'Package and upload the release to rubyforge.'
115
+ task :release => [:clean, :package] do |t|
116
+ v = ENV["VERSION"] or abort "Must supply VERSION=x.y.z"
117
+ abort "Versions don't match #{v} vs #{VERS}" unless v == VERS
118
+ pkg = "pkg/#{NAME}-#{VERS}"
119
+
120
+ require 'rubyforge'
121
+ rf = RubyForge.new.configure
122
+ puts "Logging in"
123
+ rf.login
124
+
125
+ c = rf.userconfig
126
+ # c["release_notes"] = description if description
127
+ # c["release_changes"] = changes if changes
128
+ c["preformatted"] = true
129
+
130
+ files = [
131
+ "#{pkg}.tgz",
132
+ "#{pkg}.gem"
133
+ ].compact
134
+
135
+ puts "Releasing #{NAME} v. #{VERS}"
136
+ rf.add_release RUBYFORGE_PROJECT, NAME, VERS, *files
137
+ end
138
+
139
+ desc 'Show information about the gem.'
140
+ task :debug_gem do
141
+ puts spec.to_ruby
142
+ end
143
+
144
+ desc 'Update gem spec'
145
+ task :gemspec do
146
+ open("#{NAME}.gemspec", 'w').write spec.to_ruby
147
+ end
@@ -0,0 +1,20 @@
1
+ #! /usr/bin/env rake -f
2
+ # -*- mode: ruby; coding: utf-8 -*-
3
+
4
+ require File.dirname( __FILE__ ) + '/../template/lib/shlauncher'
5
+
6
+ launcher = Shlauncher.new( File.dirname( __FILE__ ) + '/../test/script' )
7
+
8
+ launcher.tasks.each { |t|
9
+ desc launcher.desc( t )
10
+ task t do
11
+ launcher.launch( t )
12
+ end
13
+ }
14
+
15
+ task :default do
16
+ app = Rake.application
17
+ app.name = File.basename( __FILE__ )
18
+ app.options.show_task_pattern = Regexp.new('')
19
+ app.display_tasks_and_comments
20
+ end
data/bin/tractor ADDED
@@ -0,0 +1,5 @@
1
+ #! /usr/bin/env ruby
2
+
3
+ require File.dirname( __FILE__ ) + '/../lib/tractor'
4
+
5
+ Shlauncher_Tractor.new(ARGV).run
data/lib/tractor.rb ADDED
@@ -0,0 +1,87 @@
1
+ # -*- mode: ruby; coding: utf-8 -*-
2
+
3
+ require 'optparse'
4
+ require 'fileutils'
5
+ require 'erb'
6
+
7
+ class Shlauncher_Tractor
8
+ VERSION = "0.0.1"
9
+
10
+ include FileUtils::Verbose
11
+
12
+ def initialize( argv )
13
+ @argv = argv
14
+ @launcher = nil
15
+ @email = nil
16
+ @author = nil
17
+ @description = nil
18
+ end
19
+ attr_reader :launcher, :email, :author, :description
20
+
21
+ def run
22
+ @launcher = parse_args
23
+ if ( File.exist?( launcher_dir ) )
24
+ puts "'#{launcher}' directory already existed."
25
+ else
26
+ deploy_template
27
+ rewrite_template
28
+ end
29
+ end
30
+
31
+ def launcher_dir
32
+ return File.join( Dir.pwd, launcher )
33
+ end
34
+
35
+ def deploy_template
36
+ cp_r( File.expand_path( File.dirname( __FILE__ ) + '/../template/' ),
37
+ launcher_dir )
38
+ Dir.chdir( launcher_dir ) {
39
+ mkdir( 'script' )
40
+ mv( 'bin/shlauncher', "bin/#{launcher}" )
41
+ }
42
+ end
43
+
44
+ def rewrite_template
45
+ Dir.chdir( launcher_dir ) {
46
+ %w( Rakefile Changelog README ).each { |file|
47
+ open( file, 'r+' ) { |f|
48
+ erb = ERB.new( f.read )
49
+ f.rewind
50
+ f.truncate( 0 )
51
+ f.puts erb.result( binding )
52
+ }
53
+ puts "rewrited #{file}"
54
+ }
55
+ }
56
+ end
57
+
58
+ def parse_args
59
+ app = File.basename( $0 )
60
+ opt = OptionParser.new { |parser|
61
+ parser.version = VERSION
62
+ parser.banner =<<EOD
63
+ #{app} #{VERSION}
64
+
65
+ Usage: #{app} LAUNCHER_NAME
66
+ EOD
67
+ parser.on( '-e', '--email ADDR' ) { |email|
68
+ @email = email
69
+ }
70
+ parser.on( '-a', '--author NAME' ) { |author|
71
+ @author = author
72
+ }
73
+ parser.on( '-d', '--description DESC' ) { |desc|
74
+ @description = desc
75
+ }
76
+ }
77
+
78
+ rest_args = opt.parse!( @argv )
79
+ if ( rest_args.size > 0 )
80
+ return rest_args.first
81
+ else
82
+ puts opt.help
83
+ exit
84
+ end
85
+ end
86
+
87
+ end
File without changes
@@ -0,0 +1,12 @@
1
+ #! /bin/sh
2
+ # -*- mode: sh -*-
3
+
4
+ #
5
+ # just example
6
+ #
7
+ # Usage: example
8
+ #
9
+
10
+ echo "foo"
11
+
12
+ # thx
@@ -0,0 +1,5 @@
1
+ #! /bin/sh
2
+
3
+ # desc is here
4
+
5
+ echo "bar"
@@ -0,0 +1,5 @@
1
+ #! /bin/sh
2
+
3
+ # null script
4
+
5
+ echo "baz"
@@ -0,0 +1,59 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ require "test/unit"
4
+ require File.dirname(__FILE__) + '/../template/lib/shlauncher'
5
+
6
+ class ShlauncherTest < Test::Unit::TestCase
7
+ def setup
8
+ @obj = Shlauncher.new( File.dirname( __FILE__ ) + '/script' )
9
+ end
10
+
11
+ def test_tasks
12
+ assert( @obj.tasks == %w( example foo foo:bar foo:baz ) )
13
+ end
14
+
15
+ def test_commands_ignored
16
+ assert( %w( example~ example.bak ) )
17
+ end
18
+
19
+ def test_desc
20
+ assert( @obj.desc( 'example' ) == 'just example, Usage: example' )
21
+ end
22
+
23
+ def test_command_path
24
+ assert( @obj.command_path( 'abc' ) == 'abc' )
25
+ assert( @obj.command_path( 'foo:bar' ) == 'foo/bar' )
26
+ assert( @obj.command_path( 'foo/bar' ) == 'foo/bar' )
27
+ end
28
+
29
+ def test_task
30
+ assert( @obj.task( 'abc' ) == 'abc' )
31
+ assert( @obj.task( 'foo/bar' ) == 'foo:bar' )
32
+ assert( @obj.task( 'foo//bar' ) == 'foo::bar' )
33
+ assert( @obj.task( 'foo:bar' ) == 'foo:bar' )
34
+ end
35
+
36
+ def test_script_path
37
+ assert( @obj.script_path == File.expand_path( File.dirname( __FILE__ ) ) + '/script' )
38
+ end
39
+
40
+ def test_shebang_or_localvar_line?
41
+ assert( @obj.shebang_or_localvar_line?( '#! /bin/sh' ) )
42
+ assert( @obj.shebang_or_localvar_line?( '# -*- mode: ruby -*-' ) )
43
+ assert( @obj.shebang_or_localvar_line?( '# -*- coding: utf-8 -*-' ) )
44
+ assert( !@obj.shebang_or_localvar_line?( 'abc' ) )
45
+ assert( !@obj.shebang_or_localvar_line?( '# regular comment' ) )
46
+ end
47
+
48
+ def test_empty_line?
49
+ assert( @obj.empty_line?( '' ) )
50
+ assert( @obj.empty_line?( ' ' ) )
51
+ assert( !@obj.empty_line?( '#' ) )
52
+ end
53
+
54
+ def test_not_comment_line?
55
+ assert( @obj.not_comment_line?( 'abc' ) )
56
+ assert( !@obj.not_comment_line?( ' # ' ) )
57
+ assert( !@obj.not_comment_line?( '# ' ) )
58
+ end
59
+ end
@@ -0,0 +1,10 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ require "test/unit"
4
+ require File.dirname(__FILE__) + '/../lib/tractor'
5
+
6
+ class Shlauncher_TractorTest < Test::Unit::TestCase
7
+ def test_Shlauncher_Tractor
8
+ assert( true )
9
+ end
10
+ end
metadata ADDED
@@ -0,0 +1,88 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: wtnabe-shlauncher
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - wtnabe
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-08-27 00:00:00 -07:00
13
+ default_executable: tractor
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: rake
17
+ type: :runtime
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: "0"
24
+ version:
25
+ description: A shell script launcher
26
+ email: wtnabe@gmail.com
27
+ executables:
28
+ - tractor
29
+ extensions: []
30
+
31
+ extra_rdoc_files:
32
+ - README.doc
33
+ - ChangeLog
34
+ files:
35
+ - README.doc
36
+ - ChangeLog
37
+ - Rakefile
38
+ - bin/shlauncher_test
39
+ - bin/tractor
40
+ - test/script
41
+ - test/script/example
42
+ - test/script/foo
43
+ - test/script/foo/bar
44
+ - test/script/foo/baz
45
+ - test/script/README
46
+ - test/shlauncher_test.rb
47
+ - test/tractor_test.rb
48
+ - lib/tractor.rb
49
+ has_rdoc: false
50
+ homepage: ""
51
+ post_install_message:
52
+ rdoc_options:
53
+ - --title
54
+ - shlauncher documentation
55
+ - --charset
56
+ - utf-8
57
+ - --opname
58
+ - index.html
59
+ - --line-numbers
60
+ - --main
61
+ - README.doc
62
+ - --inline-source
63
+ - --exclude
64
+ - ^(examples|extras)/
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.2.0
83
+ signing_key:
84
+ specification_version: 3
85
+ summary: Scaffold your custom launcher. Launch from your shell script ( and also Ruby script ) collection.
86
+ test_files:
87
+ - test/shlauncher_test.rb
88
+ - test/tractor_test.rb