# Path: mtf/metadata/tmet/filter.py
# def filtertests(backend, location, linters, tests, tags, relevancy, applyfilters=True):
#     """
#     Basic method to use it for wrapping inside another python code,
#     allows apply tag filters and relevancy
# 
#     :param backend:
#     :param location:
#     :param linters:
#     :param tests:
#     :param tags:
#     :param relevancy:
#     :return:
#     """
#     meta = common.get_backend_class(backend)(location=location,
#                                              linters=linters,
#                                              backend=backend)
#     if tests:
#         for test in tests:
#             meta._import_tests(test)
# 
#     if applyfilters:
#         meta.add_filter(tags=tags, relevancy=relevancy)
#         return meta.apply_filters()
#     else:
#         return meta.backend_tests()
# 
# Path: mtf/metadata/tmet/common.py
# MFILENAME = "metadata.yaml"
# DESC = "description"
# SOURCE = "source"
# TESTE = "tests"
# TESTC = "tests_coverage"
# DOCUMENT = "document"
# DOCUMENT_TYPES = ["metadata", "test-metadata", "tmet"]
# SUBTYPE = "subtype"
# SUBTYPE_G = "general"
# SUBTYPE_T = "test"
# BACKEND = "backend"
# TAGS = "tags"
# RELEVANCY = "relevancy"
# DEPENDENCIES = "deps"
# COVPATH = "coverage_path"
# MODULELINT = "enable_lint"
# IMPORT_TESTS = "import_tests"
# TAG_FILETERS = "tag_filters"
# URL_DOWNLOAD = "download_urls"
# GIT_DOWNLOAD = "clone_gits"
#         MTF_LINTER_PATH = os.path.dirname(moduleframework.tests.__file__)
#         MTF_LINTER_PATH = None
#     VALID_TEST_TYPES = ["EXTERNAL", "INSTRUMENTED", "SIMPLE", "PYUNITTEST"]
# def print_debug(*args):
# def logic_formula(statement, filters, op_negation="-", op_and=",", op_or=None):
#     def logic_simple(simple):
#     def logic_and(normalform):
#     def logic_filter(actual_tag_list, tag_filter):
#     def __init__(self, location=".", linters=False, **kwargs):
#     def _git_clone_files(self,gitdict):
#     def _url_download_files(self,testdict):
#     def _import_tests(self, testglob, pathlenght=0):
#     def _import_linters(self):
#     def get_metadata(self):
#     def load_yaml(self, location):
#     def _insert_to_coverage(self, path_list, test):
#     def _parse_base_coverage(self, base=None, path=[]):
#     def _insert_to_test_tree(self, path_list, test):
#     def _load_recursive(self):
#     def get_coverage(self):
#     def get_backends(self):
#     def filter_relevancy(self, tests, envrion_description):
#     def filter_tags(self, tests, tag_list):
#     def add_filter(self, tags=[], relevancy={}):
#     def apply_filters(self):
#     def backend_tests(self):
#     def backend_passtrought_args(self):
#     def get_filters(self):
#     def _import_tests(self, testglob, pathlenght=0):
#     def _import_linters(self):
#     def __avcado_tag_args(self, tag_list, defaultparam="--filter-by-tags-include-empty"):
#     def filter_tags(self, tests, tag_list):
# def get_backend_class(backend):
# class MetadataLoader(object):
# class MetadataLoaderMTF(MetadataLoader):


import argparse
import os
import tempfile
import json
import glob
import imp
import re
import subprocess
import core, common, mtfexceptions
                import fmf
from mtf.metadata.tmet.filter import filtertests
from mtf.metadata.tmet import common as metadata_common
        from moduleframework.mtf_environment import mtfenvset
                GENERIC_TEST=common.conf["generic"]["generic_tests"]))
            self.tests += glob.glob("{MTF_TOOLS}/{STATIC_LINTERS}/*.py".format(
                MTF_TOOLS=metadata_common.MetadataLoaderMTF.MTF_LINTER_PATH,
                STATIC_LINTERS=common.conf["generic"]["static_tests"]))
        self.args = args

        # parse unknow options and try to find what parameter is test
        while unknown:
            if unknown[0] in self.A_KNOWN_PARAMS_SIMPLE:
                self.additionalAvocadoArg.append(unknown[0])
                unknown = unknown[1:]
            elif unknown[0].startswith("-"):
                if "=" in unknown[0] or len(unknown) < 2:
                    self.additionalAvocadoArg.append(unknown[0])
                    unknown = unknown[1:]
                else:
                    self.additionalAvocadoArg += unknown[0:2]
                    unknown = unknown[2:]
            elif glob.glob(unknown[0]):
                # dereference filename via globs
                testlist = glob.glob(unknown[0])
                self.tests += testlist
                unknown = unknown[1:]
            else:
                self.tests.append(unknown[0])
                unknown = unknown[1:]

        if self.args.metadata:
            core.print_info("Using Metadata loader for tests and filtering")
            metadata_tests = filtertests(backend="mtf", location=os.getcwd(), linters=False, tests=[], tags=[], relevancy="")

# Path: mtf/metadata/tmet/filter.py
# def filtertests(backend, location, linters, tests, tags, relevancy, applyfilters=True):
#     """
#     Basic method to use it for wrapping inside another python code,
#     allows apply tag filters and relevancy
# 
#     :param backend:
#     :param location:
#     :param linters:
#     :param tests:
#     :param tags:
#     :param relevancy:
#     :return:
#     """
#     meta = common.get_backend_class(backend)(location=location,
#                                              linters=linters,
#                                              backend=backend)
#     if tests:
#         for test in tests:
#             meta._import_tests(test)
# 
#     if applyfilters:
#         meta.add_filter(tags=tags, relevancy=relevancy)
#         return meta.apply_filters()
#     else:
#         return meta.backend_tests()
# 
# Path: mtf/metadata/tmet/common.py
# MFILENAME = "metadata.yaml"
# DESC = "description"
# SOURCE = "source"
# TESTE = "tests"
# TESTC = "tests_coverage"
# DOCUMENT = "document"
# DOCUMENT_TYPES = ["metadata", "test-metadata", "tmet"]
# SUBTYPE = "subtype"
# SUBTYPE_G = "general"
# SUBTYPE_T = "test"
# BACKEND = "backend"
# TAGS = "tags"
# RELEVANCY = "relevancy"
# DEPENDENCIES = "deps"
# COVPATH = "coverage_path"
# MODULELINT = "enable_lint"
# IMPORT_TESTS = "import_tests"
# TAG_FILETERS = "tag_filters"
# URL_DOWNLOAD = "download_urls"
# GIT_DOWNLOAD = "clone_gits"
#         MTF_LINTER_PATH = os.path.dirname(moduleframework.tests.__file__)
#         MTF_LINTER_PATH = None
#     VALID_TEST_TYPES = ["EXTERNAL", "INSTRUMENTED", "SIMPLE", "PYUNITTEST"]
# def print_debug(*args):
# def logic_formula(statement, filters, op_negation="-", op_and=",", op_or=None):
#     def logic_simple(simple):
#     def logic_and(normalform):
#     def logic_filter(actual_tag_list, tag_filter):
#     def __init__(self, location=".", linters=False, **kwargs):
#     def _git_clone_files(self,gitdict):
#     def _url_download_files(self,testdict):
#     def _import_tests(self, testglob, pathlenght=0):
#     def _import_linters(self):
#     def get_metadata(self):
#     def load_yaml(self, location):
#     def _insert_to_coverage(self, path_list, test):
#     def _parse_base_coverage(self, base=None, path=[]):
#     def _insert_to_test_tree(self, path_list, test):
#     def _load_recursive(self):
#     def get_coverage(self):
#     def get_backends(self):
#     def filter_relevancy(self, tests, envrion_description):
#     def filter_tags(self, tests, tag_list):
#     def add_filter(self, tags=[], relevancy={}):
#     def apply_filters(self):
#     def backend_tests(self):
#     def backend_passtrought_args(self):
#     def get_filters(self):
#     def _import_tests(self, testglob, pathlenght=0):
#     def _import_linters(self):
#     def __avcado_tag_args(self, tag_list, defaultparam="--filter-by-tags-include-empty"):
#     def filter_tags(self, tests, tag_list):
# def get_backend_class(backend):
# class MetadataLoader(object):
# class MetadataLoaderMTF(MetadataLoader):


# Path: moduleframework/mtf_scheduler.py
import argparse
import os
import tempfile
import json
import glob
import imp
import re
import subprocess
import core, common, mtfexceptions
                import fmf
from mtf.metadata.tmet.filter import filtertests
from mtf.metadata.tmet import common as metadata_common
        from moduleframework.mtf_environment import mtfenvset

                GENERIC_TEST=common.conf["generic"]["generic_tests"]))
            self.tests += glob.glob("{MTF_TOOLS}/{STATIC_LINTERS}/*.py".format(
                MTF_TOOLS=metadata_common.MetadataLoaderMTF.MTF_LINTER_PATH,
                STATIC_LINTERS=common.conf["generic"]["static_tests"]))
        self.args = args

        # parse unknow options and try to find what parameter is test
        while unknown:
            if unknown[0] in self.A_KNOWN_PARAMS_SIMPLE:
                self.additionalAvocadoArg.append(unknown[0])
                unknown = unknown[1:]
            elif unknown[0].startswith("-"):
                if "=" in unknown[0] or len(unknown) < 2:
                    self.additionalAvocadoArg.append(unknown[0])
                    unknown = unknown[1:]
                else:
                    self.additionalAvocadoArg += unknown[0:2]
                    unknown = unknown[2:]
            elif glob.glob(unknown[0]):
                # dereference filename via globs
                testlist = glob.glob(unknown[0])
                self.tests += testlist
                unknown = unknown[1:]
            else:
                self.tests.append(unknown[0])
                unknown = unknown[1:]

        if self.args.metadata:
            core.print_info("Using Metadata loader for tests and filtering")
            metadata_tests = filtertests(backend="mtf", location=os.getcwd(), linters=False, tests=[], tags=[], relevancy="")

            tests_dict = [x[metadata_common.SOURCE] for x in metadata_tests]