1
0
mirror of https://github.com/gryf/uc1541.git synced 2026-02-02 19:55:46 +01:00

4 Commits
v2.8 ... v3.2

Author SHA1 Message Date
45bde06dd3 Changed shebang back to python.
In modern linux distributions, executable "python" is a symlink to the
selected Python interpreter. There could be multiple versions installed
on the system, and appropriate tools on certain distributions exists for
selecting default one. There is no need for changing it to explicitly
"python3" executable.
2019-09-15 09:40:10 +02:00
03b6236463 Not provided subcommand is fatal on Python3. 2019-07-20 13:49:34 +02:00
711695be2b Added initial Python3 support 2018-02-13 20:19:02 +01:00
197ba7a707 Corrected shebang 2018-02-13 20:18:09 +01:00
2 changed files with 43 additions and 18 deletions

View File

@@ -57,7 +57,7 @@ file.
Rquirements
===========
* Python 2.7
* Python 2.7 or Python 3.6 or higher
* Vice installation (c1541 program in path)
Installation
@@ -87,6 +87,10 @@ script behaviour:
Changelog
=========
* **3.2** Changed shebang to ``python`` executable instead of ``python3``
* **3.1** Argparse on Python3 have different behaviour, where if no subcommand
is provided, it will pass anyway. Fixed.
* **3.0** Added beta quality Python3 support
* **2.8** Treat non standard discs a bit better
* **2.7** Added support for gzipped disk images
* **2.6** Added mkdir and run handling (or rather lack of handling :). Minor

55
uc1541
View File

@@ -1,10 +1,10 @@
#! /usr/bin/env python
#!/usr/bin/env python
"""
UC1541 Virtual filesystem
Author: Roman 'gryf' Dobosz <gryf73@gmail.com>
Date: 2014-01-04
Version: 2.8
Date: 2019-09-15
Version: 3.2
Licence: BSD
source: https://bitbucket.org/gryf/uc1541
mirror: https://github.com/gryf/uc1541
@@ -52,6 +52,18 @@ else:
pass
def _ord(string_or_int):
"""
Return an int value for the (possible) string passed in argument. This
function is for compatibility between python2 and python3, where single
element in byte string array is a string or an int respectively.
"""
try:
return ord(string_or_int)
except TypeError:
return string_or_int
class D64(object):
"""
Implement d64 directory reader
@@ -98,16 +110,16 @@ class D64(object):
def _get_raw(self, dimage):
"""Try to get contents of the D64 image either it's gzip compressed or
not."""
fobj = gzip.open(dimage)
fobj = gzip.open(dimage, 'rb')
# Although the common approach with gzipped files is to check the
# magic number, in this case there is no guarantee that first track
# does not contain exactly the same byte sequence as the magic number.
# So the only way left is to actually try to uncompress the file.
try:
self.raw = fobj.read()
except IOError:
except (IOError, OSError):
fobj.close()
fobj = open(dimage)
fobj = open(dimage, 'rb')
self.raw = fobj.read()
fobj.close()
@@ -120,10 +132,10 @@ class D64(object):
filename = list()
for chr_ in string:
if ord(chr_) == 160: # shift+space character; $a0
if _ord(chr_) == 160: # shift+space character; $a0
break
character = D64.CHAR_MAP.get(ord(chr_), '?')
character = D64.CHAR_MAP.get(_ord(chr_), '?')
filename.append(character)
# special cases
@@ -163,8 +175,8 @@ class D64(object):
if not self.current_sector_data:
return False
self.next_track = ord(self.current_sector_data[0])
self.next_sector = ord(self.current_sector_data[1])
self.next_track = _ord(self.current_sector_data[0])
self.next_sector = _ord(self.current_sector_data[1])
if (self.next_track, self.next_sector) in self._already_done:
# Just a failsafe. Endless loop is not what is expected.
@@ -217,7 +229,7 @@ class D64(object):
sector = self.current_sector_data
for dummy in range(8):
entry = sector[:32]
ftype = ord(entry[2])
ftype = _ord(entry[2])
if ftype == 0: # deleted
sector = sector[32:]
@@ -225,12 +237,12 @@ class D64(object):
type_verbose = self._get_ftype(ftype)
protect = ord(entry[2]) & 64 and "<" or " "
protect = _ord(entry[2]) & 64 and "<" or " "
fname = entry[5:21]
if ftype == 'rel':
size = ord(entry[23])
size = _ord(entry[23])
else:
size = ord(entry[30]) + ord(entry[31]) * 226
size = _ord(entry[30]) + _ord(entry[31]) * 226
self._dir_contents.append({'fname': self._map_filename(fname),
'ftype': type_verbose,
@@ -454,8 +466,15 @@ class Uc1541(object):
if dst:
command.append(dst)
self.out, self.err = Popen(command, stdout=PIPE,
stderr=PIPE).communicate()
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...
self.out, self.err = Popen(command,
universal_newlines=(cmd != 'write'),
stdout=PIPE, stderr=PIPE).communicate()
LOG.debug('an err: %s', self.err)
return not self.err
@@ -470,7 +489,9 @@ CALL_MAP = {'list': lambda a: Uc1541(a.arch).list(),
def parse_args():
"""Use ArgumentParser to check for script arguments and execute."""
parser = ArgumentParser()
subparsers = parser.add_subparsers(help='supported commands')
subparsers = parser.add_subparsers(help='supported commands',
dest='subcommand')
subparsers.required = True
parser_list = subparsers.add_parser('list', help="List contents of D64 "
"image")
parser_copyin = subparsers.add_parser('copyin', help="Copy file into D64 "