Skip to content

Commit 4ed8a8a

Browse files
committed
Apply some fixes from self review 1.
1 parent d51d94e commit 4ed8a8a

File tree

6 files changed

+54
-44
lines changed

6 files changed

+54
-44
lines changed

datashuttle/configs/canonical_folders.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ def get_datashuttle_path() -> Path:
8282
return Path.home() / ".datashuttle"
8383

8484

85-
def get_internal_datashuttle_from_path():
85+
def get_internal_datashuttle_from_path() -> Path:
8686
"""Get a placeholder path for `validate_project_from_path()`."""
8787
return get_datashuttle_path() / "_datashuttle_from_path"
8888

@@ -100,16 +100,19 @@ def get_project_datashuttle_path(project_name: str) -> Tuple[Path, Path]:
100100
return base_path, temp_logs_path
101101

102102

103-
def get_rclone_config_base_path():
103+
def get_rclone_config_base_path() -> Path:
104104
"""Return the path to the Rclone config file.
105105
106106
This is used for RClone config files for transfer targets (ssh, aws, gdrive).
107107
This should match where RClone itself stores the config by default,
108108
as described here: https://rclone.org/docs/#config-string
109109
110-
Because RClone's resolution is a little complex, in some rare cases the
111-
below may not match where RClone stores its configs. This just means that
112-
local filesystem configs and transfer configs are stored in a separate place,
110+
Because RClone's resolution process for where it stores its config files
111+
is a little complex, in some rare cases the below may not match where
112+
RClone stores its configs. This just means that local filesystem configs,
113+
which are stored in the default `rclone.conf` file for backwards compatibility
114+
reasons. and transfer configs which are stored in their own file at the
115+
path returned from this function, are stored in a separate places,
113116
which is not a huge deal.
114117
"""
115118
if platform.system() == "Windows":

datashuttle/configs/config_class.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ def __init__(
3737
) -> None:
3838
"""Initialize the Configs class with project name, file path, and config dictionary.
3939
40-
This class also holds `RCloneConfigs` under the `.rclone` attribute to manage
41-
the configs
40+
This class also holds `RCloneConfigs` that manage the Rclone config files
41+
used for transfer.
4242
4343
Parameters
4444
----------

datashuttle/configs/rclone_configs.py

Lines changed: 15 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,44 @@
11
from __future__ import annotations
22

3-
from typing import TYPE_CHECKING, Dict, Optional
3+
from typing import TYPE_CHECKING, Optional
44

55
if TYPE_CHECKING:
66
from pathlib import Path
77

8-
from datashuttle.utils.custom_types import (
9-
OverwriteExistingFiles,
10-
)
8+
from datashuttle.configs.configs_class import Configs
119

1210
import yaml
1311

1412
from datashuttle.configs import canonical_folders
15-
from datashuttle.utils import rclone_encryption, utils
13+
from datashuttle.utils import rclone_encryption
1614

1715

1816
class RCloneConfigs:
1917
"""Class to manage the RClone configuration file.
2018
2119
This is a file that RClone creates to hold all information about local and
22-
remote transfer targets. For example, the ssh RClone config holds the private key.
20+
central transfer targets. For example, the SSH RClone config holds the private key,
21+
the GDrive rclone config holds the access token, etc.
2322
2423
In datashuttle, local filesystem configs uses the Rclone default configuration file,
25-
that RClone manages. However, remote transfers to ssh, aws and gdrive are held in
26-
separate config files (set using RClone's --config argument). Then being separate
27-
means these files can be separately encrypted.
24+
that RClone manages, for backwards comatability reasons. However, SSH, AWS and GDrive
25+
configs are stored in separate config files (set using RClone's --config argument).
26+
Then being separate means these files can be separately encrypted.
2827
2928
This class tracks the state on whether a RClone config is encrypted, as well
3029
as provides the default names for the rclone conf (e.g. central_<project_name>_<connection_method>).
3130
3231
Parameters
3332
----------
33+
datashuttle_configs
34+
Parent Configs class.
35+
3436
config_base_class
3537
Path to the datashuttle configs folder where all configs for the project are stored.
3638
3739
"""
3840

39-
def __init__(self, datashuttle_configs, config_base_path):
41+
def __init__(self, datashuttle_configs: Configs, config_base_path: Path):
4042
"""Construct the class."""
4143
self.datashuttle_configs = datashuttle_configs
4244
self.rclone_encryption_state_file_path = (
@@ -73,8 +75,9 @@ def load_rclone_config_is_encrypted(self) -> dict:
7375
def set_rclone_config_encryption_state(self, value: bool) -> None:
7476
"""Store the current state of the rclone config encryption for the `connection_method`.
7577
76-
Note that this is stored to disk each call (rather than tracked locally) to ensure
77-
it is updated live if updated through the Python API while the TUI is also running.
78+
Note that this is stored to disk each call (rather than tracked in memory)
79+
to ensure it is updated properly if changed through the Python API
80+
while the TUI is also running.
7881
"""
7982
assert rclone_encryption.connection_method_requires_encryption(
8083
self.datashuttle_configs["connection_method"]
@@ -119,27 +122,6 @@ def get_rclone_central_connection_config_filepath(self) -> Path:
119122
/ f"{self.get_rclone_config_name()}.conf"
120123
)
121124

122-
def make_rclone_transfer_options(
123-
self, overwrite_existing_files: OverwriteExistingFiles, dry_run: bool
124-
) -> Dict:
125-
"""Create a dictionary of rclone transfer options."""
126-
allowed_overwrite = ["never", "always", "if_source_newer"]
127-
128-
if overwrite_existing_files not in allowed_overwrite:
129-
utils.log_and_raise_error(
130-
f"`overwrite_existing_files` not "
131-
f"recognised, must be one of: "
132-
f"{allowed_overwrite}",
133-
ValueError,
134-
)
135-
136-
return {
137-
"overwrite_existing_files": overwrite_existing_files,
138-
"show_transfer_progress": True,
139-
"transfer_verbosity": "vv",
140-
"dry_run": dry_run,
141-
}
142-
143125
def delete_existing_rclone_config_file(self) -> None:
144126
"""Delete the Rclone config file if it exists."""
145127
rclone_config_filepath = (

datashuttle/datashuttle_class.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -790,7 +790,7 @@ def _transfer_specific_file_or_folder(
790790
upload_or_download,
791791
top_level_folder,
792792
include_list,
793-
self.cfg.rclone.make_rclone_transfer_options(
793+
rclone.make_rclone_transfer_options(
794794
overwrite_existing_files, dry_run
795795
),
796796
)

datashuttle/utils/data_transfer.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ def __init__(
9999
self.__upload_or_download,
100100
self.__top_level_folder,
101101
include_list,
102-
cfg.rclone.make_rclone_transfer_options(
102+
rclone.make_rclone_transfer_options(
103103
overwrite_existing_files, dry_run
104104
),
105105
)

datashuttle/utils/rclone.py

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,10 @@
77
from subprocess import CompletedProcess
88

99
from datashuttle.configs.config_class import Configs
10-
from datashuttle.utils.custom_types import TopLevelFolder
10+
from datashuttle.utils.custom_types import (
11+
OverwriteExistingFiles,
12+
TopLevelFolder,
13+
)
1114

1215
import json
1316
import os
@@ -635,7 +638,7 @@ def transfer_data(
635638
636639
rclone_options
637640
A list of options to pass to Rclone's copy function.
638-
see `cfg.rclone.make_rclone_transfer_options()`.
641+
see `make_rclone_transfer_options()`.
639642
640643
Returns
641644
-------
@@ -677,6 +680,28 @@ def transfer_data(
677680
return output
678681

679682

683+
def make_rclone_transfer_options(
684+
overwrite_existing_files: OverwriteExistingFiles, dry_run: bool
685+
) -> Dict:
686+
"""Create a dictionary of rclone transfer options."""
687+
allowed_overwrite = ["never", "always", "if_source_newer"]
688+
689+
if overwrite_existing_files not in allowed_overwrite:
690+
utils.log_and_raise_error(
691+
f"`overwrite_existing_files` not "
692+
f"recognised, must be one of: "
693+
f"{allowed_overwrite}",
694+
ValueError,
695+
)
696+
697+
return {
698+
"overwrite_existing_files": overwrite_existing_files,
699+
"show_transfer_progress": True,
700+
"transfer_verbosity": "vv",
701+
"dry_run": dry_run,
702+
}
703+
704+
680705
def get_local_and_central_file_differences(
681706
cfg: Configs,
682707
top_level_folders_to_check: List[TopLevelFolder],

0 commit comments

Comments
 (0)