From 98bbe61f6726e6c302b3d887d06417731f3b6764 Mon Sep 17 00:00:00 2001 From: Guillaume Ayoub Date: Thu, 9 Aug 2012 17:31:36 +0200 Subject: [PATCH] Use relative imports --- radicale/__init__.py | 2 +- radicale/__main__.py | 43 +++++++++++++++++----------------- radicale/auth/IMAP.py | 2 +- radicale/auth/LDAP.py | 3 ++- radicale/auth/PAM.py | 2 +- radicale/auth/__init__.py | 2 +- radicale/auth/courier.py | 2 +- radicale/auth/htpasswd.py | 2 +- radicale/log.py | 2 +- radicale/rights/__init__.py | 2 +- radicale/storage/__init__.py | 2 +- radicale/storage/filesystem.py | 2 +- radicale/xmlutils.py | 2 +- 13 files changed, 35 insertions(+), 33 deletions(-) diff --git a/radicale/__init__.py b/radicale/__init__.py index cb8ba83..060f04f 100644 --- a/radicale/__init__.py +++ b/radicale/__init__.py @@ -46,7 +46,7 @@ except ImportError: from urlparse import urlparse # pylint: enable=F0401,E0611 -from radicale import auth, config, ical, log, rights, storage, xmlutils +from . import auth, config, ical, log, rights, storage, xmlutils VERSION = "git" diff --git a/radicale/__main__.py b/radicale/__main__.py index 175f613..b72db77 100644 --- a/radicale/__main__.py +++ b/radicale/__main__.py @@ -32,7 +32,8 @@ import signal import threading from wsgiref.simple_server import make_server -import radicale +from . import ( + Application, config, HTTPServer, HTTPSServer, log, RequestHandler, VERSION) # This is a script, many branches and variables @@ -41,40 +42,40 @@ import radicale def run(): """Run Radicale as a standalone server.""" # Get command-line options - parser = optparse.OptionParser(version=radicale.VERSION) + parser = optparse.OptionParser(version=VERSION) parser.add_option( "-d", "--daemon", action="store_true", - default=radicale.config.getboolean("server", "daemon"), + default=config.getboolean("server", "daemon"), help="launch as daemon") parser.add_option( "-p", "--pid", - default=radicale.config.get("server", "pid"), + default=config.get("server", "pid"), help="set PID filename for daemon mode") parser.add_option( "-f", "--foreground", action="store_false", dest="daemon", help="launch in foreground (opposite of --daemon)") parser.add_option( "-H", "--hosts", - default=radicale.config.get("server", "hosts"), + default=config.get("server", "hosts"), help="set server hostnames and ports") parser.add_option( "-s", "--ssl", action="store_true", - default=radicale.config.getboolean("server", "ssl"), + default=config.getboolean("server", "ssl"), help="use SSL connection") parser.add_option( "-S", "--no-ssl", action="store_false", dest="ssl", help="do not use SSL connection (opposite of --ssl)") parser.add_option( "-k", "--key", - default=radicale.config.get("server", "key"), + default=config.get("server", "key"), help="set private key file") parser.add_option( "-c", "--certificate", - default=radicale.config.get("server", "certificate"), + default=config.get("server", "certificate"), help="set certificate file") parser.add_option( "-D", "--debug", action="store_true", - default=radicale.config.getboolean("logging", "debug"), + default=config.getboolean("logging", "debug"), help="print debug information") options = parser.parse_args()[0] @@ -84,10 +85,10 @@ def run(): if key: section = "logging" if key == "debug" else "server" value = getattr(options, key) - radicale.config.set(section, key, str(value)) + config.set(section, key, str(value)) # Start logging - radicale.log.start() + log.start() # Fork if Radicale is launched as daemon if options.daemon: @@ -105,25 +106,25 @@ def run(): # Register exit function def cleanup(): """Remove the PID files.""" - radicale.log.LOGGER.debug("Cleaning up") + log.LOGGER.debug("Cleaning up") # Remove PID file if options.pid and options.daemon: os.unlink(options.pid) atexit.register(cleanup) - radicale.log.LOGGER.info("Starting Radicale") + log.LOGGER.info("Starting Radicale") # Create collection servers servers = [] - server_class = radicale.HTTPSServer if options.ssl else radicale.HTTPServer + server_class = HTTPSServer if options.ssl else HTTPServer shutdown_program = threading.Event() for host in options.hosts.split(","): address, port = host.strip().rsplit(":", 1) address, port = address.strip("[] "), int(port) servers.append( - make_server(address, port, radicale.Application(), - server_class, radicale.RequestHandler)) + make_server(address, port, Application(), + server_class, RequestHandler)) # SIGTERM and SIGINT (aka KeyboardInterrupt) should just mark this for # shutdown @@ -141,14 +142,14 @@ def run(): # when a server exists but another server is added to the list at the same # time for server in servers: - radicale.log.LOGGER.debug( + log.LOGGER.debug( "Listening to %s port %s" % ( server.server_name, server.server_port)) if options.ssl: - radicale.log.LOGGER.debug("Using SSL") + log.LOGGER.debug("Using SSL") threading.Thread(target=serve_forever, args=(server,)).start() - radicale.log.LOGGER.debug("Radicale server ready") + log.LOGGER.debug("Radicale server ready") # Main loop: wait until all servers are exited try: @@ -165,10 +166,10 @@ def run(): signal.signal(signal.SIGINT, signal.SIG_IGN) signal.signal(signal.SIGTERM, signal.SIG_IGN) - radicale.log.LOGGER.info("Stopping Radicale") + log.LOGGER.info("Stopping Radicale") for server in servers: - radicale.log.LOGGER.debug( + log.LOGGER.debug( "Closing server listening to %s port %s" % ( server.server_name, server.server_port)) server.shutdown() diff --git a/radicale/auth/IMAP.py b/radicale/auth/IMAP.py index 61203a2..f31a5df 100644 --- a/radicale/auth/IMAP.py +++ b/radicale/auth/IMAP.py @@ -32,7 +32,7 @@ Python 3.2 or newer is required for TLS. import imaplib -from radicale import config, log +from .. import config, log IMAP_SERVER = config.get("auth", "imap_auth_host_name") IMAP_SERVER_PORT = config.get("auth", "imap_auth_host_port") diff --git a/radicale/auth/LDAP.py b/radicale/auth/LDAP.py index 538deb5..bf77237 100644 --- a/radicale/auth/LDAP.py +++ b/radicale/auth/LDAP.py @@ -26,7 +26,8 @@ Authentication based on the ``python-ldap`` module """ import ldap -from radicale import config, log + +from .. import config, log BASE = config.get("auth", "ldap_base") diff --git a/radicale/auth/PAM.py b/radicale/auth/PAM.py index 6aad96a..1660af1 100644 --- a/radicale/auth/PAM.py +++ b/radicale/auth/PAM.py @@ -27,7 +27,7 @@ import grp import pam import pwd -from radicale import config, log +from .. import config, log GROUP_MEMBERSHIP = config.get("auth", "pam_group_membership") diff --git a/radicale/auth/__init__.py b/radicale/auth/__init__.py index 78275e0..4805cc9 100644 --- a/radicale/auth/__init__.py +++ b/radicale/auth/__init__.py @@ -25,7 +25,7 @@ Authentication management. import sys -from radicale import config, log +from .. import config, log def load(): diff --git a/radicale/auth/courier.py b/radicale/auth/courier.py index 3dd72dd..3be5811 100644 --- a/radicale/auth/courier.py +++ b/radicale/auth/courier.py @@ -24,7 +24,7 @@ Courier-Authdaemon authentication. import sys import socket -from radicale import config, log +from .. import config, log COURIER_SOCKET = config.get("auth", "courier_socket") diff --git a/radicale/auth/htpasswd.py b/radicale/auth/htpasswd.py index 02313c5..79a4b52 100644 --- a/radicale/auth/htpasswd.py +++ b/radicale/auth/htpasswd.py @@ -30,7 +30,7 @@ supported, but md5 is not (see ``htpasswd`` man page to understand why). import base64 import hashlib -from radicale import config +from .. import config FILENAME = config.get("auth", "htpasswd_filename") diff --git a/radicale/log.py b/radicale/log.py index 5c3fc65..4951c3d 100644 --- a/radicale/log.py +++ b/radicale/log.py @@ -29,7 +29,7 @@ import sys import logging import logging.config -from radicale import config +from . import config LOGGER = logging.getLogger() diff --git a/radicale/rights/__init__.py b/radicale/rights/__init__.py index ffb499b..c2c1e22 100644 --- a/radicale/rights/__init__.py +++ b/radicale/rights/__init__.py @@ -25,7 +25,7 @@ Rights management. import sys -from radicale import config, log +from .. import config, log def load(): diff --git a/radicale/storage/__init__.py b/radicale/storage/__init__.py index e9e1cc4..b28b69e 100644 --- a/radicale/storage/__init__.py +++ b/radicale/storage/__init__.py @@ -24,7 +24,7 @@ configuration. """ -from radicale import config, ical +from .. import config, ical def load(): diff --git a/radicale/storage/filesystem.py b/radicale/storage/filesystem.py index 57c03dc..4ef53a6 100644 --- a/radicale/storage/filesystem.py +++ b/radicale/storage/filesystem.py @@ -28,7 +28,7 @@ import json import time from contextlib import contextmanager -from radicale import config, ical +from .. import config, ical FOLDER = os.path.expanduser(config.get("storage", "filesystem_folder")) diff --git a/radicale/xmlutils.py b/radicale/xmlutils.py index 16dcb2a..012213f 100644 --- a/radicale/xmlutils.py +++ b/radicale/xmlutils.py @@ -35,7 +35,7 @@ except ImportError: import re import xml.etree.ElementTree as ET -from radicale import client, config, ical, rights +from . import client, config, ical, rights NAMESPACES = {