From cdb8e1be12b724e9f68c7e46c9a653ec37c502cb Mon Sep 17 00:00:00 2001 From: Yujun Zhang Date: Sun, 5 Feb 2017 12:24:30 +0800 Subject: Implement logfile collector and grep parser JIRA: QTIP-207 JIRA: QTIP-208 Change-Id: Icc14d3097fb305e59df716636ef87504490c9d1b Signed-off-by: Yujun Zhang --- qtip/loader/file.py | 10 +++++----- qtip/loader/module.py | 19 ------------------- qtip/loader/plan.py | 12 ++++++++++-- qtip/loader/yaml_file.py | 6 ++++-- 4 files changed, 19 insertions(+), 28 deletions(-) delete mode 100644 qtip/loader/module.py (limited to 'qtip/loader') diff --git a/qtip/loader/file.py b/qtip/loader/file.py index 00f94818..0ea4d5b6 100644 --- a/qtip/loader/file.py +++ b/qtip/loader/file.py @@ -25,12 +25,12 @@ class FileLoader(BaseLoader): _paths = [ROOT_DIR] def __init__(self, name, paths=None): - self._file = name - self._abspath = self._find(name, paths=paths) + self._filename = name + self.abspath = self.find(name, paths=paths) - def _find(self, name, paths=None): + def find(self, name, paths=None): """find a specification in searching paths""" - paths = self._paths if paths is None else paths + paths = [self.abspath] if paths is None else paths for p in paths: abspath = path.join(p, self.RELATIVE_PATH, name) if path.exists(abspath): @@ -47,4 +47,4 @@ class FileLoader(BaseLoader): item = cls(name, paths=paths) yield { BaseProp.NAME: name, - BaseProp.ABSPATH: item._abspath} + BaseProp.ABSPATH: item.abspath} diff --git a/qtip/loader/module.py b/qtip/loader/module.py deleted file mode 100644 index 05cb1b76..00000000 --- a/qtip/loader/module.py +++ /dev/null @@ -1,19 +0,0 @@ -############################################################################## -# Copyright (c) 2017 ZTE Corp and others. -# -# All rights reserved. This program and the accompanying materials -# are made available under the terms of the Apache License, Version 2.0 -# which accompanies this distribution, and is available at -# http://www.apache.org/licenses/LICENSE-2.0 -############################################################################## - - -from qtip.collector.logfile import LogfileCollector - - -# TODO(yujunz) more elegant way to load module dynamically -def load_collector(type_name): - if type_name == LogfileCollector.TYPE: - return LogfileCollector - else: - raise Exception("Invalid collector type: {}".format(type_name)) diff --git a/qtip/loader/plan.py b/qtip/loader/plan.py index 0fd9ff52..e15651a3 100644 --- a/qtip/loader/plan.py +++ b/qtip/loader/plan.py @@ -9,12 +9,20 @@ from qtip.base.constant import BaseProp -from qtip.collector.base import CollectorProp as CProp -from qtip.loader.module import load_collector +from qtip.collector import CollectorProp as CProp +from qtip.collector.logfile import LogfileCollector from qtip.loader.yaml_file import YamlFileLoader from qtip.loader.qpi import QPISpec +# TODO(yujunz) more elegant way to load module dynamically +def load_collector(type_name): + if type_name == LogfileCollector.TYPE: + return LogfileCollector + else: + raise Exception("Invalid collector type: {}".format(type_name)) + + class Plan(YamlFileLoader): """ a benchmark plan is consist of configuration and a QPI list diff --git a/qtip/loader/yaml_file.py b/qtip/loader/yaml_file.py index ccaee8db..8b78a47c 100644 --- a/qtip/loader/yaml_file.py +++ b/qtip/loader/yaml_file.py @@ -20,9 +20,11 @@ class YamlFileLoader(FileLoader): def __init__(self, name, paths=None): super(YamlFileLoader, self).__init__(name, paths) - with open(self._abspath, 'r') as stream: + abspath = self.abspath + + with open(abspath, 'r') as stream: content = yaml.safe_load(stream) if not isinstance(content, dict): - raise InvalidContent(self._abspath) + raise InvalidContent(abspath) self.content = content self.name = content.get(BaseProp.NAME, path.splitext(name)[0]) -- cgit 1.2.3-korg