wtnabe-shlauncher 0.0.2 → 0.0.3
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/Rakefile +1 -1
- data/lib/tractor.rb +2 -2
- data/templates/ChangeLog +4 -0
- data/templates/README +30 -0
- data/templates/Rakefile +77 -0
- data/templates/bin/shlauncher +20 -0
- data/templates/lib/shlauncher.rb +127 -0
- metadata +12 -4
data/Rakefile
CHANGED
data/lib/tractor.rb
CHANGED
@@ -5,7 +5,7 @@ require 'fileutils'
|
|
5
5
|
require 'erb'
|
6
6
|
|
7
7
|
class Shlauncher_Tractor
|
8
|
-
VERSION = "0.0.
|
8
|
+
VERSION = "0.0.3"
|
9
9
|
|
10
10
|
include FileUtils::Verbose
|
11
11
|
|
@@ -33,7 +33,7 @@ class Shlauncher_Tractor
|
|
33
33
|
end
|
34
34
|
|
35
35
|
def deploy_template
|
36
|
-
cp_r( File.expand_path( File.dirname( __FILE__ ) + '/../
|
36
|
+
cp_r( File.expand_path( File.dirname( __FILE__ ) + '/../templates/' ),
|
37
37
|
launcher_dir )
|
38
38
|
Dir.chdir( launcher_dir ) {
|
39
39
|
mkdir( 'script' )
|
data/templates/ChangeLog
ADDED
data/templates/README
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
|
2
|
+
= <%=launcher%>
|
3
|
+
|
4
|
+
|
5
|
+
== Description
|
6
|
+
|
7
|
+
<%=description%>
|
8
|
+
|
9
|
+
== Installation
|
10
|
+
|
11
|
+
=== Archive Installation
|
12
|
+
|
13
|
+
rake install
|
14
|
+
|
15
|
+
=== Gem Installation
|
16
|
+
|
17
|
+
gem install <%=launcher%>
|
18
|
+
|
19
|
+
|
20
|
+
== Features/Problems
|
21
|
+
|
22
|
+
|
23
|
+
== Synopsis
|
24
|
+
|
25
|
+
|
26
|
+
== Copyright
|
27
|
+
|
28
|
+
Author:: <%=author%> <<%=email%>>
|
29
|
+
Copyright:: Copyright (c) <%=Time.now.strftime("%Y")%> <%=author%>
|
30
|
+
License::
|
data/templates/Rakefile
ADDED
@@ -0,0 +1,77 @@
|
|
1
|
+
# -*- mode: ruby -*-
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'rake'
|
5
|
+
require 'rake/clean'
|
6
|
+
require 'rake/packagetask'
|
7
|
+
require 'rake/gempackagetask'
|
8
|
+
require 'fileutils'
|
9
|
+
require 'lib/shlauncher'
|
10
|
+
include FileUtils
|
11
|
+
|
12
|
+
NAME = "<%=launcher%>"
|
13
|
+
AUTHOR = "<%=author%>"
|
14
|
+
EMAIL = "<%=email%>"
|
15
|
+
DESCRIPTION = "<%=description%>"
|
16
|
+
BIN_FILES = %w( <%=launcher%> )
|
17
|
+
|
18
|
+
VERS = '0.0.1'
|
19
|
+
REV = File.read(".svn/entries")[/committed-rev="(d+)"/, 1] rescue nil
|
20
|
+
CLEAN.include ['**/.*.sw?', '*.gem', '.config']
|
21
|
+
|
22
|
+
task :default do
|
23
|
+
app = Rake.application
|
24
|
+
app.options.show_task_pattern = Regexp.new('')
|
25
|
+
app.display_tasks_and_comments
|
26
|
+
end
|
27
|
+
|
28
|
+
task :package => [:clean]
|
29
|
+
|
30
|
+
spec = Gem::Specification.new do |s|
|
31
|
+
s.name = NAME
|
32
|
+
s.version = VERS
|
33
|
+
s.platform = Gem::Platform::RUBY
|
34
|
+
s.has_rdoc = false
|
35
|
+
s.summary = DESCRIPTION
|
36
|
+
s.description = DESCRIPTION
|
37
|
+
s.author = AUTHOR
|
38
|
+
s.email = EMAIL
|
39
|
+
s.executables = BIN_FILES
|
40
|
+
s.bindir = "bin"
|
41
|
+
s.require_path = "lib"
|
42
|
+
s.homepage = ""
|
43
|
+
s.rubyforge_project = ""
|
44
|
+
#s.autorequire = ""
|
45
|
+
|
46
|
+
s.add_dependency('rake', '>= 0')
|
47
|
+
#s.required_ruby_version = '>= 1.8.2'
|
48
|
+
|
49
|
+
s.files = %w(README ChangeLog Rakefile) +
|
50
|
+
Dir.glob("{bin,doc,etc,lib,script}/**/*")
|
51
|
+
|
52
|
+
end
|
53
|
+
|
54
|
+
Rake::GemPackageTask.new(spec) do |p|
|
55
|
+
p.need_tar = true
|
56
|
+
p.gem_spec = spec
|
57
|
+
end
|
58
|
+
|
59
|
+
task :install do
|
60
|
+
name = "#{NAME}-#{VERS}.gem"
|
61
|
+
sh %{rake package}
|
62
|
+
sh %{sudo gem install pkg/#{name}}
|
63
|
+
end
|
64
|
+
|
65
|
+
task :uninstall => [:clean] do
|
66
|
+
sh %{sudo gem uninstall #{NAME}}
|
67
|
+
end
|
68
|
+
|
69
|
+
desc 'Show information about the gem.'
|
70
|
+
task :debug_gem do
|
71
|
+
puts spec.to_ruby
|
72
|
+
end
|
73
|
+
|
74
|
+
desc 'Update gem spec'
|
75
|
+
task :gemspec do
|
76
|
+
open("#{NAME}.gemspec", 'w').write spec.to_ruby
|
77
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
#! /usr/bin/env rake -f
|
2
|
+
# -*- mode: ruby; coding: utf-8 -*-
|
3
|
+
|
4
|
+
require File.dirname( __FILE__ ) + '/../lib/shlauncher'
|
5
|
+
|
6
|
+
launcher = Shlauncher.new( File.dirname( __FILE__ ) + '/../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
|
@@ -0,0 +1,127 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
|
3
|
+
class Shlauncher
|
4
|
+
VERSION = '0.0.1'
|
5
|
+
|
6
|
+
LINEBREAK = /(?:\r\n|[\r\n])/
|
7
|
+
IGNORE_PATTERNS = %w( *~ *.bak CVS .svn )
|
8
|
+
|
9
|
+
def initialize( script_path = nil )
|
10
|
+
if ( script_path and File.directory?( script_path ) )
|
11
|
+
@script_path = File.expand_path( script_path )
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def launch( task )
|
16
|
+
command = File.join( script_path, command_path( task ) )
|
17
|
+
if ( File.directory?( command ) )
|
18
|
+
tasks( command_path( task ) ).each { |t|
|
19
|
+
launch( t )
|
20
|
+
}
|
21
|
+
else
|
22
|
+
system( command )
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def commands_ignored( path = nil )
|
27
|
+
base = ( path ) ? File.join( script_path, path ) : script_path
|
28
|
+
|
29
|
+
cmds = []
|
30
|
+
IGNORE_PATTERNS.each { |p|
|
31
|
+
Dir.chdir( base ) {
|
32
|
+
a = Dir.glob( p )
|
33
|
+
cmds += a if a.is_a?( Array )
|
34
|
+
}
|
35
|
+
}
|
36
|
+
|
37
|
+
return cmds.uniq
|
38
|
+
end
|
39
|
+
|
40
|
+
def tasks( path = nil )
|
41
|
+
base = ( path ) ? File.join( script_path, path ) : script_path
|
42
|
+
|
43
|
+
tasks = nil
|
44
|
+
Dir.chdir( base ) {
|
45
|
+
tasks = Dir.glob( '*' ).map { |f|
|
46
|
+
if ( File.directory?( f ) )
|
47
|
+
[f, tasks( (( path ) ? File.join( path, f ) : f) )]
|
48
|
+
elsif ( File.executable?( f ) and
|
49
|
+
!commands_ignored( path ).include?( f ) )
|
50
|
+
( path ) ? task( File.join( path, f ) ) : f
|
51
|
+
else
|
52
|
+
nil
|
53
|
+
end
|
54
|
+
}.compact.flatten.sort
|
55
|
+
}
|
56
|
+
|
57
|
+
return tasks
|
58
|
+
end
|
59
|
+
|
60
|
+
#
|
61
|
+
# extract first comment block
|
62
|
+
#
|
63
|
+
# * read only #-style comment
|
64
|
+
# * ignore shebang and local vars defining lines
|
65
|
+
# * ignore all after body started ( even #-style comment )
|
66
|
+
#
|
67
|
+
def desc( task )
|
68
|
+
command = command_path( task )
|
69
|
+
file = File.join( script_path, command )
|
70
|
+
if ( File.exist?( file ) and File.readable?( file ) )
|
71
|
+
if ( File.directory?( file ) )
|
72
|
+
"exec all tasks in scope `#{task}'"
|
73
|
+
else
|
74
|
+
body_started = false
|
75
|
+
File.open( file ).read.split( LINEBREAK ).map { |line|
|
76
|
+
if ( shebang_or_localvar_line?( line ) or empty_line?( line ) or
|
77
|
+
body_started )
|
78
|
+
nil
|
79
|
+
else
|
80
|
+
if ( not_comment_line?( line ) )
|
81
|
+
body_started = true
|
82
|
+
nil
|
83
|
+
else
|
84
|
+
line.sub( /\A#\s*/, '' )
|
85
|
+
end
|
86
|
+
end
|
87
|
+
}.compact.map { |e|
|
88
|
+
( e.size > 0 ) ? e : nil
|
89
|
+
}.compact.join( ", " )
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
def command_path( task )
|
95
|
+
return task.gsub( /:/, '/' )
|
96
|
+
end
|
97
|
+
|
98
|
+
def task( command_path )
|
99
|
+
return command_path.gsub( /\//, ':' )
|
100
|
+
end
|
101
|
+
|
102
|
+
def script_path
|
103
|
+
if ( !@script_path )
|
104
|
+
@script_path = File.expand_path( File.dirname( __FILE__ ) + '/../script' )
|
105
|
+
end
|
106
|
+
|
107
|
+
return @script_path
|
108
|
+
end
|
109
|
+
|
110
|
+
def shebang_or_localvar_line?( line )
|
111
|
+
return ( /\A#!/ =~ line or /\A#\s*(-\*-.+:.+-\*-|vim:)/ =~ line )
|
112
|
+
end
|
113
|
+
|
114
|
+
def empty_line?( line )
|
115
|
+
return ( /[^\s]/ !~ line )
|
116
|
+
end
|
117
|
+
|
118
|
+
def not_comment_line?( line )
|
119
|
+
return ( /\A\s*#/ !~ line )
|
120
|
+
end
|
121
|
+
end
|
122
|
+
|
123
|
+
module Rake
|
124
|
+
class Application
|
125
|
+
attr_accessor :name
|
126
|
+
end
|
127
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: wtnabe-shlauncher
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- wtnabe
|
@@ -49,8 +49,16 @@ files:
|
|
49
49
|
- test/shlauncher_test.rb
|
50
50
|
- test/tractor_test.rb
|
51
51
|
- lib/tractor.rb
|
52
|
-
|
52
|
+
- templates/bin
|
53
|
+
- templates/bin/shlauncher
|
54
|
+
- templates/ChangeLog
|
55
|
+
- templates/lib
|
56
|
+
- templates/lib/shlauncher.rb
|
57
|
+
- templates/Rakefile
|
58
|
+
- templates/README
|
59
|
+
has_rdoc: true
|
53
60
|
homepage: ""
|
61
|
+
licenses:
|
54
62
|
post_install_message:
|
55
63
|
rdoc_options:
|
56
64
|
- --title
|
@@ -82,9 +90,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
82
90
|
requirements: []
|
83
91
|
|
84
92
|
rubyforge_project: ""
|
85
|
-
rubygems_version: 1.
|
93
|
+
rubygems_version: 1.3.5
|
86
94
|
signing_key:
|
87
|
-
specification_version:
|
95
|
+
specification_version: 2
|
88
96
|
summary: Scaffold your custom launcher. Launch from your shell script ( and also Ruby script ) collection.
|
89
97
|
test_files:
|
90
98
|
- test/shlauncher_test.rb
|