Example #1
0
def parse_cli():
    """
    The outline of this function needs to be like this:

    1. parse arguments
    2. validate arguments only, dont go into other logic/code
    3. run application logic
    """

    #
    # 1. parse cli arguments
    #

    __docopt__ = """
usage: pykwalify -d FILE -s FILE ... [-e FILE ...]
       [--strict-rule-validation] [--fix-ruby-style-regex] [--allow-assertions] [--encoding ENCODING]
       [-v ...] [-q]

optional arguments:
  -d FILE, --data-file FILE            the file to be tested
  -e FILE, --extension FILE            file containing python extension
  -s FILE, --schema-file FILE          schema definition file
  --fix-ruby-style-regex               This flag fixes some of the quirks of ruby style regex
                                       that is not compatible with python style regex
  --strict-rule-validation             enables strict validation of all keywords for all
                                       Rule objects to find unsupported keyword usage
  --allow-assertions                   By default assertions is disabled due to security risk.
                                       Error will be raised if assertion is used in schema
                                       but this flag is not used. This option enables assert keyword.
  --encoding ENCODING                  Specify encoding to open data and schema files with.
  -h, --help                           show this help message and exit
  -q, --quiet                          suppress terminal output
  -v, --verbose                        verbose terminal output (multiple -v increases verbosity)
  --version                            display the version number and exit
"""

    # Import pykwalify package
    import pykwalify

    args = docopt(__docopt__, version=pykwalify.__version__)

    pykwalify.init_logging(1 if args["--quiet"] else args["--verbose"])
    log = logging.getLogger(__name__)

    #
    # 2. validate arguments only, dont go into other code/logic
    #

    log.debug("Setting verbose level: %s", args["--verbose"])
    log.debug("Arguments from CLI: %s", args)

    return args
Example #2
0
def parse_cli():
    """
    The outline of this function needs to be like this:

    1. parse arguments
    2. validate arguments only, dont go into other logic/code
    3. run application logic
    """

    #
    # 1. parse cli arguments
    #

    __docopt__ = """
usage: pykwalify -d DATAFILE -s SCHEMAFILE ... [-q] [-v ...]
       pykwalify -h | --help
       pykwalify -V | --version

pyKwalify - cli for pykwalify

optional arguments:
  -d DATAFILE, --data-file DATAFILE        schema definition file
  -s SCHEMAFILE, --schema-file SCHEMAFILE  the file to be tested
  -q, --quiet                              suppress terminal output
  -v, --verbose                            verbose terminal output (multiple -v increases verbosity)
  -V, --version                            display the version number and exit
  -h, --help                               show this help message and exit
"""

    # Import pykwalify package
    import pykwalify

    args = docopt(__docopt__, version=pykwalify.__foobar__)

    pykwalify.init_logging(1 if args["--quiet"] else args["--verbose"])
    Log = logging.getLogger(__name__)

    # pykwalify importrs
    from .errors import retnames
    from .core import Core

    #
    # 2. validate arguments only, dont go into other code/logic
    #

    Log.debug("Setting verbose level: {}".format(args["--verbose"]))
    Log.debug("Arguments from CLI: {}".format(args))

    return args
Example #3
0
def parse_cli():
    """
    The outline of this function needs to be like this:

    1. parse arguments
    2. validate arguments only, dont go into other logic/code
    3. run application logic
    """

    #
    # 1. parse cli arguments
    #

    __docopt__ = """
usage: pykwalify -d FILE -s FILE ... [-e FILE ...] [-v ...] [-q]

optional arguments:
  -d FILE, --data-file FILE            schema definition file
  -e FILE, --extension FILE            file containing python extension
  -h, --help                           show this help message and exit
  -q, --quiet                          suppress terminal output
  -s FILE, --schema-file FILE          the file to be tested
  -v, --verbose                        verbose terminal output (multiple -v increases verbosity)
  --version                            display the version number and exit
"""

    # Import pykwalify package
    import pykwalify

    args = docopt(__docopt__, version=pykwalify.__version__)

    pykwalify.init_logging(1 if args["--quiet"] else args["--verbose"])
    log = logging.getLogger(__name__)

    #
    # 2. validate arguments only, dont go into other code/logic
    #

    log.debug("Setting verbose level: %s", args["--verbose"])
    log.debug("Arguments from CLI: %s", args)

    return args
Example #4
0
def main():
    """
    The outline of this function needs to be like this:

    1. parse arguments
    2. validate arguments only, dont go into other logic/code
    3. run application logic
    """

    #####
    ##### 1. parse cli arguments
    #####

    __docopt__ = """
usage: pykwalify -d DATAFILE -s SCHEMAFILE [-q] [-v ...]
       pykwalify -h | --help
       pykwalify -V | --version

pyKwalify - cli for pykwalify

optional arguments:
  -d DATAFILE, --data-file DATAFILE        schema definition file
  -s SCHEMAFILE, --schema-file SCHEMAFILE  the file to be tested
  -q, --quiet                              suppress terminal output
  -v, --verbose                            verbose terminal output (multiple -v increases verbosity)
  -V, --version                            display the version number and exit
  -h, --help                               show this help message and exit
"""

    # Import pykwalify package
    import pykwalify

    args = docopt(__docopt__, version=pykwalify.__foobar__)

    pykwalify.init_logging()
    Log = logging.getLogger(__name__)

    # pykwalify importrs
    from .errors import retnames
    from .core import Core

    #####
    ##### 2. validate arguments only, dont go into other code/logic
    #####

    # Calculates what level to set to all loggers
    # -vvvvv (5) will be logging.DEBUG,
    # -v (1) will be logging.CRITICAL
    # Default log level is INFO
    if not args["--verbose"]:
        level = 20
    else:
        # If anything is specefied
        level = 60 - (args["--verbose"] * 10)

    if args["--quiet"]:
        # This will silence all pykwalify loggers
        level = 1337

    # Loop all implemented loggers and update them
    for key, _logger in logging.Logger.manager.loggerDict.items():
        if key.startswith("pykwalify"):
            l = logging.getLogger(key)
            l.setLevel(level)
            for handler in l.handlers:
                handler.level = level

    Log.debug("Setting verbose level: {}".format(args["--verbose"]))

    Log.debug("Arguments from CLI: {}".format(args))

    #####
    ##### 3. parse cli arguments
    #####

    c = Core(source_file=args["--data-file"], schema_file=args["--schema-file"])
    c.validate()
Example #5
0
# 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.

from __future__ import absolute_import

import os
import sys

import pykwalify
import yaml
from pykwalify.core import Core as PyKwalify

from . import default

pykwalify.init_logging(1)

DEFAULT_CONFIG_FILE = "/opt/xos/xos_config.yaml"
DEFAULT_CONFIG_SCHEMA = "xos-config-schema.yaml"
INITIALIZED = False
CONFIG_FILE = None
CONFIG = {}

OVERRIDE_CONFIG = {}


class Config:
    """
    XOS Configuration APIs
    """
    @staticmethod
Example #6
0
#!/usr/bin/env python

import glob
from pykwalify.core import Core
import pykwalify

exitCode = 0

pykwalify.init_logging(0)

for file in glob.glob("radar/**/*.yaml"):
    c = Core(source_file=file, schema_files=["src/radar_entry.schema.yaml"])
    try:
        c.validate(raise_exception=True)
    except Exception as e:
        print("ERROR - " + file + "\n" + e.msg)
        exitCode += 1

for file in glob.glob("radar/**/*.yml"):
    print("ERROR - " + file + "\nIncorrect extension, rename to '.yaml'")
    exitCode += 1

if exitCode > 0:
    print(str(exitCode) + " validation error(s).")

exit(exitCode)
Example #7
0
def main():
    """
    The outline of this function needs to be like this:

    1. parse arguments
    2. validate arguments only, dont go into other logic/code
    3. run application logic
    """

    #####
    ##### 1. parse cli arguments
    #####

    __docopt__ = """
usage: pykwalify -d DATAFILE -s SCHEMAFILE [-q] [-v ...]
       pykwalify -h | --help
       pykwalify -V | --version

pyKwalify - cli for pykwalify

optional arguments:
  -d DATAFILE, --data-file DATAFILE        schema definition file
  -s SCHEMAFILE, --schema-file SCHEMAFILE  the file to be tested
  -q, --quiet                              suppress terminal output
  -v, --verbose                            verbose terminal output (multiple -v increases verbosity)
  -V, --version                            display the version number and exit
  -h, --help                               show this help message and exit
"""

    # Import pykwalify package
    import pykwalify

    args = docopt(__docopt__, version=pykwalify.__foobar__)

    pykwalify.init_logging()
    Log = logging.getLogger(__name__)

    # pykwalify importrs
    from .errors import retnames
    from .core import Core

    #####
    ##### 2. validate arguments only, dont go into other code/logic
    #####

    # Calculates what level to set to all loggers
    # -vvvvv (5) will be logging.DEBUG,
    # -v (1) will be logging.CRITICAL
    # Default log level is INFO
    if not args["--verbose"]:
        level = 20
    else:
        # If anything is specefied
        level = 60 - (args["--verbose"] * 10)

    if args["--quiet"]:
        # This will silence all pykwalify loggers
        level = 1337

    # Loop all implemented loggers and update them
    for key, _logger in logging.Logger.manager.loggerDict.items():
        if key.startswith("pykwalify"):
            l = logging.getLogger(key)
            l.setLevel(level)
            for handler in l.handlers:
                handler.level = level

    Log.debug("Setting verbose level: {}".format(args["--verbose"]))

    Log.debug("Arguments from CLI: {}".format(args))

    #####
    ##### 3. parse cli arguments
    #####

    c = Core(source_file=args["--data-file"],
             schema_file=args["--schema-file"])
    c.validate()