autobuild 1.4.5 → 1.4.6

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,3 +1,6 @@
1
+ == Version 1.4.6
2
+ * add missing importer/archive.rb file
3
+
1
4
  == Version 1.4.5
2
5
  * add support for zip in TarImporter, which is renamed ArchiveImporter to
3
6
  reflect that. Backward compatibility is retained.
@@ -13,6 +13,7 @@ lib/autobuild/import/cvs.rb
13
13
  lib/autobuild/import/darcs.rb
14
14
  lib/autobuild/import/git.rb
15
15
  lib/autobuild/import/svn.rb
16
+ lib/autobuild/import/archive.rb
16
17
  lib/autobuild/import/tar.rb
17
18
  lib/autobuild/importer.rb
18
19
  lib/autobuild/package.rb
@@ -1,5 +1,5 @@
1
1
  module Autobuild
2
- VERSION = "1.4.5" unless defined? Autobuild::VERSION
2
+ VERSION = "1.4.6" unless defined? Autobuild::VERSION
3
3
  end
4
4
 
5
5
  require 'autobuild/config'
@@ -0,0 +1,161 @@
1
+ require 'autobuild/importer'
2
+ require 'open-uri'
3
+ require 'fileutils'
4
+
5
+ module Autobuild
6
+ class ArchiveImporter < Importer
7
+ # The tarball is not compressed
8
+ Plain = 0
9
+ # The tarball is compressed with gzip
10
+ Gzip = 1
11
+ # The tarball is compressed using bzip
12
+ Bzip = 2
13
+ # Not a tarball but a zip
14
+ Zip = 3
15
+
16
+ TAR_OPTION = {
17
+ Plain => '',
18
+ Gzip => 'z',
19
+ Bzip => 'j'
20
+ }
21
+
22
+ # Known URI schemes for +url+
23
+ VALID_URI_SCHEMES = [ 'file', 'http', 'https', 'ftp' ]
24
+
25
+ # Returns the unpack mode from the file name
26
+ def self.filename_to_mode(filename)
27
+ case filename
28
+ when /\.zip$/; Zip
29
+ when /\.tar$/; Plain
30
+ when /\.tar\.gz|\.tgz$/; Gzip
31
+ when /\.bz2$/; Bzip
32
+ else
33
+ raise "unknown file type '#{filename}'"
34
+ end
35
+ end
36
+
37
+ # Updates the downloaded file in cache only if it is needed
38
+ def update_cache(package)
39
+ do_update = true
40
+
41
+ if File.file?(cachefile)
42
+ cached_size = File.lstat(cachefile).size
43
+ cached_mtime = File.lstat(cachefile).mtime
44
+
45
+ size, mtime = nil
46
+ open @url, :content_length_proc => lambda { |size| } do |file|
47
+ mtime = file.last_modified
48
+ end
49
+
50
+ if mtime && size
51
+ do_update = (size != cached_size || mtime > cached_mtime)
52
+ elsif mtime
53
+ $stderr.puts "WARNING: size is not available for #{@url}, relying on modification time"
54
+ do_update = (mtime > cached_mtime)
55
+ elsif size
56
+ $stderr.puts "WARNING: modification time is not available for #{@url}, relying on size"
57
+ do_update = (size != cached_size)
58
+ else
59
+ $stderr.puts "WARNING: neither size nor modification time available for #{@url}, will always update"
60
+ end
61
+ end
62
+
63
+ if do_update
64
+ FileUtils.mkdir_p(cachedir)
65
+ Subprocess.run(package, :import, Autobuild.tool('wget'), '-q', '-P', cachedir, @url)
66
+ true
67
+ end
68
+ end
69
+
70
+ # The source URL
71
+ attr_reader :url
72
+ # The local file (either a downloaded file if +url+ is not local, or +url+ itself)
73
+ attr_reader :cachefile
74
+ # The unpack mode. One of Zip, Bzip, Gzip or Plain
75
+ attr_reader :mode
76
+ # The directory in which remote files are cached
77
+ def cachedir; @options[:cachedir] end
78
+ # The directory contained in the tar file
79
+ #
80
+ # DEPRECATED use #archive_dir instead
81
+ def tardir; @options[:tardir] end
82
+ # The directory contained in the archive. If not set, we assume that it
83
+ # is the same than the source dir
84
+ def archive_dir; @options[:archive_dir] || tardir end
85
+
86
+ # Creates a new importer which downloads +url+ in +cachedir+ and unpacks it. The following options
87
+ # are allowed:
88
+ # [:cachedir] the cache directory. Defaults to "#{Autobuild.prefix}/cache"
89
+ # [:archive_dir] the directory contained in the archive file. If set,
90
+ # the importer will rename that directory to make it match
91
+ # Package#srcdir
92
+ # [:no_subdirectory] the archive does not have the custom archive
93
+ # subdirectory.
94
+ def initialize(url, options)
95
+ @options = options.dup
96
+ @options[:cachedir] ||= "#{Autobuild.prefix}/cache"
97
+
98
+ @url = URI.parse(url)
99
+ raise ConfigException, "invalid URL #{@url}" unless VALID_URI_SCHEMES.include?(@url.scheme)
100
+
101
+ @mode = options[:mode] || ArchiveImporter.filename_to_mode(options[:filename] || url)
102
+ if @url.scheme == 'file'
103
+ @cachefile = @url.path
104
+ else
105
+ @cachefile = File.join(cachedir, @options[:filename] || File.basename(url))
106
+ end
107
+ end
108
+
109
+ def update(package) # :nodoc:
110
+ checkout(package) if update_cache(package)
111
+ rescue OpenURI::HTTPError
112
+ raise Autobuild::Exception.new(package.name, :import)
113
+ end
114
+
115
+ def checkout(package) # :nodoc:
116
+ update_cache(package)
117
+
118
+ base_dir = File.dirname(package.srcdir)
119
+ FileUtils.mkdir_p base_dir
120
+
121
+ main_dir = if @options[:no_subdirectory] then package.srcdir
122
+ else base_dir
123
+ end
124
+
125
+ if mode == Zip
126
+ cmd = [ 'unzip', '-o', '-f', cachefile, '-d', main_dir ]
127
+ else
128
+ cmd = [ 'tar', "x#{TAR_OPTION[mode]}f", cachefile, '-C', main_dir ]
129
+ end
130
+
131
+ Subprocess.run(package, :import, *cmd)
132
+ if archive_dir
133
+ FileUtils.mv File.join(base_dir, archive_dir), package.srcdir
134
+ end
135
+ if !File.directory?(package.srcdir)
136
+ raise Autobuild::Exception, "#{cachefile} does not contain directory called #{File.basename(package.srcdir)}. Did you forget to use the :archive_dir option ?"
137
+ end
138
+
139
+ rescue OpenURI::HTTPError
140
+ raise Autobuild::Exception.new(package.name, :import)
141
+ rescue SubcommandFailed
142
+ FileUtils.rm_f cachefile
143
+ raise
144
+ end
145
+ end
146
+
147
+ # For backwards compatibility
148
+ TarImporter = ArchiveImporter
149
+
150
+ # Creates an importer which downloads a tarball from +source+ and unpacks
151
+ # it. The allowed values in +options+ are described in ArchiveImporter.new.
152
+ def self.archive(source, options = {})
153
+ ArchiveImporter.new(source, options)
154
+ end
155
+
156
+ # DEPRECATED. Use Autobuild.archive instead.
157
+ def self.tar(source, options = {})
158
+ ArchiveImporter.new(source, options)
159
+ end
160
+ end
161
+
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: autobuild
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.4.5
4
+ version: 1.4.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sylvain Joyeux
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-12-23 00:00:00 +01:00
12
+ date: 2009-12-24 00:00:00 +01:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -60,7 +60,7 @@ dependencies:
60
60
  requirements:
61
61
  - - ">="
62
62
  - !ruby/object:Gem::Version
63
- version: 2.4.0
63
+ version: 2.3.3
64
64
  version:
65
65
  description: |-
66
66
  This work is licensed under the GPLv2 license. See License.txt for details
@@ -106,6 +106,7 @@ files:
106
106
  - lib/autobuild/import/darcs.rb
107
107
  - lib/autobuild/import/git.rb
108
108
  - lib/autobuild/import/svn.rb
109
+ - lib/autobuild/import/archive.rb
109
110
  - lib/autobuild/import/tar.rb
110
111
  - lib/autobuild/importer.rb
111
112
  - lib/autobuild/package.rb