Class: PKGWizard::SpecFile

Inherits:
Object
  • Object
show all
Defined in:
lib/pkg-wizard/rpm.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#specObject

Returns the value of attribute spec.



28
29
30
# File 'lib/pkg-wizard/rpm.rb', line 28

def spec
  @spec
end

Class Method Details

.parse(file) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
# File 'lib/pkg-wizard/rpm.rb', line 30

def self.parse(file)
  f = ''
  if File.exist?(file)
    f = File.read(file)
  else
    f = file
  end
  spec = SpecFile.new
  spec.spec = f
  spec
end

Instance Method Details

#build_requiresObject



82
83
84
85
86
87
88
89
90
91
# File 'lib/pkg-wizard/rpm.rb', line 82

def build_requires
  build_requires = []
  @spec.each_line do |l|
    if l =~ /^\s*buildrequires:(.*)$/i
      build_requires = $1.split
      build_requires.reject! { |i| i !~ /^[a-zA-Z0-9]/ }
    end
  end
  build_requires
end

#changelogObject



104
105
106
107
108
109
110
111
112
113
114
115
116
117
# File 'lib/pkg-wizard/rpm.rb', line 104

def changelog
  buf = ""
  in_changelog = false
  @spec.each_line do |l|
    if l =~ /%changelog/
      in_changelog = true
      next
    end
    if in_changelog
      buf += l
    end
  end
  return buf
end

#changelog_entriesObject



119
120
121
122
123
124
125
126
127
128
129
130
131
# File 'lib/pkg-wizard/rpm.rb', line 119

def changelog_entries
  entries = []
  cursor = -1
  changelog.each_line do |l|
    if l =~ /^\*/
      cursor += 1
      entries[cursor] = l
    else
      entries[cursor] += l if not l.strip.chomp.empty?
    end
  end
  entries
end

#download_source_files(defines = [], dest_dir = '.') ⇒ Object



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
# File 'lib/pkg-wizard/rpm.rb', line 133

def download_source_files(defines = [], dest_dir = '.')
  define = ''
  if defines.is_a? Array and defines.size >= 1
    define = defines[0]
  elsif defines.is_a? String
    define = defines
  else
    define = nil
  end
  if define
    if define !~ /\w\s+\w/
      raise ArgumentError.new "Invalid --define syntax. Use 'macro_name macro_value'"
    else
      new_sources = []
      def_tokens = define.split
      sources.each do |s|
        new_sources << s.gsub(/%\{\??#{def_tokens[0]}\}/, def_tokens[1])
      end
    end
  else
    new_sources = sources
  end
  new_sources.each do |s|
    next if s !~ /http:\/\//
    yield s if block_given?
    download_from_url s, dest_dir
  end
end

#filesObject



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/pkg-wizard/rpm.rb', line 42

def files
  buf = []
  in_files = false
  @spec.each_line do |l|
    if l =~ /^\s*%files/
      in_files = true
      next
    end
    if l =~ /^\s*%(changelog|pre|pro|prep|preun|postun|post|install|clean|build|define)/ and in_files
      break
    end
    if in_files
      buf << l.strip.chomp if not l.strip.chomp.empty?
    end
  end
  buf
end

#nameObject



64
65
66
# File 'lib/pkg-wizard/rpm.rb', line 64

def name
  @spec.match(/Name:(.*?)$/i)[1].strip.chomp rescue nil
end

#pkgnameObject



162
163
164
# File 'lib/pkg-wizard/rpm.rb', line 162

def pkgname
  "#{name}-#{version}-#{release}"
end

#releaseObject



60
61
62
# File 'lib/pkg-wizard/rpm.rb', line 60

def release
  @spec.match(/Release:(.*?)$/i)[1].strip.chomp.gsub(/%\{\?.*\}/, '') rescue nil
end

#requiresObject



93
94
95
96
97
98
99
100
101
102
# File 'lib/pkg-wizard/rpm.rb', line 93

def requires
  requires = []
  @spec.each_line do |l|
    if l =~ /^\s*requires:(.*)$/i
      requires = $1.split
      requires.reject! { |i| i !~ /^[a-zA-Z0-9]/ }
    end
  end
  requires
end

#sourcesObject



72
73
74
75
76
77
78
79
80
# File 'lib/pkg-wizard/rpm.rb', line 72

def sources
  s = []
  @spec.each_line do |line|
    if line =~ /^\s*Source\d*:(.*)$/i
      s << $1.strip.chomp
    end
  end
  s
end

#versionObject



68
69
70
# File 'lib/pkg-wizard/rpm.rb', line 68

def version
  @spec.match(/Version:(.*?)$/i)[1].strip.chomp rescue nil
end