Skip to content

Commit

Permalink
lftp: fixed a parser error with 2-line chmod
Browse files Browse the repository at this point in the history
  • Loading branch information
ipsingh06 committed May 31, 2020
1 parent f030ccb commit f7093ea
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 10 deletions.
18 changes: 8 additions & 10 deletions src/python/lftp/job_status_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -438,19 +438,17 @@ def __parse_jobs(lines: List[str]) -> List[LftpJobStatus]:
result = chmod_header_m.search(line)
if result:
name = result.group("name")
# Also ignore the next two lines
# Also ignore the next one or two lines
if not lines or not lines[0].startswith("file:"):
raise ValueError("Missing 'file:' line for chmod '{}'".format(name))
lines.pop(0)
if not lines:
raise ValueError("Missing last line for chmod '{}'".format(name))
result_chmod = chmod_pattern_m.search(lines[0])
if not result_chmod:
raise ValueError("Missing last line for chmod '{}'".format(name))
name_chmod = result_chmod.group("name")
if name != name_chmod:
raise ValueError("Mismatch in names chmod '{}'".format(name))
lines.pop(0)
if lines:
result_chmod = chmod_pattern_m.search(lines[0])
if result_chmod:
name_chmod = result_chmod.group("name")
if name != name_chmod:
raise ValueError("Mismatch in names chmod '{}'".format(name))
lines.pop(0)
# Continue the outer loop
continue

Expand Down
43 changes: 43 additions & 0 deletions src/python/tests/unittests/test_lftp/test_job_status_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -1248,3 +1248,46 @@ def test_jobs_chmod(self):
self.assertEqual(2, len(statuses))
self.assertEqual(golden_job1, statuses[0])
self.assertEqual(golden_job2, statuses[1])

def test_jobs_chmod_two_liner(self):
output = """
[0] queue (sftp://someone:@localhost:22) -- 1.8 KiB/s
sftp://someone:@localhost:22/remote/path
Now executing: [1] mirror -c /remote/path/Space.Trek /local/path/ -- 3.1k/617M (0%) 1.8 KiB/s
[1] mirror -c /remote/path/Space.Trek /local/path/ -- 3.1k/617M (0%) 1.8 KiB/s
\mirror `Space.Trek.S08E04'
chmod Space.Trek.S08E04.sfv
file:/local/path/Space.Trek/Space.Trek.S08E04
\mirror `Space.Trek.S08E05' -- 605/51M (0%)
\\transfer `Space.Trek.S08E05/space.trek.s08e05.r06'
`space.trek.s08e05.r06' at 0 (0%) [Waiting for response...]
\mirror `Space.Trek.S08E06' -- 1.6k/517M (0%) 932 B/s
\\transfer `Space.Trek.S08E06/space.trek.s08e06.nfo'
`space.trek.s08e06.nfo' at 932 (100%) [Receiving data]
\mirror `Space.Trek.S08E07' -- 932/51M (0%) 932 B/s
\\transfer `Space.Trek.S08E07/space.trek.s08e07.nfo'
`space.trek.s08e07.nfo' at 932 (100%) [Receiving data]
"""
parser = LftpJobStatusParser()
statuses = parser.parse(output)

golden_job1 = LftpJobStatus(job_id=1,
job_type=LftpJobStatus.Type.MIRROR,
state=LftpJobStatus.State.RUNNING,
name="Space.Trek",
flags="-c")
golden_job1.total_transfer_state = LftpJobStatus.TransferState(3174, 646971392, 0, 1843, None)
golden_job1.add_active_file_transfer_state(
"Space.Trek.S08E05/space.trek.s08e05.r06",
LftpJobStatus.TransferState(None, None, None, None, None)
)
golden_job1.add_active_file_transfer_state(
"Space.Trek.S08E06/space.trek.s08e06.nfo",
LftpJobStatus.TransferState(None, None, None, None, None)
)
golden_job1.add_active_file_transfer_state(
"Space.Trek.S08E07/space.trek.s08e07.nfo",
LftpJobStatus.TransferState(None, None, None, None, None)
)
self.assertEqual(1, len(statuses))
self.assertEqual(golden_job1, statuses[0])

0 comments on commit f7093ea

Please sign in to comment.