ratch 0.4.1 → 1.0.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/COPYING +17 -669
- data/HISTORY +6 -0
- data/MANIFEST +36 -0
- data/METADATA +14 -0
- data/NEWS +7 -0
- data/README +67 -17
- data/bin/ratch +5 -78
- data/demo/tryme-task.ratch +12 -0
- data/demo/tryme1.ratch +6 -0
- data/lib/ratch/core_ext.rb +6 -0
- data/lib/ratch/core_ext/facets.rb +1 -0
- data/lib/ratch/core_ext/filetest.rb +52 -0
- data/lib/ratch/core_ext/object.rb +8 -0
- data/lib/ratch/core_ext/pathname.rb +38 -0
- data/lib/ratch/core_ext/string.rb +44 -0
- data/lib/ratch/{dsl/console.rb → core_ext/to_console.rb} +2 -76
- data/lib/ratch/core_ext/to_list.rb +29 -0
- data/lib/ratch/dsl.rb +494 -49
- data/lib/ratch/index.rb +4 -0
- data/lib/ratch/io.rb +116 -0
- data/lib/ratch/pathglob.rb +73 -0
- data/lib/ratch/plugin.rb +55 -0
- data/lib/ratch/runmode.rb +69 -0
- data/lib/ratch/script.rb +52 -0
- data/lib/ratch/service.rb +33 -0
- data/lib/ratch/task.rb +249 -0
- data/lib/ratch/task2.rb +298 -0
- data/test/README +1 -0
- data/test/test_helper.rb +4 -0
- data/test/test_task.rb +46 -0
- metadata +90 -150
- data/CHANGES +0 -22
- data/TODO +0 -2
- data/bin/lt +0 -56
- data/bin/ludo +0 -14
- data/bin/manifest +0 -451
- data/bin/ratch-find +0 -21
- data/demo/WILMA +0 -1
- data/demo/XR +0 -9
- data/demo/lib/foo/foo.rb +0 -7
- data/demo/p.rb +0 -9
- data/demo/r.rb +0 -6
- data/demo/t.rb +0 -3
- data/demo/task/config.yaml +0 -4
- data/demo/task/one +0 -6
- data/demo/task/simplebuild +0 -15
- data/demo/task/stats +0 -4
- data/demo/task/task +0 -6
- data/demo/task/tryme +0 -10
- data/lib/ratch/dsl/argv.rb +0 -112
- data/lib/ratch/dsl/batch.rb +0 -232
- data/lib/ratch/dsl/build.rb +0 -174
- data/lib/ratch/dsl/email.rb +0 -108
- data/lib/ratch/dsl/file.rb +0 -205
- data/lib/ratch/dsl/meta.rb +0 -125
- data/lib/ratch/dsl/options.rb +0 -98
- data/lib/ratch/dsl/setup.rb +0 -124
- data/lib/ratch/dsl/sign.rb +0 -243
- data/lib/ratch/dsl/stage.rb +0 -147
- data/lib/ratch/dsl/task.rb +0 -139
- data/lib/ratch/dsl/upload.rb +0 -436
- data/lib/ratch/dsl/zip.rb +0 -59
- data/lib/ratch/extra/email.rb +0 -5
- data/lib/ratch/extra/stage.rb +0 -5
- data/lib/ratch/extra/zip.rb +0 -5
- data/lib/ratch/manager.rb +0 -53
- data/lib/ratch/manifest.rb +0 -540
- data/lib/ratch/metadata/information.rb +0 -258
- data/lib/ratch/metadata/package.rb +0 -108
- data/lib/ratch/metadata/project.rb +0 -523
- data/lib/ratch/metadata/release.rb +0 -108
- data/lib/ratch/support/errors.rb +0 -4
- data/lib/ratch/support/filename.rb +0 -18
- data/lib/ratch/support/filetest.rb +0 -29
- data/lib/ratch/toolset/ruby/announce +0 -224
- data/lib/ratch/toolset/ruby/compile +0 -49
- data/lib/ratch/toolset/ruby/install +0 -77
- data/lib/ratch/toolset/ruby/notes +0 -185
- data/lib/ratch/toolset/ruby/pack/gem +0 -93
- data/lib/ratch/toolset/ruby/pack/tgz +0 -46
- data/lib/ratch/toolset/ruby/pack/zip +0 -46
- data/lib/ratch/toolset/ruby/publish +0 -57
- data/lib/ratch/toolset/ruby/release +0 -8
- data/lib/ratch/toolset/ruby/setup +0 -1616
- data/lib/ratch/toolset/ruby/stamp +0 -33
- data/lib/ratch/toolset/ruby/stats +0 -138
- data/lib/ratch/toolset/ruby/test/crosstest +0 -305
- data/lib/ratch/toolset/ruby/test/extest +0 -129
- data/lib/ratch/toolset/ruby/test/isotest +0 -293
- data/lib/ratch/toolset/ruby/test/load +0 -39
- data/lib/ratch/toolset/ruby/test/loadtest +0 -28
- data/lib/ratch/toolset/ruby/test/syntax +0 -29
- data/lib/ratch/toolset/ruby/test/test +0 -26
- data/lib/ratch/toolset/sandbox/query +0 -11
- data/man/ratch.man +0 -73
- data/meta/MANIFEST +0 -130
- data/meta/config.yaml +0 -9
- data/meta/icli.yaml +0 -16
- data/meta/project.yaml +0 -20
- data/meta/ratch.roll +0 -2
- data/meta/xProjectInfo +0 -41
- data/task/clobber/package +0 -10
- data/task/man +0 -14
- data/task/publish +0 -57
- data/task/release +0 -9
- data/task/setup +0 -1616
- data/task/stats +0 -138
data/lib/ratch/dsl/stage.rb
DELETED
|
@@ -1,147 +0,0 @@
|
|
|
1
|
-
# = TITLE:
|
|
2
|
-
#
|
|
3
|
-
# Stage DSL
|
|
4
|
-
#
|
|
5
|
-
# = COPYING:
|
|
6
|
-
#
|
|
7
|
-
# Copyright (c) 2007 Psi T Corp.
|
|
8
|
-
#
|
|
9
|
-
# This file is part of the ProUtils' Box program.
|
|
10
|
-
#
|
|
11
|
-
# Box is free software: you can redistribute it and/or modify
|
|
12
|
-
# it under the terms of the GNU General Public License as published by
|
|
13
|
-
# the Free Software Foundation, either version 3 of the License, or
|
|
14
|
-
# (at your option) any later version.
|
|
15
|
-
#
|
|
16
|
-
# Box is distributed in the hope that it will be useful,
|
|
17
|
-
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
18
|
-
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
19
|
-
# GNU General Public License for more details.
|
|
20
|
-
#
|
|
21
|
-
# You should have received a copy of the GNU General Public License
|
|
22
|
-
# along with Box. If not, see <http://www.gnu.org/licenses/>.
|
|
23
|
-
|
|
24
|
-
module Ratch
|
|
25
|
-
module Dsl
|
|
26
|
-
|
|
27
|
-
# Stage package by hard linking included files to a stage directory.
|
|
28
|
-
|
|
29
|
-
module Stage
|
|
30
|
-
|
|
31
|
-
# Stage package.
|
|
32
|
-
#
|
|
33
|
-
# stage Stage directory.
|
|
34
|
-
# filelist Files to link to stage.
|
|
35
|
-
|
|
36
|
-
def stage(stage, filelist)
|
|
37
|
-
stage_link(stage, filelist)
|
|
38
|
-
stage_manifest(stage)
|
|
39
|
-
return stage
|
|
40
|
-
end
|
|
41
|
-
|
|
42
|
-
# Prepare stage directory.
|
|
43
|
-
|
|
44
|
-
def stage_link(stage_directory, files)
|
|
45
|
-
return stage_directory if dryrun? # Don't link to stage if dryrun.
|
|
46
|
-
|
|
47
|
-
stage_clear(stage_directory)
|
|
48
|
-
mkdir_p(stage_directory) #dir = File.expand_path(stage)
|
|
49
|
-
|
|
50
|
-
#files = package.filelist #+ [package.manifest_file]
|
|
51
|
-
|
|
52
|
-
# TODO Dryrun test here or before folder creation?
|
|
53
|
-
files.each do |f| # Link files into staging area.
|
|
54
|
-
file = File.join(stage_directory, f)
|
|
55
|
-
if File.directory?(f)
|
|
56
|
-
mkdir_p(file)
|
|
57
|
-
else
|
|
58
|
-
unless File.exist?(file) and File.mtime(file) >= File.mtime(f)
|
|
59
|
-
ln(f, file) #safe_ln ?
|
|
60
|
-
end
|
|
61
|
-
end
|
|
62
|
-
end
|
|
63
|
-
return stage_directory
|
|
64
|
-
end
|
|
65
|
-
|
|
66
|
-
# Clear old stage, if any.
|
|
67
|
-
|
|
68
|
-
def stage_clear(stage_directory)
|
|
69
|
-
if File.directory?(stage_directory) # Ensure existance of staging area
|
|
70
|
-
#raise(OverwriteError, stage_directory) unless force?
|
|
71
|
-
rm_r(stage_directory)
|
|
72
|
-
end
|
|
73
|
-
end
|
|
74
|
-
|
|
75
|
-
# Create manifest for stage directory.
|
|
76
|
-
# TODO Do this programatically rather then via shell.
|
|
77
|
-
|
|
78
|
-
def stage_manifest(stage_directory)
|
|
79
|
-
#cd(stage_directory) do
|
|
80
|
-
# sh 'manifest up'
|
|
81
|
-
#end
|
|
82
|
-
end
|
|
83
|
-
|
|
84
|
-
end
|
|
85
|
-
|
|
86
|
-
end
|
|
87
|
-
end
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
#
|
|
94
|
-
# # Build packages.
|
|
95
|
-
# # TODO Move this to Manager ?
|
|
96
|
-
#
|
|
97
|
-
# def generate_packages
|
|
98
|
-
# package_files = formats.collect do |format|
|
|
99
|
-
# #format = clean_type(format)
|
|
100
|
-
# say '' if format == 'gem' # FIXME This is here b/c Gems outputs on it's own.
|
|
101
|
-
# file = create_package(format)
|
|
102
|
-
# unless dryrun? or (format == 'gem')
|
|
103
|
-
# report_package_built(format, file) if file
|
|
104
|
-
# end
|
|
105
|
-
# file
|
|
106
|
-
# end
|
|
107
|
-
# report_packaging_complete(package_files.size)
|
|
108
|
-
# end
|
|
109
|
-
#
|
|
110
|
-
# # Create package.
|
|
111
|
-
#
|
|
112
|
-
# def create_package(type)
|
|
113
|
-
# package.format = type
|
|
114
|
-
#
|
|
115
|
-
# builder_class = FormatBuilder.registry[type]
|
|
116
|
-
# builder = builder_class.new(package, stage_directory, options)
|
|
117
|
-
# file = builder.build
|
|
118
|
-
#
|
|
119
|
-
# transfer(file) unless dryrun?
|
|
120
|
-
#
|
|
121
|
-
# return file
|
|
122
|
-
# end
|
|
123
|
-
#
|
|
124
|
-
# # Transfer package file to storage dir.
|
|
125
|
-
#
|
|
126
|
-
# def transfer(file)
|
|
127
|
-
# dest = File.join(store, File.basename(file)) # move to store, unless already there
|
|
128
|
-
# dest = File.expand_path(dest)
|
|
129
|
-
# mv(file, store) unless file == dest
|
|
130
|
-
# end
|
|
131
|
-
#
|
|
132
|
-
# # Report that a package has been built.
|
|
133
|
-
#
|
|
134
|
-
# def report_package_built(type, file)
|
|
135
|
-
# r = ''
|
|
136
|
-
# r << "\n Successfully built #{type}"
|
|
137
|
-
# r << "\n Name: #{package.name}"
|
|
138
|
-
# r << "\n Version: #{package.version}"
|
|
139
|
-
# r << "\n File: #{File.basename(file)}"
|
|
140
|
-
# say r
|
|
141
|
-
# end
|
|
142
|
-
#
|
|
143
|
-
# # Report that packaging is complete.
|
|
144
|
-
#
|
|
145
|
-
# def report_packaging_complete(size)
|
|
146
|
-
# say "\nSuccessfully built #{size} packages at #{store}/."
|
|
147
|
-
# end
|
data/lib/ratch/dsl/task.rb
DELETED
|
@@ -1,139 +0,0 @@
|
|
|
1
|
-
# = TITLE:
|
|
2
|
-
#
|
|
3
|
-
# Task DSL
|
|
4
|
-
#
|
|
5
|
-
# = COPYING:
|
|
6
|
-
#
|
|
7
|
-
# Copyright (c) 2007 Psi T Corp.
|
|
8
|
-
#
|
|
9
|
-
# This file is part of the ProUtils' Ratch program.
|
|
10
|
-
#
|
|
11
|
-
# Ratch is free software: you can redistribute it and/or modify
|
|
12
|
-
# it under the terms of the GNU General Public License as published by
|
|
13
|
-
# the Free Software Foundation, either version 3 of the License, or
|
|
14
|
-
# (at your option) any later version.
|
|
15
|
-
#
|
|
16
|
-
# Ratch is distributed in the hope that it will be useful,
|
|
17
|
-
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
18
|
-
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
19
|
-
# GNU General Public License for more details.
|
|
20
|
-
#
|
|
21
|
-
# You should have received a copy of the GNU General Public License
|
|
22
|
-
# along with Ratch. If not, see <http://www.gnu.org/licenses/>.
|
|
23
|
-
|
|
24
|
-
module Ratch
|
|
25
|
-
module Dsl
|
|
26
|
-
|
|
27
|
-
module Tasks
|
|
28
|
-
|
|
29
|
-
# Define main task.
|
|
30
|
-
|
|
31
|
-
def main(name, &block)
|
|
32
|
-
name, deps, block = *parse_task_dependencies(name, &block)
|
|
33
|
-
define_main(name, *deps, &block)
|
|
34
|
-
end
|
|
35
|
-
|
|
36
|
-
# Define a task.
|
|
37
|
-
|
|
38
|
-
def task(name, &block)
|
|
39
|
-
name, deps, block = *parse_task_dependencies(name, &block)
|
|
40
|
-
define_task(name, *deps, &block)
|
|
41
|
-
end
|
|
42
|
-
|
|
43
|
-
# Run a task.
|
|
44
|
-
|
|
45
|
-
def run(name, arguments=nil)
|
|
46
|
-
task_plan(name).each{ |name| tasks[name].call }
|
|
47
|
-
end
|
|
48
|
-
|
|
49
|
-
private
|
|
50
|
-
|
|
51
|
-
def tasks ; @tasks ||= {} ; end
|
|
52
|
-
|
|
53
|
-
def main_task ; @main ; end
|
|
54
|
-
|
|
55
|
-
#
|
|
56
|
-
|
|
57
|
-
def parse_task_dependencies(name_deps, &block)
|
|
58
|
-
if Hash===name_deps
|
|
59
|
-
name = name_deps.keys[0]
|
|
60
|
-
deps = name_deps.values[0]
|
|
61
|
-
else
|
|
62
|
-
name = name_deps
|
|
63
|
-
deps = []
|
|
64
|
-
end
|
|
65
|
-
[name, deps, block]
|
|
66
|
-
end
|
|
67
|
-
|
|
68
|
-
def define_main(name=nil, *depend, &block)
|
|
69
|
-
@main = define_task(name, *depend, &block)
|
|
70
|
-
#@main = Task.new(name, *depend, &block)
|
|
71
|
-
#tasks[@main.name] = @main
|
|
72
|
-
end
|
|
73
|
-
|
|
74
|
-
def define_task(name, *depend, &block)
|
|
75
|
-
task = Task.new(name, *depend, &block)
|
|
76
|
-
tasks[task.name] = task
|
|
77
|
-
end
|
|
78
|
-
|
|
79
|
-
# Call main task.
|
|
80
|
-
#--
|
|
81
|
-
# TODO If @main is nil try task by same name a file (?)
|
|
82
|
-
# If so, be careful of infinite loop via method_missing.
|
|
83
|
-
#++
|
|
84
|
-
|
|
85
|
-
def run_main
|
|
86
|
-
return unless main_task
|
|
87
|
-
run(main_task.name)
|
|
88
|
-
end
|
|
89
|
-
|
|
90
|
-
# Prepare plan, checking for circular dependencies.
|
|
91
|
-
|
|
92
|
-
def task_plan(name, list=[])
|
|
93
|
-
if list.include?(name)
|
|
94
|
-
raise "Circular dependency #{name}."
|
|
95
|
-
end
|
|
96
|
-
if task = tasks[name]
|
|
97
|
-
task.needs.each do |need|
|
|
98
|
-
need = need.to_s
|
|
99
|
-
next if list.include?(need)
|
|
100
|
-
#@tasks[need].task_plan(need, list)
|
|
101
|
-
task_plan(need, list)
|
|
102
|
-
end
|
|
103
|
-
list << task.name
|
|
104
|
-
else
|
|
105
|
-
# TODO THIS TIES TASKS INTO BATCH, BETTER WAY?
|
|
106
|
-
if name != main_task && fname = batch?(name)
|
|
107
|
-
task = Task.new(name) do
|
|
108
|
-
batch(fname)
|
|
109
|
-
end
|
|
110
|
-
tasks[name] = task
|
|
111
|
-
list << task.name
|
|
112
|
-
else
|
|
113
|
-
abort "no task -- #{name}"
|
|
114
|
-
end
|
|
115
|
-
end
|
|
116
|
-
return list
|
|
117
|
-
end
|
|
118
|
-
|
|
119
|
-
end
|
|
120
|
-
|
|
121
|
-
# Task is a very simple store for defined actions
|
|
122
|
-
# and their prerequisites.
|
|
123
|
-
|
|
124
|
-
class Task
|
|
125
|
-
attr_reader :name, :needs, :action
|
|
126
|
-
|
|
127
|
-
def initialize(name, *needs, &action)
|
|
128
|
-
@name = name.to_s
|
|
129
|
-
@needs = needs
|
|
130
|
-
@action = action
|
|
131
|
-
end
|
|
132
|
-
|
|
133
|
-
def call
|
|
134
|
-
@action.call if @action
|
|
135
|
-
end
|
|
136
|
-
end
|
|
137
|
-
|
|
138
|
-
end
|
|
139
|
-
end
|
data/lib/ratch/dsl/upload.rb
DELETED
|
@@ -1,436 +0,0 @@
|
|
|
1
|
-
# = TITLE:
|
|
2
|
-
#
|
|
3
|
-
# Upload DSL
|
|
4
|
-
#
|
|
5
|
-
# = COPYING:
|
|
6
|
-
#
|
|
7
|
-
# Copyright (c) 2007 Psi T Corp.
|
|
8
|
-
#
|
|
9
|
-
# This file is part of the ProUtils' Ratch program.
|
|
10
|
-
#
|
|
11
|
-
# Ratch is free software: you can redistribute it and/or modify
|
|
12
|
-
# it under the terms of the GNU General Public License as published by
|
|
13
|
-
# the Free Software Foundation, either version 3 of the License, or
|
|
14
|
-
# (at your option) any later version.
|
|
15
|
-
#
|
|
16
|
-
# Ratch is distributed in the hope that it will be useful,
|
|
17
|
-
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
18
|
-
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
19
|
-
# GNU General Public License for more details.
|
|
20
|
-
#
|
|
21
|
-
# You should have received a copy of the GNU General Public License
|
|
22
|
-
# along with Ratch. If not, see <http://www.gnu.org/licenses/>.
|
|
23
|
-
#
|
|
24
|
-
# = TODO:
|
|
25
|
-
#
|
|
26
|
-
# - Incorporate password into scp and ftp ?
|
|
27
|
-
# - rsync needs --delete option
|
|
28
|
-
|
|
29
|
-
require 'openssl'
|
|
30
|
-
require 'shellwords'
|
|
31
|
-
require 'tmpdir'
|
|
32
|
-
|
|
33
|
-
require 'facets/openobject'
|
|
34
|
-
|
|
35
|
-
module Ratch
|
|
36
|
-
module Dsl
|
|
37
|
-
|
|
38
|
-
# Upload files to host. These means of uploading are current
|
|
39
|
-
# supported: ftp, sftp, scp and rsync.
|
|
40
|
-
#
|
|
41
|
-
# user Username for host.
|
|
42
|
-
# host Host server's domain name.
|
|
43
|
-
# root Document root path on host.
|
|
44
|
-
# copy Directory of files to publish, or
|
|
45
|
-
# Files to publish using from and to.
|
|
46
|
-
#
|
|
47
|
-
# dryrun If true only pretend to upload.
|
|
48
|
-
# quiet Supress all output.
|
|
49
|
-
# verbose Provide extra details.
|
|
50
|
-
#
|
|
51
|
-
# The copy parameter allows you to simply specify a file
|
|
52
|
-
# or directory which will be published to host's document
|
|
53
|
-
# root location.
|
|
54
|
-
#
|
|
55
|
-
# If you need more control over which files to publish
|
|
56
|
-
# where, you can use the copy parameter instead. Provide
|
|
57
|
-
# an array of pattern strings in the form of "{from} {to}".
|
|
58
|
-
# If the desitination is the host's document root you do
|
|
59
|
-
# not need to specify the {to} part. For example:
|
|
60
|
-
#
|
|
61
|
-
# copy = [ 'web/*', 'doc/api/* doc/api' ]
|
|
62
|
-
#
|
|
63
|
-
# The first copies the files under your project's web directory
|
|
64
|
-
# to the host's document root. The second copies your projects
|
|
65
|
-
# doc/api files to the doc/api location on the host.
|
|
66
|
-
#
|
|
67
|
-
# The internal template used for the outbound destination
|
|
68
|
-
# is 'username@host:root/'.
|
|
69
|
-
|
|
70
|
-
module Upload
|
|
71
|
-
|
|
72
|
-
module_function
|
|
73
|
-
|
|
74
|
-
#
|
|
75
|
-
# Upload via given protocol.
|
|
76
|
-
#
|
|
77
|
-
|
|
78
|
-
def upload( protocol, opts )
|
|
79
|
-
send(protocol.to_s.downcase,opts)
|
|
80
|
-
end
|
|
81
|
-
|
|
82
|
-
#
|
|
83
|
-
# Use ftp to upload files.
|
|
84
|
-
#
|
|
85
|
-
|
|
86
|
-
def ftp( keys )
|
|
87
|
-
keys = upload_parameters(keys)
|
|
88
|
-
|
|
89
|
-
# set transfer rules
|
|
90
|
-
if keys.stage
|
|
91
|
-
trans = stage_transfer(keys.stage)
|
|
92
|
-
else
|
|
93
|
-
files(keys.dir, keys.copy).each do |from|
|
|
94
|
-
trans << [from,from]
|
|
95
|
-
end
|
|
96
|
-
end
|
|
97
|
-
|
|
98
|
-
# append location of publication dir to from
|
|
99
|
-
dir = keys.dir
|
|
100
|
-
trans.collect!{ |from,to| [File.join(dir,from), to] }
|
|
101
|
-
|
|
102
|
-
if keys.dryrun
|
|
103
|
-
puts "ftp open #{keys.user}@#{keys.host}:#{keys.root}/"
|
|
104
|
-
keys.trans.each do |f, t|
|
|
105
|
-
puts "ftp put #{f} #{t}"
|
|
106
|
-
end
|
|
107
|
-
else
|
|
108
|
-
require 'net/ftp'
|
|
109
|
-
Net::FTP.open(keys.host) do |ftp|
|
|
110
|
-
ftp.login(keys.user) #password?
|
|
111
|
-
ftp.chdir(keys.root)
|
|
112
|
-
keys.trans.each do |f, t|
|
|
113
|
-
puts "ftp #{f} #{t}" unless keys.quiet
|
|
114
|
-
ftp.putbinaryfile( f, t, 1024 )
|
|
115
|
-
end
|
|
116
|
-
end
|
|
117
|
-
end
|
|
118
|
-
end
|
|
119
|
-
|
|
120
|
-
#
|
|
121
|
-
# Use sftp to upload files.
|
|
122
|
-
#
|
|
123
|
-
|
|
124
|
-
def sftp( keys )
|
|
125
|
-
keys = upload_parameters(keys)
|
|
126
|
-
|
|
127
|
-
# set transfer rules
|
|
128
|
-
if keys.stage
|
|
129
|
-
trans = stage_transfer(keys.stage)
|
|
130
|
-
else
|
|
131
|
-
files(keys.dir, keys.copy).each do |from|
|
|
132
|
-
trans << [from,from]
|
|
133
|
-
end
|
|
134
|
-
end
|
|
135
|
-
|
|
136
|
-
# append location of publication dir to from
|
|
137
|
-
dir = keys.dir
|
|
138
|
-
trans.collect!{ |from,to| [File.join(dir,from), to] }
|
|
139
|
-
|
|
140
|
-
if keys.dryrun
|
|
141
|
-
puts "sftp open #{keys.user}@#{keys.host}:#{keys.root}/"
|
|
142
|
-
keys.trans.each do |f,t|
|
|
143
|
-
puts "sftp put #{f} #{t}"
|
|
144
|
-
end
|
|
145
|
-
else
|
|
146
|
-
require 'net/sftp'
|
|
147
|
-
Net::SFTP.start(keys.host, keys.user, keys.pass) do |sftp|
|
|
148
|
-
#sftp.login( user )
|
|
149
|
-
sftp.chdir(keys.root)
|
|
150
|
-
keys.trans.each do |f,t|
|
|
151
|
-
puts "sftp #{f} #{t}" unless keys.quiet
|
|
152
|
-
sftp.put_file(f,t) #, 1024 )
|
|
153
|
-
end
|
|
154
|
-
end
|
|
155
|
-
end
|
|
156
|
-
end
|
|
157
|
-
|
|
158
|
-
#
|
|
159
|
-
# Use rsync to upload files.
|
|
160
|
-
#
|
|
161
|
-
|
|
162
|
-
def rsync( keys )
|
|
163
|
-
keys = upload_parameters(keys)
|
|
164
|
-
|
|
165
|
-
flags = []
|
|
166
|
-
flags << "-n" if keys.dryrun
|
|
167
|
-
flags << "-q" if keys.quiet
|
|
168
|
-
flags << "-v" if keys.verbose
|
|
169
|
-
flags << "--progress" unless keys.quiet
|
|
170
|
-
flags = flags.join(' ').strip
|
|
171
|
-
flags = ' ' + flags unless flags.empty?
|
|
172
|
-
|
|
173
|
-
manfile = 'Publish.txt'
|
|
174
|
-
|
|
175
|
-
if keys.stage
|
|
176
|
-
dir = stage_linkdir(keys.dir, keys.stage)
|
|
177
|
-
Dir.chdir(dir) do
|
|
178
|
-
cpy = files(keys.copy)
|
|
179
|
-
end
|
|
180
|
-
manifest = File.join(dir,manfile)
|
|
181
|
-
cmd = %{rsync#{flags} -L -arz --files-from='#{manifest}' #{dir} #{keys.user}@#{keys.host}:/#{keys.root}}
|
|
182
|
-
else
|
|
183
|
-
dir = keys.dir
|
|
184
|
-
cpy = files(dir, keys.copy)
|
|
185
|
-
manifest = File.join(dir,manfile)
|
|
186
|
-
cmd = %{rsync#{flags} -arz --files-from='#{manifest}' #{dir} #{keys.user}@#{keys.host}:/#{keys.root}}
|
|
187
|
-
end
|
|
188
|
-
|
|
189
|
-
#Dir.chdir(keys.dir) do
|
|
190
|
-
begin
|
|
191
|
-
File.open(manifest, 'w'){ |f| f << cpy.join("\n") }
|
|
192
|
-
ENV['RSYNC_PASSWORD'] = keys.pass if keys.pass
|
|
193
|
-
puts cmd unless keys.quiet
|
|
194
|
-
system cmd
|
|
195
|
-
ensure
|
|
196
|
-
ENV.delete('RSYNC_PASSWORD') if keys.pass
|
|
197
|
-
end
|
|
198
|
-
#end
|
|
199
|
-
|
|
200
|
-
end
|
|
201
|
-
|
|
202
|
-
# private (can't do b/c of module_function)
|
|
203
|
-
|
|
204
|
-
# parse publishing options.
|
|
205
|
-
|
|
206
|
-
def upload_parameters( keys )
|
|
207
|
-
keys = OpenObject.new(keys)
|
|
208
|
-
|
|
209
|
-
keys.copy = keys.copy || '**/*'
|
|
210
|
-
keys.host = keys.host || keys.domain
|
|
211
|
-
keys.user = keys.user || keys.username
|
|
212
|
-
keys.root = keys.root || '/'
|
|
213
|
-
#keys.pass = keys.pass || keys.password
|
|
214
|
-
|
|
215
|
-
# validate
|
|
216
|
-
raise ArgumentError, "missing publish parameter -- dir" unless keys.dir
|
|
217
|
-
raise ArgumentError, "missing publish parameter -- host" unless keys.host
|
|
218
|
-
raise ArgumentError, "missing publish parameter -- user" unless keys.user
|
|
219
|
-
#raise ArgumentError, "missing publish parameter -- copy" unless keys.copy
|
|
220
|
-
#raise ArgumentError, "missing publish parameter -- root" unless keys.root
|
|
221
|
-
|
|
222
|
-
keys.root = '' if keys.root.nil?
|
|
223
|
-
keys.root.sub!(/^\//,'')
|
|
224
|
-
|
|
225
|
-
if String===keys.copy and File.directory?(keys.copy)
|
|
226
|
-
copy = File.join(keys.copy, '*')
|
|
227
|
-
end
|
|
228
|
-
keys.copy = [keys.copy].flatten.compact
|
|
229
|
-
|
|
230
|
-
# trans = []
|
|
231
|
-
# keys.copy.each do |from|
|
|
232
|
-
# #from, to = *Shellwords.shellwords(c)
|
|
233
|
-
# #to = from if to.nil?
|
|
234
|
-
# #to = to[1..-1] if to[0,1] == '/'
|
|
235
|
-
# from.sub('*','**/*') unless from =~ /\*\*/
|
|
236
|
-
# files = Dir.glob(from)
|
|
237
|
-
# files.each do |f|
|
|
238
|
-
# #t = File.join(to,File.basename(f))
|
|
239
|
-
# #t = t[1..-1] if t[0,1] == '/'
|
|
240
|
-
# trans << [f,f]
|
|
241
|
-
# end
|
|
242
|
-
# end
|
|
243
|
-
# keys.trans = trans
|
|
244
|
-
|
|
245
|
-
return keys
|
|
246
|
-
end
|
|
247
|
-
|
|
248
|
-
# Put together the list of files to copy.
|
|
249
|
-
|
|
250
|
-
def files( dir, copy )
|
|
251
|
-
Dir.chdir(dir) do
|
|
252
|
-
del, add = copy.partition{ |f| /^[-]/ =~ f }
|
|
253
|
-
|
|
254
|
-
# remove - and + prefixes
|
|
255
|
-
del.collect!{ |f| f.sub(/^[-]/,'') }
|
|
256
|
-
add.collect!{ |f| f.sub(/^[+]/,'') }
|
|
257
|
-
|
|
258
|
-
#del.concat(must_exclude)
|
|
259
|
-
|
|
260
|
-
files = []
|
|
261
|
-
add.each{ |g| files += Dir.multiglob(g) }
|
|
262
|
-
del.each{ |g| files -= Dir.multiglob(g) }
|
|
263
|
-
|
|
264
|
-
files.collect!{ |f| f.sub(/^\//,'') }
|
|
265
|
-
|
|
266
|
-
return files
|
|
267
|
-
end
|
|
268
|
-
end
|
|
269
|
-
|
|
270
|
-
# Combine three part stage list into a two part from->to list.
|
|
271
|
-
#
|
|
272
|
-
# Using the stage list of three space separated fields.
|
|
273
|
-
#
|
|
274
|
-
# fromdir file todir
|
|
275
|
-
#
|
|
276
|
-
# This is used to generate a from -> to list of the form:
|
|
277
|
-
#
|
|
278
|
-
# fromdir/file todir/file
|
|
279
|
-
#
|
|
280
|
-
|
|
281
|
-
def stage_transfer( list )
|
|
282
|
-
trans = []
|
|
283
|
-
list.each do |line|
|
|
284
|
-
trans << Shellwords.shellwords(line)
|
|
285
|
-
end
|
|
286
|
-
|
|
287
|
-
trans.collect! do |from, base, to|
|
|
288
|
-
file = File.join(from,base)
|
|
289
|
-
to = File.join(to,base)
|
|
290
|
-
[from, to]
|
|
291
|
-
end
|
|
292
|
-
end
|
|
293
|
-
|
|
294
|
-
# When using stage options this will create temporary linked location.
|
|
295
|
-
|
|
296
|
-
def stage_linkdir( dir, list )
|
|
297
|
-
folder = File.join(Dir.tmpdir, 'ratchets', 'project', object_id.abs.to_s)
|
|
298
|
-
FileUtils.mkdir_p(folder)
|
|
299
|
-
|
|
300
|
-
Dir.chdir(dir) do
|
|
301
|
-
stage_transfer(list).each do |file, to|
|
|
302
|
-
link = File.join(folder,to)
|
|
303
|
-
FileUtils.ln_s(link,file)
|
|
304
|
-
end
|
|
305
|
-
end
|
|
306
|
-
|
|
307
|
-
return folder
|
|
308
|
-
end
|
|
309
|
-
|
|
310
|
-
end
|
|
311
|
-
|
|
312
|
-
end
|
|
313
|
-
end
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
=begin
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
#--
|
|
320
|
-
# SHELLS OUT! Need net/scp library to fix.
|
|
321
|
-
#++
|
|
322
|
-
|
|
323
|
-
# Use scp to upload files.
|
|
324
|
-
|
|
325
|
-
def scp( keys )
|
|
326
|
-
keys = upload_parameters(keys)
|
|
327
|
-
|
|
328
|
-
flags = []
|
|
329
|
-
flags << "-v" if keys.verbose
|
|
330
|
-
flags << "-q" if keys.quiet
|
|
331
|
-
flags = flags.join(' ').strip
|
|
332
|
-
flags = ' ' + flags unless flags.empty?
|
|
333
|
-
|
|
334
|
-
upload_stage(keys) do #|tmpdir|
|
|
335
|
-
cmd = "scp -r#{flags} * #{keys.user}@#{keys.host}:/#{keys.root}"
|
|
336
|
-
puts cmd unless keys.quiet
|
|
337
|
-
system cmd unless keys.dryrun
|
|
338
|
-
end
|
|
339
|
-
end
|
|
340
|
-
|
|
341
|
-
# Use rsync to upload files.
|
|
342
|
-
|
|
343
|
-
def rsync( keys )
|
|
344
|
-
keys = upload_parameters(keys)
|
|
345
|
-
|
|
346
|
-
flags = []
|
|
347
|
-
flags << "-n" if keys.dryrun
|
|
348
|
-
flags << "-v" if keys.verbose
|
|
349
|
-
flags << "-q" if keys.quiet
|
|
350
|
-
flags = flags.join(' ').strip
|
|
351
|
-
flags = ' ' + flags unless flags.empty?
|
|
352
|
-
|
|
353
|
-
upload_stage(keys) do #|tmpdir|
|
|
354
|
-
begin
|
|
355
|
-
ENV['RSYNC_PASSWORD'] = keys.pass if keys.pass
|
|
356
|
-
cmd = "rsync -R#{flags} -arz * #{keys.user}@#{keys.host} /#{keys.root}"
|
|
357
|
-
ensure
|
|
358
|
-
ENV.delete('RSYNC_PASSWORD') if keys.pass
|
|
359
|
-
end
|
|
360
|
-
end
|
|
361
|
-
end
|
|
362
|
-
|
|
363
|
-
# Use ftp to upload files.
|
|
364
|
-
|
|
365
|
-
def ftp( keys )
|
|
366
|
-
keys = upload_parameters(keys)
|
|
367
|
-
|
|
368
|
-
if keys.dryrun
|
|
369
|
-
puts "ftp open #{keys.user}@#{keys.host}:#{keys.root}/"
|
|
370
|
-
keys.trans.each do |f, t|
|
|
371
|
-
puts "ftp put #{f} #{t}"
|
|
372
|
-
end
|
|
373
|
-
else
|
|
374
|
-
require 'net/ftp'
|
|
375
|
-
Net::FTP.open(keys.host) do |ftp|
|
|
376
|
-
ftp.login(keys.user) #password?
|
|
377
|
-
ftp.chdir(keys.root)
|
|
378
|
-
keys.trans.each do |f, t|
|
|
379
|
-
puts "ftp #{f} #{t}" unless keys.quiet
|
|
380
|
-
ftp.putbinaryfile( f, t, 1024 )
|
|
381
|
-
end
|
|
382
|
-
end
|
|
383
|
-
end
|
|
384
|
-
end
|
|
385
|
-
|
|
386
|
-
# Use sftp to upload files.
|
|
387
|
-
|
|
388
|
-
def sftp( keys )
|
|
389
|
-
keys = upload_parameters(keys)
|
|
390
|
-
|
|
391
|
-
if keys.dryrun
|
|
392
|
-
puts "sftp open #{keys.user}@#{keys.host}:#{keys.root}/"
|
|
393
|
-
keys.trans.each do |f,t|
|
|
394
|
-
puts "sftp put #{f} #{t}"
|
|
395
|
-
end
|
|
396
|
-
else
|
|
397
|
-
require 'net/sftp'
|
|
398
|
-
Net::SFTP.start(keys.host, keys.user, keys.pass) do |sftp|
|
|
399
|
-
#sftp.login( user )
|
|
400
|
-
sftp.chdir(keys.root)
|
|
401
|
-
keys.trans.each do |f,t|
|
|
402
|
-
puts "sftp #{f} #{t}" unless keys.quiet
|
|
403
|
-
sftp.put_file(f,t) #, 1024 )
|
|
404
|
-
end
|
|
405
|
-
end
|
|
406
|
-
end
|
|
407
|
-
end
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
# Creates a stage from which the whole directory can be uploaded.
|
|
411
|
-
# This is needed for scp and rsync which have to shelled out,
|
|
412
|
-
# and can't conveniently copy one file at a time.
|
|
413
|
-
|
|
414
|
-
def upload_stage(keys) #:yield:
|
|
415
|
-
tmp = "scp_#{object_id.abs}_#{ Time.now.strftime("%Y%m%d%H%M%S")}"
|
|
416
|
-
tmpdir = File.join(Dir.tmpdir,tmp)
|
|
417
|
-
|
|
418
|
-
puts "mkdir -p #{tmpdir}" unless keys.quiet
|
|
419
|
-
FileUtils.mkdir_p(tmpdir) # go ahead and do this even if dryrun
|
|
420
|
-
|
|
421
|
-
fu = keys.dryrun ? FileUtils::DryRun : FileUtils
|
|
422
|
-
keys.trans.each do |f, t|
|
|
423
|
-
to = File.join(tmpdir, t)
|
|
424
|
-
fu.mv(f,to)
|
|
425
|
-
end
|
|
426
|
-
|
|
427
|
-
puts "cd #{tmpdir}" unless keys.quiet
|
|
428
|
-
Dir.chdir(tmpdir) do
|
|
429
|
-
yield #(tmpdir)
|
|
430
|
-
end
|
|
431
|
-
|
|
432
|
-
puts "rm -r #{tmpdir}" unless keys.quiet
|
|
433
|
-
FileUtils.rm_r(tmpdir) # now remove the temp dir
|
|
434
|
-
end
|
|
435
|
-
|
|
436
|
-
=end
|