1################################################################################
2#  THIS FILE IS 100% GENERATED BY ZPROJECT; DO NOT EDIT EXCEPT EXPERIMENTALLY  #
3#  Read the zproject/README.md for information about making permanent changes. #
4################################################################################
5from . import utils
6from . import destructors
7libczmq_destructors = destructors.lib
8
9class Zdir(object):
10    """
11    work with file-system directories
12    """
13
14    def __init__(self, path, parent):
15        """
16        Create a new directory item that loads in the full tree of the specified
17        path, optionally located under some parent path. If parent is "-", then
18        loads only the top-level directory, and does not use parent as a path.
19        """
20        p = utils.lib.zdir_new(utils.to_bytes(path), utils.to_bytes(parent))
21        if p == utils.ffi.NULL:
22            raise MemoryError("Could not allocate person")
23
24        # ffi.gc returns a copy of the cdata object which will have the
25        # destructor called when the Python object is GC'd:
26        # https://cffi.readthedocs.org/en/latest/using.html#ffi-interface
27        self._p = utils.ffi.gc(p, libczmq_destructors.zdir_destroy_py)
28
29    def path(self):
30        """
31        Return directory path
32        """
33        return utils.lib.zdir_path(self._p)
34
35    def modified(self):
36        """
37        Return last modification time for directory.
38        """
39        return utils.lib.zdir_modified(self._p)
40
41    def cursize(self):
42        """
43        Return total hierarchy size, in bytes of data contained in all files
44        in the directory tree.
45        """
46        return utils.lib.zdir_cursize(self._p)
47
48    def count(self):
49        """
50        Return directory count
51        """
52        return utils.lib.zdir_count(self._p)
53
54    def list(self):
55        """
56        Returns a sorted list of zfile objects; Each entry in the list is a pointer
57        to a zfile_t item already allocated in the zdir tree. Do not destroy the
58        original zdir tree until you are done with this list.
59        """
60        return utils.lib.zdir_list(self._p)
61
62    def remove(self, force):
63        """
64        Remove directory, optionally including all files that it contains, at
65        all levels. If force is false, will only remove the directory if empty.
66        If force is true, will remove all files and all subdirectories.
67        """
68        utils.lib.zdir_remove(self._p, force)
69
70    @staticmethod
71    def diff(older, newer, alias):
72        """
73        Calculate differences between two versions of a directory tree.
74        Returns a list of zdir_patch_t patches. Either older or newer may
75        be null, indicating the directory is empty/absent. If alias is set,
76        generates virtual filename (minus path, plus alias).
77        """
78        return utils.lib.zdir_diff(older._p, newer._p, utils.to_bytes(alias))
79
80    def resync(self, alias):
81        """
82        Return full contents of directory as a zdir_patch list.
83        """
84        return utils.lib.zdir_resync(self._p, utils.to_bytes(alias))
85
86    def cache(self):
87        """
88        Load directory cache; returns a hash table containing the SHA-1 digests
89        of every file in the tree. The cache is saved between runs in .cache.
90        """
91        return utils.lib.zdir_cache(self._p)
92
93    def fprint(self, file, indent):
94        """
95        Print contents of directory to open stream
96        """
97        utils.lib.zdir_fprint(self._p, file, indent)
98
99    def print_py(self, indent):
100        """
101        Print contents of directory to stdout
102        """
103        utils.lib.zdir_print(self._p, indent)
104
105    @staticmethod
106    def watch(pipe, unused):
107        """
108        Create a new zdir_watch actor instance:
109
110            zactor_t *watch = zactor_new (zdir_watch, NULL);
111
112        Destroy zdir_watch instance:
113
114            zactor_destroy (&watch);
115
116        Enable verbose logging of commands and activity:
117
118            zstr_send (watch, "VERBOSE");
119
120        Subscribe to changes to a directory path:
121
122            zsock_send (watch, "ss", "SUBSCRIBE", "directory_path");
123
124        Unsubscribe from changes to a directory path:
125
126            zsock_send (watch, "ss", "UNSUBSCRIBE", "directory_path");
127
128        Receive directory changes:
129            zsock_recv (watch, "sp", &path, &patches);
130
131            // Delete the received data.
132            free (path);
133            zlist_destroy (&patches);
134        """
135        utils.lib.zdir_watch(pipe._p, unused._p)
136
137    @staticmethod
138    def test(verbose):
139        """
140        Self test of this class.
141        """
142        utils.lib.zdir_test(verbose)
143
144################################################################################
145#  THIS FILE IS 100% GENERATED BY ZPROJECT; DO NOT EDIT EXCEPT EXPERIMENTALLY  #
146#  Read the zproject/README.md for information about making permanent changes. #
147################################################################################
148