Skip to content

Commit c9fe797

Browse files
committed
Add basic implementation
1 parent d9613c9 commit c9fe797

File tree

2 files changed

+92
-3
lines changed

2 files changed

+92
-3
lines changed

src/dmu/fsystem/fcopy.py

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
'''
2+
Module holding FCopy class and FCopyConf
3+
'''
4+
from pathlib import Path
5+
from typing import Final
6+
from pydantic import BaseModel
7+
from dmu.logging.log_store import LogStore
8+
9+
log=LogStore.add_logger('dmu:fsystem:fcopy')
10+
# ----------------------
11+
class FCopyConf(BaseModel):
12+
'''
13+
Class meant to store configuration for FCopy
14+
'''
15+
host : str
16+
# ----------------------
17+
class FCopy:
18+
'''
19+
Class meant to act as a wrapper to rsync by
20+
21+
- Checking that the server and local machine are suitable
22+
- Talking to rsync
23+
'''
24+
# ----------------------
25+
def __init__(self, cfg : FCopyConf):
26+
'''
27+
Parameters
28+
-------------
29+
cfg: Instance of FCopyConf storing configuration
30+
'''
31+
self._cfg : Final[FCopyConf] = cfg
32+
# ----------------------
33+
def copy(self, source : Path, target : Path) -> bool:
34+
'''
35+
Parameters
36+
---------------
37+
source: Path to file to be copied
38+
target: Destination path
39+
40+
Returns
41+
---------------
42+
True if success
43+
'''
44+
log.debug('')
45+
log.debug(source)
46+
log.debug('--->')
47+
log.debug(target)
48+
49+
return True
50+
# ----------------------

tests/fsystem/test_fcopy.py

Lines changed: 42 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,54 @@
22
Script with tests for FCopy class
33
'''
44

5-
from dmu import FCopy
5+
from pathlib import Path
6+
from dmu import FCopy, FCopyConf
67

78
from dmu.logging.log_store import LogStore
89

910
log=LogStore.add_logger('dmu:test_fcopy')
1011
# ----------------------
11-
def test_simple() -> None:
12+
def _make_paths(
13+
dir : Path,
14+
make_file : bool,
15+
number : int,
16+
size : int = 1) -> list[Path]:
17+
'''
18+
Parameters
19+
-------------
20+
dir : Path to directory
21+
make_file: If true, will make an empty file
22+
number : Number of paths to make
23+
size : Size in MB, default 1
24+
25+
Returns
26+
-------------
27+
List of paths
28+
'''
29+
dir.mkdir(parents=True, exist_ok=True)
30+
31+
l_path = []
32+
for index in range(number):
33+
path = dir / f'{index:03}'
34+
35+
if make_file:
36+
with open(path, 'wb') as f:
37+
f.seek(size * 1024 * 1024 - 1)
38+
f.write(b'\0')
39+
40+
l_path.append(path)
41+
42+
return l_path
43+
# ----------------------
44+
def test_simple(tmp_path) -> None:
1245
'''
1346
'''
47+
l_source = _make_paths(dir=tmp_path / 'source', make_file= True, number=10)
48+
l_target = _make_paths(dir=tmp_path / 'target', make_file=False, number=10)
49+
50+
cfg = FCopyConf(host='localhost')
1451
fcp = FCopy(cfg=cfg)
15-
fcp.copy(source=source, target=target)
52+
53+
for source, target in zip(l_source, l_target):
54+
fcp.copy(source=source, target=target)
1655
# ----------------------

0 commit comments

Comments
 (0)