#!/usr/bin/env python3 # Copyright 2018 Red Hat, Inc # # Licensed under the Apache License, Version 2.0 (the "License"); you may # not use this file except in compliance with the License. You may obtain # a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. import cgi import argparse import gzip import sys from ansible.module_utils.basic import AnsibleModule HEADER = '''
'''

FOOTER = '''
''' def run(inpath, outpath): if inpath.endswith('.gz'): infile = gzip.open(inpath, 'r') outfile = gzip.open(outpath, 'w') else: infile = open(inpath, 'r') outfile = open(outpath, 'w') outfile.write(HEADER) for i, line in enumerate(infile): i = i + 1 line = cgi.escape(line.rstrip('\n')) outfile.write('' % (i, i, i)) outfile.write(line.rstrip('\n')) outfile.write("\n") outfile.write(FOOTER) def ansible_main(): module = AnsibleModule( argument_spec=dict( input=dict(required=True, type='path'), output=dict(required=True, type='path'), ) ) p = module.params run(p.get('input'), p.get('output')) module.exit_json(changed=True) def cli_main(): parser = argparse.ArgumentParser( description="HTMLify text files" ) parser.add_argument('input', help='Input path') parser.add_argument('output', help='Output path') args = parser.parse_args() run(args.input, args.output) if __name__ == '__main__': if sys.stdin.isatty(): cli_main() else: ansible_main()