toybox 0.0.0 → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.0
1
+ 0.1.0
@@ -0,0 +1,4 @@
1
+ module Toybox
2
+ module Generators
3
+ end
4
+ end
@@ -0,0 +1,20 @@
1
+ require 'rails/generators/base'
2
+
3
+ module Toybox
4
+ module Generators
5
+ class InstallGenerator < Rails::Generators::Base
6
+
7
+ desc 'Create initial config files for toybox'
8
+ # see https://github.com/rspec/rspec-rails/blob/master/lib/generators/rspec.rb
9
+ # for alternatives
10
+ def self.source_root
11
+ @source_root ||= File.expand_path("../templates", __FILE__)
12
+ end
13
+
14
+ # all public methods in here will be run in order
15
+ def add_initializer_config
16
+ template "toybox.rb", "config/initializers/toybox.rb"
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,57 @@
1
+ Toybox.configure do
2
+ {
3
+ # app_root: the path to the final resting place of your
4
+ # package's data. Do not include the initial slash ('/')
5
+ :app_root => 'path/to/app/root',
6
+
7
+ # publish_host: the ssh-able host to publish the file to
8
+ :publish_host => 'somewhere.yourdomain.com',
9
+
10
+ # username: The user the app is to be owned by
11
+ :username => 'some_user',
12
+
13
+ # group_name: The group the app is to be owned by
14
+ :group_name => 'some_group',
15
+
16
+ # files: description to be added (TODO)
17
+ :files => [
18
+ 'debian/package.dirs',
19
+ 'rules1.mk'
20
+ ],
21
+
22
+ # other_files: description to be added (TODO)
23
+ :other_files => [
24
+ 'build-stamp',
25
+ 'install-stamp'
26
+ ],
27
+
28
+ # directories: description to be added (TODO)
29
+ :directories => [
30
+ '.'
31
+ ],
32
+
33
+ # prune_dirs: Directories to be pruned out
34
+ :prune_dirs => [
35
+ '.git',
36
+ 'debian',
37
+ 'test'
38
+ ],
39
+
40
+ # ignore_dirs: Directories to be included, even if they
41
+ # match the pattern of a prune dir. This is to assert
42
+ # that if, for instance, you have listed test in prune_dirs
43
+ # to remove the tests from the debian package, but an installed
44
+ # bundle contains the word test (think Rack::Test), it doens't
45
+ # prune it
46
+ :ignore_dirs => [
47
+ 'vendor/bundle',
48
+ 'vendor/plugins'
49
+ ],
50
+
51
+
52
+ # use_production_yamls: If enabled (true), then we will only include
53
+ # yamls that match the config/*_production.yml pattern in the package.
54
+ # If disabled, then we won't prune yaml files
55
+ :use_production_yamls => true
56
+ }
57
+ end
@@ -0,0 +1,213 @@
1
+ namespace :toybox do
2
+
3
+ FILES = Toybox.config[:files]
4
+ OTHER_FILES = Toybox.config[:other_files]
5
+
6
+ desc 'Initialize the project for debianization'
7
+ task :init, [:name, :version] => [:environment] do |t, project|
8
+ unless (project[:name]&&project[:version])
9
+ raise Exception.new("Need to provide name and version args!")
10
+ end
11
+ devel_debs = %w{build-essential cdbs debhelper sed make
12
+ devscripts dh-make dpatch dpkg-dev
13
+ fakeroot lintian}
14
+ sh "sudo apt-get install #{devel_debs.join(' ')}"
15
+ sh "dh_make -p #{project[:name]}_#{project[:version]} -b -n"
16
+ puts "Removing example files from the debian/ folder"
17
+ sh "find #{Rails.root}/debian -iname '*.ex' -exec rm {} \\;"
18
+ File.open("#{Rails.root}/debian/rules",'w') do |f|
19
+ f.puts <<EOF
20
+ #!/usr/bin/make -f
21
+
22
+ # include /usr/share/cdbs/1/rules/debhelper.mk
23
+ include /usr/share/cdbs/1/rules/buildvars.mk
24
+
25
+ PKG=$(DEB_SOURCE_PACKAGE)
26
+ LN=ln -sf
27
+
28
+ clean::
29
+ @echo "clean me"
30
+ # dh_testdir
31
+ # dh_testroot
32
+ rm -f build-stamp install-stamp
33
+ -echo $(MAKE) clean
34
+ dh_clean
35
+ -rm debian/$(PKG).dirs
36
+
37
+ package-name:
38
+ @echo DEB_SOURCE_PACKAGE=$(DEB_SOURCE_PACKAGE)
39
+
40
+
41
+ build: build-stamp
42
+
43
+ build-stamp:
44
+ dh_testdir
45
+ echo $(MAKE)
46
+ touch build-stamp
47
+
48
+ install: install-stamp
49
+
50
+ install-stamp: build-stamp install-setup install-files install-links
51
+ touch install-stamp
52
+
53
+ FAKEROOT=./debian/$(PKG)
54
+
55
+ debian/$(PKG).dirs: debian/package.dirs
56
+ @cp $< $@
57
+
58
+ install-setup: debian/$(PKG).dirs
59
+ dh_testdir
60
+ dh_testroot
61
+ dh_clean -k
62
+ mkdir $(FAKEROOT)
63
+ ( cd $(FAKEROOT) ; cat ../$(PKG).dirs | tr '\\n' '\\0'| xargs -0 -Ix install -d -m 755 x)
64
+ #dh_installdirs
65
+ #touch install-setup
66
+
67
+ include rules1.mk
68
+
69
+ install-links:
70
+ @echo 1 >/dev/null
71
+
72
+ # Build architecture-independent files here.
73
+ # We have nothing to do
74
+ binary-indep: build install
75
+ @echo nothing >/dev/null
76
+
77
+ # Build architecture-dependent files here.
78
+ binary-arch: build install
79
+ dh_testdir
80
+ dh_testroot
81
+ dh_installdocs
82
+ dh_installinit -n --name=#{Toybox.config[:username]}
83
+ dh_installinit -n --name=#{Toybox.config[:username]}-worker
84
+ # -u"start 2 3 . stop 11 1 ."
85
+ dh_installcron
86
+ dh_installman
87
+ dh_link
88
+ # dh_installchangelogs ChangeLog
89
+ dh_installchangelogs
90
+ #dh_installdebconf
91
+ # dh_strip
92
+ # dh_fixperms
93
+ chown #{Toybox.config[:username]}:#{Toybox.config[:group_name]} -R $(FAKEROOT)/#{Toybox.config[:app_root]}
94
+ dh_compress
95
+ dh_installdeb
96
+ #dh_shlibdeps
97
+ dh_gencontrol
98
+ dh_md5sums
99
+ dh_builddeb
100
+
101
+ source diff:
102
+ @echo >&2 'source and diff are obsolete - use dpkg-source -b'; false
103
+
104
+ binary: binary-indep binary-arch
105
+ .PHONY: build clean binary-indep binary-arch binary
106
+ EOF
107
+
108
+ end
109
+ end
110
+
111
+ # Change the *.rake to be:
112
+ # File.join(File.dirname(__FILE__), File.basename(__FILE__))
113
+ file 'rules1.mk' => [File.join(File.dirname(__FILE__), File.basename(__FILE__)),'Rakefile','.'] do |t|
114
+ puts 'building rules1.mk'
115
+ s = Toybox::files().map{|f| "\t@" + f.debian_install_cmd }
116
+ open(t.name,'w') do |io|
117
+ io.puts "#
118
+ # auto generated
119
+ #
120
+ ifndef SRC
121
+ SRC=.
122
+ endif
123
+ install-files::"
124
+ io.puts s
125
+ end
126
+ end
127
+
128
+ file "debian/package.dirs" => [File.join(File.dirname(__FILE__), File.basename(__FILE__)),'Rakefile','.'] do |t|
129
+ puts 'building debian/package.dirs file listing'
130
+ dirs = Toybox::dpkg_find do |path|
131
+ if Kernel.test('d', path) and not Kernel.test('l',path) then
132
+ path
133
+ end
134
+ end
135
+ open(t.name, 'w') do |io|
136
+ dirs.each { |d1| io.puts "#{Toybox.config[:app_root]}/#{d1}" }
137
+ end
138
+ end
139
+
140
+ task :files => ['debian/package.dirs', 'rules1.mk'] do |t|
141
+ puts 'built files'
142
+ end
143
+
144
+ task :bundle do |t|
145
+ Bundler.with_clean_env do
146
+ puts "******************************************"
147
+ puts "* Warning: Running bundler *"
148
+ puts "* Go drink a coffee or something *"
149
+ puts "******************************************"
150
+ sh "bundle install --deployment --without test development"
151
+ end
152
+ end
153
+
154
+ desc 'build debian package'
155
+ task :debianize => [:environment, :user, :bundle, :files].flatten do |t|
156
+ puts "building ..."
157
+ sh 'dpkg-buildpackage -rfakeroot -uc -us '
158
+ end
159
+
160
+ desc 'submit last package to somewhere.'
161
+ task :publish do |t|
162
+ changelog = parsechangelog
163
+ fn = "../#{debian_package(changelog)}"
164
+ if Kernel.test('rf', fn) then
165
+ host = Toybox.config[:publish_host]
166
+ sh "scp '#{fn}' '#{host}:' "
167
+ sh "git commit -s -m'#{package_version} build changelog' debian/changelog"
168
+ pending_commits = %x[git log --pretty=oneline origin..master | wc -l].chomp.to_i
169
+ if pending_commits == 1
170
+ sh "git push"
171
+ puts "\ndebian/changelog commited and pushed."
172
+ else
173
+ puts "\nYou have other pending commits. Please push the debian/changelog commit manually."
174
+ end
175
+ else
176
+ raise "Error, can't find or read file #{fn}"
177
+ end
178
+ end
179
+
180
+ task :user do |t|
181
+ puts Toybox.config.inspect
182
+ Etc.getgrnam(Toybox.config[:group_name])
183
+ Etc.getpwnam(Toybox.config[:username])
184
+ end
185
+
186
+ desc 'clean up'
187
+ task :clean => [:environment] do
188
+ sh 'dh_clean'
189
+ [FILES, OTHER_FILES].flatten.each {|f| rm_f f }
190
+ rm_f `ls debian/*.dirs`.strip
191
+ # rm_f 'build-stamp'
192
+ # rm_f 'install-stamp'
193
+ end
194
+
195
+ desc 'add a changelog entry - use version=0.0.0 to set version'
196
+ task :changelog do #=> [] do
197
+ v = find_ver(ENV)
198
+ opt = "-i"
199
+ opt = "-v #{v}" unless v.nil?
200
+ distro = `lsb_release -i`
201
+ if distro =~ /Ubuntu/ then
202
+ distributor = "--distributor Debian"
203
+ else
204
+ distributor = ""
205
+ end
206
+ sh "dch --no-auto-nmu #{distributor} --distribution stable #{opt}"
207
+ end
208
+ desc 'list the version of the package from changelog'
209
+ task :version => [] do
210
+ puts package_version
211
+ end
212
+
213
+ end #end of namespace
@@ -0,0 +1,119 @@
1
+ module Toybox
2
+
3
+ require 'etc'
4
+ require 'find'
5
+ require 'toybox/txtfile'
6
+ require 'toybox/configfile'
7
+ require 'toybox/exefile'
8
+ require 'toybox/linkfile'
9
+
10
+ @@config_data = {}
11
+
12
+ class ToyboxTask < Rails::Railtie
13
+ rake_tasks do
14
+ Dir[File.join(File.dirname(__FILE__),'tasks/*.rake')].each { |f| load f }
15
+ end
16
+ end
17
+
18
+ def self.app_fakeroot
19
+ "$(FAKEROOT)/#{Toybox.config[:app_root]}"
20
+ end
21
+
22
+ def self.configure(config = nil, &block)
23
+ # Given that we want things as they relate to the rails app,
24
+ # the path given as config should be relative to Rails.root
25
+ if config.is_a?(String) && config =~ /\S+\..yml/i then
26
+ @@config_data = YAML::load_file(File.join(Rails.root, config)).freeze
27
+ else
28
+ @@config_data = (yield).freeze
29
+ end
30
+ end
31
+
32
+ def self.config
33
+ @@config_data
34
+ end
35
+
36
+ def self.is_non_production_yaml?(path)
37
+ return false unless path =~ /\/config\/\w+\.yml$/
38
+ if path =~ /\/config\/\w+_production\.yml$/ then
39
+ false
40
+ else
41
+ true
42
+ end
43
+ end
44
+
45
+ def self.filetype(path)
46
+ return nil if Kernel.test('d', path) and not Kernel.test('l', path)
47
+ return nil if Toybox.config[:other_files].member? path
48
+ return nil if Toybox.config[:files].member? path
49
+ if Toybox.config[:use_production_yamls] then
50
+ if is_non_production_yaml?(path) then
51
+ STDERR.puts "skipping file: #{path}"
52
+ return nil
53
+ end
54
+ end
55
+ return nil if path =~ /config.database.yml$/
56
+ return nil if path =~ /config.ldap.yml$/
57
+ if Kernel.test('l', path) then
58
+ Linkfile.new(path)
59
+ elsif Kernel.test('x',path) then
60
+ Exefile.new(path)
61
+ elsif path =~ %r{^[\.\/]+config/} then
62
+ Configfile.new(path)
63
+ else
64
+ Txtfile.new(path)
65
+ end
66
+ end
67
+
68
+ def self.path_contains(path, arg)
69
+ arg.each do |s|
70
+ return true if path =~ Regexp.new(s)
71
+ end
72
+ false
73
+ end
74
+
75
+ def self.dpkg_find(&block)
76
+ Toybox.config[:directories].map { |dir|
77
+ f = []
78
+ Find.find(dir) do |path|
79
+ if Toybox.config[:prune_dirs].member? File.basename(path) and not path_contains(path, Toybox.config[:ignore_dirs]) then
80
+ Find.prune
81
+ elsif Toybox.config[:files].member? File.basename(path) then
82
+ next
83
+ elsif Toybox.config[:other_files].member? File.basename(path) then
84
+ next
85
+ elsif File.basename(path) =~ /^ruby_sess.*/ then
86
+ next
87
+ else
88
+ x = yield(path)
89
+ f << x
90
+ end
91
+ end
92
+ f.compact
93
+ }.flatten.compact
94
+ end
95
+
96
+ def self.files()
97
+ dpkg_find do |path|
98
+ if path =~ /\.log$/ then
99
+ nil
100
+ else
101
+ filetype(path)
102
+ end
103
+ end
104
+ end
105
+ def self.parsechangelog
106
+ changelog = %x{dpkg-parsechangelog}
107
+ package, version = changelog.split("\n")[0,2].map{|x| x.split.last }
108
+ arch = %x{dpkg-architecture -qDEB_HOST_ARCH}.chomp
109
+ [ package, version, arch ]
110
+ end
111
+ def self.debian_package(clog)
112
+ "#{clog.join('_')}.deb"
113
+ end
114
+ def self.package_version
115
+ clog = parsechangelog
116
+ clog[1]
117
+ end
118
+
119
+ end
@@ -0,0 +1,7 @@
1
+ module Toybox
2
+ class Configfile < Txtfile
3
+ def install_cmd
4
+ "install -D -m 640 "
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,7 @@
1
+ module Toybox
2
+ class Exefile < Txtfile
3
+ def install_cmd
4
+ "install -m 755 "
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,18 @@
1
+ module Toybox
2
+ class Linkfile < Txtfile
3
+ attr_accessor :link_dest
4
+ def initialize(p)
5
+ super(p)
6
+ self.link_dest = File.readlink(p)
7
+ end
8
+ def to_s
9
+ "#{self.class}: +l #{path.to_s}"
10
+ end
11
+ def install_cmd
12
+ "@ln -s "
13
+ end
14
+ def install_src
15
+ link_dest
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,26 @@
1
+ module Toybox
2
+ class Txtfile
3
+ attr_accessor :path
4
+ def initialize(p)
5
+ self.path = Pathname.new(p)
6
+ end
7
+ def to_s
8
+ "#{self.class}: #{path.to_s}"
9
+ end
10
+ def q(s)
11
+ '"' + s + '"'
12
+ end
13
+ def install_cmd
14
+ "install -D -m 644"
15
+ end
16
+ def install_src
17
+ "$(SRC)/#{path.to_s}"
18
+ end
19
+ def install_dest
20
+ "#{Toybox::app_fakeroot}/#{path.to_s}"
21
+ end
22
+ def debian_install_cmd
23
+ [install_cmd, q(install_src), q(install_dest)].join(' ')
24
+ end
25
+ end
26
+ end
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{toybox}
8
- s.version = "0.0.0"
8
+ s.version = "0.1.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Kristofer M White"]
12
- s.date = %q{2011-05-12}
12
+ s.date = %q{2011-05-26}
13
13
  s.description = %q{Debianize your rails app, the Debian way}
14
14
  s.email = %q{me@kmwhite.net}
15
15
  s.extra_rdoc_files = [
@@ -24,9 +24,18 @@ Gem::Specification.new do |s|
24
24
  "README.rdoc",
25
25
  "Rakefile",
26
26
  "VERSION",
27
+ "lib/generators/toybox.rb",
28
+ "lib/generators/toybox/install_generator.rb",
29
+ "lib/generators/toybox/templates/toybox.rb",
30
+ "lib/tasks/toybox.rake",
27
31
  "lib/toybox.rb",
32
+ "lib/toybox/configfile.rb",
33
+ "lib/toybox/exefile.rb",
34
+ "lib/toybox/linkfile.rb",
35
+ "lib/toybox/txtfile.rb",
28
36
  "test/helper.rb",
29
- "test/test_toybox.rb"
37
+ "test/test_toybox.rb",
38
+ "toybox.gemspec"
30
39
  ]
31
40
  s.homepage = %q{http://github.com/kmwhite/toybox}
32
41
  s.licenses = ["BSD"]
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: toybox
3
3
  version: !ruby/object:Gem::Version
4
- hash: 31
4
+ hash: 27
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
+ - 1
8
9
  - 0
9
- - 0
10
- version: 0.0.0
10
+ version: 0.1.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Kristofer M White
@@ -15,12 +15,13 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-05-12 00:00:00 -05:00
18
+ date: 2011-05-26 00:00:00 -05:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
22
- name: bundler
23
- version_requirements: &id001 !ruby/object:Gem::Requirement
22
+ prerelease: false
23
+ type: :development
24
+ requirement: &id001 !ruby/object:Gem::Requirement
24
25
  none: false
25
26
  requirements:
26
27
  - - ~>
@@ -31,12 +32,12 @@ dependencies:
31
32
  - 0
32
33
  - 0
33
34
  version: 1.0.0
35
+ name: bundler
36
+ version_requirements: *id001
37
+ - !ruby/object:Gem::Dependency
34
38
  prerelease: false
35
39
  type: :development
36
- requirement: *id001
37
- - !ruby/object:Gem::Dependency
38
- name: jeweler
39
- version_requirements: &id002 !ruby/object:Gem::Requirement
40
+ requirement: &id002 !ruby/object:Gem::Requirement
40
41
  none: false
41
42
  requirements:
42
43
  - - ~>
@@ -47,12 +48,12 @@ dependencies:
47
48
  - 6
48
49
  - 0
49
50
  version: 1.6.0
51
+ name: jeweler
52
+ version_requirements: *id002
53
+ - !ruby/object:Gem::Dependency
50
54
  prerelease: false
51
55
  type: :development
52
- requirement: *id002
53
- - !ruby/object:Gem::Dependency
54
- name: rcov
55
- version_requirements: &id003 !ruby/object:Gem::Requirement
56
+ requirement: &id003 !ruby/object:Gem::Requirement
56
57
  none: false
57
58
  requirements:
58
59
  - - ">="
@@ -61,12 +62,12 @@ dependencies:
61
62
  segments:
62
63
  - 0
63
64
  version: "0"
65
+ name: rcov
66
+ version_requirements: *id003
67
+ - !ruby/object:Gem::Dependency
64
68
  prerelease: false
65
69
  type: :development
66
- requirement: *id003
67
- - !ruby/object:Gem::Dependency
68
- name: reek
69
- version_requirements: &id004 !ruby/object:Gem::Requirement
70
+ requirement: &id004 !ruby/object:Gem::Requirement
70
71
  none: false
71
72
  requirements:
72
73
  - - ~>
@@ -77,12 +78,12 @@ dependencies:
77
78
  - 2
78
79
  - 8
79
80
  version: 1.2.8
81
+ name: reek
82
+ version_requirements: *id004
83
+ - !ruby/object:Gem::Dependency
80
84
  prerelease: false
81
85
  type: :development
82
- requirement: *id004
83
- - !ruby/object:Gem::Dependency
84
- name: roodi
85
- version_requirements: &id005 !ruby/object:Gem::Requirement
86
+ requirement: &id005 !ruby/object:Gem::Requirement
86
87
  none: false
87
88
  requirements:
88
89
  - - ~>
@@ -93,9 +94,8 @@ dependencies:
93
94
  - 1
94
95
  - 0
95
96
  version: 2.1.0
96
- prerelease: false
97
- type: :development
98
- requirement: *id005
97
+ name: roodi
98
+ version_requirements: *id005
99
99
  description: Debianize your rails app, the Debian way
100
100
  email: me@kmwhite.net
101
101
  executables: []
@@ -113,7 +113,15 @@ files:
113
113
  - README.rdoc
114
114
  - Rakefile
115
115
  - VERSION
116
+ - lib/generators/toybox.rb
117
+ - lib/generators/toybox/install_generator.rb
118
+ - lib/generators/toybox/templates/toybox.rb
119
+ - lib/tasks/toybox.rake
116
120
  - lib/toybox.rb
121
+ - lib/toybox/configfile.rb
122
+ - lib/toybox/exefile.rb
123
+ - lib/toybox/linkfile.rb
124
+ - lib/toybox/txtfile.rb
117
125
  - test/helper.rb
118
126
  - test/test_toybox.rb
119
127
  - toybox.gemspec