Class: Drupid::Patch
Instance Attribute Summary collapse
-
#cached_location ⇒ Object
readonly
Returns the value of attribute cached_location.
-
#descr ⇒ Object
readonly
Returns the value of attribute descr.
-
#md5 ⇒ Object
readonly
Returns the value of attribute md5.
-
#url ⇒ Object
readonly
Returns the value of attribute url.
Instance Method Summary collapse
-
#apply ⇒ Object
Applies this patch in the current directory.
-
#fetch ⇒ Object
Downloads the patch into the current directory.
-
#initialize(url, descr, md5 = nil) ⇒ Patch
constructor
A new instance of Patch.
Methods included from Utils
#blah, #bzr, #compare_paths, #curl, #cvs, #debug, #dont_debug, #git, #hg, #ignore_interrupts, #interactive_shell, #odie, #ofail, #ohai, #owarn, #runBabyRun, #svn, #tempdir, #uncompress, #which, #writeFile
Constructor Details
#initialize(url, descr, md5 = nil) ⇒ Patch
Returns a new instance of Patch.
32 33 34 35 36 37 |
# File 'lib/drupid/patch.rb', line 32 def initialize url, descr, md5 = nil @url = url @descr = descr @md5 = md5 @cached_location = nil end |
Instance Attribute Details
#cached_location ⇒ Object (readonly)
Returns the value of attribute cached_location.
30 31 32 |
# File 'lib/drupid/patch.rb', line 30 def cached_location @cached_location end |
#descr ⇒ Object (readonly)
Returns the value of attribute descr.
29 30 31 |
# File 'lib/drupid/patch.rb', line 29 def descr @descr end |
#md5 ⇒ Object (readonly)
Returns the value of attribute md5.
28 29 30 |
# File 'lib/drupid/patch.rb', line 28 def md5 @md5 end |
#url ⇒ Object (readonly)
Returns the value of attribute url.
27 28 29 |
# File 'lib/drupid/patch.rb', line 27 def url @url end |
Instance Method Details
#apply ⇒ Object
Applies this patch in the current directory. Raises an error if the patch cannot be applied.
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/drupid/patch.rb', line 55 def apply debug "Applying patch at #{Dir.pwd}" raise "Patch not fetched." if !(@cached_location and @cached_location.exist?) patch_levels = ['-p1', '-p0'] patched = false output = '' # First try with git apply patch_levels.each do |pl| begin runBabyRun 'git', ['apply', '--check', pl, @cached_location], :redirect_stderr_to_stdout => true runBabyRun 'git', ['apply', pl, @cached_location], :redirect_stderr_to_stdout => true patched = true break rescue => ex output << ex.to_s end end if not patched patch_levels.each do |pl| begin runBabyRun 'patch', ['--no-backup-if-mismatch', '-f', pl, '-d', Dir.pwd, '-i', @cached_location], :redirect_stderr_to_stdout => true patched = true break rescue => ex output << ex.to_s end end end if not patched if descr and descr != @cached_location.basename.to_s d = " (#{descr})" else d = '' end raise "Patch #{@cached_location.basename}#{d} could not be applied.\n" + output end return true end |
#fetch ⇒ Object
Downloads the patch into the current directory.
40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/drupid/patch.rb', line 40 def fetch dst = Pathname.pwd+File.basename(@url.to_s) blah "Fetching patch..." begin curl @url.to_s, '-o', dst rescue => ex raise "Patch #{File.basename(@url.to_s)} could not be fetched." debug ex. end @cached_location = dst debug "Patch downloaded into #{@cached_location}" end |