buzzware-buzzcore 0.2.2 → 0.2.3
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/buzzcore.gemspec +1 -3
- metadata +1 -3
- data/lib/buzzcore/cap_utils.rb +0 -181
- data/lib/buzzcore/ftp_extra.rb +0 -188
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.2.
|
1
|
+
0.2.3
|
data/buzzcore.gemspec
CHANGED
@@ -5,7 +5,7 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{buzzcore}
|
8
|
-
s.version = "0.2.
|
8
|
+
s.version = "0.2.3"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["buzzware"]
|
@@ -28,12 +28,10 @@ Gem::Specification.new do |s|
|
|
28
28
|
"buzzcore.vpw",
|
29
29
|
"lib/buzzcore.rb",
|
30
30
|
"lib/buzzcore.rb",
|
31
|
-
"lib/buzzcore/cap_utils.rb",
|
32
31
|
"lib/buzzcore/config.rb",
|
33
32
|
"lib/buzzcore/database_utils.rb",
|
34
33
|
"lib/buzzcore/enum.rb",
|
35
34
|
"lib/buzzcore/extend_base_classes.rb",
|
36
|
-
"lib/buzzcore/ftp_extra.rb",
|
37
35
|
"lib/buzzcore/logging.rb",
|
38
36
|
"lib/buzzcore/misc_utils.rb",
|
39
37
|
"lib/buzzcore/require_paths.rb",
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: buzzware-buzzcore
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- buzzware
|
@@ -42,12 +42,10 @@ files:
|
|
42
42
|
- buzzcore.vpj
|
43
43
|
- buzzcore.vpw
|
44
44
|
- lib/buzzcore.rb
|
45
|
-
- lib/buzzcore/cap_utils.rb
|
46
45
|
- lib/buzzcore/config.rb
|
47
46
|
- lib/buzzcore/database_utils.rb
|
48
47
|
- lib/buzzcore/enum.rb
|
49
48
|
- lib/buzzcore/extend_base_classes.rb
|
50
|
-
- lib/buzzcore/ftp_extra.rb
|
51
49
|
- lib/buzzcore/logging.rb
|
52
50
|
- lib/buzzcore/misc_utils.rb
|
53
51
|
- lib/buzzcore/require_paths.rb
|
data/lib/buzzcore/cap_utils.rb
DELETED
@@ -1,181 +0,0 @@
|
|
1
|
-
# use "extend CapUtils" inside a task to use this
|
2
|
-
require 'buzzcore/misc_utils'
|
3
|
-
require 'buzzcore/string_utils'
|
4
|
-
require 'buzzcore/xml_utils'
|
5
|
-
require 'buzzcore/shell_extras'
|
6
|
-
require 'net/ssh'
|
7
|
-
require 'net/sftp'
|
8
|
-
|
9
|
-
module CapUtils
|
10
|
-
|
11
|
-
# upload the given local file to the remote server and set the given mode.
|
12
|
-
# 0644 is the default mode
|
13
|
-
#
|
14
|
-
# Unix file modes :
|
15
|
-
# 4: read
|
16
|
-
# 2: write
|
17
|
-
# 1: execute
|
18
|
-
# 0[owner][group][other]
|
19
|
-
def upload_file(aLocalFilePath,aRemoteFilePath,aMode = 0644)
|
20
|
-
puts "* uploading #{aLocalFilePath} to #{aRemoteFilePath}"
|
21
|
-
s = nil
|
22
|
-
File.open(aLocalFilePath, "rb") { |f| s = f.read }
|
23
|
-
put(s,aRemoteFilePath,:mode => aMode)
|
24
|
-
end
|
25
|
-
|
26
|
-
def render_template_file(aTemplateFile,aXmlConfig,aOutputFile,aMoreConfig=nil)
|
27
|
-
template = MiscUtils.string_from_file(aTemplateFile)
|
28
|
-
values = XmlUtils.read_config_values(aXmlConfig)
|
29
|
-
values = values ? values.merge(aMoreConfig || {}) : aMoreConfig
|
30
|
-
result = StringUtils.render_template(template, values)
|
31
|
-
MiscUtils.string_to_file(result, aOutputFile)
|
32
|
-
end
|
33
|
-
|
34
|
-
def get_ip
|
35
|
-
run "ifconfig eth0 |grep \"inet addr\"" do |channel,stream,data|
|
36
|
-
return data.scan(/inet addr:([0-9.]+)/).flatten.pop
|
37
|
-
end
|
38
|
-
end
|
39
|
-
|
40
|
-
# check if file exists. Relies on remote ruby
|
41
|
-
def remote_file_exists?(aPath)
|
42
|
-
remote_ruby("puts File.exists?('#{aPath}').to_s")=="true\n"
|
43
|
-
end
|
44
|
-
|
45
|
-
def remote_ruby(aRubyString)
|
46
|
-
run 'ruby -e "'+aRubyString+'"' do |channel,stream,data|
|
47
|
-
return data
|
48
|
-
end
|
49
|
-
end
|
50
|
-
|
51
|
-
def sudo_run(aString)
|
52
|
-
# as = fetch(:runner, "app")
|
53
|
-
# via = fetch(:run_method, :sudo)
|
54
|
-
# invoke_command(aString, :via => via, :as => as)
|
55
|
-
# if aUseSudo
|
56
|
-
# run "sudo "+aString
|
57
|
-
# else
|
58
|
-
run aString
|
59
|
-
# end
|
60
|
-
end
|
61
|
-
|
62
|
-
def upload_file_anywhere(aSourceFile,aDestHost,aDestUser,aDestPassword,aDestFile,aDestPort=22)
|
63
|
-
Net::SSH.start(aDestHost, aDestUser, {:port => aDestPort, :password => aDestPassword, :verbose =>Logger::DEBUG}) do |ssh|
|
64
|
-
File.open(aSourceFile, "rb") { |f| ssh.sftp.upload!(f, aDestFile) }
|
65
|
-
end
|
66
|
-
end
|
67
|
-
|
68
|
-
def branch_name_from_svn_url(aURL)
|
69
|
-
prot_domain = (aURL.scan(/[^:]+:\/\/[^\/]+\//)).first
|
70
|
-
without_domain = aURL[prot_domain.length..-1]
|
71
|
-
return 'trunk' if without_domain =~ /^trunk\//
|
72
|
-
return (without_domain.scan(/branches\/(.+?)(\/|$)/)).flatten.first
|
73
|
-
end
|
74
|
-
|
75
|
-
# give block with |aText,aStream,aState| that returns response or nil
|
76
|
-
def run_respond(aCommand)
|
77
|
-
run(aCommand) do |ch,stream,text|
|
78
|
-
ch[:state] ||= { :channel => ch }
|
79
|
-
output = yield(text,stream,ch[:state])
|
80
|
-
ch.send_data(output) if output
|
81
|
-
end
|
82
|
-
end
|
83
|
-
|
84
|
-
# pass prompt to user, and return their response
|
85
|
-
def run_prompt(aCommand)
|
86
|
-
run_respond aCommand do |text,stream,state|
|
87
|
-
Capistrano::CLI.password_prompt(text)+"\n"
|
88
|
-
end
|
89
|
-
end
|
90
|
-
|
91
|
-
def ensure_link(aTo,aFrom,aDir=nil,aUserGroup=nil)
|
92
|
-
cmd = []
|
93
|
-
cmd << "cd #{aDir}" if aDir
|
94
|
-
cmd << "#{sudo} rm -f #{aFrom}"
|
95
|
-
cmd << "#{sudo} ln -sf #{aTo} #{aFrom}"
|
96
|
-
cmd << "#{sudo} chown -h #{aUserGroup} #{aFrom}" if aUserGroup
|
97
|
-
run cmd.join(' && ')
|
98
|
-
end
|
99
|
-
|
100
|
-
|
101
|
-
def file_exists?(path)
|
102
|
-
begin
|
103
|
-
run "ls #{path}"
|
104
|
-
return true
|
105
|
-
rescue Exception => e
|
106
|
-
return false
|
107
|
-
end
|
108
|
-
end
|
109
|
-
|
110
|
-
# Used in deployment to maintain folder contents between deployments.
|
111
|
-
# Normally the shared path exists and will be linked into the release.
|
112
|
-
# If it doesn't exist and the release path does, it will be moved into the shared path
|
113
|
-
# aFolder eg. "vendor/extensions/design"
|
114
|
-
# aSharedFolder eg. "design"
|
115
|
-
def preserve_folder(aReleaseFolder,aSharedFolder)
|
116
|
-
aReleaseFolder = File.join(release_path,aReleaseFolder)
|
117
|
-
aSharedFolder = File.join(shared_path,aSharedFolder)
|
118
|
-
release_exists = file_exists?(aReleaseFolder)
|
119
|
-
shared_exists = file_exists?(aSharedFolder)
|
120
|
-
if shared_exists
|
121
|
-
run "rm -rf #{aReleaseFolder}" if release_exists
|
122
|
-
else
|
123
|
-
run "mv #{aReleaseFolder} #{aSharedFolder}" if release_exists
|
124
|
-
end
|
125
|
-
ensure_link("#{aSharedFolder}","#{aReleaseFolder}",nil,"#{user}:#{apache_user}")
|
126
|
-
end
|
127
|
-
|
128
|
-
def select_target_file(aFile)
|
129
|
-
ext = MiscUtils.file_extension(aFile,false)
|
130
|
-
no_ext = MiscUtils.file_no_extension(aFile,false)
|
131
|
-
dir = File.dirname(aFile)
|
132
|
-
run "#{sudo} mv -f #{no_ext}.#{target}.#{ext} #{aFile}"
|
133
|
-
run "#{sudo} rm -f #{no_ext}.*.#{ext}"
|
134
|
-
end
|
135
|
-
|
136
|
-
def shell(aCommandline,&aBlock)
|
137
|
-
result = block_given? ? POpen4::shell(aCommandline,nil,nil,&aBlock) : POpen4::shell(aCommandline)
|
138
|
-
return result[:stdout]
|
139
|
-
end
|
140
|
-
|
141
|
-
def run_local(aString)
|
142
|
-
`#{aString}`
|
143
|
-
end
|
144
|
-
|
145
|
-
|
146
|
-
def run_for_all(aCommand,aPath,aFilesOrDirs,aPattern=nil,aInvertPattern=false,aSudo=true)
|
147
|
-
#run "#{sudo} find . -wholename '*/.svn' -prune -o -type d -print0 |xargs -0 #{sudo} chmod 750"
|
148
|
-
#sudo find . -type f -exec echo {} \;
|
149
|
-
cmd = []
|
150
|
-
cmd << "sudo" if aSudo
|
151
|
-
cmd << "find #{aPath}"
|
152
|
-
cmd << "-wholename '#{aPattern}'" if aPattern
|
153
|
-
cmd << "-prune -o" if aInvertPattern
|
154
|
-
cmd << case aFilesOrDirs.to_s[0,1]
|
155
|
-
when 'f' then '-type f'
|
156
|
-
when 'd' then '-type d'
|
157
|
-
else ''
|
158
|
-
end
|
159
|
-
cmd << "-exec"
|
160
|
-
cmd << aCommand
|
161
|
-
cmd << '{} \;'
|
162
|
-
cmd = cmd.join(' ')
|
163
|
-
run cmd
|
164
|
-
end
|
165
|
-
|
166
|
-
# if aGroup is given, that will be the users only group
|
167
|
-
def adduser(aNewUser,aPassword,aGroup=nil)
|
168
|
-
run "#{sudo} adduser --gecos '' #{aGroup ? '--ingroup '+aGroup : ''} #{aNewUser}" do |ch, stream, out|
|
169
|
-
ch.send_data aPassword+"\n" if out =~ /UNIX password:/
|
170
|
-
end
|
171
|
-
end
|
172
|
-
|
173
|
-
def add_user_to_group(aUser,aGroup)
|
174
|
-
run "#{sudo} usermod -a -G #{aGroup} #{aUser}"
|
175
|
-
end
|
176
|
-
|
177
|
-
end
|
178
|
-
|
179
|
-
class CapUtilsClass
|
180
|
-
self.extend CapUtils
|
181
|
-
end
|
data/lib/buzzcore/ftp_extra.rb
DELETED
@@ -1,188 +0,0 @@
|
|
1
|
-
require 'net/ftp'
|
2
|
-
|
3
|
-
this_path = File.dirname(__FILE__)
|
4
|
-
require this_path+'/misc_utils'
|
5
|
-
|
6
|
-
String.class_eval do
|
7
|
-
def bite!(aValue=$/,aString=self)
|
8
|
-
if aString[0,aValue.length] == aValue
|
9
|
-
aString[0,aValue.length] = ''
|
10
|
-
return aString
|
11
|
-
else
|
12
|
-
return aString
|
13
|
-
end
|
14
|
-
end
|
15
|
-
|
16
|
-
def bite(aValue=$/)
|
17
|
-
bite!(aValue,self.clone)
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
|
-
|
22
|
-
module Net
|
23
|
-
class FTP
|
24
|
-
def FTP.with_connect(aHost,aUsername,aPassword,aDir=nil)
|
25
|
-
open(aHost,aUsername,aPassword) do |f|
|
26
|
-
f.passive = true
|
27
|
-
f.chdir(aDir) if aDir
|
28
|
-
yield f
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
32
|
-
def self.crack_file_line(aString)
|
33
|
-
values = aString.scan(/(.{10}).{28}(.{13})(.*)$/).flatten
|
34
|
-
{
|
35
|
-
:bits => values[0],
|
36
|
-
:date => values[1],
|
37
|
-
:name => values[2]
|
38
|
-
}
|
39
|
-
end
|
40
|
-
|
41
|
-
# BEGIN BUGFIXES
|
42
|
-
|
43
|
-
#
|
44
|
-
# Returns the size of the given (remote) filename.
|
45
|
-
#
|
46
|
-
def size(filename)
|
47
|
-
voidcmd("TYPE I")
|
48
|
-
resp = sendcmd("SIZE " + filename)
|
49
|
-
code = resp[0, 3]
|
50
|
-
if code != "213" && code != "220"
|
51
|
-
raise FTPReplyError, resp
|
52
|
-
end
|
53
|
-
return resp[3..-1].strip.to_i
|
54
|
-
end
|
55
|
-
|
56
|
-
# END BUGFIXES
|
57
|
-
|
58
|
-
def subdirs(aPath)
|
59
|
-
list.delete_if {|line| line[0,1]=='d'}
|
60
|
-
return list
|
61
|
-
end
|
62
|
-
|
63
|
-
def files(aPath)
|
64
|
-
list.delete_if {|line| line[0,1]!='d'}
|
65
|
-
return list
|
66
|
-
end
|
67
|
-
|
68
|
-
def expand_dir(aPath,aBase=nil)
|
69
|
-
return aPath if aPath=='/'
|
70
|
-
return MiscUtils::path_relative?(aPath) ? File.expand_path(aPath,aBase || pwd()) : File.expand_path(aPath)
|
71
|
-
end
|
72
|
-
|
73
|
-
def dir_exists?(aPath)
|
74
|
-
aPath = expand_dir(aPath)
|
75
|
-
return true if aPath=='/'
|
76
|
-
dirname = File.basename(aPath)
|
77
|
-
parent = MiscUtils.path_parent(aPath)
|
78
|
-
dirname!='' && nlst(parent).include?(dirname)
|
79
|
-
end
|
80
|
-
|
81
|
-
def file_exists?(aPath)
|
82
|
-
aPath = expand_dir(aPath)
|
83
|
-
filename = File.basename(aPath)
|
84
|
-
parent = File.dirname(aPath)
|
85
|
-
filename!='' && nlst(parent).include?(filename)
|
86
|
-
end
|
87
|
-
|
88
|
-
def filelist_recurse(aPath=nil,aResult=nil,&block)
|
89
|
-
#puts "filelist_recurse: #{aPath.to_s} #{aResult.inspect}"
|
90
|
-
orig_dir = !aResult ? pwd : nil # assigned if called at top with aResult=nil
|
91
|
-
aResult ||= []
|
92
|
-
aPath ||= ''
|
93
|
-
chdir(aPath)
|
94
|
-
list('*').each do |f|
|
95
|
-
is_dir = f[0,1]=='d'
|
96
|
-
details = FTP::crack_file_line(f)
|
97
|
-
full = File.join(aPath,details[:name])
|
98
|
-
if !block_given? || yield(full)
|
99
|
-
if is_dir
|
100
|
-
filelist_recurse(full,aResult)
|
101
|
-
else
|
102
|
-
aResult << full
|
103
|
-
end
|
104
|
-
end
|
105
|
-
end
|
106
|
-
chdir(orig_dir) if orig_dir
|
107
|
-
return aResult
|
108
|
-
end
|
109
|
-
|
110
|
-
def get_files(aRemoteDir,aLocalDir,aFiles,aOptions=nil)
|
111
|
-
aOptions = {:overwrite => true}.merge(aOptions || {})
|
112
|
-
aFiles.each do |r|
|
113
|
-
relative = r.bite(MiscUtils::append_slash(aRemoteDir))
|
114
|
-
d = File.join(aLocalDir,relative)
|
115
|
-
puts "getting #{relative}"
|
116
|
-
getbinaryfile(r, d) unless !aOptions[:overwrite] && File.exists?(d)
|
117
|
-
end
|
118
|
-
end
|
119
|
-
|
120
|
-
def get_dir(aRemoteDir,aLocalDir,aOptions=nil,&block)
|
121
|
-
remote_files = block_given? ? filelist_recurse(aRemoteDir,nil,&block) : filelist_recurse(aRemoteDir)
|
122
|
-
get_files(aRemoteDir,aLocalDir,remote_files,aOptions)
|
123
|
-
end
|
124
|
-
|
125
|
-
def highest_existing(aPath)
|
126
|
-
sep = MiscUtils::sniff_seperator(aPath)
|
127
|
-
path = MiscUtils::path_parts(File.expand_path(aPath)) if aPath.is_a?(String)
|
128
|
-
# now assume path is an Array
|
129
|
-
depth = path.length-1
|
130
|
-
depth.downto(0) do |i| # from full path up to root
|
131
|
-
curr = (path[0]=='' && i==0) ? '/' : path[0..i].join(sep)
|
132
|
-
return curr if dir_exists?(curr)
|
133
|
-
end
|
134
|
-
return sep # root
|
135
|
-
end
|
136
|
-
|
137
|
-
def ensure_dir(aPath,aThorough=false)
|
138
|
-
if !aThorough
|
139
|
-
mkdir(aPath) unless dir_exists?(aPath)
|
140
|
-
else
|
141
|
-
return if dir_exists?(aPath)
|
142
|
-
path = expand_dir(aPath)
|
143
|
-
hi_existing = highest_existing(path)
|
144
|
-
# path to create under hi_existing
|
145
|
-
to_create = MiscUtils::path_debase(path,hi_existing)
|
146
|
-
parts = MiscUtils::path_parts(to_create)
|
147
|
-
curr_path = hi_existing
|
148
|
-
|
149
|
-
parts.each do |part|
|
150
|
-
curr_path = File.join(curr_path,part)
|
151
|
-
mkdir(curr_path)
|
152
|
-
end
|
153
|
-
end
|
154
|
-
end
|
155
|
-
|
156
|
-
def put_files(aLocalDir,aRemoteDir,aFiles,aOptions=nil)
|
157
|
-
aOptions = {:overwrite => true}.merge(aOptions || {})
|
158
|
-
|
159
|
-
# convert all files to relative to aLocalDir
|
160
|
-
aFiles = aFiles.map { |f| f.bite(MiscUtils::append_slash(aLocalDir)) }.sort
|
161
|
-
|
162
|
-
filelist = nil
|
163
|
-
this_dir = last_dir = nil
|
164
|
-
aFiles.each do |r|
|
165
|
-
d = File.expand_path(r,aRemoteDir)
|
166
|
-
this_dir = File.dirname(d)
|
167
|
-
if this_dir!=last_dir
|
168
|
-
ensure_dir(this_dir,true)
|
169
|
-
filelist = files(this_dir) - ['.','..','.svn']
|
170
|
-
end
|
171
|
-
if aOptions[:overwrite] || !filelist.member?(File.basename(r))
|
172
|
-
puts "Putting #{r}"
|
173
|
-
putbinaryfile(File.expand_path(r,aLocalDir), d)
|
174
|
-
else
|
175
|
-
puts "Skipping #{relative}"
|
176
|
-
end
|
177
|
-
last_dir = this_dir
|
178
|
-
end
|
179
|
-
end
|
180
|
-
|
181
|
-
def put_dir(aLocalDir,aRemoteDir,&block)
|
182
|
-
local_files = block_given? ? MiscUtils::recursive_file_list(aLocalDir,true,&block) : MiscUtils::recursive_file_list(aLocalDir)
|
183
|
-
put_files(aLocalDir,aRemoteDir,local_files)
|
184
|
-
end
|
185
|
-
|
186
|
-
end
|
187
|
-
end
|
188
|
-
|