diff options
Diffstat (limited to 'cli-tools/cura/cura_address.py')
-rw-r--r-- | cli-tools/cura/cura_address.py | 79 |
1 files changed, 0 insertions, 79 deletions
diff --git a/cli-tools/cura/cura_address.py b/cli-tools/cura/cura_address.py deleted file mode 100644 index 467a1c2..0000000 --- a/cli-tools/cura/cura_address.py +++ /dev/null @@ -1,79 +0,0 @@ -#!/usr/bin/env python -# Copyright (C) 2012 Peter Hatina <phatina@redhat.com> -# -# This program is free software; you can redistribute it and/or -# modify it under the terms of the GNU General Public License -# as published by the Free Software Foundation; either version 2 -# of the License, or (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program; if not, see <http://www.gnu.org/licenses/>. - -import re -import sys -import itertools - -class CuraIpv4Addr: - class CuraIpv4Member: - def __init__(self, member): - self.m_member = member - - def enumerate(self): - pattern = re.compile("^{(.*)}$") - match = pattern.search(self.m_member) - member = match.group(1) if match else [] - if not member: - return [self.m_member] - ranges = (x.split("-") for x in member.split(";")) - try: - members = [] - for r in ranges: - if not 0 <= int(r[0]) <= 255 or not 0 <= int(r[-1]) <= 255: - return [] - low = int(r[0]) - high = int(r[-1]) - if low > high: - low, high = high, low - members += [str(i) for i in range(low, high + 1)] - except ValueError: - return [] - return members - - def __init__(self, addr_pattern): - self.m_addr_pattern = addr_pattern - - def enumerate(self): - str_members = self.m_addr_pattern.split(".") - if len(str_members) != 4: - return [] - members = [] - for m in str_members: - ipm = CuraIpv4Addr.CuraIpv4Member(m) - members.append(ipm) - addresses = members[3].enumerate() - if not addresses: - return [] - for i in reversed(range(0, 3)): - combined = [] - members_to_combine = members[i].enumerate() - if not members_to_combine: - return [] - for r in itertools.product(members_to_combine, addresses): - combined.append(".".join([r[0], r[1]])) - addresses = combined - return sorted(set(addresses)) - -class CuraIpv4AddrGenerator: - def __init__(self, addresses): - self.m_addresses = addresses - - def enumerate(self): - rval = [] - for addr in self.m_addresses.split(","): - rval += CuraIpv4Addr(addr).enumerate() - return rval |