Class: Debian

Inherits:
Object
  • Object
show all
Defined in:
lib/msp_release/debian.rb

Defined Under Namespace

Modules: Versions

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(basedir, fname) ⇒ Debian

Returns a new instance of Debian.



130
131
132
# File 'lib/msp_release/debian.rb', line 130

def initialize(basedir, fname)
  @fname = File.join(basedir, fname)
end

Instance Attribute Details

#fnameObject (readonly)

Returns the value of attribute fname.



134
135
136
# File 'lib/msp_release/debian.rb', line 134

def fname
  @fname
end

Instance Method Details

#add(version, stub, distribution = self.distribution) ⇒ Object



193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
# File 'lib/msp_release/debian.rb', line 193

def add(version, stub, distribution=self.distribution)
  tline = create_top_line(version, distribution)
  all = File.open(@fname, 'r') {|f| f.readlines }
  new =
    [
     tline,
     "",
     "  * #{stub}",
     "",
     create_signoff + "\n",
     ""
    ]

  File.open(@fname, 'w') {|f| f.write(new.join("\n")); f.write(all.join) }

  version
end

#amend(version, distribution = self.distribution) ⇒ Object



176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
# File 'lib/msp_release/debian.rb', line 176

def amend(version, distribution=self.distribution)
  # replace the first line
  tline, *all = File.open(@fname, 'r') {|f|f.readlines}
  cur_version = /^[^\(]+\(([^\)]+).+/.match(tline)[1]
  tline = tline.gsub(cur_version, "#{version}").
    gsub(distribution_pattern) {|m|"#{$1}#{distribution}" }

  all.unshift(tline)

  signoff_idx = all.index {|l| /^ -- .+$/.match(l) }
  all[signoff_idx] = create_signoff

  File.open(@fname, 'w') { |f| all.each {|l|f.puts(l) } }

  version
end

#create_signoffObject



215
216
217
218
219
# File 'lib/msp_release/debian.rb', line 215

def create_signoff
  date = MSPRelease.time_rfc
  author = MSPRelease.author
  " -- #{author.name} <#{author.email}>  #{date}"
end

#create_top_line(v, distribution) ⇒ Object



221
222
223
224
225
226
# File 'lib/msp_release/debian.rb', line 221

def create_top_line(v, distribution)
  tline = "#{package_name} (#{v})"

  # FIXME, un-hardcode this?
  tline + " #{distribution}; urgency=low"
end

#default_distributionObject



128
# File 'lib/msp_release/debian.rb', line 128

def default_distribution ; "msp" ; end

#distributionObject



156
157
158
# File 'lib/msp_release/debian.rb', line 156

def distribution
  (m = distribution_pattern.match(read_top_line)) && m[2]
end

#distribution_patternObject



152
153
154
# File 'lib/msp_release/debian.rb', line 152

def distribution_pattern
  /([^ ]+ [^ ]+ )([^;]+)/
end

#matches(version) ⇒ Object



172
173
174
# File 'lib/msp_release/debian.rb', line 172

def matches(version)
  self.version == version
end

#package_nameObject



160
161
162
# File 'lib/msp_release/debian.rb', line 160

def package_name
  /[a-z0-9\-]+/.match(read_top_line)
end

#read_top_lineObject



136
137
138
# File 'lib/msp_release/debian.rb', line 136

def read_top_line
  File.open(@fname, 'r') {|f|f.readline}
end

#reset_at(project_version) ⇒ Object



211
212
213
# File 'lib/msp_release/debian.rb', line 211

def reset_at(project_version)
  Versions::Unreleased.new_from_version(project_version).bump
end

#versionObject



144
145
146
147
148
149
150
# File 'lib/msp_release/debian.rb', line 144

def version
  version_classes.each do |c|
    v = c.new_if_matches(version_string_from_top_line) and
      return v
  end
  Versions::Unrecognized.new(version_string_from_top_line)
end

#version_classesObject



140
141
142
# File 'lib/msp_release/debian.rb', line 140

def version_classes
  [Versions::Unreleased, Versions::Stable, Versions::Development]
end

#version_string_from_top_lineObject



164
165
166
167
168
169
170
# File 'lib/msp_release/debian.rb', line 164

def version_string_from_top_line
  tline = read_top_line
  match = /[a-z\-]+ \(([^\)]+)\)/.match(tline)

  match && match[1] or
    raise "could not parse version info from #{tline}"
end