Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
A
ansible
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
OpenEdx
ansible
Commits
b4f16a5e
Commit
b4f16a5e
authored
Apr 02, 2015
by
Toshio Kuratomi
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #10605 from ansible/v2-pyyaml-c-2
Port v2 to use the C version of pyyaml instead of pure python
parents
811a9063
d277c6b8
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
62 additions
and
33 deletions
+62
-33
v2/ansible/parsing/__init__.py
+17
-3
v2/ansible/parsing/yaml/constructor.py
+17
-19
v2/ansible/parsing/yaml/loader.py
+20
-6
v2/bin/ansible-playbook
+8
-5
No files found.
v2/ansible/parsing/__init__.py
View file @
b4f16a5e
...
...
@@ -29,7 +29,7 @@ from ansible.errors.yaml_strings import YAML_SYNTAX_ERROR
from
ansible.parsing.vault
import
VaultLib
from
ansible.parsing.splitter
import
unquote
from
ansible.parsing.yaml.loader
import
AnsibleLoader
from
ansible.parsing.yaml.objects
import
AnsibleBaseYAMLObject
from
ansible.parsing.yaml.objects
import
AnsibleBaseYAMLObject
,
AnsibleUnicode
from
ansible.utils.path
import
unfrackpath
class
DataLoader
():
...
...
@@ -70,13 +70,27 @@ class DataLoader():
# we first try to load this data as JSON
return
json
.
loads
(
data
)
except
:
try
:
# if loading JSON failed for any reason, we go ahead
# and try to parse it as YAML instead
return
self
.
_safe_load
(
data
,
file_name
=
file_name
)
if
isinstance
(
data
,
AnsibleUnicode
):
# The PyYAML's libyaml bindings use PyUnicode_CheckExact so
# they are unable to cope with our subclass.
# Unwrap and re-wrap the unicode so we can keep track of line
# numbers
new_data
=
unicode
(
data
)
else
:
new_data
=
data
try
:
new_data
=
self
.
_safe_load
(
new_data
,
file_name
=
file_name
)
except
YAMLError
as
yaml_exc
:
self
.
_handle_error
(
yaml_exc
,
file_name
,
show_content
)
if
isinstance
(
data
,
AnsibleUnicode
):
new_data
=
AnsibleUnicode
(
new_data
)
new_data
.
ansible_pos
=
data
.
ansible_pos
return
new_data
def
load_from_file
(
self
,
file_name
):
''' Loads data from a file, which can contain either JSON or YAML. '''
...
...
v2/ansible/parsing/yaml/constructor.py
View file @
b4f16a5e
...
...
@@ -20,7 +20,6 @@ from __future__ import (absolute_import, division, print_function)
__metaclass__
=
type
from
yaml.constructor
import
Constructor
from
ansible.utils.unicode
import
to_unicode
from
ansible.parsing.yaml.objects
import
AnsibleMapping
,
AnsibleUnicode
class
AnsibleConstructor
(
Constructor
):
...
...
@@ -33,20 +32,11 @@ class AnsibleConstructor(Constructor):
yield
data
value
=
self
.
construct_mapping
(
node
)
data
.
update
(
value
)
data
.
ansible_pos
=
value
.
ansible_pos
data
.
ansible_pos
=
self
.
_node_position_info
(
node
)
def
construct_mapping
(
self
,
node
,
deep
=
False
):
ret
=
AnsibleMapping
(
super
(
Constructor
,
self
)
.
construct_mapping
(
node
,
deep
))
# in some cases, we may have pre-read the data and then
# passed it to the load() call for YAML, in which case we
# want to override the default datasource (which would be
# '<string>') to the actual filename we read in
if
self
.
_ansible_file_name
:
data_source
=
self
.
_ansible_file_name
else
:
data_source
=
node
.
__datasource__
ret
.
ansible_pos
=
(
data_source
,
node
.
__line__
,
node
.
__column__
)
ret
.
ansible_pos
=
self
.
_node_position_info
(
node
)
return
ret
...
...
@@ -54,17 +44,25 @@ class AnsibleConstructor(Constructor):
# Override the default string handling function
# to always return unicode objects
value
=
self
.
construct_scalar
(
node
)
value
=
to_unicode
(
value
)
ret
=
AnsibleUnicode
(
self
.
construct_scalar
(
node
))
ret
=
AnsibleUnicode
(
value
)
if
self
.
_ansible_file_name
:
data_source
=
self
.
_ansible_file_name
else
:
data_source
=
node
.
__datasource__
ret
.
ansible_pos
=
(
data_source
,
node
.
__line__
,
node
.
__column__
)
ret
.
ansible_pos
=
self
.
_node_position_info
(
node
)
return
ret
def
_node_position_info
(
self
,
node
):
# the line number where the previous token has ended (plus empty lines)
column
=
node
.
start_mark
.
column
+
1
line
=
node
.
start_mark
.
line
+
1
# in some cases, we may have pre-read the data and then
# passed it to the load() call for YAML, in which case we
# want to override the default datasource (which would be
# '<string>') to the actual filename we read in
datasource
=
self
.
_ansible_file_name
or
node
.
start_mark
.
name
return
(
datasource
,
line
,
column
)
AnsibleConstructor
.
add_constructor
(
u'tag:yaml.org,2002:map'
,
AnsibleConstructor
.
construct_yaml_map
)
...
...
v2/ansible/parsing/yaml/loader.py
View file @
b4f16a5e
...
...
@@ -19,15 +19,30 @@
from
__future__
import
(
absolute_import
,
division
,
print_function
)
__metaclass__
=
type
from
yaml.reader
import
Reader
from
yaml.scanner
import
Scanner
from
yaml.parser
import
Parser
try
:
from
_yaml
import
CParser
,
CEmitter
HAVE_PYYAML_C
=
True
except
ImportError
:
HAVE_PYYAML_C
=
False
from
yaml.resolver
import
Resolver
from
ansible.parsing.yaml.composer
import
AnsibleComposer
from
ansible.parsing.yaml.constructor
import
AnsibleConstructor
class
AnsibleLoader
(
Reader
,
Scanner
,
Parser
,
AnsibleComposer
,
AnsibleConstructor
,
Resolver
):
if
HAVE_PYYAML_C
:
class
AnsibleLoader
(
CParser
,
AnsibleConstructor
,
Resolver
):
def
__init__
(
self
,
stream
,
file_name
=
None
):
CParser
.
__init__
(
self
,
stream
)
AnsibleConstructor
.
__init__
(
self
,
file_name
=
file_name
)
Resolver
.
__init__
(
self
)
else
:
from
yaml.reader
import
Reader
from
yaml.scanner
import
Scanner
from
yaml.parser
import
Parser
from
ansible.parsing.yaml.composer
import
AnsibleComposer
class
AnsibleLoader
(
Reader
,
Scanner
,
Parser
,
AnsibleComposer
,
AnsibleConstructor
,
Resolver
):
def
__init__
(
self
,
stream
,
file_name
=
None
):
Reader
.
__init__
(
self
,
stream
)
Scanner
.
__init__
(
self
)
...
...
@@ -35,4 +50,3 @@ class AnsibleLoader(Reader, Scanner, Parser, AnsibleComposer, AnsibleConstructor
AnsibleComposer
.
__init__
(
self
)
AnsibleConstructor
.
__init__
(
self
,
file_name
=
file_name
)
Resolver
.
__init__
(
self
)
v2/bin/ansible-playbook
View file @
b4f16a5e
#!/usr/bin/env python
from
__future__
import
(
absolute_import
,
division
,
print_function
)
__metaclass__
=
type
import
os
import
stat
...
...
@@ -19,7 +21,8 @@ from ansible.utils.vault import read_vault_file
from
ansible.vars
import
VariableManager
# Implement an ansible.utils.warning() function later
warning
=
getattr
(
__builtins__
,
'print'
)
def
warning
(
*
args
,
**
kwargs
):
print
(
*
args
,
**
kwargs
)
#---------------------------------------------------------------------------------------------------
...
...
@@ -134,12 +137,12 @@ if __name__ == "__main__":
#display(" ", log_only=True)
try
:
sys
.
exit
(
main
(
sys
.
argv
[
1
:]))
except
AnsibleError
,
e
:
except
AnsibleError
as
e
:
#display("ERROR: %s" % e, color='red', stderr=True)
print
e
print
(
e
)
sys
.
exit
(
1
)
except
KeyboardInterrupt
,
ke
:
except
KeyboardInterrupt
:
#display("ERROR: interrupted", color='red', stderr=True)
print
"keyboard interrupt"
print
(
"keyboard interrupt"
)
sys
.
exit
(
1
)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment