Skip to content

Commit

Permalink
Merge pull request #8 from learningequality/master
Browse files Browse the repository at this point in the history
Further beta releases in 0.11
  • Loading branch information
benjaoming authored Aug 1, 2017
2 parents 6ec6477 + 1f15358 commit b8cfd18
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 40 deletions.
5 changes: 4 additions & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,11 @@ Windows compatibility.
* Only cross-platform features are now guaranteed to be in the result set:
``['inet', 'ether', 'inet6', 'netmask']``
* IPv6 addresses are now stored in a list.
* Removed prefixlen, as it should be added to one IPv6 address, not the
* Removed prefixlen and scopeid, as they should be added for each IPv6 address, not the
interface
* Allow ``ifcfg`` to be imported despite whether or not the OS system is
recognized.
* Remove ``ifcfg.exc`` module


0.10.1
Expand Down
6 changes: 3 additions & 3 deletions src/ifcfg/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,9 @@
import os
import platform
from . import tools
from . import exc
from . import parser

__version__ = "0.11b2"
__version__ = "0.11b4"

Log = tools.minimal_logger(__name__)

Expand All @@ -30,7 +29,8 @@ def get_parser_class():
# https://stackoverflow.com/a/2145582/405682
Parser = parser.WindowsParser
else:
raise exc.IfcfgParserError("Unknown distro type '%s'." % distro)
Parser = parser.NullParser
Log.error("Unknown distro type '%s'." % distro)
Log.debug("Distro detected as '%s'" % distro)
Log.debug("Using '%s'" % Parser)

Expand Down
12 changes: 0 additions & 12 deletions src/ifcfg/exc.py

This file was deleted.

24 changes: 22 additions & 2 deletions src/ifcfg/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,28 @@ def default_interface(self):
raise NotImplementedError()


class NullParser(Parser):
"""
Doesn't do anything, useful to maintain internal interfaces in case we
don't want to do anything (because we haven't determined the OS)
"""

def __init__(self, ifconfig=None):
self._interfaces = {}
self.ifconfig_data = ifconfig

def parse(self, ifconfig=None):
raise NotImplementedError()

@property
def interfaces(self):
return []

@property
def default_interface(self):
return None


class WindowsParser(Parser):

@classmethod
Expand Down Expand Up @@ -193,7 +215,6 @@ def get_patterns(cls):
'.*broadcast (?P<broadcast>[^\s]*).*',
'.*netmask (?P<netmask>[^\s]*).*',
'.*ether (?P<ether>[^\s]*).*',
'.*scopeid (?P<scopeid>[^\s]*).*',
]

@property
Expand Down Expand Up @@ -244,7 +265,6 @@ def get_patterns(cls):
'.*(P-t-P:)(?P<ptp>[^\s]*).*',
'.*(Bcast:)(?P<broadcast>[^\s]*).*',
'.*(Mask:)(?P<netmask>[^\s]*).*',
'.*(Scope:)(?P<scopeid>[^\s]*).*',
'.*(RX bytes:)(?P<rxbytes>\d+).*',
'.*(TX bytes:)(?P<txbytes>\d+).*',
]
Expand Down
21 changes: 0 additions & 21 deletions tests/exc_tests.py

This file was deleted.

3 changes: 2 additions & 1 deletion tests/ifconfig_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from __future__ import unicode_literals

import ifcfg
from ifcfg.parser import NullParser
from nose.tools import eq_, ok_, raises

from . import ifconfig_out
Expand All @@ -17,10 +18,10 @@ def test_ifcfg(self):
res = len(interfaces) > 0
ok_(res)

@raises(ifcfg.exc.IfcfgParserError)
def test_unknown(self):
ifcfg.distro = 'Bogus'
ifcfg.Parser = ifcfg.get_parser_class()
self.assertTrue(issubclass(ifcfg.Parser, NullParser))

@raises(RuntimeError)
def test_illegal(self):
Expand Down
16 changes: 16 additions & 0 deletions tests/no_mock_tests.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# -*- coding: utf-8 -*-
"""
Tests that don't mock anything, just run on the host system.
"""
from __future__ import unicode_literals

import ifcfg

from .base import IfcfgTestCase


class IfcfgTestCase(IfcfgTestCase):

def test_ifcfg(self):
for interface in ifcfg.interfaces():
print(interface)

0 comments on commit b8cfd18

Please sign in to comment.