~ubuntu-branches/ubuntu/raring/kde-wallpapers/raring-proposed

« back to all changes in this revision

Viewing changes to debian/copyrightgen.rb

  • Committer: Bazaar Package Importer
  • Author(s): Harald Sitter
  • Date: 2011-07-10 11:26:21 UTC
  • Revision ID: james.westby@ubuntu.com-20110710112621-84vy5ygamxrztq9x
Tags: 4:4.6.90-0ubuntu1
New upstream release (moved out of kde(base)-workspace)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/env ruby
 
2
 
 
3
class ParsableLine < String
 
4
  def intialize(str)
 
5
    replace(str.chop!)
 
6
  end
 
7
 
 
8
  def group?()
 
9
    return true if self =~ /^\[.*\]$/
 
10
    return false
 
11
  end
 
12
 
 
13
  def key?()
 
14
    return true if self =~ /(.*?)=(.*?)/
 
15
    return false
 
16
  end
 
17
end
 
18
 
 
19
class IniFile
 
20
  def initialize(file)
 
21
    @groups = Hash.new()
 
22
    group   = String.new()
 
23
    keys    = Hash.new()
 
24
 
 
25
    File.open(file).readlines.each do | line |
 
26
      line = ParsableLine.new(line)
 
27
      next if line.empty?
 
28
      if line.group?
 
29
        keys = Hash.new()
 
30
        group = line.gsub(/(^\[)(.*?[^\[])(\]$)/, '\2').chomp
 
31
        next
 
32
      elsif line.key?
 
33
        key, value = line.split(/\s*=\s*/)
 
34
        key.gsub!(/\s/, '')
 
35
        value.gsub!(/^\s|\s$|[#;].*$/, '') if value
 
36
        keys.store(key, value)
 
37
      end
 
38
      if group.length > 0 and not key.nil? and key.size > 0
 
39
        @groups.store(group, keys)
 
40
      end
 
41
    end
 
42
  end
 
43
 
 
44
  def key?(group, key)
 
45
    if group?(group)
 
46
      keys = @groups[group]
 
47
      return keys.has_key?(key)
 
48
    end
 
49
  end
 
50
 
 
51
  def group?(group)
 
52
    return @groups.has_key?(group)
 
53
  end
 
54
 
 
55
  def readEntry(group, key)
 
56
    return if not group?(group)
 
57
    keys = @groups[group]
 
58
    return keys[key] if keys.has_key?(key)
 
59
    return nil
 
60
  end
 
61
end
 
62
 
 
63
class Metadata < IniFile
 
64
  def initialzie(file)
 
65
    super(file)
 
66
  end
 
67
 
 
68
  def relative_path?()
 
69
    # TODO: impl
 
70
  end
 
71
 
 
72
  def name?()
 
73
    return readEntry("Desktop Entry", "X-KDE-PluginInfo-Name")
 
74
  end
 
75
 
 
76
  def author?()
 
77
    return readEntry("Desktop Entry", "X-KDE-PluginInfo-Author")
 
78
  end
 
79
 
 
80
  def email?()
 
81
    return readEntry("Desktop Entry", "X-KDE-PluginInfo-Email")
 
82
  end
 
83
 
 
84
  def license?()
 
85
    return readEntry("Desktop Entry", "X-KDE-PluginInfo-License")
 
86
  end
 
87
end
 
88
 
 
89
Dir.glob("*/metadata.desktop").each do | metadataPath |
 
90
  metadata = Metadata.new(metadataPath)
 
91
  puts "Files: #{metadataPath.split("/")[0]}/*"
 
92
  puts "Copyright: #{metadata.author?} <#{metadata.email?}>"
 
93
  license = metadata.license?
 
94
  if license == "LGPLv3"
 
95
    license = "LGPL-3"
 
96
  else
 
97
    license = "UNKNOWN"
 
98
  end
 
99
  puts "License: #{license}"
 
100
  puts ""
 
101
end