summaryrefslogtreecommitdiffstats
path: root/src/twisted/plugins/git_tftpd_plugin.py
blob: a58ffed5bcf221130d77038bbf9ee41bbb330309 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
from git_tftpd.backend import GitBackend
from git_tftpd.protocol import TFTPProtocol

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

from zope.interface import implementer

class Options(usage.Options):
    optParameters = [
        ['port', 'p', 50069, 'The port number to listen on.'],
        ['repo', 'r', None, 'The path to the git repo. [required]'],
    ]


@implementer(IServiceMaker, IPlugin)
class MyServiceMaker(object):
    tapname = 'git-tftpd'
    description = 'A tftp server, that commits the files into a git repo.'
    options = Options

    def makeService(self, options):
        if options['repo'] is None:
            raise usage.UsageError('Missing required argument')

        backend = GitBackend(options['repo'])
        return internet.UDPServer(int(options["port"]), TFTPProtocol(backend))


serviceMaker = MyServiceMaker()