archive: PEP8 compliancy, pylint and docs (#30842)
This PR includes; - PEP8 compliancy fixes - pylint fixes - Documentation updates
This commit is contained in:
parent
a4e077b357
commit
0129b96065
2 changed files with 50 additions and 51 deletions
|
@ -13,12 +13,11 @@ ANSIBLE_METADATA = {'metadata_version': '1.1',
|
||||||
'status': ['preview'],
|
'status': ['preview'],
|
||||||
'supported_by': 'community'}
|
'supported_by': 'community'}
|
||||||
|
|
||||||
|
|
||||||
DOCUMENTATION = '''
|
DOCUMENTATION = '''
|
||||||
---
|
---
|
||||||
module: archive
|
module: archive
|
||||||
version_added: 2.3
|
version_added: '2.3'
|
||||||
short_description: Creates a compressed archive of one or more files or trees.
|
short_description: Creates a compressed archive of one or more files or trees
|
||||||
extends_documentation_fragment: files
|
extends_documentation_fragment: files
|
||||||
description:
|
description:
|
||||||
- Packs an archive. It is the opposite of M(unarchive). By default, it assumes the compression source exists on the target. It will not copy the
|
- Packs an archive. It is the opposite of M(unarchive). By default, it assumes the compression source exists on the target. It will not copy the
|
||||||
|
@ -31,70 +30,70 @@ options:
|
||||||
format:
|
format:
|
||||||
description:
|
description:
|
||||||
- The type of compression to use.
|
- The type of compression to use.
|
||||||
choices: [ 'gz', 'bz2', 'zip' ]
|
choices: [ bz2, gz, tar, zip ]
|
||||||
default: 'gz'
|
default: gz
|
||||||
dest:
|
dest:
|
||||||
description:
|
description:
|
||||||
- The file name of the destination archive. This is required when C(path) refers to multiple files by either specifying a glob, a directory or
|
- The file name of the destination archive. This is required when C(path) refers to multiple files by either specifying a glob, a directory or
|
||||||
multiple paths in a list.
|
multiple paths in a list.
|
||||||
required: false
|
|
||||||
default: null
|
|
||||||
exclude_path:
|
exclude_path:
|
||||||
version_added: 2.4
|
version_added: '2.4'
|
||||||
description:
|
description:
|
||||||
- Remote absolute path, glob, or list of paths or globs for the file or files to exclude from the archive
|
- Remote absolute path, glob, or list of paths or globs for the file or files to exclude from the archive
|
||||||
required: false
|
|
||||||
remove:
|
remove:
|
||||||
description:
|
description:
|
||||||
- Remove any added source files and trees after adding to archive.
|
- Remove any added source files and trees after adding to archive.
|
||||||
required: false
|
type: bool
|
||||||
default: false
|
default: 'no'
|
||||||
|
|
||||||
author: "Ben Doherty (@bendoh)"
|
author:
|
||||||
|
- Ben Doherty (@bendoh)
|
||||||
notes:
|
notes:
|
||||||
- requires tarfile, zipfile, gzip, and bzip2 packages on target host
|
- requires tarfile, zipfile, gzip, and bzip2 packages on target host
|
||||||
- can produce I(gzip), I(bzip2) and I(zip) compressed files or archives
|
- can produce I(gzip), I(bzip2) and I(zip) compressed files or archives
|
||||||
'''
|
'''
|
||||||
|
|
||||||
EXAMPLES = '''
|
EXAMPLES = '''
|
||||||
# Compress directory /path/to/foo/ into /path/to/foo.tgz
|
- name: Compress directory /path/to/foo/ into /path/to/foo.tgz
|
||||||
- archive:
|
archive:
|
||||||
path: /path/to/foo
|
path: /path/to/foo
|
||||||
dest: /path/to/foo.tgz
|
dest: /path/to/foo.tgz
|
||||||
|
|
||||||
# Compress regular file /path/to/foo into /path/to/foo.gz and remove it
|
- name: Compress regular file /path/to/foo into /path/to/foo.gz and remove it
|
||||||
- archive:
|
archive:
|
||||||
path: /path/to/foo
|
path: /path/to/foo
|
||||||
remove: True
|
remove: yes
|
||||||
|
|
||||||
# Create a zip archive of /path/to/foo
|
- name: Create a zip archive of /path/to/foo
|
||||||
- archive:
|
archive:
|
||||||
path: /path/to/foo
|
path: /path/to/foo
|
||||||
format: zip
|
format: zip
|
||||||
|
|
||||||
# Create a bz2 archive of multiple files, rooted at /path
|
- name: Create a bz2 archive of multiple files, rooted at /path
|
||||||
- archive:
|
archive:
|
||||||
path:
|
path:
|
||||||
- /path/to/foo
|
- /path/to/foo
|
||||||
- /path/wong/foo
|
- /path/wong/foo
|
||||||
dest: /path/file.tar.bz2
|
dest: /path/file.tar.bz2
|
||||||
format: bz2
|
format: bz2
|
||||||
|
|
||||||
# Create a bz2 archive of a globbed path, while excluding specific dirnames - archive:
|
- name: Create a bz2 archive of a globbed path, while excluding specific dirnames
|
||||||
|
archive:
|
||||||
path:
|
path:
|
||||||
- /path/to/foo/*
|
- /path/to/foo/*
|
||||||
dest: /path/file.tar.bz2
|
dest: /path/file.tar.bz2
|
||||||
exclude_path:
|
exclude_path:
|
||||||
- /path/to/foo/bar
|
- /path/to/foo/bar
|
||||||
- /path/to/foo/baz
|
- /path/to/foo/baz
|
||||||
format: bz2
|
format: bz2
|
||||||
|
|
||||||
# Create a bz2 archive of a globbed path, while excluding a glob of dirnames
|
- name: Create a bz2 archive of a globbed path, while excluding a glob of dirnames
|
||||||
|
archive:
|
||||||
path:
|
path:
|
||||||
- /path/to/foo/*
|
- /path/to/foo/*
|
||||||
dest: /path/file.tar.bz2
|
dest: /path/file.tar.bz2
|
||||||
exclude_path:
|
exclude_path:
|
||||||
- /path/to/foo/ba*
|
- /path/to/foo/ba*
|
||||||
format: bz2
|
format: bz2
|
||||||
'''
|
'''
|
||||||
|
|
||||||
|
@ -130,28 +129,29 @@ expanded_exclude_paths:
|
||||||
returned: always
|
returned: always
|
||||||
'''
|
'''
|
||||||
|
|
||||||
import os
|
|
||||||
import re
|
|
||||||
import glob
|
|
||||||
import shutil
|
|
||||||
import gzip
|
|
||||||
import bz2
|
import bz2
|
||||||
import filecmp
|
import filecmp
|
||||||
import zipfile
|
import glob
|
||||||
|
import gzip
|
||||||
|
import os
|
||||||
|
import re
|
||||||
|
import shutil
|
||||||
import tarfile
|
import tarfile
|
||||||
|
import zipfile
|
||||||
from traceback import format_exc
|
from traceback import format_exc
|
||||||
|
|
||||||
from ansible.module_utils.basic import AnsibleModule
|
from ansible.module_utils.basic import AnsibleModule
|
||||||
from ansible.module_utils._text import to_native
|
from ansible.module_utils._text import to_native
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
module = AnsibleModule(
|
module = AnsibleModule(
|
||||||
argument_spec = dict(
|
argument_spec=dict(
|
||||||
path = dict(type='list', required=True),
|
path=dict(type='list', required=True),
|
||||||
format = dict(choices=['gz', 'bz2', 'zip', 'tar'], default='gz', required=False),
|
format=dict(type='str', default='gz', choices=['bz2', 'gz', 'tar', 'zip']),
|
||||||
dest = dict(required=False, type='path'),
|
dest=dict(type='path'),
|
||||||
exclude_path = dict(type='list', required=False),
|
exclude_path=dict(type='list'),
|
||||||
remove = dict(required=False, default=False, type='bool'),
|
remove=dict(type='bool', default=False),
|
||||||
),
|
),
|
||||||
add_file_common_args=True,
|
add_file_common_args=True,
|
||||||
supports_check_mode=True,
|
supports_check_mode=True,
|
||||||
|
@ -204,7 +204,7 @@ def main():
|
||||||
else:
|
else:
|
||||||
expanded_exclude_paths.append(exclude_path)
|
expanded_exclude_paths.append(exclude_path)
|
||||||
|
|
||||||
if len(expanded_paths) == 0:
|
if not expanded_paths:
|
||||||
return module.fail_json(path=', '.join(paths), expanded_paths=', '.join(expanded_paths), msg='Error, no source paths were found')
|
return module.fail_json(path=', '.join(paths), expanded_paths=', '.join(expanded_paths), msg='Error, no source paths were found')
|
||||||
|
|
||||||
# If we actually matched multiple files or TRIED to, then
|
# If we actually matched multiple files or TRIED to, then
|
||||||
|
@ -235,7 +235,7 @@ def main():
|
||||||
break
|
break
|
||||||
|
|
||||||
if i < len(arcroot):
|
if i < len(arcroot):
|
||||||
arcroot = os.path.dirname(arcroot[0:i+1])
|
arcroot = os.path.dirname(arcroot[0:i + 1])
|
||||||
|
|
||||||
arcroot += os.sep
|
arcroot += os.sep
|
||||||
|
|
||||||
|
@ -258,11 +258,11 @@ def main():
|
||||||
|
|
||||||
# Multiple files, or globbiness
|
# Multiple files, or globbiness
|
||||||
elif archive:
|
elif archive:
|
||||||
if len(archive_paths) == 0:
|
if not archive_paths:
|
||||||
# No source files were found, but the archive is there.
|
# No source files were found, but the archive is there.
|
||||||
if os.path.lexists(dest):
|
if os.path.lexists(dest):
|
||||||
state = 'archive'
|
state = 'archive'
|
||||||
elif len(missing) > 0:
|
elif missing:
|
||||||
# SOME source files were found, but not all of them
|
# SOME source files were found, but not all of them
|
||||||
state = 'incomplete'
|
state = 'incomplete'
|
||||||
|
|
||||||
|
@ -342,7 +342,7 @@ def main():
|
||||||
arcfile.close()
|
arcfile.close()
|
||||||
state = 'archive'
|
state = 'archive'
|
||||||
|
|
||||||
if len(errors) > 0:
|
if errors:
|
||||||
module.fail_json(msg='Errors when writing archive at %s: %s' % (dest, '; '.join(errors)))
|
module.fail_json(msg='Errors when writing archive at %s: %s' % (dest, '; '.join(errors)))
|
||||||
|
|
||||||
if state in ['archive', 'incomplete'] and remove:
|
if state in ['archive', 'incomplete'] and remove:
|
||||||
|
@ -355,14 +355,14 @@ def main():
|
||||||
except OSError as e:
|
except OSError as e:
|
||||||
errors.append(path)
|
errors.append(path)
|
||||||
|
|
||||||
if len(errors) > 0:
|
if errors:
|
||||||
module.fail_json(dest=dest, msg='Error deleting some source files: ' + str(e), files=errors)
|
module.fail_json(dest=dest, msg='Error deleting some source files: ' + str(e), files=errors)
|
||||||
|
|
||||||
# Rudimentary check: If size changed then file changed. Not perfect, but easy.
|
# Rudimentary check: If size changed then file changed. Not perfect, but easy.
|
||||||
if not check_mode and os.path.getsize(dest) != size:
|
if not check_mode and os.path.getsize(dest) != size:
|
||||||
changed = True
|
changed = True
|
||||||
|
|
||||||
if len(successes) and state != 'incomplete':
|
if successes and state != 'incomplete':
|
||||||
state = 'archive'
|
state = 'archive'
|
||||||
|
|
||||||
# Simple, single-file compression
|
# Simple, single-file compression
|
||||||
|
@ -393,7 +393,7 @@ def main():
|
||||||
arcfile = zipfile.ZipFile(dest, 'w', zipfile.ZIP_DEFLATED, True)
|
arcfile = zipfile.ZipFile(dest, 'w', zipfile.ZIP_DEFLATED, True)
|
||||||
arcfile.write(path, path[len(arcroot):])
|
arcfile.write(path, path[len(arcroot):])
|
||||||
arcfile.close()
|
arcfile.close()
|
||||||
state = 'archive' # because all zip files are archives
|
state = 'archive' # because all zip files are archives
|
||||||
|
|
||||||
else:
|
else:
|
||||||
f_in = open(path, 'rb')
|
f_in = open(path, 'rb')
|
||||||
|
|
|
@ -149,7 +149,6 @@ lib/ansible/modules/database/vertica/vertica_facts.py
|
||||||
lib/ansible/modules/database/vertica/vertica_role.py
|
lib/ansible/modules/database/vertica/vertica_role.py
|
||||||
lib/ansible/modules/database/vertica/vertica_schema.py
|
lib/ansible/modules/database/vertica/vertica_schema.py
|
||||||
lib/ansible/modules/database/vertica/vertica_user.py
|
lib/ansible/modules/database/vertica/vertica_user.py
|
||||||
lib/ansible/modules/files/archive.py
|
|
||||||
lib/ansible/modules/files/assemble.py
|
lib/ansible/modules/files/assemble.py
|
||||||
lib/ansible/modules/files/blockinfile.py
|
lib/ansible/modules/files/blockinfile.py
|
||||||
lib/ansible/modules/files/synchronize.py
|
lib/ansible/modules/files/synchronize.py
|
||||||
|
|
Loading…
Reference in a new issue