pre-packager 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: de0ea591935f7883fd0ad2425b3dcf7a19b6c794
4
+ data.tar.gz: 961acfbd2873b8a6b1194c466238a53b3503915b
5
+ SHA512:
6
+ metadata.gz: d2c3dddee3c508e59d356010b20549545492da2397551711adfa6044548d33b811788f18c479d5f9d6627e175ed077dcc52932d26715eb3470d9676f20ebbe95
7
+ data.tar.gz: 52bf9263f37ed318b280a5a330c99f8f0865f763412a847e88b138781db75cb4170f02fcc549343292d7d9a1eea7d19efd5a9a04ae492225c705a28bc7f35336
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ mkmf.log
15
+ e2e/*.tar.gz
16
+ e2e/**
17
+ !e2e/*.rb
data/.ruby-gemset ADDED
@@ -0,0 +1 @@
1
+ app-creator
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 2.2.0
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
data/Guardfile ADDED
@@ -0,0 +1,9 @@
1
+ guard 'rspec', cmd: 'bundle exec rspec' do
2
+ watch(%r{^lib/(.+).rb$}) do |m|
3
+ "spec/#{m[1]}_spec.rb"
4
+ end
5
+
6
+ watch(%r{^spec/(.+).rb$}) do |m|
7
+ "spec/#{m[1]}.rb"
8
+ end
9
+ end
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Gonzalo Matheu
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,31 @@
1
+ # Pre-Packager
2
+
3
+ Creates directory structure for linux applications
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'pre-packager'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install pre-packager
20
+
21
+ ## Usage
22
+
23
+ TODO: Write usage instructions here
24
+
25
+ ## Contributing
26
+
27
+ 1. Fork it (https://gitlab.com/gmatheu/pre-packager.git)
28
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
29
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
30
+ 4. Push to the branch (`git push origin my-new-feature`)
31
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,14 @@
1
+ require 'rspec/core/rake_task'
2
+ require 'bundler/gem_tasks'
3
+
4
+ RSpec::Core::RakeTask.new(:spec) do |task|
5
+ task.rspec_opts = ['--color']
6
+ end
7
+
8
+ RSpec::Core::RakeTask.new(:e2e) do |task|
9
+ task.rspec_opts = ['--color']
10
+ task.pattern = 'e2e/**{,/*/**}/*_spec.rb'
11
+ end
12
+
13
+ task :default => :spec
14
+
data/e2e/idea-14.rb ADDED
@@ -0,0 +1,19 @@
1
+ #! /usr/bin/env ruby
2
+
3
+ require 'pre-packager'
4
+ include PrePackager
5
+ Application.new(name: 'ideaIC-$version',
6
+ version: '14',
7
+ minor_version: '0.2').
8
+ download_from 'https://gitlab.com/gmatheu/app-tree-creator/raw/master/mock-files/$name.$minor_version.tar.gz' do |p|
9
+ # download_from 'http://download-cf.jetbrains.com/idea/$name.$minor_version.tar.gz' do |p|
10
+ p.extract('/opt', strip: 1, use_name: true) do |content|
11
+ content.link 'bin/idea.sh', use_name: true
12
+ end
13
+ end.
14
+ with_templates('idea-14-templates/*', '/usr/local/share/applications').
15
+ create_package(dry_run: true,
16
+ version: '$version.$minor_version',
17
+ description: 'IntelliJ Idea $version Community Edition',
18
+ maintainer: 'Gonzalo Matheu <gonzalommj@gmail.com>')
19
+
@@ -0,0 +1,47 @@
1
+ require 'spec_helper'
2
+ require 'shell'
3
+
4
+ def in_dir
5
+ Dir.chdir 'e2e' do
6
+ yield
7
+ end
8
+ end
9
+ def in_target
10
+ in_dir do
11
+ Dir.chdir 'ideaIC-14' do
12
+ yield
13
+ end
14
+ end
15
+ end
16
+ RSpec.describe 'Idea IC 14' do
17
+ let(:file) {'ideaIC-14.0.2.tar.gz'}
18
+ let(:target) {'ideaIC-14'}
19
+
20
+ after :each do
21
+ # in_dir { File.delete file if File.exists? file }
22
+ # in_dir { FileUtils.rm_rf target if File.exists? target }
23
+ end
24
+
25
+ context 'downloading file' do
26
+ in_dir { require './idea-14.rb' }
27
+
28
+ it 'downloads file' do
29
+ in_dir { expect(File.exists?(file)).to be_truthy }
30
+ end
31
+ it 'creates temp dir structure' do
32
+ in_target { expect(Pathname.new('opt/ideaIC-14').directory?).to be_truthy }
33
+ end
34
+ it 'creates symlink in path' do
35
+ in_target do
36
+ link = 'usr/local/bin/ideaIC-14'
37
+ expect(Pathname.new(link).exist?).to be_truthy
38
+ expect(Pathname.new(link).symlink?).to be_truthy
39
+ expect(File.readlink(link)).to eql '/opt/ideaIC-14/bin/idea.sh'
40
+ end
41
+ end
42
+ it 'copies templates in given directory' do
43
+ in_target { expect(Pathname.new('usr/local/share/applications').directory?).to be_truthy }
44
+ in_target { expect(File.exists?('usr/local/share/applications/idea-ic-14.desktop')).to be_truthy }
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,159 @@
1
+ require 'logger'
2
+ require 'uri'
3
+ require 'fileutils'
4
+ require 'pathname'
5
+
6
+ require 'pre-packager/version'
7
+ require 'pre-packager/interpolator'
8
+
9
+ module PrePackager
10
+ class Logger < Logger
11
+ def initialize
12
+ super STDOUT
13
+ self.formatter = proc do |severity, datetime, progname, msg|
14
+ "#{severity}: #{msg}\n"
15
+ end
16
+ end
17
+ end
18
+
19
+ module Executor
20
+ @@LOGGER = Logger.new
21
+ def execute cmd
22
+ @@LOGGER.info "Executing: #{cmd}"
23
+ `#{cmd}`
24
+ end
25
+ end
26
+
27
+ class ParamsAssertion
28
+ def initialize *values
29
+ @values = values
30
+ end
31
+
32
+ def included? opts
33
+ @values.each do |v|
34
+ raise ArgumentError.new "Should contain option: #{v}" unless opts.key? v
35
+ end
36
+ end
37
+ end
38
+
39
+ class Content
40
+ include Executor
41
+ @@LINK_BASE_DEFAULT = '/usr/local/bin'
42
+
43
+ def initialize context
44
+ @context = context
45
+ end
46
+
47
+ def link file, options
48
+ link_base = File.join @context.root, @@LINK_BASE_DEFAULT
49
+ FileUtils.mkdir_p link_base
50
+
51
+ target = File.join @context.base, @context.name, file
52
+ linkname = Pathname.new(file).basename.to_s
53
+ linkname = @context.name if options[:use_name]
54
+ link = File.join link_base, linkname
55
+
56
+ execute "ln -sf #{target} #{link}"
57
+ # File.symlink File.join(file), File.join(@path, @@LINK_BASE_DEFAULT, link)
58
+ end
59
+ end
60
+
61
+ class Package
62
+ include Executor
63
+ @@LOGGER = Logger.new
64
+
65
+ def initialize path, interpolator=Interpolator.new
66
+ @interpolator = interpolator
67
+ @file = path
68
+ end
69
+
70
+ class Context
71
+ attr_reader :name, :base, :root, :local_base
72
+
73
+ def initialize base, interpolator, opts
74
+ @base = base
75
+ @interpolator = interpolator
76
+
77
+ real_target = "./$name#{base}"
78
+ real_target = "#{real_target}/$name" if opts[:use_name]
79
+ @local_base = @interpolator.value_for real_target
80
+
81
+ @name = @interpolator.value_for '$name'
82
+ @root = File.join @local_base, '..', '..'
83
+ end
84
+ end
85
+
86
+ def extract target, opts
87
+ ctx = Context.new target, @interpolator, opts
88
+
89
+ strip = opts[:strip] || 0
90
+ FileUtils.mkdir_p ctx.local_base
91
+ execute "tar -xf #{@file} -C #{ctx.local_base} --strip #{strip}"
92
+
93
+ yield Content.new ctx
94
+ end
95
+ end
96
+
97
+ class Application
98
+ include Executor
99
+
100
+ @@VALID_FIELDS = [:description, :maintainer]
101
+ @@LOGGER = Logger.new
102
+
103
+ def initialize values={}
104
+ ParamsAssertion.new(:name).included? values
105
+ @interpolator = Interpolator.new values
106
+ end
107
+
108
+ def download_from url
109
+ uri = URI.parse interpolate(url)
110
+ file = File.basename uri.path
111
+
112
+ @@LOGGER.info "Downloading #{uri}"
113
+ execute "wget -nc #{uri}"
114
+
115
+ if block_given?
116
+ yield Package.new file, @interpolator
117
+ self
118
+ else
119
+ file
120
+ end
121
+ end
122
+
123
+ def with_templates from, to
124
+ FileUtils.mkdir_p interpolate("$name/#{to}")
125
+ target = interpolate("$name/#{to}")
126
+ Dir.glob(from).each {|f| FileUtils.cp_r f, target}
127
+
128
+ self
129
+ end
130
+
131
+ def create_package opts
132
+ ParamsAssertion.new(:version).included? opts
133
+ name = interpolate '$name'
134
+ paths = Pathname.new(name).
135
+ children.
136
+ map(&:basename).
137
+ map(&:to_s).
138
+ join ' '
139
+ valid_fields = Proc.new { |k, v| @@VALID_FIELDS.include? k}
140
+ compose_field = Proc.new { |k, v| %Q|--#{k} "#{v}"|}
141
+ fields = opts.
142
+ keep_if(&valid_fields).
143
+ map(&compose_field).
144
+ join ' '
145
+ cmd = interpolate %Q|
146
+ fpm -s dir -t deb -C #{name} -n #{name} -v #{opts[:version]} -a all #{fields} #{paths}
147
+ |
148
+ if opts[:dry_run]
149
+ @@LOGGER.info "Command to generate package: #{cmd}"
150
+ else
151
+ execute cmd
152
+ end
153
+ end
154
+
155
+ private def interpolate var
156
+ @interpolator.value_for var
157
+ end
158
+ end
159
+ end
@@ -0,0 +1,17 @@
1
+ require 'pre-packager/interpolator'
2
+
3
+ module PrePackager
4
+ class Interpolator
5
+ DEFAULT_CHARACTER='$'
6
+
7
+ def initialize vars = {}
8
+ @variables = vars
9
+ end
10
+
11
+ def value_for var
12
+ @variables.reduce(var) {
13
+ |acc, (k, v)| acc.gsub "#{DEFAULT_CHARACTER}#{k}", v
14
+ }
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,5 @@
1
+ module App
2
+ module Creator
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
Binary file
@@ -0,0 +1,29 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'pre-packager/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "pre-packager"
8
+ spec.version = App::Creator::VERSION
9
+ spec.authors = ["Gonzalo Matheu"]
10
+ spec.email = ["gonzalommj@gmail.com"]
11
+ spec.summary = %q{Creates directory structure for linux applications}
12
+ spec.description = %q{Provides a DSL to create directories, files and links structure from different sources (e.g: tar.gz, templates)}
13
+ spec.homepage = "https://gitlab.com/gmatheu/pre-packager"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.6"
22
+ spec.add_development_dependency "rake", "~> 10.0"
23
+ spec.add_development_dependency "rspec"
24
+ spec.add_development_dependency "guard"
25
+ spec.add_development_dependency "guard-rspec"
26
+ spec.add_development_dependency "pry"
27
+ spec.add_development_dependency "pry-nav"
28
+ spec.add_development_dependency "webmock"
29
+ end
@@ -0,0 +1,49 @@
1
+
2
+ require 'spec_helper'
3
+
4
+ require 'open-uri'
5
+
6
+ module Executor
7
+ def execute cmd
8
+ cmd
9
+ end
10
+ end
11
+
12
+ RSpec.describe Application do
13
+ describe "#download_from" do
14
+ let(:file) { 'file.tar.gz'}
15
+ let(:url) { "http://url/#{file}" }
16
+ subject { Application.new name: ''}
17
+
18
+ before :each do
19
+ stub_request(:get, url)
20
+ end
21
+
22
+ context 'just download' do
23
+ it 'returns file path' do
24
+ path = subject.download_from url
25
+ expect(path).to eq file
26
+ end
27
+ end
28
+ end
29
+
30
+ context 'interpolation' do
31
+ describe "#download_from" do
32
+ let(:file) { 'file-$version.tar.gz'}
33
+ let(:filename) { 'file-X.tar.gz' }
34
+ let(:url) { "http://url/#{file}" }
35
+ subject { Application.new name: 'name', version: 'X' }
36
+
37
+ before :each do
38
+ stub_request(:get, url)
39
+ end
40
+
41
+ context 'just download' do
42
+ it 'returns file path' do
43
+ path = subject.download_from url
44
+ expect(path).to eq filename
45
+ end
46
+ end
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,21 @@
1
+ require 'spec_helper'
2
+
3
+ RSpec.describe Interpolator do
4
+ describe "#value_for" do
5
+ context 'no interpolation' do
6
+ let(:value) { "variable" }
7
+ subject { Interpolator.new.value_for value }
8
+
9
+ it { is_expected.to eql value }
10
+ end
11
+
12
+ context 'interpolate a simple var' do
13
+ let(:val) { 'VAL' }
14
+ let(:var) { 'variable$val' }
15
+ let(:interpolator) { Interpolator.new val: val}
16
+ subject { interpolator.value_for var }
17
+
18
+ it { is_expected.to eql "variable#{val}"}
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,5 @@
1
+ require 'pry'
2
+ require 'webmock/rspec'
3
+ require 'pre-packager'
4
+
5
+ include PrePackager
metadata ADDED
@@ -0,0 +1,178 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: pre-packager
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Gonzalo Matheu
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-01-19 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.6'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.6'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: guard
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: guard-rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: pry
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: pry-nav
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: webmock
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ description: 'Provides a DSL to create directories, files and links structure from
126
+ different sources (e.g: tar.gz, templates)'
127
+ email:
128
+ - gonzalommj@gmail.com
129
+ executables: []
130
+ extensions: []
131
+ extra_rdoc_files: []
132
+ files:
133
+ - ".gitignore"
134
+ - ".ruby-gemset"
135
+ - ".ruby-version"
136
+ - Gemfile
137
+ - Guardfile
138
+ - LICENSE.txt
139
+ - README.md
140
+ - Rakefile
141
+ - e2e/idea-14.rb
142
+ - e2e/idea-14_spec.rb
143
+ - lib/pre-packager.rb
144
+ - lib/pre-packager/interpolator.rb
145
+ - lib/pre-packager/version.rb
146
+ - mock-files/ideaIC-14.0.2.tar.gz
147
+ - pre-packager.gemspec
148
+ - spec/application_spec.rb
149
+ - spec/interpolator_spec.rb
150
+ - spec/spec_helper.rb
151
+ homepage: https://gitlab.com/gmatheu/pre-packager
152
+ licenses:
153
+ - MIT
154
+ metadata: {}
155
+ post_install_message:
156
+ rdoc_options: []
157
+ require_paths:
158
+ - lib
159
+ required_ruby_version: !ruby/object:Gem::Requirement
160
+ requirements:
161
+ - - ">="
162
+ - !ruby/object:Gem::Version
163
+ version: '0'
164
+ required_rubygems_version: !ruby/object:Gem::Requirement
165
+ requirements:
166
+ - - ">="
167
+ - !ruby/object:Gem::Version
168
+ version: '0'
169
+ requirements: []
170
+ rubyforge_project:
171
+ rubygems_version: 2.4.3
172
+ signing_key:
173
+ specification_version: 4
174
+ summary: Creates directory structure for linux applications
175
+ test_files:
176
+ - spec/application_spec.rb
177
+ - spec/interpolator_spec.rb
178
+ - spec/spec_helper.rb