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,27 @@
1
+ module DpkgTools
2
+ module Package
3
+ module ControlFiles
4
+ class Copyright < DpkgTools::Package::ControlFiles::Base
5
+ class << self
6
+ def filename
7
+ 'copyright'
8
+ end
9
+
10
+ def formatter_class
11
+ CopyrightFormatter
12
+ end
13
+ end
14
+
15
+ def license_file
16
+ data.license
17
+ end
18
+ end
19
+
20
+ class CopyrightFormatter < DpkgTools::Package::ControlFiles::BaseFormatter
21
+ def build
22
+ metadata.license_file
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,28 @@
1
+ module DpkgTools
2
+ module Package
3
+ module ControlFiles
4
+ class Rakefile < DpkgTools::Package::ControlFiles::Base
5
+ class << self
6
+ def filename
7
+ nil
8
+ end
9
+
10
+ def formatter_class
11
+ RakefileFormatter
12
+ end
13
+ end
14
+
15
+ def file_path
16
+ base_method, filename = @data.rakefile_location
17
+ File.join(@config.send(base_method), filename)
18
+ end
19
+ end
20
+
21
+ class RakefileFormatter < DpkgTools::Package::ControlFiles::BaseFormatter
22
+ def build
23
+ metadata.rakefile
24
+ end
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,29 @@
1
+ module DpkgTools
2
+ module Package
3
+ module ControlFiles
4
+ class Rules < DpkgTools::Package::ControlFiles::Base
5
+ class << self
6
+ def filename
7
+ 'rules'
8
+ end
9
+
10
+ def formatter_class
11
+ RulesFormatter
12
+ end
13
+ end
14
+
15
+ def executable?
16
+ true
17
+ end
18
+ end
19
+
20
+ class RulesFormatter < DpkgTools::Package::ControlFiles::BaseFormatter
21
+ def build
22
+ "#!/bin/sh\n" \
23
+ "\n" \
24
+ "/usr/bin/rake $@\n" \
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,125 @@
1
+ module DpkgTools
2
+ module Package
3
+ class DebYAMLParseError < StandardError; end
4
+
5
+ class Data
6
+ module YamlConfigHelpers
7
+ # Should be overridden by subclasses to return a list of base (i.e. always required,
8
+ # don't need to be specified) gem dependencies. Should return an array of hashes
9
+ # of the form {:name => 'rails-rubygem', :requirements => ['>= 1.2.5-1']}
10
+ def base_gem_deps
11
+ []
12
+ end
13
+
14
+ # Should be overridden by subclasses to return a list of base (i.e. always required,
15
+ # don't need to be specified) dpkg package dependencies. Should return an array of hashes
16
+ # of the form {:name => 'mysql-server', :requirements => ['>= 1.2.5-1']}
17
+ def base_package_deps
18
+ []
19
+ end
20
+
21
+ def package_data_file_path(base_path, filename)
22
+ File.join(base_path, filename)
23
+ end
24
+
25
+ def load_package_data(base_path, filename)
26
+ file_path = package_data_file_path(base_path, filename)
27
+ YAML.load_file(file_path) if File.exist?(file_path)
28
+ end
29
+
30
+ def process_dependencies(data)
31
+ all_deps = base_gem_deps + base_package_deps
32
+ if data.has_key?('dependencies') && !data['dependencies'].empty?
33
+ raise DebYAMLParseError, "dependencies: is not a collection of items!" unless data['dependencies'].kind_of?(Hash)
34
+ all_deps += process_dependencies_by_type(data['dependencies'], 'gem', 'rubygem') {|req| "#{req}-1"}
35
+ all_deps += process_dependencies_by_type(data['dependencies'], 'package')
36
+ end
37
+ all_deps
38
+ end
39
+
40
+ def process_dependencies_by_type(dependencies, dependency_type, suffix = nil)
41
+ processed_dependencies = []
42
+ if dependencies.has_key?(dependency_type)
43
+ unless dependencies[dependency_type].kind_of?(Array) || dependencies[dependency_type].nil?
44
+ raise DebYAMLParseError, "dependencies: #{dependency_type}: is not a list of items!"
45
+ end
46
+ unless dependencies[dependency_type].nil?
47
+ dependencies[dependency_type].each do |dependency|
48
+ name = dependency.kind_of?(Hash) ? dependency.keys.first : dependency
49
+ requirements = dependency.kind_of?(Hash) ? dependency.values.first : nil
50
+ unless requirements.kind_of?(Array) || requirements.kind_of?(String) || requirements.nil?
51
+ raise DebYAMLParseError, "The #{dependency_type} dependency #{name}'s version requirements MUST be either a list of items, or a single item!"
52
+ end
53
+ requirements = [requirements] if requirements.kind_of?(String)
54
+ requirements.collect! { |req| yield(req) } if block_given?
55
+ processed_dependencies << {:name => "#{name}#{"-"+ suffix unless suffix.nil?}", :requirements => requirements}
56
+ end
57
+ end
58
+ end
59
+ processed_dependencies
60
+ end
61
+ end
62
+
63
+ class << self
64
+ def resources_dirname
65
+ 'data'
66
+ end
67
+
68
+ def resources_path
69
+ dirs_to_climb_up = Array.new(File.expand_path(File.dirname(__FILE__)).split('/').reverse.index('lib') + 1).collect { '..' }
70
+ File.expand_path(File.join(File.dirname(__FILE__), dirs_to_climb_up, 'resources', self.resources_dirname))
71
+ end
72
+ end
73
+
74
+ def name
75
+ "name"
76
+ end
77
+
78
+ def version
79
+ "1.0.0"
80
+ end
81
+
82
+ def full_name
83
+ "#{name}-#{version}"
84
+ end
85
+
86
+ def debian_revision
87
+ "1"
88
+ end
89
+
90
+ def debian_arch
91
+ "all"
92
+ end
93
+
94
+ def architecture_independent?
95
+ debian_arch == 'all'
96
+ end
97
+
98
+ def dependencies
99
+ [{:name => "dep-name", :requirements => [">= 1.0.0"]}]
100
+ end
101
+
102
+ def build_dependencies
103
+ [{:name => "dep-name", :requirements => [">= 1.0.0"]}]
104
+ end
105
+
106
+ def summary
107
+ "Summary description"
108
+ end
109
+
110
+ def license
111
+ "MIT License text"
112
+ end
113
+
114
+ def rakefile_location
115
+ [:base_path, 'Rakefile']
116
+ end
117
+
118
+ def resources_path
119
+ self.class.resources_path
120
+ end
121
+
122
+ public :binding
123
+ end
124
+ end
125
+ end
@@ -0,0 +1,26 @@
1
+ require 'dpkg-tools/package/etc/data'
2
+ require 'dpkg-tools/package/etc/setup'
3
+ require 'dpkg-tools/package/etc/builder'
4
+ require 'dpkg-tools/package/etc/control_files'
5
+ require 'dpkg-tools/package/etc/rake'
6
+
7
+ module DpkgTools
8
+ module Package
9
+ module Etc
10
+ class << self
11
+ def create_builder(path_to_app)
12
+ Builder.from_path(path_to_app)
13
+ end
14
+
15
+ def create_setup(path_to_app)
16
+ Setup.from_path(path_to_app)
17
+ end
18
+
19
+ def setup_from_path(path_to_app)
20
+ Dir.mkdir(path_to_app) unless File.directory?(path_to_app)
21
+ create_setup(path_to_app).create_structure
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,19 @@
1
+ module DpkgTools
2
+ module Package
3
+ module Etc
4
+ class Builder < DpkgTools::Package::Builder
5
+ def config_options
6
+ {:base_path => data.base_path}
7
+ end
8
+
9
+ def create_install_dirs
10
+ create_dir_if_needed(config.etc_install_path)
11
+ end
12
+
13
+ def install_package_files
14
+ FileUtils.cp_r(config.base_path + '/etc', config.etc_install_path)
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,22 @@
1
+ require 'dpkg-tools/package/etc/control_files/changelog'
2
+ require 'dpkg-tools/package/etc/control_files/rakefile'
3
+
4
+ module DpkgTools
5
+ module Package
6
+ module Etc
7
+ module ControlFiles
8
+ class << self
9
+ def classes
10
+ [
11
+ DpkgTools::Package::Etc::ControlFiles::Changelog,
12
+ DpkgTools::Package::ControlFiles::Control,
13
+ DpkgTools::Package::ControlFiles::Copyright,
14
+ DpkgTools::Package::Etc::ControlFiles::Rakefile,
15
+ DpkgTools::Package::ControlFiles::Rules
16
+ ]
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,30 @@
1
+ require 'time'
2
+
3
+ module DpkgTools
4
+ module Package
5
+ module Etc
6
+ module ControlFiles
7
+ class Changelog < DpkgTools::Package::ControlFiles::Changelog
8
+ def changelog
9
+ changelog_yaml = YAML::load_file(config.base_path + '/changelog.yml')
10
+ changelog_entries = []
11
+ changelog_yaml.each do |change|
12
+ change_lines = []
13
+ change_lines << "#{config.package_name} (#{change['version']}-1) cp-gutsy; urgency=low"
14
+ change['changes'].each do |lines|
15
+ lines = lines.split("\n")
16
+ # first line is different to the others
17
+ change_lines << " * " + lines.shift
18
+ lines.each { |line| change_lines << " " + line }
19
+ end
20
+ change_lines << " -- Matt Patterson <matt@reprocessed.org> #{Time.xmlschema(change['date']).rfc822}"
21
+ changelog_entries << change_lines.join("\n")
22
+ end
23
+ changelog_entries << "" # for that final newline
24
+ changelog_entries.join("\n")
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,18 @@
1
+ module DpkgTools
2
+ module Package
3
+ module Etc
4
+ module ControlFiles
5
+ class Rakefile < DpkgTools::Package::ControlFiles::Rakefile
6
+ def rakefile
7
+ "require 'rubygems'\n" \
8
+ "require 'dpkg-tools'\n" \
9
+ "\n" \
10
+ "DpkgTools::Package::Etc::BuildTasks.new do |t|\n" \
11
+ " t.base_path = Rake.original_dir\n" \
12
+ "end\n"
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,48 @@
1
+ module DpkgTools
2
+ module Package
3
+ module Etc
4
+ class Data < DpkgTools::Package::Data
5
+ class << self
6
+ include DpkgTools::Package::Data::YamlConfigHelpers
7
+
8
+ def resources_dirname
9
+ 'etc'
10
+ end
11
+ end
12
+
13
+ attr_reader :config, :base_path
14
+
15
+ def initialize(base_path)
16
+ @data = self.class.load_package_data(base_path, 'deb.yml')
17
+
18
+ @dependencies = self.class.process_dependencies(@data)
19
+ @base_path = base_path
20
+ end
21
+
22
+ def name
23
+ @data['name']
24
+ end
25
+
26
+ def version
27
+ @data['version']
28
+ end
29
+
30
+ def license
31
+ @data['license']
32
+ end
33
+
34
+ def dependencies
35
+ @dependencies
36
+ end
37
+
38
+ def build_dependencies
39
+ @dependencies
40
+ end
41
+
42
+ def summary
43
+ @data['summary']
44
+ end
45
+ end
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,31 @@
1
+ module DpkgTools
2
+ module Package
3
+ module Etc
4
+ class BuildTasks < DpkgTools::Package::BuildTasks
5
+ attr_accessor :base_path
6
+
7
+ def check_setup
8
+ raise ArgumentError, "Needs to have base_path set" unless @base_path
9
+ end
10
+
11
+ def create_builder
12
+ DpkgTools::Package::Etc.create_builder(@base_path)
13
+ end
14
+
15
+ def create_setup
16
+ DpkgTools::Package::Etc.create_setup(@base_path)
17
+ end
18
+
19
+ def define_tasks
20
+ task "binary-arch" do
21
+ create_builder.binary_package
22
+ end
23
+
24
+ task "binary-indep" do
25
+ create_builder.binary_package
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,30 @@
1
+ module DpkgTools
2
+ module Package
3
+ module Etc
4
+ class Setup < DpkgTools::Package::Setup
5
+ class << self
6
+ def data_class
7
+ DpkgTools::Package::Etc::Data
8
+ end
9
+
10
+ def bootstrap_files
11
+ ['deb.yml', 'changelog.yml']
12
+ end
13
+ end
14
+
15
+ def control_file_classes
16
+ DpkgTools::Package::Etc::ControlFiles.classes
17
+ end
18
+
19
+ def config_options
20
+ {:base_path => @data.base_path}
21
+ end
22
+
23
+ def prepare_package
24
+ etc_path = @config.base_path + '/etc'
25
+ Dir.mkdir(etc_path) unless File.directory?(etc_path)
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end