diff --git a/hazelnut/__init__.py b/hazelnut/__init__.py index c0b3023..a02b5da 100644 --- a/hazelnut/__init__.py +++ b/hazelnut/__init__.py @@ -7,4 +7,4 @@ __repo__ = 'https://github.com/c0ding/hazelnut' __license__ = 'Apache v2.0 License' -from core import MemInfo \ No newline at end of file +from .core import MemInfo diff --git a/hazelnut/core.py b/hazelnut/core.py index a8d6455..34c87e0 100644 --- a/hazelnut/core.py +++ b/hazelnut/core.py @@ -3,36 +3,29 @@ import re -__title__ = 'hazelnut' -__version__ = '0.2' -__author__ = 'Martin Simon ' -__repo__ = 'https://github.com/c0ding/hazelnut' -__license__ = 'Apache v2.0 License' class MemInfo(object): - - def __init__(self, path='/proc/meminfo'): - self.path = path - - def __str__(self): - with open(self.get_path(), 'r') as f: - lines = [line.strip() for line in f] - return '\n'.join(lines) - - def __repr__(self): - return self.__str__() - - def get_path(self): - return self.path - - def dict(self): - d = {} - with open(self.get_path(), 'r') as f: - d = dict(x.strip().split(None, 1) for x in f) - return d - - def search(self, user_inp): - with open(self.get_path(), 'r') as f: - matcher = re.compile(user_inp, re.IGNORECASE) - match = filter(matcher.match, f) - return match + def __init__(self, path='/proc/meminfo'): + self.path = path + + def fileobj(self): + return open(self.get_path(), 'r') + + def __str__(self): + with self.fileobj() as f: + lines = [line.strip() for line in f] + return '\n'.join(lines) + + def __repr__(self): + return self.__str__() + + def dict(self): + with self.fileobj() as f: + d = dict(x.strip().split(None, 1) for x in f) + return d + + def search(self, regex): + with self.fileobj() as f: + matcher = re.compile(regex, re.IGNORECASE) + match = filter(matcher.match, f) + return match diff --git a/setup.py b/setup.py index fc537cb..bc15207 100644 --- a/setup.py +++ b/setup.py @@ -4,15 +4,15 @@ from distutils.core import setup setup( - name = 'hazelnut', - version = '0.2', - url = 'https://github.com/c0ding/hazelnut', - download_url = 'https://github.com/c0ding/hazelnut/archive/master.zip', - author = 'Martin Simon', - author_email = 'me@martinsimon.me', - license = 'Apache v2.0 License', - packages = ['hazelnut'], - description = 'A pythonic library to parse /proc/meminfo', - long_description = file('README.md','r').read(), - keywords = ['memory', 'RAM', 'system information', 'meminfo', '/proc'], + name='hazelnut', + version='0.2', + url='https://github.com/c0ding/hazelnut', + download_url='https://github.com/c0ding/hazelnut/archive/master.zip', + author='Martin Simon', + author_email='me@martinsimon.me', + license='Apache v2.0 License', + packages=['hazelnut'], + description='A pythonic library to parse /proc/meminfo', + long_description=file('README.md','r').read(), + keywords=['memory', 'RAM', 'system information', 'meminfo', '/proc'], )