upackage 0.0.1 → 0.0.3

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4fa0734acd7165197e7726a35a200d656092f5ae
4
- data.tar.gz: 9b6c0ca4ca6057789d8c4aef16235431f7199df3
3
+ metadata.gz: 10ac4607048ad9d873e7eab3103f217ff1f4277e
4
+ data.tar.gz: d65363bee84f620b9521b5aad2c53b0a374aa441
5
5
  SHA512:
6
- metadata.gz: 570efe8290b0c24eb1e73fa2ad4e35f5eb90c7be3a0b170931aff9e0006f1cd395f968af0bed98f7584b31ebeabba7a5fc2a7f0550056fd83e76aa6e84ff749d
7
- data.tar.gz: ab31735b8c7f979751d739b0ce3c3f5742b0d9354d1a0017632a784cb741fbc57b846898dc3e200f869d4190e36653494938df68a710b55a18f8991443f24b39
6
+ metadata.gz: 286dbe872ea8071ccd01dd61ebf04900293d18b39ec2ecf2a5c7a2bdcc545cd2d42a0546fee72f9e7962c1cbadec30e3d38c4bb00333fa5378816c628ac07cd5
7
+ data.tar.gz: 087b54da7a721d46be336dd0739f6be0ef884d65763990b8d130f46726cdc25d7784f956ff1c85d09c71e0445bbf149d5c4421d25a303529d0049daf67047eab
data/.gitignore CHANGED
@@ -20,3 +20,6 @@ tmp
20
20
  *.o
21
21
  *.a
22
22
  mkmf.log
23
+ /.idea
24
+ /debian
25
+ *.swp
data/.rspec ADDED
@@ -0,0 +1,4 @@
1
+ --color
2
+ --warnings
3
+ --format documentation
4
+ --require spec_helper
data/Gemfile CHANGED
@@ -2,3 +2,6 @@ source 'https://rubygems.org'
2
2
 
3
3
  # Specify your gem's dependencies in upackage.gemspec
4
4
  gemspec
5
+
6
+ gem 'pry'
7
+ gem 'rspec-expectations'
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env ruby
2
+ # encoding: utf-8
3
+
4
+ require 'upackage'
5
+
6
+ Upackage::Creator.create
@@ -0,0 +1,58 @@
1
+ # encoding: utf-8
2
+ require 'system_gateway'
3
+
4
+ class Requirements
5
+
6
+ CONFIG_FILES = %w(changelog compat control)
7
+
8
+ class << self
9
+
10
+ def valid?
11
+ config_files && packages
12
+ end
13
+
14
+ private
15
+
16
+ def config_files
17
+ CONFIG_FILES.each do |config_file|
18
+ file = "debian/#{ config_file }"
19
+ unless File.exist?(file)
20
+ puts "There are no such file #{ file }"
21
+ return false
22
+ end
23
+ end
24
+ end
25
+
26
+ def packages
27
+ # Читаем control и ставим зависимости Build-Depends:
28
+ depends,not_installed = [], []
29
+ lines = File.readlines('debian/control')
30
+ lines.each do |line|
31
+ if line.start_with?('Build-Depends:')
32
+ depends = (line.sub('Build-Depends:', '').gsub(/\(.*\)/, '').split(','))
33
+ end
34
+ end
35
+ depends.each do |package|
36
+ command = "dpkg-query -l #{ package.strip } 2>&1 |awk 'END { if($1==\"ii\") exit 0; else exit 1; }'"
37
+ unless SystemGateway.perform_with_exit_code(command)
38
+ not_installed.push(package)
39
+ end
40
+ end
41
+ if not_installed.any?
42
+ puts "Installing packages...."
43
+ not_installed.each do |package|
44
+ command = "apt-get install -y -q #{ package }"
45
+ unless SystemGateway.perform_with_exit_code(command)
46
+ puts "Error occurred during install package: #{ package }"
47
+ return false
48
+ end
49
+ end
50
+ end
51
+
52
+ true
53
+ end
54
+
55
+
56
+ end
57
+
58
+ end
@@ -0,0 +1,15 @@
1
+ # encoding: utf-8
2
+ class SystemGateway
3
+
4
+ def self.perform(command)
5
+ puts "\033[34mPerforming: #{ command }\033[0m"
6
+ IO.popen(command).read
7
+ end
8
+
9
+ def self.perform_with_exit_code(command)
10
+ puts "\033[34mPerforming: #{ command }\033[0m"
11
+ system(command)
12
+ $?.success?
13
+ end
14
+
15
+ end
@@ -1,5 +1,75 @@
1
- require "upackage/version"
1
+ # encoding: utf-8
2
+ require 'upackage/version'
3
+ require 'requirements'
4
+ require 'system_gateway'
5
+ require 'yaml'
6
+ require 'pry'
7
+ require 'date'
2
8
 
3
9
  module Upackage
4
- # Your code goes here...
10
+
11
+ class Creator
12
+
13
+ class << self
14
+
15
+
16
+ def check_version
17
+ begin
18
+ distro = SystemGateway.perform('lsb_release -s -c').strip || 'unknown'
19
+ version = SystemGateway.perform('git describe --tags $(git rev-list --tags --max-count=1)').strip
20
+ version.delete('a-zA-Z<=~()').concat('-').concat(distro)
21
+ rescue
22
+ version = '0.1.0'.concat('-unknown')
23
+ end
24
+ end
25
+
26
+ def generate_changelog
27
+ comment = SystemGateway.perform('git --no-pager log -1 --oneline')
28
+ date = DateTime.now.strftime("%a, %e %b %Y %T %z")
29
+ project = File.basename(Dir.pwd)
30
+ lines = ["#{ project } (#{ self.check_version }) stable; urgency=medium",
31
+ " * #{ comment }",
32
+ " -- UNIQ systems <info@uniqsystems.ru> #{ date }"]
33
+ return lines
34
+ end
35
+
36
+ def clear
37
+ puts "deleting temporary files...."
38
+ SystemGateway.perform('git clean -fd')
39
+ SystemGateway.perform('git reset --hard')
40
+ end
41
+
42
+ def create
43
+ puts "\033[32mShow me what u got!\033[0m\n\n"
44
+ begin
45
+ File.open('debian/changelog', 'a') do |file|
46
+ self.generate_changelog.each do |line|
47
+ file.puts("#{ line }\n")
48
+ end
49
+ end
50
+ rescue
51
+ return 'Can\'t create debian/changelog file...'
52
+ end
53
+ if Requirements.valid?
54
+ if SystemGateway.perform_with_exit_code('dpkg-buildpackage -uc -us -b')
55
+ clear
56
+ begin
57
+ File.open('current_version', 'w'){ |file| file.write(self.check_version) }
58
+ rescue
59
+ puts "\033[31mCan't write version into version file!\033[0m"
60
+ end
61
+ puts "\033[32mYey! We have new package!\033[0m"
62
+ else
63
+ puts "\033[31mError while running 'dpkg-buildpackage'!\033[0m"
64
+ exit 1
65
+ end
66
+ else
67
+ 'Requirements are not satisfied :,('
68
+ end
69
+ end
70
+
71
+ end
72
+
73
+ end
74
+
5
75
  end
@@ -1,3 +1,4 @@
1
+ # encoding: utf-8
1
2
  module Upackage
2
- VERSION = "0.0.1"
3
+ VERSION = '0.0.3'
3
4
  end
@@ -0,0 +1,37 @@
1
+ # encoding: utf-8
2
+ describe Requirements do
3
+
4
+ describe 'valid?' do
5
+
6
+ it 'sholud return false' do
7
+ expect(Requirements.valid?).to be(false)
8
+ end
9
+
10
+ it 'should raise ENOENT exception cose we have no control' do
11
+ allow(File).to receive(:exist?).and_return(true)
12
+ expect { Requirements.valid? }.to raise_error(Errno::ENOENT, 'No such file or directory - debian/control')
13
+ end
14
+
15
+ it 'should return false if we have no installed packages' do
16
+ allow(File).to receive(:readlines).with('debian/control').and_return(['Build-Depends: cow, apt'])
17
+ allow(File).to receive(:exist?).and_return(true)
18
+ allow(SystemGateway).to receive(:perform_with_exit_code).and_return(false)
19
+ expect(Requirements.valid?).to be(false)
20
+ end
21
+
22
+ end
23
+
24
+ end
25
+
26
+ describe Upackage do
27
+
28
+ context 'when no permissions' do
29
+
30
+ it 'can\'t read changelog file' do
31
+ allow(File).to receive(:open).with('debian/changelog','a').and_raise(Errno::EACCES)
32
+ expect(Creator.create).to eq('Can\'t create debian/changelog file...')
33
+ end
34
+
35
+ end
36
+
37
+ end
@@ -0,0 +1,55 @@
1
+ # encoding: utf-8
2
+ describe Upackage do
3
+ it 'should take version from git tags' do
4
+ allow(SystemGateway).to receive(:perform).with('git describe --abbrev=0 --tags').and_return('v1.2.1')
5
+ expect(Creator.check_version).to eq('1.2.1')
6
+ end
7
+
8
+ it 'should generate changelog file' do
9
+ allow(SystemGateway).to receive(:perform).with('git describe --abbrev=0 --tags').and_return('v1.2.1')
10
+ allow(SystemGateway).to receive(:perform).with('git --no-pager log -1 --oneline').and_return('bug closed #123123')
11
+ allow( File).to receive(:basename).and_return('omg-cashier')
12
+ lines=[ 'omg-cashier (1.2.1) stable; urgency=medium',
13
+ ' * bug closed #123123',
14
+ " -- UNIQ systems <info@uniqsystems.ru> #{ DateTime.now.strftime("%a, %e %b %Y %T %z") }"]
15
+ expect(Creator.generate_changelog).to eq(lines)
16
+ end
17
+
18
+ it 'should install neccesarry packages' do
19
+ allow(File).to receive(:readlines).with('debian/control').and_return(['Build-Depends: apt, cow'])
20
+ allow(File).to receive(:exist?).and_return(true)
21
+ allow(File).to receive(:open).and_return(true)
22
+ [
23
+ "dpkg-query -l apt 2>&1 |awk 'END { if($1==\"ii\") exit 0; else exit 1; }'",
24
+ "dpkg-query -l cow 2>&1 |awk 'END { if($1==\"ii\") exit 0; else exit 1; }'"
25
+ ].each do |command|
26
+ allow(SystemGateway).to receive(:perform_with_exit_code).with(command).and_return(false)
27
+ end
28
+ [
29
+ "apt-get install -q -y apt 2>&1",
30
+ "apt-get install -q -y cow 2>&1"
31
+ ].each do |command|
32
+ expect(SystemGateway).to receive(:perform_with_exit_code).with(command)
33
+ end
34
+ end
35
+
36
+ it 'should build package' do
37
+ allow(File).to receive(:readlines).with('debian/control').and_return(['Build-Depends: apt, cow'])
38
+ allow(File).to receive(:exist?).and_return(true)
39
+ allow(File).to receive(:open).and_return(true)
40
+ allow(SystemGateway).to receive(:perform).and_return(true)
41
+ allow(SystemGateway).to receive(:perform_with_exit_code).and_return(true)
42
+
43
+ [
44
+ "dpkg-query -l apt 2>&1 |awk 'END { if($1==\"ii\") exit 0; else exit 1; }'",
45
+ "dpkg-query -l cow 2>&1 |awk 'END { if($1==\"ii\") exit 0; else exit 1; }'"
46
+ ].each do |command|
47
+ expect(SystemGateway).to receive(:perform_with_exit_code).with(command)
48
+ end
49
+ %w(changelog compat control).each do |file|
50
+ expect(File).to receive(:exist?).with("debian/#{file}")
51
+ end
52
+
53
+ Creator.create
54
+ end
55
+ end
@@ -0,0 +1,83 @@
1
+ # encoding: utf-8
2
+ require 'upackage'
3
+
4
+ include Upackage
5
+
6
+ # This file was generated by the `rspec --init` command. Conventionally, all
7
+ # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
8
+ # The generated `.rspec` file contains `--require spec_helper` which will cause this
9
+ # file to always be loaded, without a need to explicitly require it in any files.
10
+ #
11
+ # Given that it is always loaded, you are encouraged to keep this file as
12
+ # light-weight as possible. Requiring heavyweight dependencies from this file
13
+ # will add to the boot time of your test suite on EVERY test run, even for an
14
+ # individual file that may not need all of that loaded. Instead, make a
15
+ # separate helper file that requires this one and then use it only in the specs
16
+ # that actually need it.
17
+ #
18
+ # The `.rspec` file also contains a few flags that are not defaults but that
19
+ # users commonly want.
20
+ #
21
+ # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
22
+ RSpec.configure do |config|
23
+ # The settings below are suggested to provide a good initial experience
24
+ # with RSpec, but feel free to customize to your heart's content.
25
+ =begin
26
+ # These two settings work together to allow you to limit a spec run
27
+ # to individual examples or groups you care about by tagging them with
28
+ # `:focus` metadata. When nothing is tagged with `:focus`, all examples
29
+ # get run.
30
+ config.filter_run :focus
31
+ config.run_all_when_everything_filtered = true
32
+
33
+ # Many RSpec users commonly either run the entire suite or an individual
34
+ # file, and it's useful to allow more verbose output when running an
35
+ # individual spec file.
36
+ if config.files_to_run.one?
37
+ # Use the documentation formatter for detailed output,
38
+ # unless a formatter has already been configured
39
+ # (e.g. via a command-line flag).
40
+ config.default_formatter = 'doc'
41
+ end
42
+
43
+ # Print the 10 slowest examples and example groups at the
44
+ # end of the spec run, to help surface which specs are running
45
+ # particularly slow.
46
+ config.profile_examples = 10
47
+
48
+ # Run specs in random order to surface order dependencies. If you find an
49
+ # order dependency and want to debug it, you can fix the order by providing
50
+ # the seed, which is printed after each run.
51
+ # --seed 1234
52
+ config.order = :random
53
+
54
+ # Seed global randomization in this process using the `--seed` CLI option.
55
+ # Setting this allows you to use `--seed` to deterministically reproduce
56
+ # test failures related to randomization by passing the same `--seed` value
57
+ # as the one that triggered the failure.
58
+ Kernel.srand config.seed
59
+
60
+ # rspec-expectations config goes here. You can use an alternate
61
+ # assertion/expectation library such as wrong or the stdlib/minitest
62
+ # assertions if you prefer.
63
+ config.expect_with :rspec do |expectations|
64
+ # Enable only the newer, non-monkey-patching expect syntax.
65
+ # For more details, see:
66
+ # - http://myronmars.to/n/dev-blog/2012/06/rspecs-new-expectation-syntax
67
+ expectations.syntax = :expect
68
+ end
69
+
70
+ # rspec-mocks config goes here. You can use an alternate test double
71
+ # library (such as bogus or mocha) by changing the `mock_with` option here.
72
+ config.mock_with :rspec do |mocks|
73
+ # Enable only the newer, non-monkey-patching expect syntax.
74
+ # For more details, see:
75
+ # - http://teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
76
+ mocks.syntax = :expect
77
+
78
+ # Prevents you from mocking or stubbing a method that does not exist on
79
+ # a real object. This is generally recommended.
80
+ mocks.verify_partial_doubles = true
81
+ end
82
+ =end
83
+ end
@@ -13,10 +13,11 @@ Gem::Specification.new do |spec|
13
13
  spec.license = "MIT"
14
14
 
15
15
  spec.files = `git ls-files -z`.split("\x0")
16
- spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
16
+ spec.executables = 'upackage'
17
17
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
18
18
  spec.require_paths = ["lib"]
19
19
 
20
20
  spec.add_development_dependency "bundler", "~> 1.6"
21
21
  spec.add_development_dependency "rake"
22
+ spec.add_development_dependency "rspec"
22
23
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: upackage
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ivan Kasatenko
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-06-05 00:00:00.000000000 Z
11
+ date: 2014-09-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -38,20 +38,42 @@ dependencies:
38
38
  - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: '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'
41
55
  description:
42
56
  email:
43
57
  - sky.31338@gmail.com
44
- executables: []
58
+ executables:
59
+ - upackage
45
60
  extensions: []
46
61
  extra_rdoc_files: []
47
62
  files:
48
63
  - ".gitignore"
64
+ - ".rspec"
49
65
  - Gemfile
50
66
  - LICENSE.txt
51
67
  - README.md
52
68
  - Rakefile
69
+ - bin/upackage
70
+ - lib/requirements.rb
71
+ - lib/system_gateway.rb
53
72
  - lib/upackage.rb
54
73
  - lib/upackage/version.rb
74
+ - spec/cli/exceptions_spec.rb
75
+ - spec/cli/packaging_spec.rb
76
+ - spec/spec_helper.rb
55
77
  - upackage.gemspec
56
78
  homepage: ''
57
79
  licenses:
@@ -77,4 +99,7 @@ rubygems_version: 2.2.2
77
99
  signing_key:
78
100
  specification_version: 4
79
101
  summary: Debian packaging for Ruby and Ruby on Rails applications
80
- test_files: []
102
+ test_files:
103
+ - spec/cli/exceptions_spec.rb
104
+ - spec/cli/packaging_spec.rb
105
+ - spec/spec_helper.rb