More work on file transmission
This commit is contained in:
parent
5eb87b9f10
commit
ee852cf5fc
@ -14,7 +14,7 @@ from kitty.file_transmission import (
|
||||
|
||||
from ..tui.handler import Handler
|
||||
from ..tui.loop import Loop, debug
|
||||
from .utils import random_id
|
||||
from .utils import expand_home, random_id
|
||||
|
||||
debug
|
||||
|
||||
@ -102,7 +102,7 @@ def files_for_receive(cli_opts: TransferCLIOptions, dest: str, files: List[File]
|
||||
spec_paths = [posixpath.join('~', posixpath.relpath(x, home)) for x in spec_paths]
|
||||
for spec_id, files_for_spec in spec_map.items():
|
||||
spec = spec_paths[spec_id]
|
||||
tree = make_tree(files_for_spec, os.path.dirname(os.path.expanduser(spec)))
|
||||
tree = make_tree(files_for_spec, os.path.dirname(expand_home(spec)))
|
||||
for x in tree:
|
||||
yield x.entry
|
||||
else:
|
||||
@ -112,7 +112,7 @@ def files_for_receive(cli_opts: TransferCLIOptions, dest: str, files: List[File]
|
||||
dest_path = os.path.join(dest, posixpath.basename(files_for_spec[0].remote_path))
|
||||
else:
|
||||
dest_path = dest
|
||||
tree = make_tree(files_for_spec, os.path.expanduser(dest_path))
|
||||
tree = make_tree(files_for_spec, expand_home(dest_path))
|
||||
for x in tree:
|
||||
yield x.entry
|
||||
|
||||
|
||||
@ -141,6 +141,10 @@ def home_path() -> str:
|
||||
return _home or os.path.expanduser('~')
|
||||
|
||||
|
||||
def cwd_path() -> str:
|
||||
return _cwd or os.getcwd()
|
||||
|
||||
|
||||
def expand_home(path: str) -> str:
|
||||
if path.startswith('~' + os.sep) or (os.altsep and path.startswith('~' + os.altsep)):
|
||||
return os.path.join(home_path(), path[2:].lstrip(os.sep + (os.altsep or '')))
|
||||
|
||||
@ -13,10 +13,10 @@ from kittens.transfer.librsync import (
|
||||
LoadSignature, PatchFile, delta_for_file, signature_of_file
|
||||
)
|
||||
from kittens.transfer.main import parse_transfer_args
|
||||
from kittens.transfer.receive import files_for_receive, File
|
||||
from kittens.transfer.receive import File, files_for_receive
|
||||
from kittens.transfer.rsync import decode_utf8_buffer, parse_ftc
|
||||
from kittens.transfer.send import files_for_send
|
||||
from kittens.transfer.utils import set_paths, home_path
|
||||
from kittens.transfer.utils import expand_home, home_path, set_paths, cwd_path
|
||||
from kitty.file_transmission import (
|
||||
Action, Compression, FileTransmissionCommand, FileType,
|
||||
TestFileTransmission as FileTransmission, TransmissionType,
|
||||
@ -357,10 +357,10 @@ class TestFileTransmission(BaseTest):
|
||||
|
||||
def am(files, kw):
|
||||
m = {f.remote_path: f.expanded_local_path for f in files}
|
||||
kw = {str(k): str(v) for k, v in kw.items()}
|
||||
kw = {str(k): expand_home(str(v)) for k, v in kw.items()}
|
||||
self.ae(kw, m)
|
||||
|
||||
def tf(args, expected):
|
||||
def tf(args, expected, different_home=''):
|
||||
if opts.mode == 'mirror':
|
||||
all_specs = args
|
||||
dest = ''
|
||||
@ -369,13 +369,19 @@ class TestFileTransmission(BaseTest):
|
||||
dest = args[-1]
|
||||
specs = list((str(i), str(s)) for i, s in enumerate(all_specs))
|
||||
files = list(map(File, iter_file_metadata(specs)))
|
||||
files = list(files_for_receive(opts, dest, files, home_path(), specs))
|
||||
self.ae(len(files), len(expected))
|
||||
am(files, expected)
|
||||
orig_home = home_path()
|
||||
with set_paths(cwd_path(), different_home or orig_home):
|
||||
files = list(files_for_receive(opts, dest, files, orig_home, specs))
|
||||
self.ae(len(files), len(expected))
|
||||
am(files, expected)
|
||||
|
||||
opts.mode = 'mirror'
|
||||
with set_paths(cwd=b, home='/foo/bar'):
|
||||
tf([b/'r', b/'d'], {b/'r': b/'r', b/'d': b/'d', b/'d'/'r': b/'d'/'r'})
|
||||
tf([b/'r', b/'d/r'], {b/'r': b/'r', b/'d'/'r': b/'d'/'r'})
|
||||
with set_paths(cwd=b, home=self.tdir):
|
||||
tf([b/'r', b/'d'], {b/'r': '~/b/r', b/'d': '~/b/d', b/'d'/'r': '~/b/d/r'}, different_home='/foo/bar')
|
||||
opts.mode = 'normal'
|
||||
|
||||
def test_path_mapping_send(self):
|
||||
opts = parse_transfer_args([])[0]
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user