stat: PEP8, imports, cosmetics (#24653)

- Make PEP8 compliant
- Ensure imports are specific
- Few cosmetic changes (sort lists, casing, punctuation)
This commit is contained in:
Dag Wieers 2017-05-30 19:31:56 +02:00 committed by John R Barker
commit 09ba70f7c4
2 changed files with 38 additions and 42 deletions

View file

@ -18,66 +18,62 @@ ANSIBLE_METADATA = {'metadata_version': '1.0',
'status': ['stableinterface'], 'status': ['stableinterface'],
'supported_by': 'core'} 'supported_by': 'core'}
DOCUMENTATION = r'''
DOCUMENTATION = '''
--- ---
module: stat module: stat
version_added: "1.3" version_added: "1.3"
short_description: retrieve file or file system status short_description: Retrieve file or file system status
description: description:
- Retrieves facts for a file similar to the linux/unix 'stat' command. - Retrieves facts for a file similar to the linux/unix 'stat' command.
options: options:
path: path:
description: description:
- The full path of the file/object to get the facts of - The full path of the file/object to get the facts of.
required: true required: true
default: null
follow: follow:
description: description:
- Whether to follow symlinks - Whether to follow symlinks.
required: false choices: [ 'no', 'yes' ]
default: no default: 'no'
get_md5: get_md5:
description: description:
- Whether to return the md5 sum of the file. - Whether to return the md5 sum of the file.
- Will return None if not a regular file or if we're - Will return None if not a regular file or if we're
unable to use md5 (Common for FIPS-140 compliant systems) unable to use md5 (Common for FIPS-140 compliant systems).
required: false choices: [ 'no', 'yes' ]
default: yes default: 'yes'
get_checksum: get_checksum:
description: description:
- Whether to return a checksum of the file (default sha1) - Whether to return a checksum of the file (default sha1).
required: false choices: [ 'no', 'yes' ]
default: yes default: 'yes'
version_added: "1.8" version_added: "1.8"
checksum_algorithm: checksum_algorithm:
description: description:
- Algorithm to determine checksum of file. Will throw an error if the - Algorithm to determine checksum of file. Will throw an error if the
host is unable to use specified algorithm. host is unable to use specified algorithm.
required: false choices: [ sha1, sha224, sha256, sha384, sha512 ]
choices: [ 'sha1', 'sha224', 'sha256', 'sha384', 'sha512' ]
default: sha1 default: sha1
aliases: [ 'checksum_algo', 'checksum' ] aliases: [ checksum, checksum_algo ]
version_added: "2.0" version_added: "2.0"
get_mime: get_mime:
description: description:
- Use file magic and return data about the nature of the file. this uses - Use file magic and return data about the nature of the file. this uses
the 'file' utility found on most Linux/Unix systems. the 'file' utility found on most Linux/Unix systems.
- This will add both `mime_type` and 'charset' fields to the return, if possible. - This will add both `mime_type` and 'charset' fields to the return, if possible.
- In 2.3 this option changed from 'mime' to 'get_mime' and the default changed to 'Yes' - In 2.3 this option changed from 'mime' to 'get_mime' and the default changed to 'Yes'.
required: false choices: [ 'no', 'yes' ]
choices: [ Yes, No ] default: 'yes'
default: Yes
version_added: "2.1" version_added: "2.1"
aliases: [ 'mime', 'mime_type', 'mime-type' ] aliases: [ mime, mime_type, mime-type ]
get_attributes: get_attributes:
description: description:
- Get file attributes using lsattr tool if present. - Get file attributes using lsattr tool if present.
required: false choices: [ 'no', 'yes' ]
default: True default: 'yes'
version_added: "2.3" version_added: "2.3"
aliases: [ 'attributes', 'attr' ] aliases: [ attr, attributes ]
author: "Bruce Pennypacker (@bpennypacker)" author: Bruce Pennypacker (@bpennypacker)
''' '''
EXAMPLES = ''' EXAMPLES = '''
@ -136,7 +132,7 @@ EXAMPLES = '''
checksum_algorithm: sha256 checksum_algorithm: sha256
''' '''
RETURN = ''' RETURN = r'''
stat: stat:
description: dictionary containing all the stat data, some platforms might add additional fields description: dictionary containing all the stat data, some platforms might add additional fields
returned: success returned: success
@ -366,10 +362,11 @@ import pwd
import stat import stat
# import module snippets # import module snippets
from ansible.module_utils.basic import AnsibleModule, format_attributes from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.pycompat24 import get_exception from ansible.module_utils.pycompat24 import get_exception
from ansible.module_utils._text import to_bytes from ansible.module_utils._text import to_bytes
def format_output(module, path, st): def format_output(module, path, st):
mode = st.st_mode mode = st.st_mode
@ -410,9 +407,9 @@ def format_output(module, path, st):
# Platform dependant flags: # Platform dependant flags:
for other in [ for other in [
# Some Linux # Some Linux
('st_blocks','blocks'), ('st_blocks', 'blocks'),
('st_blksize', 'block_size'), ('st_blksize', 'block_size'),
('st_rdev','device_type'), ('st_rdev', 'device_type'),
('st_flags', 'flags'), ('st_flags', 'flags'),
# Some Berkley based # Some Berkley based
('st_gen', 'generation'), ('st_gen', 'generation'),
@ -429,7 +426,6 @@ def format_output(module, path, st):
if hasattr(st, other[0]): if hasattr(st, other[0]):
output[other[1]] = getattr(st, other[0]) output[other[1]] = getattr(st, other[0])
return output return output
@ -437,16 +433,16 @@ def main():
module = AnsibleModule( module = AnsibleModule(
argument_spec=dict( argument_spec=dict(
path=dict(required=True, type='path'), path=dict(required=True, type='path'),
follow=dict(default='no', type='bool'), follow=dict(type='bool', default='no'),
get_md5=dict(default='yes', type='bool'), get_md5=dict(type='bool', default='yes'),
get_checksum=dict(default='yes', type='bool'), get_checksum=dict(type='bool', default='yes'),
get_mime=dict(default=True, type='bool', aliases=['mime', 'mime_type', 'mime-type']), get_mime=dict(type='bool', default='yes', aliases=['mime', 'mime_type', 'mime-type']),
get_attributes=dict(default=True, type='bool', aliases=['attributes', 'attr']), get_attributes=dict(type='bool', default='yes', aliases=['attr', 'attributes']),
checksum_algorithm=dict(default='sha1', type='str', checksum_algorithm=dict(type='str', default='sha1',
choices=['sha1', 'sha224', 'sha256', 'sha384', 'sha512'], choices=['sha1', 'sha224', 'sha256', 'sha384', 'sha512'],
aliases=['checksum_algo', 'checksum']), aliases=['checksum', 'checksum_algo']),
), ),
supports_check_mode=True supports_check_mode=True,
) )
path = module.params.get('path') path = module.params.get('path')
@ -483,13 +479,13 @@ def main():
if output.get('islnk'): if output.get('islnk'):
output['lnk_source'] = os.path.realpath(b_path) output['lnk_source'] = os.path.realpath(b_path)
try: # user data try: # user data
pw = pwd.getpwuid(st.st_uid) pw = pwd.getpwuid(st.st_uid)
output['pw_name'] = pw.pw_name output['pw_name'] = pw.pw_name
except: except:
pass pass
try: # group data try: # group data
grp_info = grp.getgrgid(st.st_gid) grp_info = grp.getgrgid(st.st_gid)
output['gr_name'] = grp_info.gr_name output['gr_name'] = grp_info.gr_name
except: except:
@ -534,5 +530,6 @@ def main():
module.exit_json(changed=False, stat=output) module.exit_json(changed=False, stat=output)
if __name__ == '__main__': if __name__ == '__main__':
main() main()

View file

@ -316,7 +316,6 @@ lib/ansible/modules/files/ini_file.py
lib/ansible/modules/files/iso_extract.py lib/ansible/modules/files/iso_extract.py
lib/ansible/modules/files/patch.py lib/ansible/modules/files/patch.py
lib/ansible/modules/files/replace.py lib/ansible/modules/files/replace.py
lib/ansible/modules/files/stat.py
lib/ansible/modules/files/synchronize.py lib/ansible/modules/files/synchronize.py
lib/ansible/modules/files/tempfile.py lib/ansible/modules/files/tempfile.py
lib/ansible/modules/files/unarchive.py lib/ansible/modules/files/unarchive.py