Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 30 additions & 6 deletions python/vyos/remote.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@

from ftplib import FTP
from ftplib import FTP_TLS
from typing import Optional

from paramiko import SSHClient, SSHException
from paramiko import MissingHostKeyPolicy
Expand Down Expand Up @@ -350,7 +351,7 @@ def download(self, location: str):
raise NotImplementedError("not supported")

@umask(0o077)
def upload(self, location: str):
def upload(self, location: str, subdirectory: Optional[str] = None):
scheme = self.url.scheme
_, _, scheme = scheme.partition("+")
netloc = self.url.netloc
Expand Down Expand Up @@ -395,10 +396,17 @@ def upload(self, location: str):

# git add
filename = Path(Path(self.url.path).name).stem
dst = path_repository / filename
if subdirectory:
subdir_path = Path(subdirectory)
os.mkdir(path_repository / subdir_path)
dst = path_repository / subdirectory / filename
dst_file = subdir_path / filename
else:
dst = path_repository / filename
dst_file = filename
shutil.copy2(location, dst)
rc, out = rc_cmd(
[self.command, "-C", str(path_repository), "add", filename],
[self.command, "-C", str(path_repository), "add", dst_file],
env=env,
shell=False,
)
Expand Down Expand Up @@ -457,11 +465,27 @@ def download(local_path, urlstring, progressbar=False, check_space=False,
print_error('\nDownload aborted by user.')
sys.exit(1)

def upload(local_path, urlstring, progressbar=False,
source_host='', source_port=0, timeout=10.0):

def upload(
local_path,
urlstring,
progressbar=False,
source_host='',
source_port=0,
timeout=10.0,
subdirectory: Optional[str] = None,
):
try:
progressbar = progressbar and is_interactive()
urlc(urlstring, progressbar, False, source_host, source_port, timeout).upload(local_path)
urlc(
urlstring,
progressbar,
False,
source_host,
source_port,
timeout,
subdirectory,
).upload(local_path)
except Exception as err:
print_error(f'Unable to upload "{urlstring}": {err}')
sys.exit(1)
Expand Down
Loading