dpkg-tools 0.3.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (100) hide show
  1. data/CHANGES +198 -0
  2. data/MIT-LICENSE +20 -0
  3. data/README +17 -0
  4. data/Rakefile +1 -0
  5. data/bin/dpkg-etc +6 -0
  6. data/bin/dpkg-gem +6 -0
  7. data/bin/dpkg-rails +6 -0
  8. data/lib/dpkg-tools.rb +6 -0
  9. data/lib/dpkg-tools/command_line.rb +142 -0
  10. data/lib/dpkg-tools/package.rb +30 -0
  11. data/lib/dpkg-tools/package/builder.rb +112 -0
  12. data/lib/dpkg-tools/package/config.rb +96 -0
  13. data/lib/dpkg-tools/package/control_files.rb +24 -0
  14. data/lib/dpkg-tools/package/control_files/base.rb +75 -0
  15. data/lib/dpkg-tools/package/control_files/changelog.rb +23 -0
  16. data/lib/dpkg-tools/package/control_files/control.rb +148 -0
  17. data/lib/dpkg-tools/package/control_files/copyright.rb +27 -0
  18. data/lib/dpkg-tools/package/control_files/rakefile.rb +28 -0
  19. data/lib/dpkg-tools/package/control_files/rules.rb +29 -0
  20. data/lib/dpkg-tools/package/data.rb +125 -0
  21. data/lib/dpkg-tools/package/etc.rb +26 -0
  22. data/lib/dpkg-tools/package/etc/builder.rb +19 -0
  23. data/lib/dpkg-tools/package/etc/control_files.rb +22 -0
  24. data/lib/dpkg-tools/package/etc/control_files/changelog.rb +30 -0
  25. data/lib/dpkg-tools/package/etc/control_files/rakefile.rb +18 -0
  26. data/lib/dpkg-tools/package/etc/data.rb +48 -0
  27. data/lib/dpkg-tools/package/etc/rake.rb +31 -0
  28. data/lib/dpkg-tools/package/etc/setup.rb +30 -0
  29. data/lib/dpkg-tools/package/fs_methods.rb +10 -0
  30. data/lib/dpkg-tools/package/gem.rb +43 -0
  31. data/lib/dpkg-tools/package/gem/builder.rb +77 -0
  32. data/lib/dpkg-tools/package/gem/control_files.rb +23 -0
  33. data/lib/dpkg-tools/package/gem/control_files/changelog.rb +19 -0
  34. data/lib/dpkg-tools/package/gem/control_files/copyright.rb +24 -0
  35. data/lib/dpkg-tools/package/gem/control_files/rakefile.rb +19 -0
  36. data/lib/dpkg-tools/package/gem/data.rb +115 -0
  37. data/lib/dpkg-tools/package/gem/gem_format.rb +10 -0
  38. data/lib/dpkg-tools/package/gem/rake.rb +37 -0
  39. data/lib/dpkg-tools/package/gem/setup.rb +159 -0
  40. data/lib/dpkg-tools/package/rails.rb +26 -0
  41. data/lib/dpkg-tools/package/rails/builder.rb +77 -0
  42. data/lib/dpkg-tools/package/rails/cap.rb +30 -0
  43. data/lib/dpkg-tools/package/rails/control_files.rb +22 -0
  44. data/lib/dpkg-tools/package/rails/control_files/changelog.rb +19 -0
  45. data/lib/dpkg-tools/package/rails/control_files/rakefile.rb +24 -0
  46. data/lib/dpkg-tools/package/rails/data.rb +160 -0
  47. data/lib/dpkg-tools/package/rails/rake.rb +40 -0
  48. data/lib/dpkg-tools/package/rails/setup.rb +84 -0
  49. data/lib/dpkg-tools/package/rake.rb +90 -0
  50. data/lib/dpkg-tools/package/setup.rb +145 -0
  51. data/lib/dpkg-tools/version.rb +23 -0
  52. data/spec/dpkg-tools/command_line_spec.rb +9 -0
  53. data/spec/dpkg-tools/package/builder_spec.rb +159 -0
  54. data/spec/dpkg-tools/package/config_spec.rb +150 -0
  55. data/spec/dpkg-tools/package/control_files/base_spec.rb +111 -0
  56. data/spec/dpkg-tools/package/control_files/changelog_spec.rb +22 -0
  57. data/spec/dpkg-tools/package/control_files/control_spec.rb +131 -0
  58. data/spec/dpkg-tools/package/control_files/copyright_spec.rb +29 -0
  59. data/spec/dpkg-tools/package/control_files/rakefile_spec.rb +37 -0
  60. data/spec/dpkg-tools/package/control_files/rules_spec.rb +16 -0
  61. data/spec/dpkg-tools/package/control_files_spec.rb +12 -0
  62. data/spec/dpkg-tools/package/data_spec.rb +115 -0
  63. data/spec/dpkg-tools/package/etc/builder_spec.rb +28 -0
  64. data/spec/dpkg-tools/package/etc/control_files/changelog_spec.rb +21 -0
  65. data/spec/dpkg-tools/package/etc/control_files/rakefile_spec.rb +16 -0
  66. data/spec/dpkg-tools/package/etc/control_files_spec.rb +12 -0
  67. data/spec/dpkg-tools/package/etc/data_spec.rb +74 -0
  68. data/spec/dpkg-tools/package/etc/rake_spec.rb +71 -0
  69. data/spec/dpkg-tools/package/etc/setup_spec.rb +62 -0
  70. data/spec/dpkg-tools/package/etc_spec.rb +39 -0
  71. data/spec/dpkg-tools/package/fs_methods_spec.rb +33 -0
  72. data/spec/dpkg-tools/package/gem/builder_spec.rb +84 -0
  73. data/spec/dpkg-tools/package/gem/control_files/changelog_spec.rb +25 -0
  74. data/spec/dpkg-tools/package/gem/control_files/copyright_spec.rb +28 -0
  75. data/spec/dpkg-tools/package/gem/control_files/rakefile_spec.rb +17 -0
  76. data/spec/dpkg-tools/package/gem/control_files_spec.rb +12 -0
  77. data/spec/dpkg-tools/package/gem/data_spec.rb +176 -0
  78. data/spec/dpkg-tools/package/gem/gem_format_spec.rb +26 -0
  79. data/spec/dpkg-tools/package/gem/rake_spec.rb +102 -0
  80. data/spec/dpkg-tools/package/gem/setup_spec.rb +274 -0
  81. data/spec/dpkg-tools/package/gem_spec.rb +68 -0
  82. data/spec/dpkg-tools/package/rails/builder_spec.rb +113 -0
  83. data/spec/dpkg-tools/package/rails/cap_spec.rb +37 -0
  84. data/spec/dpkg-tools/package/rails/control_files/changelog_spec.rb +25 -0
  85. data/spec/dpkg-tools/package/rails/control_files/rakefile_spec.rb +24 -0
  86. data/spec/dpkg-tools/package/rails/control_files_spec.rb +12 -0
  87. data/spec/dpkg-tools/package/rails/data_spec.rb +178 -0
  88. data/spec/dpkg-tools/package/rails/rake_spec.rb +78 -0
  89. data/spec/dpkg-tools/package/rails/setup_spec.rb +152 -0
  90. data/spec/dpkg-tools/package/rails_spec.rb +27 -0
  91. data/spec/dpkg-tools/package/rake_spec.rb +87 -0
  92. data/spec/dpkg-tools/package/setup_spec.rb +247 -0
  93. data/spec/dpkg-tools/package_spec.rb +34 -0
  94. data/spec/fixtures/BlueCloth-1.0.0.gem +1190 -0
  95. data/spec/fixtures/database.yml +33 -0
  96. data/spec/spec.opts +1 -0
  97. data/spec/spec_helper.rb +52 -0
  98. data/tasks/dist.rake +118 -0
  99. data/tasks/rspec.rake +21 -0
  100. metadata +165 -0
@@ -0,0 +1,112 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ module DpkgTools
5
+ module Package
6
+ class Builder
7
+ include DpkgTools::Package::FSMethods
8
+
9
+ attr_reader :data, :config
10
+
11
+ def initialize(data)
12
+ @data = data
13
+ @config = DpkgTools::Package::Config.new(@data.name, @data.version, config_options)
14
+ end
15
+
16
+ def config_options
17
+ {}
18
+ end
19
+
20
+ def architecture_independent?
21
+ @data.architecture_independent?
22
+ end
23
+
24
+ def create_intermediate_buildroot
25
+ create_dir_if_needed(config.intermediate_buildroot)
26
+ end
27
+
28
+ def create_buildroot
29
+ create_dir_if_needed(config.buildroot)
30
+ end
31
+
32
+ def create_install_dirs
33
+ end
34
+
35
+ def build_package_files
36
+ end
37
+
38
+ def install_package_files
39
+ end
40
+
41
+ def render_template(template)
42
+ conf_file = ERB.new(template, nil, '-').result(data.binding)
43
+ end
44
+
45
+ def maintainer_script_targets
46
+ names = Dir.entries(config.debian_path).select do |name|
47
+ ['postinst.erb', 'preinst.erb', 'postrm.erb', 'prerm.erb'].include?(name)
48
+ end
49
+ names.collect { |name| name[/^(.+)\.erb$/, 1] }
50
+ end
51
+
52
+ def generate_maintainer_script(script_name)
53
+ template = File.read(File.join(config.debian_path, "#{script_name}.erb"))
54
+ target_path = File.join(config.buildroot_DEBIAN_path, script_name)
55
+ File.open(target_path, 'w') do |f|
56
+ f.write(render_template(template))
57
+ end
58
+ File.chmod(0755, target_path)
59
+ end
60
+
61
+ def generate_maintainer_scripts
62
+ maintainer_script_targets.each do |target|
63
+ generate_maintainer_script(target)
64
+ end
65
+ end
66
+
67
+ def create_DEBIAN_dir
68
+ Dir.mkdir(config.buildroot_DEBIAN_path) unless File.directory?(config.buildroot_DEBIAN_path)
69
+ end
70
+
71
+ # create DEBIAN/* package metadata by running dpkg-gencontrol
72
+ # Note: this assumes that command is run from package base dir
73
+ def create_control_files
74
+ sh "dpkg-gencontrol"
75
+ end
76
+
77
+ def deb_filename
78
+ config.deb_filename(data.debian_revision, data.debian_arch)
79
+ end
80
+
81
+ def built_deb_path
82
+ File.join(config.root_path, deb_filename)
83
+ end
84
+
85
+ # create the .deb binary package by running dpkg-deb --build with the appropriate options
86
+ def create_deb
87
+ sh "dpkg-deb --build \"#{config.buildroot}\" \"#{built_deb_path}\""
88
+ end
89
+
90
+ def build_package
91
+ create_buildroot
92
+ create_install_dirs
93
+ build_package_files
94
+ end
95
+
96
+ def binary_package
97
+ create_buildroot
98
+ create_install_dirs
99
+ install_package_files
100
+ create_DEBIAN_dir
101
+ generate_maintainer_scripts
102
+ create_control_files
103
+ create_deb
104
+ end
105
+
106
+ def remove_build_products
107
+ FileUtils.remove_dir(config.buildroot) if File.exists?(config.buildroot)
108
+ FileUtils.remove_dir(config.intermediate_buildroot) if File.exists?(config.intermediate_buildroot)
109
+ end
110
+ end
111
+ end
112
+ end
@@ -0,0 +1,96 @@
1
+ module DpkgTools
2
+ module Package
3
+ class << self
4
+ def config(name_version_pair)
5
+ @config ||= {}
6
+ @config[name_version_pair] ||= DpkgTools::Package::Config.new(*name_version_pair)
7
+ yield(@config[name_version_pair]) if block_given?
8
+ @config[name_version_pair]
9
+ end
10
+ end
11
+
12
+ class Config
13
+ class << self
14
+ attr_accessor :root_path
15
+ end
16
+
17
+ attr_reader :name, :version
18
+
19
+ def initialize(name, version, options = {})
20
+ @name = name
21
+ @version = version
22
+ @options = options
23
+ end
24
+
25
+ def full_name
26
+ @name + "-" + @version
27
+ end
28
+
29
+ def package_name
30
+ @name.downcase.tr("_", "-") + (@options[:suffix].nil? ? '' : "-#{@options[:suffix]}")
31
+ end
32
+
33
+ def package_dir_name
34
+ File.basename(base_path)
35
+ end
36
+
37
+ def base_path
38
+ return @options[:base_path] if @options.has_key?(:base_path)
39
+ File.join(root_path, "#{package_name}-#{version}")
40
+ end
41
+
42
+ def root_path
43
+ return File.dirname(@options[:base_path]) if @options.has_key?(:base_path)
44
+ self.class.root_path
45
+ end
46
+
47
+ def debian_path
48
+ File.join(base_path, 'debian')
49
+ end
50
+
51
+ def gem_filename
52
+ full_name + '.gem'
53
+ end
54
+
55
+ def gem_path
56
+ File.join(base_path, gem_filename)
57
+ end
58
+
59
+ def orig_tarball_path
60
+ base_path + ".orig.tar.gz"
61
+ end
62
+
63
+ def buildroot
64
+ File.join(debian_path, 'tmp')
65
+ end
66
+
67
+ def intermediate_buildroot
68
+ File.join(base_path, 'dpkg-tools-tmp')
69
+ end
70
+
71
+ def bin_install_path
72
+ File.join(buildroot, 'usr/bin')
73
+ end
74
+
75
+ def gem_install_path
76
+ File.join(buildroot, 'usr/lib/ruby/gems/1.8')
77
+ end
78
+
79
+ def etc_install_path
80
+ File.join(buildroot, 'etc')
81
+ end
82
+
83
+ def buildroot_DEBIAN_path
84
+ File.join(buildroot, 'DEBIAN')
85
+ end
86
+
87
+ def deb_filename(deb_revision, deb_arch)
88
+ "#{package_name}_#{deb_version(deb_revision)}_#{deb_arch}.deb"
89
+ end
90
+
91
+ def deb_version(deb_revision)
92
+ "#{version}-#{deb_revision}"
93
+ end
94
+ end
95
+ end
96
+ end
@@ -0,0 +1,24 @@
1
+ require 'dpkg-tools/package/control_files/base'
2
+ require 'dpkg-tools/package/control_files/control'
3
+ require 'dpkg-tools/package/control_files/copyright'
4
+ require 'dpkg-tools/package/control_files/changelog'
5
+ require 'dpkg-tools/package/control_files/rules'
6
+ require 'dpkg-tools/package/control_files/rakefile'
7
+
8
+ module DpkgTools
9
+ module Package
10
+ module ControlFiles
11
+ class << self
12
+ def classes
13
+ [
14
+ DpkgTools::Package::ControlFiles::Changelog,
15
+ DpkgTools::Package::ControlFiles::Control,
16
+ DpkgTools::Package::ControlFiles::Copyright,
17
+ DpkgTools::Package::ControlFiles::Rakefile,
18
+ DpkgTools::Package::ControlFiles::Rules
19
+ ]
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,75 @@
1
+ module DpkgTools
2
+ module Package
3
+ module ControlFiles
4
+ class Base
5
+ class << self
6
+ def check_target_dir(target_dir_path)
7
+ Dir.mkdir(target_dir_path) unless File.exists?(target_dir_path)
8
+ end
9
+
10
+ def write(file_path, contents)
11
+ check_target_dir(File.dirname(file_path))
12
+ File.open(file_path, 'w') do |f|
13
+ f.write(contents)
14
+ end
15
+ end
16
+
17
+ def write_executable(file_path, contents)
18
+ self.write(file_path, contents)
19
+ File.chmod(0755, file_path)
20
+ end
21
+
22
+ def filename
23
+ 'base'
24
+ end
25
+
26
+ def formatter_class
27
+ BaseFormatter
28
+ end
29
+ end
30
+
31
+ attr_reader :data, :config, :formatter
32
+
33
+ def initialize(data, config)
34
+ @data = data
35
+ @config = config
36
+ @formatter = self.class.formatter_class.new(self)
37
+ end
38
+
39
+ def executable?
40
+ false
41
+ end
42
+
43
+ def filename
44
+ self.class.filename
45
+ end
46
+
47
+ def file_path
48
+ File.join(@config.debian_path, filename)
49
+ end
50
+
51
+ def to_s
52
+ formatter.build
53
+ end
54
+
55
+ def write
56
+ write_method = executable? ? :write_executable : :write
57
+ self.class.send(write_method, file_path, self.to_s)
58
+ end
59
+
60
+ def needs_reset?
61
+ return true unless File.exist?(file_path)
62
+ File.read(file_path) != self.to_s
63
+ end
64
+ end
65
+
66
+ class BaseFormatter
67
+ attr_reader :metadata, :output
68
+
69
+ def initialize(metadata)
70
+ @metadata = metadata
71
+ end
72
+ end
73
+ end
74
+ end
75
+ end
@@ -0,0 +1,23 @@
1
+ module DpkgTools
2
+ module Package
3
+ module ControlFiles
4
+ class Changelog < DpkgTools::Package::ControlFiles::Base
5
+ class << self
6
+ def filename
7
+ 'changelog'
8
+ end
9
+
10
+ def formatter_class
11
+ ChangelogFormatter
12
+ end
13
+ end
14
+ end
15
+
16
+ class ChangelogFormatter < DpkgTools::Package::ControlFiles::BaseFormatter
17
+ def build
18
+ metadata.changelog
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,148 @@
1
+ module DpkgTools
2
+ module Package
3
+ module ControlFiles
4
+ class Control < DpkgTools::Package::ControlFiles::Base
5
+ class << self
6
+ def filename
7
+ 'control'
8
+ end
9
+
10
+ def formatter_class
11
+ ControlFormatter
12
+ end
13
+ end
14
+
15
+ # Source: package-name
16
+ def source
17
+ config.package_name
18
+ end
19
+
20
+ # Maintainer: name/email address
21
+ def maintainer
22
+ ["Matt Patterson", "matt@reprocessed.org"]
23
+ end
24
+
25
+ # Section: hardwired to 'libs' for now
26
+ def section
27
+ 'libs'
28
+ end
29
+
30
+ # Priority: hardwired to 'optional' for now
31
+ def priority
32
+ 'optional'
33
+ end
34
+
35
+ # Build-Depends: build-time package deps
36
+ def build_depends
37
+ data.build_dependencies
38
+ end
39
+
40
+ # Standards-Version: the version we currently implement
41
+ def standards_version
42
+ DpkgTools::Package.standards_version
43
+ end
44
+
45
+ # Package: package name for binary .deb
46
+ def package
47
+ config.package_name
48
+ end
49
+
50
+ # Architecture: Binary package's architecture
51
+ def architecture
52
+ data.debian_arch
53
+ end
54
+
55
+ # Essential: Hardwired to 'no' because nothing but Debian/Ubuntu base packages are essential
56
+ def essential
57
+ "no"
58
+ end
59
+
60
+ # Depends: install- and run-time package deps
61
+ def depends
62
+ data.dependencies
63
+ end
64
+
65
+ # Description: We only return the summary for now
66
+ def description
67
+ data.summary
68
+ end
69
+ end
70
+
71
+ class ControlFormatter < DpkgTools::Package::ControlFiles::BaseFormatter
72
+ def source_field_names
73
+ [:source, :maintainer, :uploaders, :section, :priority,
74
+ :build_depends, :build_depends_indep, :build_conflicts,
75
+ :build_conflicts_indep, :standards_version]
76
+ end
77
+
78
+ def binary_field_names
79
+ [:package, :architecture, :section, :priority, :essential,
80
+ :depends, :recommends, :suggests, :enhances, :pre_depends,
81
+ :description]
82
+ end
83
+
84
+ def field_names_map
85
+ {:source => "Source", :maintainer => "Maintainer", :uploaders => "Uploaders",
86
+ :section => "Section", :priority => "Priority", :build_depends => "Build-Depends",
87
+ :build_depends_indep => "Build-Depends-Indep", :build_conflicts => "Build-Conflicts",
88
+ :build_conflicts_indep => "Build-Conflicts-Indep", :standards_version => "Standards-Version",
89
+ :package => "Package", :architecture => "Architecture", :essential => "Essential",
90
+ :depends => "Depends", :recommends => "Recommends", :suggests => "Suggests",
91
+ :enhances => "Enhances", :pre_depends => "Pre-Depends", :description => "Description"}
92
+ end
93
+
94
+ # Dynamically define methods to handle dependency lines (they're all the same bar the name...)
95
+ [:build_depends, :build_depends_indep, :build_conflicts, :build_conflicts_indep,
96
+ :depends, :recommends, :suggests, :enhances, :pre_depends].each do |field_name|
97
+ define_method(field_name) {depends_line(field_name)}
98
+ end
99
+
100
+ # generate the Maintainer line
101
+ def maintainer
102
+ "Maintainer: #{metadata.maintainer[0]} <#{metadata.maintainer[1]}>"
103
+ end
104
+
105
+ def build
106
+ @output = []
107
+ # Source 'paragraph'
108
+ source_field_names.each {|field_name| process_field(field_name)}
109
+
110
+ # line break to make new debian/control 'paragraph'
111
+ output << ""
112
+
113
+ # Binary 'paragraph'
114
+ binary_field_names.each {|field_name| process_field(field_name)}
115
+
116
+ # required final newline
117
+ output << ""
118
+ output.join("\n")
119
+ end
120
+
121
+ private
122
+
123
+ def process_field(field_name)
124
+ if metadata.respond_to?(field_name)
125
+ if self.respond_to?(field_name)
126
+ output << self.send(field_name)
127
+ else
128
+ output << "#{field_names_map[field_name]}: #{metadata.send(field_name)}"
129
+ end
130
+ end
131
+ end
132
+
133
+ def deps_string(dependencies)
134
+ deps = []
135
+ dependencies.each do |dependency|
136
+ reqs = dependency.has_key?(:requirements) ? dependency[:requirements].collect {|req| "(#{req})"} : []
137
+ deps << ([dependency[:name]] + reqs).join(" ")
138
+ end
139
+ deps.join(", ")
140
+ end
141
+
142
+ def depends_line(field_name)
143
+ "#{field_names_map[field_name]}: #{deps_string(metadata.send(field_name))}"
144
+ end
145
+ end
146
+ end
147
+ end
148
+ end