aboutsummaryrefslogtreecommitdiff
blob: 5d110db81f2ec79ab40a45168efd178e2fd2410d (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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
"""
A base package source module.
A package source module shall provide two classes: a class representing
a package (implementation details of the source, package-specific metadata,
fetching logic etc.), and the source per se: it is responsible for parsing
package specifications and fetching the specified package, as well as
instantiating specific packages from the metadata directory.
"""

from pomu.source import dispatcher

class PackageBase():
    """
    This is a base class for storing package-specific metadata.
    It shall be subclassed explicitely.
    The class is responsible for fetching the package, and reading/writing
    the package-specific metadata.
    """

    """The implementation shall provide a name for the package type"""
    __name__ = None

    def fetch(self):
        """
        A method which is responsible for fetching the package: it should return a Package object (specifying set of files with sufficient metadata), and specify this package object as the backend for the Package object (to store source-specific metadata).
        """
        raise NotImplementedError()

    @staticmethod
    def from_data_dir(pkgdir):
        """
        This method is responsible for instantiating source-specific metadata
        from the metadata directory.
        It shall return an instance of this class, and take a path to the meta
        directory.
        """
        raise NotImplementedError()

    def write_meta(self, pkgdir):
        """
        This method shall write source-specific metadata to the provided
        metadata directory.
        """
        raise NotImplementedError()

    def __str__(self):
        """
        The implementation shall provide a method to pretty-print
        package-specific metadata (displayed in show command).
        Example:
        return '{}/{}-{} (from {})'.format(self.category, self.name, self.version, self.path)
        """
        raise NotImplementedError()

@dispatcher.source
class BaseSource:
    """
    This is the base package source class.
    It should be decorated with @dispatcher.source.
    The implementation shall provide methods to parse the package specification,
    which would be called by the dispatcher (see manager.py for details).
    Parser methods shall be decorated with @dispatcher.handler(priority=...)
    decorator (default is 5).
    It shall provide a method to instantiate a package of this type from the
    metadata directory.
    """
    @dispatcher.handler()
    def parse_full(uri):
        """
        This method shall parse a full package specification (which starts with
        the backend name, followed by a colon).
        It shall return a package, wrapped in Result.
        """
        raise NotImplementedError()

    @classmethod
    def from_meta_dir(cls, metadir):
        """
        This method is responsible for instantiating package-specific metadata
        from the metadata directory.
        Example:
        return PackageBase.from_data_dir(metadir)
        """
        raise NotImplementedError()