1# Copyright 2017 - The Android Open Source Project 2# 3# Licensed under the Apache License, Version 2.0 (the "License"); 4# you may not use this file except in compliance with the License. 5# You may obtain a copy of the License at 6# 7# http://www.apache.org/licenses/LICENSE-2.0 8# 9# Unless required by applicable law or agreed to in writing, software 10# distributed under the License is distributed on an "AS IS" BASIS, 11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12# See the License for the specific language governing permissions and 13# limitations under the License. 14 15"""Provides class PropDumper.""" 16 17import logging 18import re 19 20 21class PropDumper(object): 22 23 def __init__(self, file_accessor, args): 24 filename_in_mount = args[0] 25 logging.debug('Parse %s...', filename_in_mount) 26 with file_accessor.prepare_file(filename_in_mount) as filename: 27 if filename: 28 with open(filename) as fp: 29 self._content = fp.read() 30 31 def __enter__(self): 32 # do nothing 33 return self 34 35 def __exit__(self, exc_type, exc_val, exc_tb): 36 if hasattr(self, '_content'): 37 del self._content 38 39 def dump(self, lookup_key): 40 if not hasattr(self, '_content'): 41 return None 42 43 match = re.search('%s=(.*)' % (lookup_key), self._content) 44 return match.group(1) if match else None 45