Skip to content

Commit e53984b

Browse files
author
shrey
committed
update: config dict inplace change for backward compatibility, use existing rclone function, moving type hint imports in the conditional block
1 parent 8beaa42 commit e53984b

4 files changed

Lines changed: 30 additions & 27 deletions

File tree

datashuttle/configs/config_class.py

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -127,14 +127,13 @@ def load_from_file(self) -> None:
127127

128128
load_configs.convert_str_and_pathlib_paths(config_dict, "str_to_path")
129129

130-
config_dict = self.ensure_backwards_compatibilty_for_config(
131-
config_dict
132-
)
130+
self.update_config_for_backward_compatability_if_required(config_dict)
131+
133132
self.data = config_dict
134133

135-
def ensure_backwards_compatibilty_for_config(
134+
def update_config_for_backward_compatability_if_required(
136135
self, config_dict: Dict
137-
) -> Dict:
136+
):
138137
canonical_config_keys_to_add = [
139138
"gdrive_client_id",
140139
"gdrive_root_folder_id",
@@ -143,16 +142,20 @@ def ensure_backwards_compatibilty_for_config(
143142
]
144143

145144
# All keys shall be missing for a backwards compatibility update
146-
needs_update = all(
147-
key not in config_dict.keys()
148-
for key in canonical_config_keys_to_add
149-
)
150-
if needs_update:
145+
if not (
146+
all(
147+
key in config_dict.keys()
148+
for key in canonical_config_keys_to_add
149+
)
150+
):
151+
assert not any(
152+
key in config_dict.keys()
153+
for key in canonical_config_keys_to_add
154+
)
155+
151156
for key in canonical_config_keys_to_add:
152157
config_dict[key] = None
153158

154-
return config_dict
155-
156159
# -------------------------------------------------------------------------
157160
# Utils
158161
# -------------------------------------------------------------------------

datashuttle/tui/screens/setup_aws.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ def compose(self) -> ComposeResult:
3131
yield Container(
3232
Horizontal(
3333
Static(
34-
"Ready to setup AWS connection. " "Press OK to proceed",
34+
"Ready to setup AWS connection. Press OK to proceed",
3535
id="setup_aws_messagebox_message",
3636
),
3737
id="setup_aws_messagebox_message_container",

datashuttle/utils/folders.py

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
from __future__ import annotations
22

33
import json
4-
import subprocess
54
from typing import (
65
TYPE_CHECKING,
76
Any,
@@ -22,7 +21,7 @@
2221
from pathlib import Path
2322

2423
from datashuttle.configs import canonical_folders, canonical_tags
25-
from datashuttle.utils import ssh, utils, validation
24+
from datashuttle.utils import rclone, ssh, utils, validation
2625
from datashuttle.utils.custom_exceptions import NeuroBlueprintError
2726

2827
# -----------------------------------------------------------------------------
@@ -564,16 +563,11 @@ def search_gdrive_or_aws_for_folders(
564563
The json contains file/folder info about each file/folder like name, type, etc.
565564
"""
566565

567-
command = (
568-
"rclone lsjson "
566+
output = rclone.call_rclone(
567+
"lsjson "
569568
f"{cfg.get_rclone_config_name()}:{search_path.as_posix()} "
570569
f'--include "{search_prefix}"',
571-
)
572-
output = subprocess.run(
573-
command,
574-
stdout=subprocess.PIPE,
575-
stderr=subprocess.PIPE,
576-
shell=True,
570+
pipe_std=True,
577571
)
578572

579573
all_folder_names: List[str] = []

datashuttle/utils/rclone.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,20 @@
1+
from __future__ import annotations
2+
3+
from typing import TYPE_CHECKING, Dict, List, Literal, Optional
4+
5+
if TYPE_CHECKING:
6+
from pathlib import Path
7+
8+
from datashuttle.configs.config_class import Configs
9+
from datashuttle.utils.custom_types import TopLevelFolder
10+
111
import os
212
import platform
313
import subprocess
414
import tempfile
5-
from pathlib import Path
615
from subprocess import CompletedProcess
7-
from typing import Dict, List, Literal, Optional
816

9-
from datashuttle.configs.config_class import Configs
1017
from datashuttle.utils import utils
11-
from datashuttle.utils.custom_types import TopLevelFolder
1218

1319

1420
def call_rclone(command: str, pipe_std: bool = False) -> CompletedProcess:

0 commit comments

Comments
 (0)