Skip to content

Commit

Permalink
Merge pull request #2 from eugene-eeo/master
Browse files Browse the repository at this point in the history
Modernize library
  • Loading branch information
barnumbirr committed Apr 18, 2015
2 parents e67b529 + 6e76515 commit dc226ae
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 43 deletions.
2 changes: 1 addition & 1 deletion hazelnut/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@
__repo__ = 'https://github.com/c0ding/hazelnut'
__license__ = 'Apache v2.0 License'

from core import MemInfo
from .core import MemInfo
55 changes: 24 additions & 31 deletions hazelnut/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,36 +3,29 @@

import re

__title__ = 'hazelnut'
__version__ = '0.2'
__author__ = 'Martin Simon <me@martinsimon.me>'
__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
22 changes: 11 additions & 11 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'],
)

0 comments on commit dc226ae

Please sign in to comment.