qb 0.3.9 → 0.3.10

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: d3fd3a036ee3a1411833a1e6ac82066a7ee291c0
4
- data.tar.gz: 9caacbd64094d48b491115d62a80940e1932438f
3
+ metadata.gz: 3e3857fd48613a9211357d03cfd036acb2ecc589
4
+ data.tar.gz: a2ad6ea73512c132ce1ba5975e62503ee42d0dbd
5
5
  SHA512:
6
- metadata.gz: bf5bbd2d09e43ba8be882cfbf5fee05669c124c7366eda20b31e1ad86e13ec844dc7c9a237d342475994a187c12565ab7f8d8d21d5f88ab92b79bf128dbfae1b
7
- data.tar.gz: 4f6351760bb78e66626ea2870d74c48468d6b5a102d12371a5caab719718dd799178762c4ac0ec755c55b73f9aed756572ca708c191b859293703a57914c7e22
6
+ metadata.gz: 49b2fc25bac49cdbd6f85fd95f1fe0927e1031a3fc44b426d8a1932ef0a249f8457002b8e38dfef88131d9c7fa2808642cd31502c7c49b561ca8302c57361489
7
+ data.tar.gz: f94a7b6b066b97171e9fe09167ad6e53b7e3998738954adcfccc1a9f26033c6c1e45620925acd21dc4abf088d00ac558ebfec7e7f2e67e48eb22f1b822eb366b
File without changes
@@ -0,0 +1,90 @@
1
+ from __future__ import (absolute_import, division, print_function)
2
+ __metaclass__ = type
3
+
4
+ from ansible.errors import AnsibleError
5
+
6
+ import subprocess
7
+ import yaml
8
+ import os
9
+ from ansible.parsing.yaml.dumper import AnsibleDumper
10
+
11
+
12
+ QB_ROOT = os.path.realpath(
13
+ os.path.join(
14
+ os.path.dirname(os.path.realpath(__file__)), # //lib/python/qb
15
+ '..', # //lib/python
16
+ '..', # //lib
17
+ '..', # //
18
+ )
19
+ )
20
+
21
+ INTEROP_RECEIVE_EXE = os.path.join( QB_ROOT, 'exe', '.qb_interop_receive' )
22
+
23
+
24
+ def send_payload( payload ):
25
+ '''
26
+ Send a payload to QB Ruby code via a subprocess.
27
+ '''
28
+
29
+ input = yaml.dump( payload, Dumper=AnsibleDumper )
30
+
31
+ process = subprocess.Popen(
32
+ [ INTEROP_RECEIVE_EXE ],
33
+ stdin=subprocess.PIPE,
34
+ stdout=subprocess.PIPE,
35
+ stderr=subprocess.PIPE,
36
+ env=os.environ,
37
+ )
38
+
39
+ out, err = process.communicate( input )
40
+
41
+ if process.returncode != 0:
42
+ raise AnsibleError('''
43
+ qb_send failed!
44
+
45
+ ERROR:
46
+ %s
47
+ ''' % (err))
48
+
49
+ try:
50
+ result = yaml.safe_load(out)
51
+ except Exception as error:
52
+ raise AnsibleError('''
53
+ qb_send failed to parse response:
54
+
55
+ %s
56
+ ''' % out)
57
+
58
+ return result
59
+
60
+
61
+ def send( data, method, *args, **kwds ):
62
+ '''
63
+ Load data as an object in ruby and send it a message (call a method).
64
+ '''
65
+
66
+ return send_payload({
67
+ 'data': data,
68
+ 'method': method,
69
+ 'args': args,
70
+ 'kwds': kwds,
71
+ })
72
+
73
+
74
+ def send_const( name, method, *args, **kwds ):
75
+ '''
76
+ Send a message (call a method) to a Ruby constant by name.
77
+ '''
78
+
79
+ return send_payload({
80
+ 'const': name,
81
+ 'method': method,
82
+ 'args': args,
83
+ 'kwds': kwds,
84
+ })
85
+
86
+
87
+ # Testing with doctest
88
+ if __name__ == '__main__':
89
+ import doctest
90
+ doctest.testmod()
@@ -4,7 +4,7 @@ module QB
4
4
 
5
5
  GEM_NAME = 'qb'
6
6
 
7
- VERSION = "0.3.9"
7
+ VERSION = "0.3.10"
8
8
 
9
9
  MIN_ANSIBLE_VERSION = Gem::Version.new '2.1.2'
10
10
 
@@ -1,86 +1,28 @@
1
1
  from __future__ import (absolute_import, division, print_function)
2
2
  __metaclass__ = type
3
3
 
4
+ import os
5
+ import sys
6
+
4
7
  from ansible.errors import AnsibleError
5
8
 
6
- import subprocess
7
- import yaml
8
- import os
9
- from ansible.parsing.yaml.dumper import AnsibleDumper
10
9
 
10
+ HERE = os.path.dirname(os.path.realpath(__file__))
11
11
 
12
- QB_ROOT = os.path.realpath(
12
+ PROJECT_ROOT = os.path.realpath(
13
13
  os.path.join(
14
- os.path.dirname(os.path.realpath(__file__)), # /plugins/filter_plugins
15
- '..', # /plugins
16
- '..', # /
14
+ HERE, # //plugins/filter_plugins
15
+ '..', # //plugins
16
+ '..', # //
17
17
  )
18
18
  )
19
19
 
20
- INTEROP_RECEIVE_EXE = os.path.join( QB_ROOT, 'exe', '.qb_interop_receive' )
21
-
22
-
23
- def send_to_interop( payload ):
24
- '''
25
- Send a payload to QB Ruby code via a subprocess.
26
- '''
27
-
28
- input = yaml.dump( payload, Dumper=AnsibleDumper )
29
-
30
- process = subprocess.Popen(
31
- [ INTEROP_RECEIVE_EXE ],
32
- stdin=subprocess.PIPE,
33
- stdout=subprocess.PIPE,
34
- stderr=subprocess.PIPE,
35
- env=os.environ,
36
- )
37
-
38
- out, err = process.communicate( input )
39
-
40
- if process.returncode != 0:
41
- raise AnsibleError('''
42
- qb_send failed!
43
-
44
- ERROR:
45
- %s
46
- ''' % (err))
47
-
48
- try:
49
- result = yaml.safe_load(out)
50
- except Exception as error:
51
- raise AnsibleError('''
52
- qb_send failed to parse response:
53
-
54
- %s
55
- ''' % out)
56
-
57
- return result
58
-
20
+ LIB_PYTHON_DIR = os.path.join( PROJECT_ROOT, 'lib', 'python' )
59
21
 
60
- def qb_send( data, method, *args, **kwds ):
61
- '''
62
- Load data as an object in ruby and send it a message (call a method).
63
- '''
64
-
65
- return send_to_interop({
66
- 'data': data,
67
- 'method': method,
68
- 'args': args,
69
- 'kwds': kwds,
70
- })
22
+ if not (LIB_PYTHON_DIR in sys.path):
23
+ sys.path.insert(0, LIB_PYTHON_DIR)
71
24
 
72
-
73
- def qb_send_const( name, method, *args, **kwds ):
74
- '''
75
- Send a message (call a method) to a Ruby constant by name.
76
- '''
77
-
78
- return send_to_interop({
79
- 'const': name,
80
- 'method': method,
81
- 'args': args,
82
- 'kwds': kwds,
83
- })
25
+ import qb.interop
84
26
 
85
27
 
86
28
  class FilterModule( object ):
@@ -90,14 +32,14 @@ class FilterModule( object ):
90
32
 
91
33
  def filters( self ):
92
34
  return {
93
- 'qb_send': qb_send,
94
- 'qb_send_const': qb_send_const,
35
+ 'qb_send': qb.interop.send,
36
+ 'qb_send_const': qb.interop.send_const,
95
37
  }
96
38
  # filters()
97
39
  # FilterModule
98
40
 
99
41
 
100
- # testing - call camel_case on first cli arg and print result
42
+ # Testing with doctest
101
43
  if __name__ == '__main__':
102
44
  import doctest
103
45
  doctest.testmod()
@@ -126,6 +126,14 @@ def qb_version_parse(version_string):
126
126
  return version
127
127
 
128
128
 
129
+ def qb_read_version(file_path):
130
+ '''Read a QB::Package::Version from a file.
131
+ '''
132
+
133
+ with open(file_path, 'r') as file:
134
+ return qb_version_parse(file.read())
135
+
136
+
129
137
  class FilterModule(object):
130
138
  ''' version manipulation filters '''
131
139
 
@@ -134,6 +142,7 @@ class FilterModule(object):
134
142
  'semver_inc': semver_inc,
135
143
  'semver_parse': semver_parse,
136
144
  'qb_version_parse': qb_version_parse,
145
+ 'qb_read_version': qb_read_version,
137
146
  }
138
147
  # filters()
139
148
  # FilterModule
@@ -0,0 +1,63 @@
1
+ # Be more Python 3
2
+ from __future__ import (absolute_import, division, print_function)
3
+ __metaclass__ = type
4
+
5
+ import sys
6
+ import os
7
+
8
+ from ansible.errors import AnsibleError, AnsibleParserError
9
+ from ansible.plugins.lookup import LookupBase
10
+
11
+ try:
12
+ from __main__ import display
13
+ except ImportError:
14
+ from ansible.utils.display import Display
15
+ display = Display()
16
+
17
+
18
+ HERE = os.path.dirname(os.path.realpath(__file__))
19
+
20
+ PROJECT_ROOT = os.path.realpath(
21
+ os.path.join(
22
+ HERE, # //plugins/filter_plugins
23
+ '..', # //plugins
24
+ '..', # //
25
+ )
26
+ )
27
+
28
+ LIB_PYTHON_DIR = os.path.join( PROJECT_ROOT, 'lib', 'python' )
29
+
30
+ if not (LIB_PYTHON_DIR in sys.path):
31
+ sys.path.insert(0, LIB_PYTHON_DIR)
32
+
33
+ import qb.interop
34
+
35
+
36
+ class LookupModule(LookupBase):
37
+
38
+ def run(self, terms, variables=None, **kwargs):
39
+ path = os.path.join(*terms)
40
+
41
+ if not os.path.isabs(path):
42
+ path = os.path.join(variables['qb_dir'], path)
43
+
44
+ if not os.path.isfile(path):
45
+ path_with_version = os.path.join(path, 'VERSION')
46
+
47
+ if not os.path.isfile(path_with_version):
48
+ raise AnsibleError(
49
+ "Neither path %s or %s exists" % (path, path_with_version)
50
+ )
51
+
52
+ path = path_with_version
53
+
54
+ with open(path, 'r') as file:
55
+ raw = file.read().strip()
56
+
57
+ version = qb.interop.send_const(
58
+ 'QB::Package::Version',
59
+ 'from_string',
60
+ raw,
61
+ )
62
+
63
+ return version
data/qb.gemspec CHANGED
@@ -97,7 +97,7 @@ Gem::Specification.new do |spec|
97
97
  spec.add_development_dependency "yard"
98
98
  spec.add_development_dependency "pry"
99
99
 
100
- spec.add_dependency "cmds", '~> 0.0', ">= 0.2.2"
100
+ spec.add_dependency "cmds", '~> 0.0', ">= 0.2.3"
101
101
  spec.add_dependency "nrser", '~> 0.0', ">= 0.0.28"
102
102
  spec.add_dependency "nrser-extras", '~> 0.0', ">= 0.0.3"
103
103
  spec.add_dependency "state_mate", '~> 0.0', ">= 0.0.9"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: qb
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.9
4
+ version: 0.3.10
5
5
  platform: ruby
6
6
  authors:
7
7
  - nrser
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-12-06 00:00:00.000000000 Z
11
+ date: 2017-12-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -89,7 +89,7 @@ dependencies:
89
89
  version: '0.0'
90
90
  - - ">="
91
91
  - !ruby/object:Gem::Version
92
- version: 0.2.2
92
+ version: 0.2.3
93
93
  type: :runtime
94
94
  prerelease: false
95
95
  version_requirements: !ruby/object:Gem::Requirement
@@ -99,7 +99,7 @@ dependencies:
99
99
  version: '0.0'
100
100
  - - ">="
101
101
  - !ruby/object:Gem::Version
102
- version: 0.2.2
102
+ version: 0.2.3
103
103
  - !ruby/object:Gem::Dependency
104
104
  name: nrser
105
105
  requirement: !ruby/object:Gem::Requirement
@@ -250,6 +250,8 @@ files:
250
250
  - ansible.cfg
251
251
  - exe/.qb_interop_receive
252
252
  - exe/qb
253
+ - lib/python/qb/__init__.py
254
+ - lib/python/qb/interop.py
253
255
  - lib/qb.rb
254
256
  - lib/qb/ansible.rb
255
257
  - lib/qb/ansible/cmds/playbook.rb
@@ -306,6 +308,7 @@ files:
306
308
  - plugins/filter_plugins/version_plugins.py
307
309
  - plugins/lookup_plugins/every.py
308
310
  - plugins/lookup_plugins/resolve.py
311
+ - plugins/lookup_plugins/version.py
309
312
  - qb.gemspec
310
313
  - roles/nrser.blockinfile/CONTRIBUTING.md
311
314
  - roles/nrser.blockinfile/README.md