Class: Reap::Package

Inherits:
Task
  • Object
show all
Defined in:
lib/reap/task/package.rb

Constant Summary collapse

MUST_EXCLUDE =
[ 'InstalledFiles', '**/CVS/**/*', '**/*~', 'dist', 'pkg' ]
LOCATIONS =
[ 'dist', 'pkg', '../packages', '../dist', '../pkg' ]

Constants inherited from Task

Task::RUBY

Instance Method Summary collapse

Methods inherited from Task

#ask, #execute, inherited, #initialize, #initiate, master, #master, #provide_setup_rb, #section, section_required, section_required?, #section_required?, #sh, #task, task_attr, #task_desc, task_desc, #task_help, task_help, task_list, #task_name, task_name, #tell, #use_subsection, verify?

Constructor Details

This class inherits a constructor from Reap::Task

Instance Method Details

#runObject



83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
# File 'lib/reap/task/package.rb', line 83

def run

  # setup package defaults

  # Do not look in master information for this
  pkg.dir = section.dir || LOCATIONS.find { |f| File.directory?(f)  } || 'dist'

  pkg.status       ||= 'beta/stable'
  pkg.date         ||= Time.now.strftime("%Y-%m-%d")
  pkg.series       ||= '1'
  pkg.author       ||= "Anonymous"
  pkg.maintainer   ||= pkg.author
  pkg.email        ||= ""
  pkg.summary      ||= ""
  pkg.architecture ||= 'any'
  pkg.license      ||= 'Ruby/GPL'
  pkg.project      ||= master.rubyforge.project
  pkg.homepage     ||= master.rubyforge.homepage

  d = pkg.date.split('-').collect{ |e| e.to_i }
  #d[0] = d[0] - 2000  # No need to keep the 2000
  pkg.version      ||= d.join('.')

  if $BUILD_VERSION
    pkg.buildno = Time.now.strftime("%H*60+%M")
    pkg.version += ".#{pkg.buildno}"
  end

  pkg.package_name ||= "#{pkg.name}-#{pkg.version}"

  pkg.exclude      ||= []
  pkg.exclude      |= MUST_EXCLUDE

  pkg.include      ||= ['**/*']

  # distribute types include 'tgz', 'tbz', 'zip', 'tar.gz' 'tar.bz2', 'gem', 'pac' and 'deb'.

  pkg.distribute   ||= [ 'gem', 'tar.bz2', 'zip' ]
  pkg.distribute = [pkg.distribute].flatten.collect { |t| t.to_s.strip.downcase }

  pkg.dependencies ||= []
  pkg.executables  ||= []
  pkg.requirements ||= []
  pkg.recommends   ||= []
  pkg.conflicts    ||= []
  pkg.replaces     ||= []

  # Gem specific properties

  if defined?(::Gem) and pkg.gem
    if pkg.gem.platform
      begin
        pkg.gem.platform = ::Gem::Platform.const_get(pkg.gem.platform.upcase)
      rescue NameError
        pkg.gem.platform = ::Gem::Platform::RUBY
      end
    else
      pkg.gem.platform = ::Gem::Platform::RUBY
    end
    #@autorequire
  end

  # package it up

  group_dir_path = File.join( pkg.dir, pkg.package_name )
  package_dir_path = File.join( pkg.dir, pkg.package_name, pkg.package_name )

  if FileTest.directory?(group_dir_path)
    if $FORCE
      puts "Removing old directory '#{File.expand_path(group_dir_path)}'..."
      FileUtils.rm_r(group_dir_path)
    else
      puts "Package directory '#{pkg.package_name}' already exists. Use -f option to overwrite."
      return nil
    end
  end

  puts "Creating #{pkg.distribute.join(',')} packages..."

  package_files = FileList.new
  package_files.include(*pkg.include)
  package_files.exclude(*pkg.exclude) if pkg.exclude and not pkg.exclude.empty?
  FileUtils.mkdir_p pkg.dir #rescue nil
  package_files.each do |f|
    pkgf = File.join(package_dir_path, f)
    fdir = File.dirname(pkgf)
    FileUtils.mkdir_p(fdir) if not File.exist?(fdir)
    if File.directory?(f)
      FileUtils.mkdir_p(pkgf)
    else
      FileUtils.rm_f(pkgf)
      FileUtils.safe_ln(f, pkgf)
    end
  end

  # create standard package files
  FileUtils.chdir( File.join( pkg.dir, pkg.package_name ) ) do
    pkg.distribute.each do |t|
      sh_cmd = nil
      prefix = 'ERROR' # in case of unforseen bug
      case t
      when 'tbz', 'bz2', 'bzip2', 'tar.bz2'
        prefix = ( t == 'tbz' ? 'tbz' : 'tar.bz2' )
        sh_cmd = 'tar --bzip2 -cvf'
        puts "\nReap is shelling out work to tar and bzip2..."
      when 'tgz', 'tar.gz'
        prefix = ( t == 'tgz' ? 'tgz' : 'tar.gz' )
        sh_cmd = 'tar --gzip -cvf'
        puts "\nReap is shelling out work to tar and gzip..."
      when 'zip'
        prefix = 'zip'
        sh_cmd = 'zip -r'
        puts "\nReap is shelling out work to zip..."
      when 'gem', 'deb', 'pac'
        sh_cmd = nil
      else
        puts "Unknown package type '#{t}' skipped."
        sh_cmd = nil
      end
      sh %{#{sh_cmd} #{pkg.package_name}.#{prefix} #{pkg.package_name}} if sh_cmd
    end
    puts
  end

  # create gem package

  if pkg.distribute.include?('gem')
    if defined?(::Gem)
      run_gem
    else
      tell "Package .gem requested, but rubygems not found (skipped)."
    end
  end

  # create debian package

  if pkg.distribute.include?('deb')
    if true # TODO ensure required debian tools here
      run_deb
    else
      tell "Package .deb requested, but debian tools not found (skipped)."
    end
  end

  # create PKGBUILD (pacman, archlinux)

  if pkg.distribute.include?('pac')
    if true # TODO ensure required tools here
      run_pacman
    else
      tell "Pacman package requested, but required tools not found (skipped)."
    end
  end

  return true
end