mirror of
				https://github.com/ARM-software/devlib.git
				synced 2025-11-01 14:31:22 +00:00 
			
		
		
		
	collector: Update the Collector Interface
Update `get_trace` to `get_data` to better reflect the purpose. The return type of said method will be a `CollectorOutput` object will contain one or more `CollectorOutputEntry` objects which will be used to provide the `path`and `path_kind` attributes to indicate the path to the obtained output and it's type (currently a "file" or "directory") respectively.
This commit is contained in:
		| @@ -15,12 +15,14 @@ | ||||
|  | ||||
| import logging | ||||
|  | ||||
| from devlib.utils.types import caseless_string | ||||
|  | ||||
| class CollectorBase(object): | ||||
|  | ||||
|     def __init__(self, target): | ||||
|         self.target = target | ||||
|         self.logger = logging.getLogger(self.__class__.__name__) | ||||
|         self.output_path = None | ||||
|  | ||||
|     def reset(self): | ||||
|         pass | ||||
| @@ -31,6 +33,12 @@ class CollectorBase(object): | ||||
|     def stop(self): | ||||
|         pass | ||||
|  | ||||
|     def set_output(self, output_path): | ||||
|         self.output_path = output_path | ||||
|  | ||||
|     def get_data(self): | ||||
|         return CollectorOutput() | ||||
|  | ||||
|     def __enter__(self): | ||||
|         self.reset() | ||||
|         self.start() | ||||
| @@ -39,5 +47,29 @@ class CollectorBase(object): | ||||
|     def __exit__(self, exc_type, exc_value, traceback): | ||||
|         self.stop() | ||||
|  | ||||
|     def get_trace(self, outfile): | ||||
|         pass | ||||
| class CollectorOutputEntry(object): | ||||
|  | ||||
|     path_kinds = ['file', 'directory'] | ||||
|  | ||||
|     def __init__(self, path, path_kind): | ||||
|         self.path = path | ||||
|  | ||||
|         path_kind = caseless_string(path_kind) | ||||
|         if path_kind not in self.path_kinds: | ||||
|             msg = '{} is not a valid path_kind [{}]' | ||||
|             raise ValueError(msg.format(path_kind, ' '.join(self.path_kinds))) | ||||
|         self.path_kind = path_kind | ||||
|  | ||||
|     def __str__(self): | ||||
|         return self.path | ||||
|  | ||||
|     def __repr__(self): | ||||
|         return '<{} ({})>'.format(self.path, self.path_kind) | ||||
|  | ||||
|     def __fspath__(self): | ||||
|         """Allow using with os.path operations""" | ||||
|         return self.path | ||||
|  | ||||
|  | ||||
| class CollectorOutput(list): | ||||
|     pass | ||||
|   | ||||
		Reference in New Issue
	
	Block a user