Anons79 Mini Shell

Directory : /lib/python2.7/site-packages/ansible/modules/files/
Upload File :
Current File : //lib/python2.7/site-packages/ansible/modules/files/read_csv.pyo

�
�Udac@`s�ddlmZmZmZeZidd6dgd6dd6ZdZd	Zd
Z	ddl
Z
ddlmZm
Z
dd
lmZddlmZddlmZde
jfd��YZe
jde�d�Zedkr�e�ndS(i(tabsolute_importtdivisiontprint_functions1.1tmetadata_versiontpreviewtstatust	communitytsupported_bysV
---
module: read_csv
version_added: '2.8'
short_description: Read a CSV file
description:
- Read a CSV file and return a list or a dictionary, containing one dictionary per row.
author:
- Dag Wieers (@dagwieers)
options:
  path:
    description:
    - The CSV filename to read data from.
    type: path
    required: yes
    aliases: [ filename ]
  key:
    description:
    - The column name used as a key for the resulting dictionary.
    - If C(key) is unset, the module returns a list of dictionaries,
      where each dictionary is a row in the CSV file.
    type: str
  dialect:
    description:
    - The CSV dialect to use when parsing the CSV file.
    - Possible values include C(excel), C(excel-tab) or C(unix).
    type: str
    default: excel
  fieldnames:
    description:
    - A list of field names for every column.
    - This is needed if the CSV does not have a header.
    type: list
  unique:
    description:
    - Whether the C(key) used is expected to be unique.
    type: bool
    default: yes
  delimiter:
    description:
    - A one-character string used to separate fields.
    - When using this parameter, you change the default value used by C(dialect).
    - The default value depends on the dialect used.
    type: str
  skipinitialspace:
    description:
    - Whether to ignore any whitespaces immediately following the delimiter.
    - When using this parameter, you change the default value used by C(dialect).
    - The default value depends on the dialect used.
    type: bool
  strict:
    description:
    - Whether to raise an exception on bad CSV input.
    - When using this parameter, you change the default value used by C(dialect).
    - The default value depends on the dialect used.
    type: bool
notes:
- Ansible also ships with the C(csvfile) lookup plugin, which can be used to do selective lookups in CSV files from Jinja.
s�
# Example CSV file with header
#
#   name,uid,gid
#   dag,500,500
#   jeroen,501,500

# Read a CSV file and access user 'dag'
- name: Read users from CSV file and return a dictionary
  read_csv:
    path: users.csv
    key: name
  register: users
  delegate_to: localhost

- debug:
    msg: 'User {{ users.dict.dag.name }} has UID {{ users.dict.dag.uid }} and GID {{ users.dict.dag.gid }}'

# Read a CSV file and access the first item
- name: Read users from CSV file and return a list
  read_csv:
    path: users.csv
  register: users
  delegate_to: localhost

- debug:
    msg: 'User {{ users.list.1.name }} has UID {{ users.list.1.uid }} and GID {{ users.list.1.gid }}'

# Example CSV file without header and semi-colon delimiter
#
#   dag;500;500
#   jeroen;501;500

# Read a CSV file without headers
- name: Read users from CSV file and return a list
  read_csv:
    path: users.csv
    fieldnames: name,uid,gid
    delimiter: ';'
  register: users
  delegate_to: localhost
s�
dict:
  description: The CSV content as a dictionary.
  returned: success
  type: dict
  sample:
    dag:
      name: dag
      uid: 500
      gid: 500
    jeroen:
      name: jeroen
      uid: 501
      gid: 500
list:
  description: The CSV content as a list.
  returned: success
  type: list
  sample:
  - name: dag
    uid: 500
    gid: 500
  - name: jeroen
    uid: 501
    gid: 500
N(tBytesIOtStringIO(t
AnsibleModule(tto_text(tPY3tunix_dialectcB`s5eZdZdZdZeZeZdZ	e
jZRS(s:Describe the usual properties of Unix-generated CSV files.t,t"s
(
t__name__t
__module__t__doc__t	delimitert	quotechartTruetdoublequotetFalsetskipinitialspacetlineterminatortcsvt	QUOTE_ALLtquoting(((sB/usr/lib/python2.7/site-packages/ansible/modules/files/read_csv.pyR
�stunixcC`s�tdtdtdddtddg�dtddd	d
�dtdd�dtdd
�dtddd	t�dtdd�dtdd�dtdd��dt�}|jd}|jd}|jd}|jd}|jd}|tj�kr|jdd|�ntd|jdd|jdd|jd�}td�|j�D��}|r�ytjd||�Wn-t	k
r�}|jddt
|��nXd}ny(t|d��}	|	j�}
WdQXWn3t
tfk
r}|jddt
|��nXtr<t
|
dd�}
t|
�}nt|
�}tj|d|d|�}|r�||jkr�|jdd|dj|j�f�nt�}
t�}|dkry"x|D]}|j|�q�WWq�tjk
r}|jddt
|��q�Xn�yZxS|D]K}|r^|||
kr^|jdd |||f�n||
||<q!WWn0tjk
r�}|jddt
|��nX|jd!|
d
|�dS("Nt
argument_spectpathttypetrequiredtaliasestfilenametdialecttstrtdefaulttexceltkeyt
fieldnamestlisttuniquetboolRRtstricttsupports_check_modetmsgs8Dialect '%s' is not supported by your version of python.cs`s-|]#\}}|dk	r||fVqdS(N(tNone(t.0tktv((sB/usr/lib/python2.7/site-packages/ansible/modules/files/read_csv.pys	<genexpr>�stcustoms#Unable to create custom dialect: %strbsUnable to open file: %sterrorstsurrogate_or_stricts3Key '%s' was not found in the CSV header fields: %ss, sUnable to process file: %ss%Key '%s' is not unique for value '%s'tdict(R
R8RtparamsRt
list_dialectst	fail_jsontitemstregister_dialectt	TypeErrorRtopentreadtIOErrortOSErrorRR	Rt
DictReaderR)tjoinR*R0tappendtErrort	exit_json(tmoduleRR$R(R)R+tdialect_optionstdialect_paramstetftdatatfake_fhtreadert	data_dictt	data_listtrow((sB/usr/lib/python2.7/site-packages/ansible/modules/files/read_csv.pytmain�sr	






	)		
!
!t__main__(t
__future__RRRR t
__metaclass__tANSIBLE_METADATAt
DOCUMENTATIONtEXAMPLEStRETURNRtioRR	tansible.module_utils.basicR
tansible.module_utils._textRtansible.module_utils.sixRtDialectR
R=RSR(((sB/usr/lib/python2.7/site-packages/ansible/modules/files/read_csv.pyt<module>s"


<+
	N

Anons79 File Manager Version 1.0, Coded By Anons79
Email: [email protected]