6
6
from bubop import check_optional_mutually_exclusive , format_dict , logger , loguru_tqdm_sink
7
7
8
8
from syncall import inform_about_app_extras
9
- from syncall .cli import opt_filename_extension , opt_gkeep_ignore_labels
9
+ from syncall .cli import opt_filename_extension , opt_gkeep_ignore_labels , opts_miscellaneous
10
10
11
11
try :
12
12
from syncall import GKeepNoteSide
16
16
from syncall import (
17
17
Aggregator ,
18
18
FilesystemSide ,
19
- __version__ ,
20
19
cache_or_reuse_cached_combination ,
21
20
convert_filesystem_file_to_gkeep_note ,
22
21
convert_gkeep_note_to_filesystem_file ,
23
22
fetch_app_configuration ,
24
23
get_resolution_strategy ,
25
- inform_about_combination_name_usage ,
26
24
list_named_combinations ,
27
- report_toplevel_exception ,
28
25
)
29
26
from syncall .app_utils import (
30
27
app_log_to_syslog ,
31
28
gkeep_read_username_password_token ,
29
+ register_teardown_handler ,
32
30
write_to_pass_manager ,
33
31
)
34
32
from syncall .cli import (
35
- opt_combination ,
36
- opt_custom_combination_savename ,
37
33
opt_filesystem_root ,
38
34
opt_gkeep_labels ,
39
35
opt_gkeep_passwd_pass_path ,
40
36
opt_gkeep_token_pass_path ,
41
37
opt_gkeep_user_pass_path ,
42
- opt_list_combinations ,
43
- opt_resolution_strategy ,
44
38
)
45
39
46
40
55
49
@opt_filename_extension ()
56
50
@opt_filesystem_root ()
57
51
# misc options --------------------------------------------------------------------------------
58
- @opt_list_combinations ("Filesystem" , "Google Keep" )
59
- @opt_resolution_strategy ()
60
- @opt_combination ("Filesystem" , "Google Keep" )
61
- @opt_custom_combination_savename ("Filesystem" , "Google Keep" )
62
- @click .option ("-v" , "--verbose" , count = True )
63
- @click .version_option (__version__ )
52
+ @opts_miscellaneous ("Filesystem" , "Google Keep" )
64
53
def main (
65
54
filesystem_root : Optional [str ],
55
+ filename_extension : str ,
66
56
gkeep_labels : Sequence [str ],
67
57
gkeep_ignore_labels : Sequence [str ],
68
58
gkeep_user_pass_path : str ,
@@ -73,7 +63,8 @@ def main(
73
63
combination_name : str ,
74
64
custom_combination_savename : str ,
75
65
do_list_combinations : bool ,
76
- filename_extension : str ,
66
+ list_resolution_strategies : bool ,
67
+ pdb_on_error : bool ,
77
68
):
78
69
"""
79
70
Synchronize Notes from your Google Keep with text files in a directory on your filesystem.
@@ -136,6 +127,7 @@ def main(
136
127
gkeep_labels = app_config ["gkeep_labels" ]
137
128
gkeep_ignore_labels = app_config ["gkeep_ignore_labels" ]
138
129
filename_extension = app_config ["filename_extension" ]
130
+
139
131
# combination manually specified ----------------------------------------------------------
140
132
else :
141
133
inform_about_config = True
@@ -188,7 +180,6 @@ def main(
188
180
gkeep_token_pass_path ,
189
181
)
190
182
191
- # initialize google keep -----------------------------------------------------------------
192
183
gkeep_side = GKeepNoteSide (
193
184
gkeep_labels = gkeep_labels ,
194
185
gkeep_ignore_labels = gkeep_ignore_labels ,
@@ -197,12 +188,19 @@ def main(
197
188
gkeep_token = gkeep_token ,
198
189
)
199
190
200
- # initialize Filesystem Side --------------------------------------------------------------
201
191
filesystem_side = FilesystemSide (
202
192
filesystem_root = filesystem_root_path , filename_extension = filename_extension
203
193
)
204
194
205
- # sync ------------------------------------------------------------------------------------
195
+ # teardown function and exception handling ------------------------------------------------
196
+ register_teardown_handler (
197
+ pdb_on_error = pdb_on_error ,
198
+ inform_about_config = inform_about_config ,
199
+ combination_name = combination_name ,
200
+ verbose = verbose ,
201
+ )
202
+
203
+ # take extra arguments into account -------------------------------------------------------
206
204
def converter_A_to_B (gkeep_note ):
207
205
return convert_gkeep_note_to_filesystem_file (
208
206
gkeep_note = gkeep_note ,
@@ -212,40 +210,31 @@ def converter_A_to_B(gkeep_note):
212
210
213
211
converter_A_to_B .__doc__ = convert_gkeep_note_to_filesystem_file .__doc__
214
212
215
- try :
216
- with Aggregator (
217
- side_A = gkeep_side ,
218
- side_B = filesystem_side ,
219
- converter_B_to_A = convert_filesystem_file_to_gkeep_note ,
220
- converter_A_to_B = converter_A_to_B ,
221
- resolution_strategy = get_resolution_strategy (
222
- resolution_strategy ,
223
- side_A_type = type (gkeep_side ),
224
- side_B_type = type (filesystem_side ),
225
- ),
226
- config_fname = combination_name ,
227
- ignore_keys = (
228
- (),
229
- (),
230
- ),
231
- ) as aggregator :
232
- aggregator .sync ()
233
- except KeyboardInterrupt :
234
- logger .error ("Exiting..." )
235
- return 1
236
- except :
237
- report_toplevel_exception (is_verbose = verbose >= 1 )
238
- return 1
239
-
240
- # cache the token
213
+ # sync ------------------------------------------------------------------------------------
214
+ with Aggregator (
215
+ side_A = gkeep_side ,
216
+ side_B = filesystem_side ,
217
+ converter_B_to_A = convert_filesystem_file_to_gkeep_note ,
218
+ converter_A_to_B = converter_A_to_B ,
219
+ resolution_strategy = get_resolution_strategy (
220
+ resolution_strategy ,
221
+ side_A_type = type (gkeep_side ),
222
+ side_B_type = type (filesystem_side ),
223
+ ),
224
+ config_fname = combination_name ,
225
+ ignore_keys = (
226
+ (),
227
+ (),
228
+ ),
229
+ ) as aggregator :
230
+ aggregator .sync ()
231
+
232
+ # cache the token -------------------------------------------------------------------------
241
233
token = gkeep_side .get_master_token ()
242
234
if token is not None :
243
235
logger .debug (f"Caching the gkeep token in pass -> { gkeep_token_pass_path } ..." )
244
236
write_to_pass_manager (password_path = gkeep_token_pass_path , passwd = token )
245
237
246
- if inform_about_config :
247
- inform_about_combination_name_usage (combination_name )
248
-
249
238
return 0
250
239
251
240
0 commit comments