From ad6ee3879af6d9c0f8f0decc84f59adbbbf8aa3e Mon Sep 17 00:00:00 2001 From: gryf Date: Fri, 20 Sep 2019 18:09:09 +0200 Subject: [PATCH] Clean up the code. There was an issue regarding c1541 in old version - during removal of the file from the image, as a success message 'ERRORCODE 1' was placed on the stdout. If there was an issue with the file different message was placed also on stdout. Luckily, that weird behaviour was fixed in 3.x series of the Vice. So now we can remove unnecessary code. Also, fixed two bugs for pyton3, introduced during new formats development. --- uc1541 | 25 +++++++++++-------------- 1 file changed, 11 insertions(+), 14 deletions(-) diff --git a/uc1541 b/uc1541 index b59e509..1da649f 100755 --- a/uc1541 +++ b/uc1541 @@ -102,7 +102,7 @@ def _get_implementation(disk): 196608: D64, # 40 track, no errors 197376: D64} # 40 track, 768 error bytes - if disk[:32].startswith('C64'): + if disk[:32].startswith(b'C64'): return # T64 return len_map.get(len(disk))(disk) @@ -434,14 +434,6 @@ class Uc1541(object): if not self._call_command('delete', dst=dst): return self._show_error() - # During removing, a message containing ERRORCODE is sent to stdout - # instead of stderr. Everything other than 'ERRORCODE 1' (which means: - # 'everything fine') is actually a failure. In case of verbose error - # output it is needed to copy self.out to self.err. - if '\nERRORCODE 1\n' not in self.out: - self.err = self.out - return self._show_error() - return 0 def copyin(self, dst, src): @@ -594,14 +586,19 @@ class Uc1541(object): command.append(dst) LOG.debug('executing command: %s', ' '.join(command)) - # For some reason using write command and reading output confuses - # Python3 beneath MC and as a consequence MC report an error... - # therefore for write command let's not use universal_newlines... + # For some reason using write and delete commands and reading output + # confuses Python3 beneath MC and as a consequence MC report an + # error...therefore for those commands let's not use + # universal_newlines... + universal_newlines = True + if cmd in ['delete', 'write']: + universal_newlines = False self.out, self.err = Popen(command, - universal_newlines=(cmd != 'write'), + universal_newlines=universal_newlines, stdout=PIPE, stderr=PIPE).communicate() - LOG.debug('an err: %s', self.err) + if self.err: + LOG.debug('an err: %s', self.err) return not self.err