Skip to content

Commit

Permalink
Merge pull request #17 from xionghuichen/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
xionghuichen authored Jun 14, 2022
2 parents c86c6c6 + 90f672c commit 6011068
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 11 deletions.
5 changes: 3 additions & 2 deletions RLA/auto_ftp.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,13 +197,14 @@ def upload_file(self, remote_dir, local_dir, local_file):
self.close()

def download_file(self, remote_file, local_file):
self.sftp = self.sftpconnect()
logger.info("try download {}".format(local_file))
if not os.path.isfile(local_file):
logger.info("new file {}".format(local_file))
self.sftp.get(remote_file)
self.sftp.get(remote_file, local_file)
elif self.sftp.stat(remote_file).st_size != os.path.getsize(local_file):
logger.info("update file {}".format(local_file))
self.sftp.get(remote_file)
self.sftp.get(remote_file, local_file)
else:
logger.info("skip download file {}".format(remote_file))

Expand Down
15 changes: 8 additions & 7 deletions RLA/easy_log/tester.py
Original file line number Diff line number Diff line change
Expand Up @@ -313,16 +313,17 @@ def sync_log_file(self):
from RLA.auto_ftp import FTPHandler
from RLA.auto_ftp import SFTPHandler
try:
try:
ftp = FTPHandler(ftp_server=self.private_config["REMOTE_SETTING"]["ftp_server"],
username=self.private_config["REMOTE_SETTING"]["username"],
password=self.private_config["REMOTE_SETTING"]["password"])
except Exception as e:
logger.warn("sending log file failed. {}".format(e))
logger.warn("try to send log file through sftp")
if 'file_transfer_protocol' not in self.private_config["REMOTE_SETTING"].keys() or self.private_config["REMOTE_SETTING"]['file_transfer_protocol'] is 'sftp':
ftp = SFTPHandler(sftp_server=self.private_config["REMOTE_SETTING"]["ftp_server"],
username=self.private_config["REMOTE_SETTING"]["username"],
password=self.private_config["REMOTE_SETTING"]["password"])
elif self.private_config["REMOTE_SETTING"]['file_transfer_protocol'] is 'ftp':
ftp = FTPHandler(ftp_server=self.private_config["REMOTE_SETTING"]["ftp_server"],
username=self.private_config["REMOTE_SETTING"]["username"],
password=self.private_config["REMOTE_SETTING"]["password"])
else:
raise ValueError("designated file_transfer_protocol {} is not supported".format(self.private_config["REMOTE_SETTING"]['file_transfer_protocol']))

for root, dirs, files in os.walk(self.log_dir):
suffix = root.split("/{}/".format(LOG))
assert len(suffix) == 2, "root should only have one pattern \"/log/\""
Expand Down
16 changes: 14 additions & 2 deletions test/test_scripts.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
from test._base import BaseTest
from RLA.easy_log.log_tools import DeleteLogTool, Filter
from RLA.easy_log.log_tools import ArchiveLogTool, ViewLogTool

from RLA.easy_log.tester import exp_manager
from RLA.auto_ftp import SFTPHandler
import os

class ScriptTest(BaseTest):

Expand Down Expand Up @@ -55,4 +57,14 @@ def test_archive(self):
def test_view(self):
self.remove_and_copy_data()
dlt = ViewLogTool(proj_root=self.TARGET_DATA_ROOT, task_table_name=self.TASK_NAME, regex='2022/03/01/21-13*')
dlt.view_log(skip_ask=True)
dlt.view_log(skip_ask=True)

def test_sync_log(self):
exp_manager.configure(task_name='test',
private_config_path='./test/test_data_root/rla_config.yaml',
log_root='./test/test_data_root/source/')
ftp = SFTPHandler(sftp_server=exp_manager.private_config["REMOTE_SETTING"]["ftp_server"],
username=exp_manager.private_config["REMOTE_SETTING"]["username"],
password=exp_manager.private_config["REMOTE_SETTING"]["password"])
ftp.upload_file(os.getcwd() + '/' + 'test/test_data_root/target/', 'test/test_data_root/source/', 'test.txt')
ftp.download_file(os.getcwd() + '/' + 'test/test_data_root/source/download.txt', 'test/test_data_root/target/download.txt')

0 comments on commit 6011068

Please sign in to comment.