1
+ from __future__ import annotations
2
+
1
3
import contextlib
2
4
import errno
3
5
import importlib
12
14
from .. import BUGTRACKER_HOME
13
15
from .. import DOCS_HOME
14
16
from .. import exceptions
17
+ from ..storage .base import Storage
15
18
from ..sync .exceptions import IdentConflict
16
19
from ..sync .exceptions import PartialSync
17
20
from ..sync .exceptions import StorageEmpty
27
30
28
31
class _StorageIndex :
29
32
def __init__ (self ):
30
- self ._storages = {
33
+ self ._storages : dict [ str , str ] = {
31
34
"caldav" : "vdirsyncer.storage.dav.CalDAVStorage" ,
32
35
"carddav" : "vdirsyncer.storage.dav.CardDAVStorage" ,
33
36
"filesystem" : "vdirsyncer.storage.filesystem.FilesystemStorage" ,
@@ -37,7 +40,7 @@ def __init__(self):
37
40
"google_contacts" : "vdirsyncer.storage.google.GoogleContactsStorage" ,
38
41
}
39
42
40
- def __getitem__ (self , name ) :
43
+ def __getitem__ (self , name : str ) -> Storage :
41
44
item = self ._storages [name ]
42
45
if not isinstance (item , str ):
43
46
return item
@@ -154,13 +157,18 @@ def handle_cli_error(status_name=None, e=None):
154
157
cli_logger .debug ("" .join (tb ))
155
158
156
159
157
- def get_status_name (pair , collection ) :
160
+ def get_status_name (pair : str , collection : str | None ) -> str :
158
161
if collection is None :
159
162
return pair
160
163
return pair + "/" + collection
161
164
162
165
163
- def get_status_path (base_path , pair , collection = None , data_type = None ):
166
+ def get_status_path (
167
+ base_path : str ,
168
+ pair : str ,
169
+ collection : str | None = None ,
170
+ data_type : str | None = None ,
171
+ ) -> str :
164
172
assert data_type is not None
165
173
status_name = get_status_name (pair , collection )
166
174
path = expand_path (os .path .join (base_path , status_name ))
@@ -174,7 +182,12 @@ def get_status_path(base_path, pair, collection=None, data_type=None):
174
182
return path
175
183
176
184
177
- def load_status (base_path , pair , collection = None , data_type = None ):
185
+ def load_status (
186
+ base_path : str ,
187
+ pair : str ,
188
+ collection : str | None = None ,
189
+ data_type : str | None = None
190
+ ) -> dict | None :
178
191
path = get_status_path (base_path , pair , collection , data_type )
179
192
if not os .path .exists (path ):
180
193
return None
@@ -189,7 +202,7 @@ def load_status(base_path, pair, collection=None, data_type=None):
189
202
return {}
190
203
191
204
192
- def prepare_status_path (path ) :
205
+ def prepare_status_path (path : str ) -> None :
193
206
dirname = os .path .dirname (path )
194
207
195
208
try :
@@ -200,7 +213,7 @@ def prepare_status_path(path):
200
213
201
214
202
215
@contextlib .contextmanager
203
- def manage_sync_status (base_path , pair_name , collection_name ):
216
+ def manage_sync_status (base_path : str , pair_name : str , collection_name : str ):
204
217
path = get_status_path (base_path , pair_name , collection_name , "items" )
205
218
status = None
206
219
legacy_status = None
@@ -225,7 +238,13 @@ def manage_sync_status(base_path, pair_name, collection_name):
225
238
yield status
226
239
227
240
228
- def save_status (base_path , pair , collection = None , data_type = None , data = None ):
241
+ def save_status (
242
+ base_path : str ,
243
+ pair : str ,
244
+ collection : str | None = None ,
245
+ data_type : str | None = None ,
246
+ data : dict | None = None ,
247
+ ) -> None :
229
248
assert data_type is not None
230
249
assert data is not None
231
250
status_name = get_status_name (pair , collection )
@@ -319,7 +338,7 @@ def handle_storage_init_error(cls, config):
319
338
)
320
339
321
340
322
- def assert_permissions (path , wanted ) :
341
+ def assert_permissions (path : str , wanted : int ) -> None :
323
342
permissions = os .stat (path ).st_mode & 0o777
324
343
if permissions > wanted :
325
344
cli_logger .warning (
0 commit comments