File: fs_endpoint_lib.py

package info (click to toggle)
aptly 1.6.2-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 49,928 kB
  • sloc: python: 10,398; sh: 252; makefile: 184
file content (51 lines) | stat: -rw-r--r-- 1,929 bytes parent folder | download | duplicates (4)
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import os
from lib import BaseTest


class FileSystemEndpointTest(BaseTest):
    """
    BaseTest + support for filesystem endpoints
    """

    def prepare(self):
        self.configOverride = {"FileSystemPublishEndpoints": {
            "symlink": {
                "rootDir": os.path.join(os.environ["HOME"], ".aptly", "public_symlink"),
                "linkMethod": "symlink"
            },
            "hardlink": {
                "rootDir": os.path.join(os.environ["HOME"], ".aptly", "public_hardlink"),
                "linkMethod": "hardlink"
            },
            "copy": {
                "rootDir": os.path.join(os.environ["HOME"], ".aptly", "public_copy"),
                "linkMethod": "copy",
                "verifyMethod": "md5"
            },
            "copysize": {
                "rootDir": os.path.join(os.environ["HOME"], ".aptly", "public_copysize"),
                "linkMethod": "copy",
                "verifyMethod": "size"
            }
        }}
        super(FileSystemEndpointTest, self).prepare()

    def check_is_regular(self, path):
        if not os.path.isfile(os.path.join(os.environ["HOME"], ".aptly", path)):
            raise Exception("path %s is not a regular file" % (path, ))

    def check_is_symlink(self, path):
        if not os.path.islink(os.path.join(os.environ["HOME"], ".aptly", path)):
            raise Exception("path %s is not a symlink" % (path, ))

    def is_hardlink(self, path):
        return os.stat(os.path.join(os.environ["HOME"], ".aptly", path)).st_nlink >= 2

    def check_is_hardlink(self, path):
        if not self.is_hardlink(path):
            raise Exception("path %s is not a hardlink" % (path, ))

    def check_is_copy(self, path):
        fullpath = os.path.join(os.environ["HOME"], ".aptly", path)
        if not (os.path.isfile(fullpath) and not self.is_hardlink(path)):
            raise Exception("path %s is not a copy" % (path, ))