summaryrefslogtreecommitdiffstats
path: root/src/git_tftpd/backend.py
blob: 2d45916e2fce72e4de412083c22baae059b3c581 (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
from .writer import GitWriter

from tftp.backend import IBackend
from tftp.errors import Unsupported, AccessViolation
from tftp.util import deferred

from twisted.python.context import get
from twisted.python.filepath import FilePath, InsecurePath

from zope.interface import implementer


@implementer(IBackend)
class GitBackend(object):
    def __init__(self, base_path):
        self.base_path = base_path
        self.base = FilePath(base_path)

    @deferred
    def get_reader(self,  file_name):
        raise Unsupported("Reading not supported")

    @deferred
    def get_writer(self, file_name):
        try:
            target_path = self.base.descendant(file_name.split("/"))
        except InsecurePath as e:
            raise AccessViolation("Insecure path: %s" % e)
        return GitWriter(target_path, self.base_path, get('remote'))