import yaml

from zope.interface import implements

from twisted.python import usage
from twisted.plugin import IPlugin
from twisted.application.service import IServiceMaker
from twisted.application import internet
from twisted.web import server

from docker_xylem import service


class Options(usage.Options):
    optParameters = [
        ["config", "c", "xylem-plugin.yml", "Config file"],
    ]


class DockerServiceMaker(object):
    implements(IServiceMaker, IPlugin)
    tapname = "docker_xylem"
    description = "A docker plugin service for xylem"
    options = Options

    def makeService(self, options):
        config = yaml.load(open(options['config']))

        return internet.UNIXServer(config.get(
            'socket', "/run/docker/plugins/xylem.sock"),
            server.Site(service.DockerService(config)))


serviceMaker = DockerServiceMaker()

@@ -71,16 +71,26 @@
 n import
+ filepath,
  usage%0Af
@@ -671,16 +671,165 @@
 nfig'%5D))
+%0A        sockfp = filepath.FilePath(%22/run/docker/plugins/xylem.sock%22)%0A        if not sockfp.parent().exists():%0A            sockfp.parent().makedirs()
 %0A%0A      
@@ -861,19 +861,8 @@
 ver(
-config.get(
 %0A   
@@ -874,50 +874,40 @@
     
-'socket', %22/run/docker/plugins/xylem.sock%22
+config.get('socket', sockfp.path
 ),%0A 

Create /run/docker/plugins before using it. (@bearnard)