Skip to content

Commit f7093ea

Browse files
committed
lftp: fixed a parser error with 2-line chmod
1 parent f030ccb commit f7093ea

File tree

2 files changed

+51
-10
lines changed

2 files changed

+51
-10
lines changed

src/python/lftp/job_status_parser.py

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -438,19 +438,17 @@ def __parse_jobs(lines: List[str]) -> List[LftpJobStatus]:
438438
result = chmod_header_m.search(line)
439439
if result:
440440
name = result.group("name")
441-
# Also ignore the next two lines
441+
# Also ignore the next one or two lines
442442
if not lines or not lines[0].startswith("file:"):
443443
raise ValueError("Missing 'file:' line for chmod '{}'".format(name))
444444
lines.pop(0)
445-
if not lines:
446-
raise ValueError("Missing last line for chmod '{}'".format(name))
447-
result_chmod = chmod_pattern_m.search(lines[0])
448-
if not result_chmod:
449-
raise ValueError("Missing last line for chmod '{}'".format(name))
450-
name_chmod = result_chmod.group("name")
451-
if name != name_chmod:
452-
raise ValueError("Mismatch in names chmod '{}'".format(name))
453-
lines.pop(0)
445+
if lines:
446+
result_chmod = chmod_pattern_m.search(lines[0])
447+
if result_chmod:
448+
name_chmod = result_chmod.group("name")
449+
if name != name_chmod:
450+
raise ValueError("Mismatch in names chmod '{}'".format(name))
451+
lines.pop(0)
454452
# Continue the outer loop
455453
continue
456454

src/python/tests/unittests/test_lftp/test_job_status_parser.py

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1248,3 +1248,46 @@ def test_jobs_chmod(self):
12481248
self.assertEqual(2, len(statuses))
12491249
self.assertEqual(golden_job1, statuses[0])
12501250
self.assertEqual(golden_job2, statuses[1])
1251+
1252+
def test_jobs_chmod_two_liner(self):
1253+
output = """
1254+
[0] queue (sftp://someone:@localhost:22) -- 1.8 KiB/s
1255+
sftp://someone:@localhost:22/remote/path
1256+
Now executing: [1] mirror -c /remote/path/Space.Trek /local/path/ -- 3.1k/617M (0%) 1.8 KiB/s
1257+
[1] mirror -c /remote/path/Space.Trek /local/path/ -- 3.1k/617M (0%) 1.8 KiB/s
1258+
\mirror `Space.Trek.S08E04'
1259+
chmod Space.Trek.S08E04.sfv
1260+
file:/local/path/Space.Trek/Space.Trek.S08E04
1261+
\mirror `Space.Trek.S08E05' -- 605/51M (0%)
1262+
\\transfer `Space.Trek.S08E05/space.trek.s08e05.r06'
1263+
`space.trek.s08e05.r06' at 0 (0%) [Waiting for response...]
1264+
\mirror `Space.Trek.S08E06' -- 1.6k/517M (0%) 932 B/s
1265+
\\transfer `Space.Trek.S08E06/space.trek.s08e06.nfo'
1266+
`space.trek.s08e06.nfo' at 932 (100%) [Receiving data]
1267+
\mirror `Space.Trek.S08E07' -- 932/51M (0%) 932 B/s
1268+
\\transfer `Space.Trek.S08E07/space.trek.s08e07.nfo'
1269+
`space.trek.s08e07.nfo' at 932 (100%) [Receiving data]
1270+
"""
1271+
parser = LftpJobStatusParser()
1272+
statuses = parser.parse(output)
1273+
1274+
golden_job1 = LftpJobStatus(job_id=1,
1275+
job_type=LftpJobStatus.Type.MIRROR,
1276+
state=LftpJobStatus.State.RUNNING,
1277+
name="Space.Trek",
1278+
flags="-c")
1279+
golden_job1.total_transfer_state = LftpJobStatus.TransferState(3174, 646971392, 0, 1843, None)
1280+
golden_job1.add_active_file_transfer_state(
1281+
"Space.Trek.S08E05/space.trek.s08e05.r06",
1282+
LftpJobStatus.TransferState(None, None, None, None, None)
1283+
)
1284+
golden_job1.add_active_file_transfer_state(
1285+
"Space.Trek.S08E06/space.trek.s08e06.nfo",
1286+
LftpJobStatus.TransferState(None, None, None, None, None)
1287+
)
1288+
golden_job1.add_active_file_transfer_state(
1289+
"Space.Trek.S08E07/space.trek.s08e07.nfo",
1290+
LftpJobStatus.TransferState(None, None, None, None, None)
1291+
)
1292+
self.assertEqual(1, len(statuses))
1293+
self.assertEqual(golden_job1, statuses[0])

0 commit comments

Comments
 (0)