yore 0.0.4 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
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/Rakefile CHANGED
@@ -1,57 +1,64 @@
1
- require 'rubygems'
2
- require 'rake/rdoctask'
3
- require 'rake/testtask'
4
- %w[rubygems rake rake/clean fileutils newgem rubigen].each { |f| require f }
5
- require File.dirname(__FILE__) + '/lib/yore.orig'
6
-
7
- # built following http://newgem.rubyforge.org/
8
- # using RSpec option (later converted to shoulda)
9
- # and had to add processor_ids from dr nic :
10
- # http://groups.google.com/group/new-gem-generator/browse_thread/thread/648f70da782e607a/928ea0fe8319d886?lnk=raot
11
-
12
- # Generate all the Rake tasks
13
- # Run 'rake -T' to see list of generated tasks (from gem root directory)
14
- $hoe = Hoe.new('yore', Yore::VERSION) do |p|
15
- p.developer('Gary McGhee', 'contact@buzz@ware@com@au')
16
- p.changes = p.paragraphs_of("History.txt", 0..1).join("\n\n")
17
- #p.post_install_message = 'PostInstall.txt' # TODO remove if post-install message not required
18
- p.rubyforge_name = 'buzzware' #p.name # TODO this is default value
19
- p.extra_deps = [
20
- ['RequirePaths','>= 1.0.1'],
21
- ['cmdparse', '>= 2.0.2'],
22
- ['s3sync', '>= 1.2.5'],
23
- ['shairontoledo-popen4', '>= 0.1.2']
24
- ]
25
- p.extra_dev_deps = [
26
- ['newgem', ">= #{::Newgem::VERSION}"]
27
- ]
28
-
29
- p.clean_globs |= %w[**/.DS_Store tmp *.log]
30
- path = (p.rubyforge_name == p.name) ? p.rubyforge_name : "\#{p.rubyforge_name}/\#{p.name}"
31
- p.remote_rdoc_dir = File.join(path.gsub(/^#{p.rubyforge_name}\/?/,''), 'rdoc')
32
- p.rsync_args = '-av --delete --ignore-errors'
33
- end
34
-
35
- require 'newgem/tasks' # load /tasks/*.rake
36
- Dir['tasks/**/*.rake'].each { |t| load t }
37
-
38
- # TODO - want other tests/tasks run by default? Add them to the list
39
- # task :default => [:spec, :features]
40
- # this was generated by netbeans
41
- # Rake::RDocTask.new do |rdoc|
42
- # files =['README', 'LICENSE', 'lib/**/*.rb']
43
- # rdoc.rdoc_files.add(files)
44
- # rdoc.main = "README" # page to start on
45
- # rdoc.title = "yore Docs"
46
- # rdoc.rdoc_dir = 'doc/rdoc' # rdoc output folder
47
- # rdoc.options << '--line-numbers'
48
- # end
49
- #
50
- # Rake::TestTask.new do |t|
51
- # t.test_files = FileList['test/**/*.rb']
52
- # end
53
-
54
- #Spec::Rake::SpecTask.new do |t|
55
- # t.spec_files = FileList['spec/**/*.rb']
56
- #end
57
-
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gem|
7
+ gem.name = "yore"
8
+ gem.summary = %Q{yore (as in "days of yore") is a user data management utility for web applications.}
9
+ gem.description = %Q{yore (as in "days of yore") is a user data management utility for web applications.}
10
+ gem.email = "contact@buzzware.com.au"
11
+ gem.homepage = "http://github.com/buzzware/yore"
12
+ gem.authors = ["buzzware"]
13
+ gem.rubyforge_project = "buzzware"
14
+ gem.add_dependency('buzzcore', '>= 0.2.5')
15
+ gem.add_development_dependency "thoughtbot-shoulda"
16
+ #gem.files.include %w(
17
+ # lib/buzzcore.rb
18
+ #)
19
+ # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
20
+ end
21
+ Jeweler::RubyforgeTasks.new do |rubyforge|
22
+ rubyforge.doc_task = "rdoc"
23
+ end
24
+ rescue LoadError
25
+ puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
26
+ end
27
+
28
+ require 'rake/testtask'
29
+ Rake::TestTask.new(:test) do |test|
30
+ test.libs << 'lib' << 'test'
31
+ test.pattern = 'test/**/*_test.rb'
32
+ test.verbose = true
33
+ end
34
+
35
+ begin
36
+ require 'rcov/rcovtask'
37
+ Rcov::RcovTask.new do |test|
38
+ test.libs << 'test'
39
+ test.pattern = 'test/**/*_test.rb'
40
+ test.verbose = true
41
+ end
42
+ rescue LoadError
43
+ task :rcov do
44
+ abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
45
+ end
46
+ end
47
+
48
+ task :test => :check_dependencies
49
+
50
+ task :default => :test
51
+
52
+ require 'rake/rdoctask'
53
+ Rake::RDocTask.new do |rdoc|
54
+ if File.exist?('VERSION')
55
+ version = File.read('VERSION')
56
+ else
57
+ version = ""
58
+ end
59
+
60
+ rdoc.rdoc_dir = 'rdoc'
61
+ rdoc.title = "yore #{version}"
62
+ rdoc.rdoc_files.include('README*')
63
+ rdoc.rdoc_files.include('lib/**/*.rb')
64
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.0.5
data/bin/yore CHANGED
@@ -3,15 +3,9 @@
3
3
  require 'fileutils'
4
4
 
5
5
  require 'rubygems'
6
- gem 'RequirePaths'; require 'require_paths'
7
- require_paths '.','../../..'
8
-
6
+ gem 'buzzware-buzzcore'; require 'buzzcore';
9
7
  gem 'cmdparse'; require 'cmdparse'
10
8
 
11
- require 'ihl_ruby/misc_utils'
12
- require 'ihl_ruby/xml_utils'
13
- require 'ihl_ruby/extend_base_classes'
14
-
15
9
  require 'yore/yore_core'
16
10
 
17
11
  CMD_OPTIONS = {} # options given on command line
@@ -23,10 +17,11 @@ def command(aParser,aController,aAction,aShortDescription=nil,aOptionParser=nil,
23
17
  c.description = aOther[:description] if aOther[:description]
24
18
  c.options = aOptionParser if aOptionParser
25
19
  c.set_execution_block do |args|
26
- if job = CMD_OPTIONS[:config]
27
- aController.configure(job,CMD_OPTIONS)
28
- end
29
- aController.do_action(aAction,args,CMD_OPTIONS)
20
+ CMD_OPTIONS[:config] = args.first if aAction == :backup
21
+ CMD_OPTIONS[:config] = 'yore.config.xml' if !CMD_OPTIONS[:config] && File.exists?('yore.config.xml')
22
+ aController.configure(CMD_OPTIONS[:config],CMD_OPTIONS) unless CMD_OPTIONS.empty?
23
+
24
+ aController.do_action(aAction,args)
30
25
  end
31
26
  aParser.add_command(c)
32
27
  end
@@ -1,20 +1,9 @@
1
1
  require 'rubygems'
2
- gem 'RequirePaths'; require 'require_paths'
3
- require_paths '.','..'
4
-
2
+ gem 'buzzware-buzzcore'; require 'buzzcore';
5
3
 
6
4
  require 'fileutils'
7
5
  require 'net/smtp'
8
6
 
9
- require 'ihl_ruby/misc_utils'
10
- require 'ihl_ruby/logging'
11
- require 'ihl_ruby/string_utils'
12
- require 'ihl_ruby/xml_utils'
13
- require 'ihl_ruby/extend_base_classes'
14
- require 'ihl_ruby/shell_extras'
15
- require 'ihl_ruby/config'
16
- require 'ihl_ruby/database_utils'
17
-
18
7
  THIS_FILE = File.expand_path(__FILE__)
19
8
  THIS_DIR = File.dirname(THIS_FILE)
20
9
 
@@ -156,11 +145,20 @@ module YoreCore
156
145
  return xdoc.root
157
146
  end
158
147
 
159
- def get_rails_db_details(aRailsPath,aRailsEnv)
148
+ def get_rails_db_details(aRailsPath,aRailsEnv,aFile=nil)
160
149
  return nil unless aRailsPath && aRailsEnv && aRailsEnv!=''
161
- return nil unless dbyml = (YAML::load(File.open(File.expand_path('config/database.yml',aRailsPath))) rescue nil)
150
+ yml_file = MiscUtils.path_combine(aRailsPath,aFile || 'config/database.yml')
151
+ return nil unless dbyml = (YAML::load(File.open(yml_file)) rescue nil)
162
152
  return dbyml[aRailsEnv] && dbyml[aRailsEnv].symbolize_keys
163
153
  end
154
+
155
+ def self.find_upwards(aStartPath,aPath)
156
+ curr_path = File.expand_path(aStartPath)
157
+ while curr_path && !(test_path_exists = File.exists?(test_path = File.join(curr_path,aPath))) do
158
+ curr_path = MiscUtils.path_parent(curr_path)
159
+ end
160
+ curr_path && test_path_exists ? test_path : nil
161
+ end
164
162
 
165
163
  def expand_app_option(kind=nil)
166
164
  kind = config[:kind] unless kind && !kind.empty?
@@ -173,7 +171,23 @@ module YoreCore
173
171
  if xmlSources
174
172
  strSource = <<-EOS
175
173
  <Source Type="File">
176
- <IncludePath>public/assets/products</IncludePath>
174
+ <IncludePath BasePath="public/assets">products</IncludePath>
175
+ </Source>
176
+ EOS
177
+ XmlUtils.add_xml_from_string(strSource,xmlSources)
178
+ end
179
+ expand_app_option('rails') # do again
180
+ #
181
+ # if capistrano deployed, uploads are assumed to be in shared/uploads
182
+ #
183
+ when 'browsercms'
184
+ # add file source
185
+ xmlSources = XmlUtils.single_node(config.xmlRoot,'/Yore/Sources')
186
+ if xmlSources
187
+ uploadParent = File.join(config[:basepath],'tmp') unless config[:basepath]['/releases/'] && uploadParent = Yore.find_upwards(config[:basepath],'shared')
188
+ strSource = <<-EOS
189
+ <Source Type="File">
190
+ <IncludePath BasePath="#{uploadParent}">uploads</IncludePath>
177
191
  </Source>
178
192
  EOS
179
193
  XmlUtils.add_xml_from_string(strSource,xmlSources)
@@ -185,12 +199,12 @@ module YoreCore
185
199
  #if (dbyml = YAML::load(File.open(File.expand_path('config/database.yml',config[:basepath]))) rescue nil)
186
200
  # if env = (config[:RAILS_ENV] && config[:RAILS_ENV]!='' && config[:RAILS_ENV])
187
201
  # if (db_details = dbyml[env]) &&
188
- db_details = get_rails_db_details(config[:basepath],config[:RAILS_ENV])
189
202
  xmlSources = XmlUtils.single_node(config.xmlRoot,'/Yore/Sources')
190
- if db_details && xmlSources
203
+ if xmlSources
204
+ #<Database Name="#{db_details[:database]}" Host="#{db_details[:host]}" User="#{db_details[:username]}" Password="#{db_details[:password]}">
191
205
  strSource = <<-EOS
192
206
  <Source Type="MySql" >
193
- <Database Name="#{db_details[:database]}" Host="#{db_details[:host]}" User="#{db_details[:username]}" Password="#{db_details[:password]}">
207
+ <Database Yml="config/database.yml">
194
208
  <ArchiveFile>rails_app.sql</ArchiveFile>
195
209
  </Database>
196
210
  </Source>
@@ -240,10 +254,10 @@ module YoreCore
240
254
  @keepers << KeepMonthly.new(config[:keep_monthly])
241
255
  end
242
256
 
243
- def do_action(aAction,aArgs,aCmdOptions)
257
+ def do_action(aAction,aArgs)
244
258
  logger.info "Executing command: #{aAction} ...\n"
245
259
  begin
246
- send(aAction,aArgs,aCmdOptions)
260
+ send(aAction,aArgs)
247
261
  rescue Exception => e
248
262
  logger.info {e.backtrace.join("\n")}
249
263
  logger.warn "#{e.class.to_s}: during #{aAction.to_s}(#{(aArgs && aArgs.inspect).to_s}): #{e.message.to_s}"
@@ -416,15 +430,25 @@ module YoreCore
416
430
  )
417
431
  end
418
432
 
419
- def self.database_from_xml(aDatabaseNode)
420
- return {
421
- :host => aDatabaseNode.attributes['Host'],
422
- :username => aDatabaseNode.attributes['User'],
423
- :password => aDatabaseNode.attributes['Password'],
424
- :database => aDatabaseNode.attributes['Name'],
433
+ def database_from_xml(aDatabaseNode)
434
+ result = {
425
435
  :file => XmlUtils::peek_node_value(aDatabaseNode, "ToFile"),
426
436
  :archive_file => XmlUtils::peek_node_value(aDatabaseNode, "ArchiveFile")
427
- }
437
+ }
438
+ if config[:RAILS_ENV] && (yml=aDatabaseNode.attributes['Yml'] || !aDatabaseNode.attributes['Name']) # has yml or doesn't have database name
439
+ raise StandardError.new("RAILS_ENV must be given to read #{yml}") if !config[:RAILS_ENV] || config[:RAILS_ENV].empty?
440
+ db_details = get_rails_db_details(config[:basepath],config[:RAILS_ENV],yml)
441
+ raise StandardError.new('insufficient or missing database configuration') if !db_details
442
+ result.merge!(db_details)
443
+ else
444
+ result.merge!({
445
+ :host => aDatabaseNode.attributes['Host'],
446
+ :username => aDatabaseNode.attributes['User'],
447
+ :password => aDatabaseNode.attributes['Password'],
448
+ :database => aDatabaseNode.attributes['Name'],
449
+ })
450
+ end
451
+ result
428
452
  end
429
453
 
430
454
 
@@ -438,10 +462,11 @@ module YoreCore
438
462
  when 'File' then
439
463
  # BasePath tag provides base path for IncludePaths to be relative to. Also indicates root folder for archive
440
464
  bp = MiscUtils.path_combine(config[:basepath],XmlUtils::peek_node_value(xmlSource, "@BasePath"))
441
- filelist << '-C'+bp
442
465
  REXML::XPath.each(xmlSource, 'IncludePath') do |xmlPath|
443
- files = MiscUtils::recursive_file_list(MiscUtils::path_combine(bp,xmlPath.text))
444
- files.map!{|f| MiscUtils.path_debase(f,bp)}
466
+ bp2 = MiscUtils.path_combine(bp,XmlUtils::peek_node_value(xmlPath,"@BasePath"))
467
+ filelist << '-C'+bp2
468
+ files = MiscUtils::recursive_file_list(MiscUtils::path_combine(bp2,xmlPath.text))
469
+ files.map!{|f| MiscUtils.path_debase(f,bp2)}
445
470
  filelist += files
446
471
  sourceFound = true
447
472
  end
@@ -452,10 +477,10 @@ module YoreCore
452
477
  # </Database>
453
478
  #</Source>
454
479
  REXML::XPath.each(xmlSource, 'Database') do |xmlDb|
455
- args = Yore::database_from_xml(xmlDb)
480
+ args = database_from_xml(xmlDb)
456
481
  file = args.delete(:file) #legacy, absolute path
457
482
  arc_file = args.delete(:archive_file) #path in archive
458
- unless args[:host] && args[:username] && args[:password] && args[:database] && (file||arc_file)
483
+ unless args[:username] && args[:password] && args[:database] && (file||arc_file)
459
484
  raise StandardError.new("Invalid or missing parameter")
460
485
  end
461
486
  if arc_file
@@ -506,17 +531,12 @@ module YoreCore
506
531
  # ACTIONS
507
532
  #
508
533
 
509
- def save(aArgs,aCmdOptions=nil)
534
+ def save(aArgs)
510
535
  fnArchive = aArgs.is_a?(Array) ? aArgs.first : aArgs #only supported argument
511
- configure(nil,aCmdOptions)
512
536
  save_internal(fnArchive)
513
537
  end
514
538
 
515
- def backup(aArgs,aCmdOptions=nil) # was aJobFiles
516
- unless aCmdOptions && aCmdOptions[:config] # assume already configured if config option specified, but back supports first arg being config file
517
- job = aArgs.first
518
- configure(job,aCmdOptions || {})
519
- end
539
+ def backup(aArgs) # was aJobFiles
520
540
  temp_file = File.expand_path('backup.tar',temp_path)
521
541
  save_internal(temp_file)
522
542
  backup_file = File.expand_path(encode_file_name(),temp_path)
@@ -527,7 +547,6 @@ module YoreCore
527
547
 
528
548
  def load(aArgs,aCmdOptions=nil)
529
549
  fnArchive = aArgs.is_a?(Array) ? aArgs.first : aArgs #only supported argument
530
- configure(nil,aCmdOptions)
531
550
 
532
551
  FileUtils.mkdir_p(archive_path = File.join(temp_path,'archive'))
533
552
  uncompress(fnArchive,archive_path)
@@ -538,18 +557,26 @@ module YoreCore
538
557
  #<Source Type="File">
539
558
  # <IncludePath>public/assets/products</IncludePath>
540
559
  #</Source>
560
+ #
561
+ # arcparent = parent_folder(IncludePath.text)
562
+ # arcfolder = File.basename(IncludePath.text)
563
+ # destination = MiscUtils.path_combine(basepath,IncludePath.text)
564
+ bpSource = MiscUtils.path_combine(config[:basepath],XmlUtils::peek_node_value(xmlSource, "@BasePath"))
541
565
  REXML::XPath.each(xmlSource,'IncludePath') do |xmlIncludePath|
566
+ bpInclude = MiscUtils.path_combine(bpSource,XmlUtils::peek_node_value(xmlIncludePath, "@BasePath"))
567
+
542
568
  pathArchive = xmlIncludePath.text()
543
569
  pathUncompressed = File.join(archive_path,pathArchive)
544
570
  pathTmp = File.join(rails_tmp_path,pathArchive)
545
- pathDest = File.join(config[:basepath],pathArchive)
546
- # move basepath/relativepath to tmp/yore/090807-010203/relativepath
571
+ pathDest = File.join(bpInclude,pathArchive)
572
+
573
+ # move basepath/relativepath to tmp/yore/090807-010203/relativepath (out of the way)
547
574
  Yore::move_folder(pathDest,pathTmp) if File.exists?(pathDest)
548
575
  # get <IncludeFiles> and copy to basepath/relativepath
549
576
  Yore::copy_folder(pathUncompressed,pathDest) if File.exists?(pathUncompressed)
550
577
  end
551
578
  when 'MySql' then
552
- db_details = Yore::database_from_xml(XmlUtils.single_node(xmlSource,'Database'))
579
+ db_details = database_from_xml(XmlUtils.single_node(xmlSource,'Database'))
553
580
  DatabaseUtils.load_database(db_details,File.join(archive_path,db_details[:archive_file]))
554
581
  end
555
582
  end
data/notes.txt ADDED
@@ -0,0 +1,27 @@
1
+
2
+ debug,info,warning,error
3
+
4
+ * log warning and above to STDERR
5
+ * report used with all detail levels, all sent to log ?
6
+ * log warning and above sent to report
7
+
8
+ Perhaps :
9
+ * one logger.
10
+ * Report includes info+
11
+ * STDERR includes warning+
12
+
13
+ Write log splitter that looks like a logger, and is created with an array of other loggers.
14
+ All log actions are replicated on the array of loggers
15
+
16
+ loggers :
17
+ ConsoleLogger: (debug-info to STDOUT,warning+ to STDERR) (no timestamp)
18
+ ReportLogger: (info+ to report file) standard logger class (minimised timestamp)
19
+ SystemLogger: all levels to /var/log (rolling file) SysLogLogger ? (standard timestamp)
20
+
21
+
22
+ * only 2 files
23
+ *
24
+
25
+ *** Use this for parsing PHP configs
26
+ http://github.com/mattfawcett/ruby-reads-php/tree/master
27
+
data/test/S3_test.rb CHANGED
@@ -1,8 +1,5 @@
1
1
  require 'rubygems'
2
- gem 'RequirePaths'; require 'require_paths'
3
- require_paths '../../..','../lib'
4
- require 'ihl_ruby/misc_utils'
5
- require 'ihl_ruby/shell_extras'
2
+ gem 'buzzware-buzzcore'; require 'buzzcore';
6
3
  require 'yore/yore_core'
7
4
  require 'test/unit'
8
5
  gem 'Shoulda'; require 'shoulda'
@@ -93,7 +90,7 @@ class S3Test < Test::Unit::TestCase
93
90
  _xmlRoot = XmlUtils.get_xml_root(job_content)
94
91
  cmd_options = {:config => job_file}
95
92
  @yore_upload = YoreCore::Yore::launch(_xmlRoot,cmd_options,{:basepath => File.dirname(File.expand_path(job_file))})
96
- @yore_upload.backup([job_file],cmd_options)
93
+ @yore_upload.backup([job_file])
97
94
  rescue ::StandardError => e
98
95
  flunk e.inspect
99
96
  end
@@ -0,0 +1,10 @@
1
+ require 'rubygems'
2
+ require 'test/unit'
3
+ require 'shoulda'
4
+
5
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
6
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
7
+ require 'yore'
8
+
9
+ class Test::Unit::TestCase
10
+ end
data/test/test_job_b.xml CHANGED
@@ -12,7 +12,7 @@
12
12
  <Item Name="log_level">INFO</Item>
13
13
  <Item Name="email_report">false</Item>
14
14
 
15
- <Item Name="mail_host">mail.authsmtp.com</Item>
15
+ <Item Name="mail_host">mail.com</Item>
16
16
  <Item Name="mail_port">25</Item>
17
17
  <Item Name="mail_helodomain">blah.com</Item>
18
18
  <Item Name="mail_user">erewrwer</Item>