@@ -475,8 +475,8 @@ def transfer_data(
475475 return output
476476
477477
478- def log_rclone_output_python_api (stdout , stderr ) :
479- """"""
478+ def log_stdout_stderr_python_api (stdout : str , stderr : str ) -> None :
479+ """Log `stdout` and `stderr`. """
480480 message = (
481481 f"\n \n ************** STDOUT **************\n "
482482 f"{ stdout } "
@@ -488,7 +488,12 @@ def log_rclone_output_python_api(stdout, stderr):
488488
489489
490490def log_rclone_copy_errors_api (errors ):
491- """"""
491+ """Log the `errors` dictionary.
492+
493+ The `errors` dictionary contains all pertinent information on
494+ issues that occurred when running `rclone copy`. Note this logs
495+ for the API, the TUI display is handled separately.
496+ """
492497 message = ""
493498
494499 if errors ["nothing_was_transferred_rawdata" ] is True :
@@ -517,7 +522,12 @@ def log_rclone_copy_errors_api(errors):
517522
518523
519524def parse_rclone_copy_output (top_level_folder , output ):
520- """"""
525+ """Format the `rclone copy` output ready for logging.
526+
527+ Reformat and combine the string streams and `errors`
528+ dictionary from stdout and stderr output of `rclone copy`.
529+ see `reformat_rclone_copy_output() for details.
530+ """
521531 stdout , out_errors = reformat_rclone_copy_output (
522532 output .stdout , top_level_folder = top_level_folder
523533 )
@@ -526,9 +536,9 @@ def parse_rclone_copy_output(top_level_folder, output):
526536 output .stderr , top_level_folder = top_level_folder
527537 )
528538
539+ # Combine the two `errors` output
529540 all_errors = {
530- "file_names" : out_errors ["file_names" ]
531- + err_errors ["file_names" ], # TODO: this is so messy
541+ "file_names" : out_errors ["file_names" ] + err_errors ["file_names" ],
532542 "messages" : out_errors ["messages" ] + err_errors ["messages" ],
533543 "nothing_was_transferred_rawdata" : err_errors [
534544 "nothing_was_transferred_rawdata"
@@ -544,6 +554,11 @@ def parse_rclone_copy_output(top_level_folder, output):
544554
545555
546556def get_empty_errors_dict () -> TransferErrors :
557+ """Return the `errors` dictionary with default values.
558+
559+ The `errors` dictionary holds information
560+ about errors which occurred during `rclone copy` transfer.
561+ """
547562 return {
548563 "file_names" : [],
549564 "messages" : [],
@@ -556,7 +571,34 @@ def reformat_rclone_copy_output(
556571 stream : bytes ,
557572 top_level_folder : TopLevelFolder | None = None ,
558573) -> tuple [str , TransferErrors ]:
559- """:return:"""
574+ """Parse the output of `rclone copy` for convenient error checking.
575+
576+ Rclone's `copy` command (called with `--use-json-log`) outputs a lot of
577+ information related to the transfer. We dump this in text form to a log
578+ file. However, we also want to grab any key events (errors, or complete
579+ lack of transferred files) so these can be displayed separately.
580+
581+ This function iterates through all lines in the `rclone copy` output.
582+ This output is typically a mix of string format and json format.
583+ If the line is json-encoded, then we extract important information
584+ and format it to string, and re-insert it into the output.
585+
586+ In this way, we have a string-format output ready to be
587+ dumped to the logs, as well as an `errors` dictionary containing
588+ details on all key information.
589+
590+ Returns
591+ -------
592+ format_stream
593+ The input stream, converted to string and with all
594+ json-formatted lines reformatted as string. This is ready
595+ to be dumped to a log file.
596+
597+ errors
598+ A dictionary (`TransferErrors`) containing key information
599+ about issues in the transfer.
600+
601+ """
560602 split_stream = stream .decode ("utf-8" ).split ("\n " )
561603
562604 errors = get_empty_errors_dict ()
0 commit comments