Use relative imports

This commit is contained in:
Guillaume Ayoub 2012-08-09 17:31:36 +02:00
parent 9f446cb261
commit 98bbe61f67
13 changed files with 35 additions and 33 deletions

View File

@ -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"

View File

@ -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()

View File

@ -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")

View File

@ -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")

View File

@ -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")

View File

@ -25,7 +25,7 @@ Authentication management.
import sys
from radicale import config, log
from .. import config, log
def load():

View File

@ -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")

View File

@ -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")

View File

@ -29,7 +29,7 @@ import sys
import logging
import logging.config
from radicale import config
from . import config
LOGGER = logging.getLogger()

View File

@ -25,7 +25,7 @@ Rights management.
import sys
from radicale import config, log
from .. import config, log
def load():

View File

@ -24,7 +24,7 @@ configuration.
"""
from radicale import config, ical
from .. import config, ical
def load():

View File

@ -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"))

View File

@ -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 = {