Skip to content

Instantly share code, notes, and snippets.

View sivel's full-sized avatar
😏

Matt Martz sivel

😏
View GitHub Profile
@sivel
sivel / syncat.py
Last active May 15, 2017 18:33
Python file that works similarly to cat, while performing (guessed) syntax highlighting
#!/usr/bin/env python
from __future__ import print_function
import sys
from pygments import highlight
from pygments.lexers import guess_lexer
from pygments.formatters import Terminal256Formatter as Formatter
# Try to load the Solarized256Style
# https://github.com/johnmastro/solarized256-pygments
@sivel
sivel / builddocs.py
Last active May 31, 2017 17:22
Build DOCUMENTATION skeleton from argument_spec for an Ansible module
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# Copyright (C) 2015 Matt Martz <matt@sivel.net>
# Copyright (C) 2015 Rackspace US, Inc.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
@sivel
sivel / constants2json.py
Created June 1, 2017 20:59
Ansible constants to JSON
import ast
import json
import os
import sys
import ansible.constants as C
things = {}
op_map = {
ast.Add: '+',
@sivel
sivel / gfm2html
Created September 14, 2013 15:35
Code to convert github flavored markdown to RST
#!/usr/bin/env python
import requests
import sys
import json
import re
if len(sys.argv) == 2:
markdown_file = sys.argv[1]
diff --git a/lib/ansible/cli/__init__.py b/lib/ansible/cli/__init__.py
index 24100f10c3..361b016bd5 100644
--- a/lib/ansible/cli/__init__.py
+++ b/lib/ansible/cli/__init__.py
@@ -34,10 +34,10 @@ from abc import ABCMeta, abstractmethod
import ansible
from ansible import constants as C
-from ansible.errors import AnsibleOptionsError, AnsibleError
+from ansible.errors import AnsibleOptionsError, AnsibleError, AnsibleFileNotFound
Request: <?xml version="1.0" encoding="UTF-8"?>
<Envelope xmlns="http://schemas.xmlsoap.org/soap/envelope/"><Header></Header><Body><RetrieveProperties xmlns="urn:vim25"><_this type="PropertyCollector">propertyCollector</_this><specSet><propSet><type>SessionManager</type><pathSet>currentSession</pathSet></propSet><objectSet><obj type="SessionManager">SessionManager</obj><skip>false</skip></objectSet></specSet></RetrieveProperties></Body></Envelope>
Response: <?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><soapenv:Body><RetrievePropertiesResponse xmlns="urn:vim25"></RetrievePropertiesResponse></soapenv:Body></soapenv:Envelope>
Request: <?xml version="1.0" encoding="UTF-8"?>
<Envelope xmlns="http://schemas.xmlsoap.org/soap/envelope/"><Header></Header><Body><RetrieveServiceContent xmlns="urn:
# Copyright: 2018, Matt Martz <matt@sivel.net>
# Simplified BSD License (see licenses/simplified_bsd.txt or https://opensource.org/licenses/BSD-2-Clause )
from __future__ import (absolute_import, division, print_function)
__metaclass__ = type
__all__ = ['Version', 'parse']
try:
from packaging.version import LegacyVersion, Version as Pep440Version, parse
@sivel
sivel / changelog.py
Last active February 20, 2018 21:24
Simple script that looks for issue/pr references in commit messages, and generates something like a changelog
#!/usr/bin/env python
import os
import re
import mistune # mistune
from github import Github # PyGithub
from argparse import ArgumentParser
@sivel
sivel / duration.py
Last active February 27, 2018 20:16
Module for parsing a time duration and returning a float or a timedelta object
# Copyright (c) 2018 Matt Martz <matt@sivel.net>
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
import datetime
import itertools
import re
DURATION_RE = re.compile(
'(?P<sign>[-+]?)(?P<value>[0-9]*(?:\.[0-9]*)?)(?P<unit>[a-z]{1,2})'
)
@sivel
sivel / memrecap.py
Last active March 26, 2018 17:26
This is an ansible callback plugin that profiles maximum memory usage of ansible per task, and displays a recap at the end
# (c) 2018 Matt Martz <matt@sivel.net>
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
# Make coding more python3-ish
from __future__ import (absolute_import, division, print_function)
__metaclass__ = type
ANSIBLE_METADATA = {'metadata_version': '1.1',
'status': ['preview'],
'supported_by': 'community'}