Skip to content

Commit

Permalink
Merge pull request #3 from c0ding/development
Browse files Browse the repository at this point in the history
v.0.4
  • Loading branch information
barnumbirr committed Apr 28, 2015
2 parents ba47c73 + 789edf9 commit 408f5ab
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 55 deletions.
95 changes: 51 additions & 44 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ From source use
or install from PyPi

$ pip install hazelnut

## Documentation:

- Basic use:
Expand Down Expand Up @@ -73,49 +73,49 @@ DirectMap2M: 8187904 kB
```
>>> mem.dict()
{
"Inactive:": "671312 kB",
"Mlocked:": "0 kB",
"HardwareCorrupted:": "0 kB",
"Bounce:": "0 kB",
"Active:": "1746544 kB",
"Cached:": "1299720 kB",
"Unevictable:": "0 kB",
"SReclaimable:": "159256 kB",
"DirectMap2M:": "8187904 kB",
"Buffers:": "484736 kB",
"Hugepagesize:": "2048 kB",
"MemAvailable:": "7126028 kB",
"HugePages_Rsvd:": "0",
"Inactive(anon):": "111312 kB",
"CommitLimit:": "20822312 kB",
"SUnreclaim:": "24940 kB",
"Inactive(file):": "560000 kB",
"SwapCached:": "0 kB",
"HugePages_Total:": "0",
"Active(file):": "1223340 kB",
"Writeback:": "0 kB",
"Dirty:": "0 kB",
"PageTables:": "5700 kB",
"Shmem:": "1120 kB",
"MemFree:": "5432004 kB",
"Mapped:": "96256 kB",
"WritebackTmp:": "0 kB",
"Slab:": "184196 kB",
"HugePages_Free:": "0",
"AnonPages:": "633396 kB",
"HugePages_Surp:": "0",
"DirectMap4k:": "97980 kB",
"Committed_AS:": "1774860 kB",
"VmallocUsed:": "362896 kB",
"MemTotal:": "8092252 kB",
"SwapTotal:": "16776188 kB",
"NFS_Unstable:": "0 kB",
"VmallocTotal:": "34359738367 kB",
"Active(anon):": "523204 kB",
"KernelStack:": "3856 kB",
"SwapFree:": "16776188 kB",
"AnonHugePages:": "0 kB",
"VmallocChunk:": "34359343324 kB"
"Inactive": "671312 kB",
"Mlocked": "0 kB",
"HardwareCorrupted": "0 kB",
"Bounce": "0 kB",
"Active": "1746544 kB",
"Cached": "1299720 kB",
"Unevictable": "0 kB",
"SReclaimable": "159256 kB",
"DirectMap2M": "8187904 kB",
"Buffers": "484736 kB",
"Hugepagesize": "2048 kB",
"MemAvailable": "7126028 kB",
"HugePages_Rsvd": "0",
"Inactive(anon)": "111312 kB",
"CommitLimit": "20822312 kB",
"SUnreclaim": "24940 kB",
"Inactive(file)": "560000 kB",
"SwapCached": "0 kB",
"HugePages_Total": "0",
"Active(file)": "1223340 kB",
"Writeback": "0 kB",
"Dirty": "0 kB",
"PageTables": "5700 kB",
"Shmem": "1120 kB",
"MemFree": "5432004 kB",
"Mapped": "96256 kB",
"WritebackTmp": "0 kB",
"Slab": "184196 kB",
"HugePages_Free": "0",
"AnonPages": "633396 kB",
"HugePages_Surp": "0",
"DirectMap4k": "97980 kB",
"Committed_AS": "1774860 kB",
"VmallocUsed": "362896 kB",
"MemTotal": "8092252 kB",
"SwapTotal": "16776188 kB",
"NFS_Unstable": "0 kB",
"VmallocTotal": "34359738367 kB",
"Active(anon)": "523204 kB",
"KernelStack": "3856 kB",
"SwapFree": "16776188 kB",
"AnonHugePages": "0 kB",
"VmallocChunk": "34359343324 kB"
}
```

Expand All @@ -126,6 +126,13 @@ DirectMap2M: 8187904 kB
['SwapCached: 0 kB\n', 'SwapTotal: 16776188 kB\n', 'SwapFree: 16776188 kB\n']
```

- Get memory usage as int (is case insensitive):

```
>>> mem.get('Inactive(anon)')
111312
```

## License:

```
Expand Down
18 changes: 9 additions & 9 deletions STATS
Original file line number Diff line number Diff line change
@@ -1,31 +1,31 @@

Analyzing: https://github.com/c0ding/hazelnut/blob/master/hazelnut/core.py

Total Lines: 30
Total Lines: 40

Code Lines: 22 (73.3333%)
Blank Lines: 7 (23.3333%)
Code Lines: 30 (75.0%)
Blank Lines: 9 (22.5%)

Comment Lines: 1 (3.33333%)
Comment Lines: 1 (2.5%)
Doc String Lines: 0 (0.0%)
Inline Comments: 1
Doc Strings: 0
Total Comments: 2

Longest Code Line: 41
Shortest Code Line: 12 [return match]
Longest Code Line: 57
Shortest Code Line: 20 [return int(match[0])]

Longest Comment Line: 23
Shortest Comment Line: 23 [# -*- coding: utf-8 ...]

Imports: 1
Functions: 6
Functions: 7
Classes: 1
If Statements: 0
If Statements: 1
Try Statements: 0
Except Statements: 0
Print Statements: 0
Assignments: 5
Assignments: 8
Variables: 5

Done analyzing: https://github.com/c0ding/hazelnut/blob/master/hazelnut/core.py
Expand Down
2 changes: 1 addition & 1 deletion hazelnut/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# -*- coding: utf-8 -*-

__title__ = 'hazelnut'
__version__ = '0.3'
__version__ = '0.4'
__author__ = 'Martin Simon <[email protected]>'
__repo__ = 'https://github.com/c0ding/hazelnut'
__license__ = 'Apache v2.0 License'
Expand Down
10 changes: 10 additions & 0 deletions hazelnut/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import re

class MemInfo(object):

def __init__(self, path='/proc/meminfo'):
self.path = path

Expand All @@ -21,10 +22,19 @@ def __repr__(self):
def dict(self):
with self.fileobj() as f:
d = dict(x.strip().split(None, 1) for x in f)
d = {key.strip(':'): item.strip() for key, item in d.items()}
return d

def search(self, regex):
with self.fileobj() as f:
matcher = re.compile(regex, re.IGNORECASE)
match = filter(matcher.match, f)
return match

def get(self, string):
with self.fileobj() as f:
lines = [line.strip() for line in f]
for item in lines:
if item.startswith(string):
match = re.findall(r'([0-9]+)\s', item)
return int(match[0])
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

setup(
name='hazelnut',
version='0.3',
version='0.4',
url='https://github.com/c0ding/hazelnut',
download_url='https://github.com/c0ding/hazelnut/archive/master.zip',
author='Martin Simon',
Expand Down

0 comments on commit 408f5ab

Please sign in to comment.