buzzware-buzzcore 0.2.2

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/.document ADDED
@@ -0,0 +1,5 @@
1
+ README.rdoc
2
+ lib/**/*.rb
3
+ bin/*
4
+ features/**/*.feature
5
+ LICENSE
data/.gitignore ADDED
@@ -0,0 +1,5 @@
1
+ *.sw?
2
+ .DS_Store
3
+ coverage
4
+ rdoc
5
+ pkg
data/LICENSE ADDED
@@ -0,0 +1,23 @@
1
+ Copyright (c) 2008-2009 Gary McGhee - Buzzware Solutions, Western Australia - gary@buzzware.com.au
2
+
3
+ MIT Licence
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23
+
data/README.rdoc ADDED
@@ -0,0 +1,46 @@
1
+ = buzzcore
2
+
3
+ * Author : http://www.buzzware.com.au
4
+
5
+ == DESCRIPTION:
6
+
7
+ Core library of Buzzware Solutions
8
+
9
+ == FEATURES/PROBLEMS:
10
+
11
+ * something
12
+
13
+ == REQUIREMENTS:
14
+
15
+ * tested on MacOS and Linux
16
+
17
+ == INSTALL:
18
+
19
+ sudo gem sources -a http://gems.github.com
20
+ sudo gem install buzzware-buzzcore
21
+
22
+ == LICENSE:
23
+
24
+ (The MIT License)
25
+
26
+ Copyright (c) 2009 Gary McGhee, Buzzware Solutions
27
+
28
+ Permission is hereby granted, free of charge, to any person obtaining
29
+ a copy of this software and associated documentation files (the
30
+ 'Software'), to deal in the Software without restriction, including
31
+ without limitation the rights to use, copy, modify, merge, publish,
32
+ distribute, sublicense, and/or sell copies of the Software, and to
33
+ permit persons to whom the Software is furnished to do so, subject to
34
+ the following conditions:
35
+
36
+ The above copyright notice and this permission notice shall be
37
+ included in all copies or substantial portions of the Software.
38
+
39
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
40
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
41
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
42
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
43
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
44
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
45
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
46
+
data/Rakefile ADDED
@@ -0,0 +1,63 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gem|
7
+ gem.name = "buzzcore"
8
+ gem.summary = %Q{buzzcore is the ruby core library developed and used by Buzzware Solutions.}
9
+ gem.description = %Q{buzzcore is the ruby core library developed and used by Buzzware Solutions.}
10
+ gem.email = "contact@buzzware.com.au"
11
+ gem.homepage = "http://github.com/buzzware/buzzcore"
12
+ gem.authors = ["buzzware"]
13
+ #gem.rubyforge_project = "buzzware"
14
+ gem.add_development_dependency "thoughtbot-shoulda"
15
+ gem.files.include %w(
16
+ lib/buzzcore.rb
17
+ )
18
+ # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
19
+ end
20
+ Jeweler::RubyforgeTasks.new do |rubyforge|
21
+ rubyforge.doc_task = "rdoc"
22
+ end
23
+ rescue LoadError
24
+ puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
25
+ end
26
+
27
+ require 'rake/testtask'
28
+ Rake::TestTask.new(:test) do |test|
29
+ test.libs << 'lib' << 'test'
30
+ test.pattern = 'test/**/*_test.rb'
31
+ test.verbose = true
32
+ end
33
+
34
+ begin
35
+ require 'rcov/rcovtask'
36
+ Rcov::RcovTask.new do |test|
37
+ test.libs << 'test'
38
+ test.pattern = 'test/**/*_test.rb'
39
+ test.verbose = true
40
+ end
41
+ rescue LoadError
42
+ task :rcov do
43
+ abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
44
+ end
45
+ end
46
+
47
+ task :test => :check_dependencies
48
+
49
+ task :default => :test
50
+
51
+ require 'rake/rdoctask'
52
+ Rake::RDocTask.new do |rdoc|
53
+ if File.exist?('VERSION')
54
+ version = File.read('VERSION')
55
+ else
56
+ version = ""
57
+ end
58
+
59
+ rdoc.rdoc_dir = 'rdoc'
60
+ rdoc.title = "buzzcore #{version}"
61
+ rdoc.rdoc_files.include('README*')
62
+ rdoc.rdoc_files.include('lib/**/*.rb')
63
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.2.2
data/buzzcore.gemspec ADDED
@@ -0,0 +1,77 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run `rake gemspec`
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{buzzcore}
8
+ s.version = "0.2.2"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["buzzware"]
12
+ s.date = %q{2009-09-10}
13
+ s.description = %q{buzzcore is the ruby core library developed and used by Buzzware Solutions.}
14
+ s.email = %q{contact@buzzware.com.au}
15
+ s.extra_rdoc_files = [
16
+ "LICENSE",
17
+ "README.rdoc"
18
+ ]
19
+ s.files = [
20
+ ".document",
21
+ ".gitignore",
22
+ "LICENSE",
23
+ "README.rdoc",
24
+ "Rakefile",
25
+ "VERSION",
26
+ "buzzcore.gemspec",
27
+ "buzzcore.vpj",
28
+ "buzzcore.vpw",
29
+ "lib/buzzcore.rb",
30
+ "lib/buzzcore.rb",
31
+ "lib/buzzcore/cap_utils.rb",
32
+ "lib/buzzcore/config.rb",
33
+ "lib/buzzcore/database_utils.rb",
34
+ "lib/buzzcore/enum.rb",
35
+ "lib/buzzcore/extend_base_classes.rb",
36
+ "lib/buzzcore/ftp_extra.rb",
37
+ "lib/buzzcore/logging.rb",
38
+ "lib/buzzcore/misc_utils.rb",
39
+ "lib/buzzcore/require_paths.rb",
40
+ "lib/buzzcore/shell_extras.rb",
41
+ "lib/buzzcore/string_utils.rb",
42
+ "lib/buzzcore/text_doc.rb",
43
+ "lib/buzzcore/thread_utils.rb",
44
+ "lib/buzzcore/xml_utils.rb",
45
+ "test/buzzcore_test.rb",
46
+ "test/config_test.rb",
47
+ "test/credentials_test.rb",
48
+ "test/shell_test.rb",
49
+ "test/test_helper.rb"
50
+ ]
51
+ s.has_rdoc = true
52
+ s.homepage = %q{http://github.com/buzzware/buzzcore}
53
+ s.rdoc_options = ["--charset=UTF-8"]
54
+ s.require_paths = ["lib"]
55
+ s.rubygems_version = %q{1.3.1}
56
+ s.summary = %q{buzzcore is the ruby core library developed and used by Buzzware Solutions.}
57
+ s.test_files = [
58
+ "test/buzzcore_test.rb",
59
+ "test/config_test.rb",
60
+ "test/credentials_test.rb",
61
+ "test/shell_test.rb",
62
+ "test/test_helper.rb"
63
+ ]
64
+
65
+ if s.respond_to? :specification_version then
66
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
67
+ s.specification_version = 2
68
+
69
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
70
+ s.add_development_dependency(%q<thoughtbot-shoulda>, [">= 0"])
71
+ else
72
+ s.add_dependency(%q<thoughtbot-shoulda>, [">= 0"])
73
+ end
74
+ else
75
+ s.add_dependency(%q<thoughtbot-shoulda>, [">= 0"])
76
+ end
77
+ end
data/buzzcore.vpj ADDED
@@ -0,0 +1,93 @@
1
+ <!DOCTYPE Project SYSTEM "http://www.slickedit.com/dtd/vse/10.0/vpj.dtd">
2
+ <Project
3
+ Version="10.0"
4
+ VendorName="SlickEdit"
5
+ WorkingDir=".">
6
+ <Config
7
+ Name="Release"
8
+ OutputFile=""
9
+ CompilerConfigName="Latest Version">
10
+ <Menu>
11
+ <Target
12
+ Name="Compile"
13
+ MenuCaption="&amp;Compile"
14
+ CaptureOutputWith="ProcessBuffer"
15
+ SaveOption="SaveCurrent"
16
+ RunFromDir="%rw">
17
+ <Exec/>
18
+ </Target>
19
+ <Target
20
+ Name="Build"
21
+ MenuCaption="&amp;Build"
22
+ CaptureOutputWith="ProcessBuffer"
23
+ SaveOption="SaveWorkspaceFiles"
24
+ RunFromDir="%rw">
25
+ <Exec/>
26
+ </Target>
27
+ <Target
28
+ Name="Rebuild"
29
+ MenuCaption="&amp;Rebuild"
30
+ CaptureOutputWith="ProcessBuffer"
31
+ SaveOption="SaveWorkspaceFiles"
32
+ RunFromDir="%rw">
33
+ <Exec/>
34
+ </Target>
35
+ <Target
36
+ Name="Debug"
37
+ MenuCaption="&amp;Debug"
38
+ SaveOption="SaveNone"
39
+ RunFromDir="%rw">
40
+ <Exec/>
41
+ </Target>
42
+ <Target
43
+ Name="Execute"
44
+ MenuCaption="E&amp;xecute"
45
+ SaveOption="SaveNone"
46
+ RunFromDir="%rw"
47
+ CaptureOutputWith="ProcessBuffer"
48
+ ClearProcessBuffer="1">
49
+ <Exec CmdLine="source actions.sh execute"/>
50
+ </Target>
51
+ </Menu>
52
+ </Config>
53
+ <CustomFolders>
54
+ <Folder
55
+ Name="Source Files"
56
+ Filters="*.c;*.C;*.cc;*.cpp;*.cp;*.cxx;*.c++;*.prg;*.pas;*.dpr;*.asm;*.s;*.bas;*.java;*.cs;*.sc;*.e;*.cob;*.html;*.rc;*.tcl;*.py;*.pl"/>
57
+ <Folder
58
+ Name="Header Files"
59
+ Filters="*.h;*.H;*.hh;*.hpp;*.hxx;*.inc;*.sh;*.cpy;*.if"/>
60
+ <Folder
61
+ Name="Resource Files"
62
+ Filters="*.ico;*.cur;*.dlg"/>
63
+ <Folder
64
+ Name="Bitmaps"
65
+ Filters="*.bmp"/>
66
+ <Folder
67
+ Name="Other Files"
68
+ Filters="">
69
+ </Folder>
70
+ </CustomFolders>
71
+ <Files AutoFolders="DirectoryView">
72
+ <Folder Name="lib">
73
+ <F
74
+ N="lib/*"
75
+ Recurse="1"
76
+ Refilter="0"
77
+ Excludes=""/>
78
+ </Folder>
79
+ <Folder Name="test">
80
+ <F
81
+ N="test/*"
82
+ Recurse="0"
83
+ Refilter="0"
84
+ Excludes=".svn/"/>
85
+ </Folder>
86
+ <F N="buzzcore.gemspec"/>
87
+ <F N="History.txt"/>
88
+ <F N="Manifest.txt"/>
89
+ <F N="PostInstall.txt"/>
90
+ <F N="Rakefile"/>
91
+ <F N="README.rdoc"/>
92
+ </Files>
93
+ </Project>
data/buzzcore.vpw ADDED
@@ -0,0 +1,6 @@
1
+ <!DOCTYPE Workspace SYSTEM "http://www.slickedit.com/dtd/vse/10.0/vpw.dtd">
2
+ <Workspace Version="10.0" VendorName="SlickEdit">
3
+ <Projects>
4
+ <Project File="buzzcore.vpj" />
5
+ </Projects>
6
+ </Workspace>
data/lib/buzzcore.rb ADDED
@@ -0,0 +1,2 @@
1
+ Dir.chdir(File.dirname(__FILE__)) { Dir['buzzcore/*'] }.each {|f| require f }
2
+
@@ -0,0 +1,181 @@
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