From c33655a12cdf93d78479f12a7f86493beee6bac5 Mon Sep 17 00:00:00 2001 From: gryf Date: Wed, 18 Oct 2023 15:08:00 +0200 Subject: [PATCH] Parse stderr for unadf banner. Unadf does return 0 exit code always, even, if there was an issue in either parsing image, mounting it or on any other issue. To be worst, it always throw an banner to the stderr, so it cannot be used to check if there was an error either. As a workaround, let's check if there is a banner, strip it out and then see if anything extra is on the stderr, so that it can be used to see if there was any issues. --- uadf | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/uadf b/uadf index 8e03903..42a2a8f 100755 --- a/uadf +++ b/uadf @@ -43,6 +43,10 @@ import tempfile import extfslib +BANNER_PAT = re.compile(r'unADF v\d.\d : a unzip like for .ADF files, ' + r'powered by ADFlib (.*)\n\n') + + class UAdf(extfslib.Archive): """ Class for interact with c1541 program and MC @@ -111,6 +115,16 @@ class UAdf(extfslib.Archive): except (subprocess.CalledProcessError, OSError): pass + def _parse_banner(self, string): + match = BANNER_PAT.match(string) + if not match: + return + + if match.end() == len(string): + return + + return string[match.end():] + def _map_name(self, name): if name.startswith(" "): new_name = "".join(["~", name[1:]]) @@ -123,8 +137,9 @@ class UAdf(extfslib.Archive): out = subprocess.run([self.ARCHIVER, self.CMDS['list'], self._arch], capture_output=True, encoding="latin-1") - if out.stderr: - sys.stderr.write(out.stderr) + error_msg = self._parse_banner(out.stderr) + if error_msg: + sys.stderr.write(error_msg) for line in out.stdout.split("\n"): match = self.LINE_PAT.match(line)