itamae-plugin-resource-pip 0.1.0 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 585b791c1cc78b0711d872c051b8a50d402d900d
4
- data.tar.gz: a4caf09814e071e7b2fdfc7758b5d55b08cf5b15
3
+ metadata.gz: ce7f115766e4005ac824399c3d9825d2864663a7
4
+ data.tar.gz: ed9a1594bfe82fd27b86ad7ea50a519990d6d976
5
5
  SHA512:
6
- metadata.gz: 347a34a691b455141705915bc2623d026fb60bea4d4119a68407e5860e36ccb0928b8e0ea010d802f536601d41de7657f4fe1bf69770450ca602a89ffee5d95b
7
- data.tar.gz: 3c4e216f424705a8e3a66d94e6ac9963b262800e0ef0e8645395d5b12f47a9de0deaeff4974c4d896d34dae535180e31eeecc0bd817a13fb48ad761fc8f6d81e
6
+ metadata.gz: 968fb21ac7e683a93c99c7204a1db231ba93025510ef73f7f6aafaf1175293946159e2e69107dfc362563582932769cdb855f72ddf927b2aec54da5d3ccf1192
7
+ data.tar.gz: 92c4685c5815b17a25645aed52dca76f0d8811b1d3266d2c7f065f5b0cd232656be292e7da01ebd5bd34433cbd5fbfccdbbb4513aa35375cbc8bb78293d9d1fe
@@ -4,7 +4,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
4
 
5
5
  Gem::Specification.new do |spec|
6
6
  spec.name = "itamae-plugin-resource-pip"
7
- spec.version = "0.1.0"
7
+ spec.version = "1.0.0"
8
8
  spec.authors = ["MATSUMOTO, Katsuyoshi"]
9
9
  spec.email = ["github@katsyoshi.org"]
10
10
 
@@ -13,6 +13,14 @@ Gem::Specification.new do |spec|
13
13
  spec.license = "MIT"
14
14
  spec.homepage = "https://github.com/katsyoshi/itamae-plugin-resource-pip"
15
15
 
16
+ # Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or
17
+ # delete this section to allow pushing this gem to any host.
18
+ if spec.respond_to?(:metadata)
19
+ spec.metadata['allowed_push_host'] = "https://rubygems.org"
20
+ else
21
+ raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
22
+ end
23
+
16
24
  spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
17
25
  spec.bindir = "exe"
18
26
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
@@ -57,7 +57,7 @@ module Itamae
57
57
  pips = []
58
58
  run_command([*Array(attributes.pip_binary), 'freeze']).stdout.each_line do |line|
59
59
  name, version = line.split(/==/)
60
- pips << {name: name, version: version}
60
+ pips << {name: name, version: version.chomp}
61
61
  end
62
62
  pips
63
63
  rescue Backend::CommandExecutionError
@@ -0,0 +1,14 @@
1
+ module MItamae
2
+ module Plugin
3
+ module Resource
4
+ class Pip < MItamae::Resource::Base
5
+ define_attribute :action, default: :install
6
+ define_attribute :pip_binary, type: [String, Array], default: 'pip'
7
+ define_attribute :package_name, type: String, default_name: true
8
+ define_attribute :version, type: String, default: false
9
+
10
+ self.available_actions = [:install, :uninstall, :upgrade]
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,81 @@
1
+ module MItamae
2
+ module Plugin
3
+ module ResourceExecutor
4
+ class Pip < MItamae::ResourceExecutor::Base
5
+ def apply(current, desired)
6
+ if desired.installed
7
+ if current.installed
8
+ if desired.version && current.version != desired.version
9
+ install!
10
+ updated!
11
+ end
12
+ else
13
+ install!
14
+ updated!
15
+ end
16
+ else
17
+ uninstall! if current.installed
18
+ end
19
+ end
20
+
21
+ private
22
+
23
+ def set_current_attributes(current, action)
24
+ installed = installed_pips.find {|pip| pip[:name] == attributes.package_name }
25
+ current.installed = !!installed
26
+
27
+ if current.installed
28
+ version = installed[:version]
29
+ current.version = version if version != attributes.version
30
+ end
31
+ end
32
+
33
+ def installed_pips
34
+ pips = []
35
+ run_command([*Array(attributes.pip_binary), 'freeze']).stdout.each_line do |line|
36
+ name, version = line.chomp.split(/==/)
37
+ pips << {name: name, version: version}
38
+ end
39
+ pips
40
+ rescue Backend::CommandExecutionError
41
+ []
42
+ end
43
+
44
+ def set_desired_attributes(desired, action)
45
+ case action
46
+ when :install, :upgrade
47
+ desired.installed = true
48
+ when :uninstall
49
+ desired.installed = false
50
+ end
51
+ end
52
+
53
+ def build_pip_install_command
54
+ end
55
+
56
+ def install!
57
+ cmd = [*Array(attributes.pip_binary), 'install']
58
+ if attributes.version
59
+ cmd << "#{attributes.package_name}==#{attributes.version}"
60
+ else
61
+ cmd << attributes.package_name
62
+ end
63
+
64
+ run_command(cmd)
65
+ end
66
+
67
+ def uninstall!
68
+ cmd = [*Array(attributes.pip_binary), 'uninstall']
69
+ if attributes.version
70
+ cmd << "#{attributes.package_name}==#{attributes.version}"
71
+ else
72
+ cmd << attributes.package_name
73
+ end
74
+ cmd << '-y'
75
+
76
+ run_command(cmd)
77
+ end
78
+ end
79
+ end
80
+ end
81
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: itamae-plugin-resource-pip
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - MATSUMOTO, Katsuyoshi
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2015-08-24 00:00:00.000000000 Z
11
+ date: 2016-11-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: itamae
@@ -66,10 +66,13 @@ files:
66
66
  - Rakefile
67
67
  - itamae-plugin-resource-pip.gemspec
68
68
  - lib/itamae/plugin/resource/pip.rb
69
+ - mrblib/itamae/plugin/resource/pip.rb
70
+ - mrblib/itamae/plugin/resource_executor/pip.rb
69
71
  homepage: https://github.com/katsyoshi/itamae-plugin-resource-pip
70
72
  licenses:
71
73
  - MIT
72
- metadata: {}
74
+ metadata:
75
+ allowed_push_host: https://rubygems.org
73
76
  post_install_message:
74
77
  rdoc_options: []
75
78
  require_paths:
@@ -86,7 +89,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
86
89
  version: '0'
87
90
  requirements: []
88
91
  rubyforge_project:
89
- rubygems_version: 2.4.5.1
92
+ rubygems_version: 2.5.2
90
93
  signing_key:
91
94
  specification_version: 4
92
95
  summary: itamae plugin resource pip