From: Leandro Lucarella Date: Thu, 4 Oct 2007 16:10:14 +0000 (-0300) Subject: Create a package named pymin with all the pymin modules. X-Git-Url: https://git.llucax.com/software/pymin.git/commitdiff_plain/296d853cc95fd5bef262248cfe21b507abd26a4f?ds=inline;hp=--cc Create a package named pymin with all the pymin modules. --- 296d853cc95fd5bef262248cfe21b507abd26a4f diff --git a/config.py b/config.py index a0f1c45..059faae 100644 --- a/config.py +++ b/config.py @@ -1,7 +1,7 @@ # vim: set et sts=4 sw=4 encoding=utf-8 : -from services import * -from dispatcher import handler +from pymin.services import * +from pymin.dispatcher import handler # XXX for testing only @handler diff --git a/pymin/__init__.py b/pymin/__init__.py new file mode 100644 index 0000000..292a66b --- /dev/null +++ b/pymin/__init__.py @@ -0,0 +1,4 @@ +# vim: set encoding=utf-8 et sw=4 sts=4 : + +from pymin.pymindaemon import PyminDaemon + diff --git a/dispatcher.py b/pymin/dispatcher.py similarity index 100% rename from dispatcher.py rename to pymin/dispatcher.py diff --git a/eventloop.py b/pymin/eventloop.py similarity index 100% rename from eventloop.py rename to pymin/eventloop.py diff --git a/pymindaemon.py b/pymin/pymindaemon.py similarity index 96% rename from pymindaemon.py rename to pymin/pymindaemon.py index b440c52..be2c975 100644 --- a/pymindaemon.py +++ b/pymin/pymindaemon.py @@ -11,9 +11,8 @@ command-line. import signal import socket -import dispatcher -import eventloop -import serializer +from pymin import eventloop +from pymin import serializer class PyminDaemon(eventloop.EventLoop): r"""PyminDaemon(bind_addr, routes) -> PyminDaemon instance @@ -45,7 +44,7 @@ class PyminDaemon(eventloop.EventLoop): # Create EventLoop eventloop.EventLoop.__init__(self, sock) # Create Dispatcher - self.dispatcher = dispatcher.Dispatcher(routes) + self.dispatcher = Dispatcher(routes) # Signal handling def quit(signum, frame): print "Shuting down ..." diff --git a/seqtools.py b/pymin/seqtools.py similarity index 100% rename from seqtools.py rename to pymin/seqtools.py diff --git a/serializer.py b/pymin/serializer.py similarity index 97% rename from serializer.py rename to pymin/serializer.py index e76030b..c9d3dbb 100644 --- a/serializer.py +++ b/pymin/serializer.py @@ -1,7 +1,7 @@ # vim: set encoding=utf-8 et sw=4 sts=4 : -import ucsv -import seqtools +from pymin import ucsv +from pymin import seqtools r"UTF-8 encoded CSV serializer." diff --git a/pymin/services/__init__.py b/pymin/services/__init__.py new file mode 100644 index 0000000..a9f8d03 --- /dev/null +++ b/pymin/services/__init__.py @@ -0,0 +1,8 @@ +# vim: set encoding=utf-8 et sw=4 sts=4 : + +from pymin.services.dhcp import DhcpHandler +from pymin.services.dns import DnsHandler +from pymin.services.firewall import FirewallHandler +from pymin.services.ip import IpHandler +from pymin.services.proxy import ProxyHandler + diff --git a/services/dhcp/__init__.py b/pymin/services/dhcp/__init__.py similarity index 96% rename from services/dhcp/__init__.py rename to pymin/services/dhcp/__init__.py index c9c25b4..8f42e1a 100644 --- a/services/dhcp/__init__.py +++ b/pymin/services/dhcp/__init__.py @@ -2,10 +2,10 @@ from os import path -from seqtools import Sequence -from dispatcher import Handler, handler, HandlerError -from services.util import Restorable, ConfigWriter -from services.util import InitdHandler, TransactionalHandler, ParametersHandler +from pymin.seqtools import Sequence +from pymin.dispatcher import Handler, handler, HandlerError +from pymin.services.util import Restorable, ConfigWriter, InitdHandler, \ + TransactionalHandler, ParametersHandler __ALL__ = ('DhcpHandler', 'Error', 'HostError', 'HostAlreadyExistsError', 'HostNotFoundError') @@ -134,6 +134,7 @@ class HostHandler(Handler): r"show() -> list of Hosts :: List all the complete hosts information." return self.hosts.values() + class DhcpHandler(Restorable, ConfigWriter, InitdHandler, TransactionalHandler, ParametersHandler): r"""DhcpHandler([pickle_dir[, config_dir]]) -> DhcpHandler instance. @@ -179,6 +180,7 @@ class DhcpHandler(Restorable, ConfigWriter, InitdHandler, TransactionalHandler, def _get_config_vars(self, config_file): return dict(hosts=self.hosts.values(), **self.params) + if __name__ == '__main__': import os diff --git a/services/dhcp/templates/dhcpd.conf b/pymin/services/dhcp/templates/dhcpd.conf similarity index 100% rename from services/dhcp/templates/dhcpd.conf rename to pymin/services/dhcp/templates/dhcpd.conf diff --git a/services/dns/__init__.py b/pymin/services/dns/__init__.py similarity index 94% rename from services/dns/__init__.py rename to pymin/services/dns/__init__.py index 2ff6f60..624dfc4 100644 --- a/services/dns/__init__.py +++ b/pymin/services/dns/__init__.py @@ -5,10 +5,10 @@ from os import path from os import unlink from new import instancemethod -from seqtools import Sequence -from dispatcher import handler, HandlerError, Handler -from services.util import Restorable, ConfigWriter, call -from services.util import InitdHandler, TransactionalHandler, ParametersHandler +from pymin.seqtools import Sequence +from pymin.dispatcher import handler, HandlerError, Handler +from pymin.services.util import Restorable, ConfigWriter, InitdHandler, \ + TransactionalHandler, ParametersHandler, call __ALL__ = ('DnsHandler', 'Error', 'ZoneError', 'ZoneNotFoundError', 'ZoneAlreadyExistsError', @@ -48,7 +48,6 @@ class ZoneError(Error, KeyError): r"Initialize the object. See class documentation for more info." self.message = 'Zone error: "%s"' % zonename - class ZoneNotFoundError(ZoneError): r""" ZoneNotFoundError(hostname) -> ZoneNotFoundError instance @@ -61,7 +60,6 @@ class ZoneNotFoundError(ZoneError): r"Initialize the object. See class documentation for more info." self.message = 'zone not found: "%s"' % zonename - class ZoneAlreadyExistsError(ZoneError): r""" ZoneAlreadyExistsError(hostname) -> ZoneAlreadyExistsError instance @@ -73,7 +71,6 @@ class ZoneAlreadyExistsError(ZoneError): r"Initialize the object. See class documentation for more info." self.message = 'Zone already exists: "%s"' % zonename - class HostError(Error, KeyError): r""" HostError(hostname) -> HostError instance @@ -108,7 +105,6 @@ class HostNotFoundError(HostError): r"Initialize the object. See class documentation for more info." self.message = 'Host not found: "%s"' % hostname - class MailExchangeError(Error, KeyError): r""" MailExchangeError(hostname) -> MailExchangeError instance @@ -120,7 +116,6 @@ class MailExchangeError(Error, KeyError): r"Initialize the object. See class documentation for more info." self.message = 'Mail Exchange error: "%s"' % mx - class MailExchangeAlreadyExistsError(MailExchangeError): r""" MailExchangeAlreadyExistsError(hostname) -> MailExchangeAlreadyExistsError instance @@ -132,7 +127,6 @@ class MailExchangeAlreadyExistsError(MailExchangeError): r"Initialize the object. See class documentation for more info." self.message = 'Mail Exchange already exists: "%s"' % mx - class MailExchangeNotFoundError(MailExchangeError): r""" MailExchangeNotFoundError(hostname) -> MailExchangeNotFoundError instance @@ -145,8 +139,6 @@ class MailExchangeNotFoundError(MailExchangeError): r"Initialize the object. See class documentation for more info." self.message = 'Mail Exchange not found: "%s"' % mx - - class NameServerError(Error, KeyError): r""" NameServerError(ns) -> NameServerError instance @@ -182,29 +174,6 @@ class NameServerNotFoundError(NameServerError): self.message = 'Mail Exchange not found: "%s"' % ns -class ParameterError(Error, KeyError): - r""" - ParameterError(paramname) -> ParameterError instance - - This is the base exception for all DhcpHandler parameters related errors. - """ - - def __init__(self, paramname): - r"Initialize the object. See class documentation for more info." - self.message = 'Parameter error: "%s"' % paramname - -class ParameterNotFoundError(ParameterError): - r""" - ParameterNotFoundError(hostname) -> ParameterNotFoundError instance - - This exception is raised when trying to operate on a parameter that doesn't - exists. - """ - - def __init__(self, paramname): - r"Initialize the object. See class documentation for more info." - self.message = 'Parameter not found: "%s"' % paramname - class Host(Sequence): def __init__(self, name, ip): self.name = name @@ -395,6 +364,7 @@ class ZoneHandler(Handler): def show(self): return self.zones.values() + class DnsHandler(Restorable, ConfigWriter, InitdHandler, TransactionalHandler, ParametersHandler): r"""DnsHandler([pickle_dir[, config_dir]]) -> DnsHandler instance. @@ -485,6 +455,7 @@ class DnsHandler(Restorable, ConfigWriter, InitdHandler, TransactionalHandler, self.mod = False self.reload() + if __name__ == '__main__': dns = DnsHandler(); diff --git a/services/dns/templates/named.conf b/pymin/services/dns/templates/named.conf similarity index 100% rename from services/dns/templates/named.conf rename to pymin/services/dns/templates/named.conf diff --git a/services/dns/templates/zoneX.zone b/pymin/services/dns/templates/zoneX.zone similarity index 100% rename from services/dns/templates/zoneX.zone rename to pymin/services/dns/templates/zoneX.zone diff --git a/services/firewall/__init__.py b/pymin/services/firewall/__init__.py similarity index 97% rename from services/firewall/__init__.py rename to pymin/services/firewall/__init__.py index ca9bd5d..dbf9b15 100644 --- a/services/firewall/__init__.py +++ b/pymin/services/firewall/__init__.py @@ -5,10 +5,10 @@ from os import path -from seqtools import Sequence -from dispatcher import Handler, handler, HandlerError -from services.util import Restorable, ConfigWriter -from services.util import ServiceHandler, TransactionalHandler +from pymin.seqtools import Sequence +from pymin.dispatcher import Handler, handler, HandlerError +from pymin.services.util import Restorable, ConfigWriter, ServiceHandler, \ + TransactionalHandler __ALL__ = ('FirewallHandler', 'Error', 'RuleError', 'RuleAlreadyExistsError', 'RuleNotFoundError') @@ -64,6 +64,7 @@ class RuleNotFoundError(RuleError): r"Initialize the object. See class documentation for more info." self.message = 'Rule not found: "%s"' % rule + class Rule(Sequence): r"""Rule(chain, target[, src[, dst[, ...]]]) -> Rule instance. @@ -173,6 +174,7 @@ class RuleHandler(Handler): r"show() -> list of Rules :: List all the complete rules information." return self.rules + class FirewallHandler(Restorable, ConfigWriter, ServiceHandler, TransactionalHandler): r"""FirewallHandler([pickle_dir[, config_dir]]) -> FirewallHandler instance. @@ -209,6 +211,7 @@ class FirewallHandler(Restorable, ConfigWriter, ServiceHandler, def _get_config_vars(self, config_file): return dict(rules=self.rules) + if __name__ == '__main__': import os diff --git a/services/firewall/templates/iptables.sh b/pymin/services/firewall/templates/iptables.sh similarity index 100% rename from services/firewall/templates/iptables.sh rename to pymin/services/firewall/templates/iptables.sh diff --git a/services/ip/__init__.py b/pymin/services/ip/__init__.py similarity index 95% rename from services/ip/__init__.py rename to pymin/services/ip/__init__.py index a27e0d8..4330eeb 100644 --- a/services/ip/__init__.py +++ b/pymin/services/ip/__init__.py @@ -3,13 +3,14 @@ from subprocess import Popen, PIPE from os import path -from seqtools import Sequence -from dispatcher import handler, HandlerError, Handler -from services.util import Restorable, ConfigWriter -from services.util import InitdHandler, TransactionalHandler +from pymin.seqtools import Sequence +from pymin.dispatcher import handler, HandlerError, Handler +from pymin.services.util import Restorable, ConfigWriter, InitdHandler, \ + TransactionalHandler -__ALL__ = ('IpHandler','Error','DeviceError','DeviceNotFoundError','RouteError','RouteNotFoundError', - 'RouteAlreadyExistsError','AddressError','AddressNotFoundError','AddressAlreadyExistsError') +__ALL__ = ('IpHandler', 'Error','DeviceError', 'DeviceNotFoundError', + 'RouteError', 'RouteNotFoundError', 'RouteAlreadyExistsError', + 'AddressError', 'AddressNotFoundError', 'AddressAlreadyExistsError') class Error(HandlerError): r""" @@ -68,6 +69,7 @@ class RouteAlreadyExistsError(RouteError): def __init__(self, route): self.message = 'Route already exists : "%s"' % route + class Route(Sequence): def __init__(self, net_addr, prefix, gateway): @@ -134,6 +136,7 @@ class RouteHandler(Handler): k = list() return k + class Address(Sequence): def __init__(self, ip, prefix, broadcast): @@ -187,6 +190,7 @@ class AddressHandler(Handler): k = list() return k + class Device(Sequence): def __init__(self, name, mac): @@ -230,6 +234,7 @@ class DeviceHandler(Handler): def show(self): return self.devices.items() + def get_devices(): p = Popen(('ip', 'link', 'list'), stdout=PIPE, close_fds=True) string = p.stdout.read() diff --git a/services/ip/templates/device b/pymin/services/ip/templates/device similarity index 100% rename from services/ip/templates/device rename to pymin/services/ip/templates/device diff --git a/services/ip/templates/ip_add b/pymin/services/ip/templates/ip_add similarity index 100% rename from services/ip/templates/ip_add rename to pymin/services/ip/templates/ip_add diff --git a/services/ip/templates/ip_del b/pymin/services/ip/templates/ip_del similarity index 100% rename from services/ip/templates/ip_del rename to pymin/services/ip/templates/ip_del diff --git a/services/ip/templates/ip_flush b/pymin/services/ip/templates/ip_flush similarity index 100% rename from services/ip/templates/ip_flush rename to pymin/services/ip/templates/ip_flush diff --git a/services/ip/templates/route_add b/pymin/services/ip/templates/route_add similarity index 100% rename from services/ip/templates/route_add rename to pymin/services/ip/templates/route_add diff --git a/services/ip/templates/route_del b/pymin/services/ip/templates/route_del similarity index 100% rename from services/ip/templates/route_del rename to pymin/services/ip/templates/route_del diff --git a/services/ip/templates/route_flush b/pymin/services/ip/templates/route_flush similarity index 100% rename from services/ip/templates/route_flush rename to pymin/services/ip/templates/route_flush diff --git a/services/proxy/__init__.py b/pymin/services/proxy/__init__.py similarity index 77% rename from services/proxy/__init__.py rename to pymin/services/proxy/__init__.py index 6aff5cd..b3b1172 100644 --- a/services/proxy/__init__.py +++ b/pymin/services/proxy/__init__.py @@ -2,13 +2,13 @@ from os import path -from seqtools import Sequence -from dispatcher import Handler, handler, HandlerError -from services.util import Restorable, ConfigWriter -from services.util import InitdHandler, TransactionalHandler, ParametersHandler +from pymin.seqtools import Sequence +from pymin.dispatcher import Handler, handler, HandlerError +from pymin.services.util import Restorable, ConfigWriter, InitdHandler, \ + TransactionalHandler, ParametersHandler __ALL__ = ('ProxyHandler', 'Error', 'HostError', 'HostAlreadyExistsError', - 'HostNotFoundError', 'ParameterError', 'ParameterNotFoundError') + 'HostNotFoundError') class Error(HandlerError): r""" @@ -61,28 +61,6 @@ class HostNotFoundError(HostError): r"Initialize the object. See class documentation for more info." self.message = 'Host not found: "%s"' % hostname -class ParameterError(Error, KeyError): - r""" - ParameterError(paramname) -> ParameterError instance - - This is the base exception for all DhcpHandler parameters related errors. - """ - - def __init__(self, paramname): - r"Initialize the object. See class documentation for more info." - self.message = 'Parameter error: "%s"' % paramname - -class ParameterNotFoundError(ParameterError): - r""" - ParameterNotFoundError(hostname) -> ParameterNotFoundError instance - - This exception is raised when trying to operate on a parameter that doesn't - exists. - """ - - def __init__(self, paramname): - r"Initialize the object. See class documentation for more info." - self.message = 'Parameter not found: "%s"' % paramname class Host(Sequence): diff --git a/services/proxy/templates/squid.conf b/pymin/services/proxy/templates/squid.conf similarity index 100% rename from services/proxy/templates/squid.conf rename to pymin/services/proxy/templates/squid.conf diff --git a/services/util.py b/pymin/services/util.py similarity index 99% rename from services/util.py rename to pymin/services/util.py index 7239867..81b2767 100644 --- a/services/util.py +++ b/pymin/services/util.py @@ -9,7 +9,7 @@ try: except ImportError: import pickle -from dispatcher import Handler, handler, HandlerError +from pymin.dispatcher import Handler, handler, HandlerError #DEBUG = False DEBUG = True @@ -95,6 +95,7 @@ class ParameterNotFoundError(ParameterError): r"Initialize the object. See class documentation for more info." self.message = 'Parameter not found: "%s"' % paramname + def call(command, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE, close_fds=True, universal_newlines=True, **kw): @@ -340,6 +341,7 @@ class ConfigWriter: for t in self._config_writer_files: self._write_single_config(t) + class ServiceHandler(Handler): r"""ServiceHandler([start[, stop[, restart[, reload]]]]) -> ServiceHandler. diff --git a/ucsv.py b/pymin/ucsv.py similarity index 100% rename from ucsv.py rename to pymin/ucsv.py diff --git a/pymind b/pymind index 37feab9..27a9722 100755 --- a/pymind +++ b/pymind @@ -1,7 +1,7 @@ #!/usr/bin/env python # vim: set encoding=utf-8 et sw=4 sts=4 : -from pymindaemon import PyminDaemon +from pymin.pymindaemon import PyminDaemon import config PyminDaemon(config.routes, config.bind_addr).run() diff --git a/services/__init__.py b/services/__init__.py deleted file mode 100644 index 4d4dfb6..0000000 --- a/services/__init__.py +++ /dev/null @@ -1,8 +0,0 @@ -# vim: set encoding=utf-8 et sw=4 sts=4 : - -from services.dhcp import DhcpHandler -from services.dns import DnsHandler -from services.firewall import FirewallHandler -from services.ip import IpHandler -from services.proxy import ProxyHandler -