Adapt ulzx to python3
This commit is contained in:
@@ -5,13 +5,13 @@ plugins for Midnight Commander.
|
|||||||
Tested against python 3.6 and mc 4.8.22
|
Tested against python 3.6 and mc 4.8.22
|
||||||
|
|
||||||
Changelog:
|
Changelog:
|
||||||
2.0 Switch to python3
|
1.2 Switch to python3
|
||||||
1.1 Added item pattern, and common git/uid attrs
|
1.1 Added item pattern, and common git/uid attrs
|
||||||
1.0 Initial release
|
1.0 Initial release
|
||||||
|
|
||||||
Author: Roman 'gryf' Dobosz <gryf73@gmail.com>
|
Author: Roman 'gryf' Dobosz <gryf73@gmail.com>
|
||||||
Date: 2019-06-30
|
Date: 2019-06-30
|
||||||
Version: 2.0
|
Version: 1.2
|
||||||
Licence: BSD
|
Licence: BSD
|
||||||
"""
|
"""
|
||||||
import argparse
|
import argparse
|
||||||
|
|||||||
61
ulzx
61
ulzx
@@ -1,19 +1,20 @@
|
|||||||
#! /usr/bin/env python
|
#!/usr/bin/env python3
|
||||||
"""
|
"""
|
||||||
Read only, Amiga LZX[1] archiver Virtual filesystem executive for Midnight
|
Read only, Amiga LZX[1] archiver Virtual filesystem executive for Midnight
|
||||||
Commander.
|
Commander.
|
||||||
|
|
||||||
Tested against python 2.7, unlzx[1] 1.1 and mc 4.8.7
|
Tested against python 3.6, unlzx[1] 1.1 and mc 4.8.22
|
||||||
|
|
||||||
[1] ftp://us.aminet.net/pub/aminet/misc/unix/unlzx.c.gz.readme
|
[1] ftp://us.aminet.net/pub/aminet/misc/unix/unlzx.c.gz.readme
|
||||||
|
|
||||||
Changelog:
|
Changelog:
|
||||||
|
1.2 Use python3
|
||||||
1.1 Moved common code into extfslib library
|
1.1 Moved common code into extfslib library
|
||||||
1.0 Initial release
|
1.0 Initial release
|
||||||
|
|
||||||
Author: Roman 'gryf' Dobosz <gryf73@gmail.com>
|
Author: Roman 'gryf' Dobosz <gryf73@gmail.com>
|
||||||
Date: 2013-05-12
|
Date: 2019-06-30
|
||||||
Version: 1.1
|
Version: 1.2
|
||||||
Licence: BSD
|
Licence: BSD
|
||||||
"""
|
"""
|
||||||
import os
|
import os
|
||||||
@@ -28,26 +29,27 @@ from extfslib import Archive, parse_args
|
|||||||
|
|
||||||
class ULzx(Archive):
|
class ULzx(Archive):
|
||||||
"""Archive handle. Provides interface to MC's extfs subsystem"""
|
"""Archive handle. Provides interface to MC's extfs subsystem"""
|
||||||
LINE_PAT = re.compile("^\s+(?P<size>\d+)\s+"
|
LINE_PAT = re.compile(b"^\s+(?P<size>\d+)\s+"
|
||||||
"((n/a)|\d+)\s"
|
b"((n/a)|\d+)\s"
|
||||||
"(?P<time>\d{2}:\d{2}:\d{2})\s+"
|
b"(?P<time>\d{2}:\d{2}:\d{2})\s+"
|
||||||
"(?P<date>\d+-[a-z]{3}-\d{4})\s"
|
b"(?P<date>\d+-[a-z]{3}-\d{4})\s"
|
||||||
"(?P<perms>[h-][s-][p-][a-][r-][w-][e-][d-])\s"
|
b"(?P<perms>[h-][s-][p-][a-][r-][w-][e-][d-])\s"
|
||||||
"\"(?P<fpath>.*)\"")
|
b"\"(?P<fpath>.*)\"")
|
||||||
ARCHIVER = "unlzx"
|
ARCHIVER = b"unlzx"
|
||||||
CMDS = {"list": "-v",
|
CMDS = {"list": b"-v",
|
||||||
"read": "-x"}
|
"read": b"-x"}
|
||||||
DATETIME = "%02d-%02d-%s %02d:%02d"
|
DATETIME = b"%02d-%02d-%s %02d:%02d"
|
||||||
|
|
||||||
def _get_date(self, time, date):
|
def _get_date(self, time, date):
|
||||||
"""Return MM-DD-YYYY hh:mm formatted date out of time and date
|
"""Return MM-DD-YYYY hh:mm formatted date out of time and date
|
||||||
strings"""
|
strings"""
|
||||||
month_list = ["jan", "feb", "mar", "apr", "may", "jun", "jul", "aug",
|
month_list = [b"jan", b"feb", b"mar", b"apr", b"may", b"jun", b"jul",
|
||||||
"sep", "oct", "nov", "dec"]
|
b"aug", b"sep", b"oct", b"nov", b"dec"]
|
||||||
day, month, year = date.split("-")
|
day, month, year = date.split(b"-")
|
||||||
month = month_list.index(month) + 1
|
month = month_list.index(month) + 1
|
||||||
hours, minutes, dummy = time.split(":")
|
hours, minutes, dummy = time.split(b":")
|
||||||
return self.DATETIME % (month, int(day), year, int(hours), int(minutes))
|
return self.DATETIME % (month, int(day), year, int(hours),
|
||||||
|
int(minutes))
|
||||||
|
|
||||||
def _get_dir(self):
|
def _get_dir(self):
|
||||||
"""Prepare archive file listing"""
|
"""Prepare archive file listing"""
|
||||||
@@ -57,17 +59,22 @@ class ULzx(Archive):
|
|||||||
if not out:
|
if not out:
|
||||||
return
|
return
|
||||||
|
|
||||||
for line in out.split("\n"):
|
for line in out.split(b"\n"):
|
||||||
match = self.LINE_PAT.match(line)
|
match = self.LINE_PAT.match(line)
|
||||||
if not match:
|
if not match:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
entry = match.groupdict()
|
match_entry = match.groupdict()
|
||||||
entry['datetime'] = self._get_date(entry['time'], entry['date'])
|
entry = {}
|
||||||
entry['display_name'] = self._map_name(entry['fpath'])
|
for key in match_entry:
|
||||||
entry['perms'] = "-rw-r--r--" # lzx doesn't store empty dirs
|
entry[bytes(key, 'utf-8')] = match_entry[key]
|
||||||
entry['uid'] = self._uid
|
del match_entry
|
||||||
entry['gid'] = self._gid
|
|
||||||
|
entry[b'datetime'] = self._get_date(entry[b'time'], entry[b'date'])
|
||||||
|
entry[b'display_name'] = self._map_name(entry[b'fpath'])
|
||||||
|
entry[b'perms'] = b"-rw-r--r--" # lzx doesn't store empty dirs
|
||||||
|
entry[b'uid'] = bytes(str(self._uid), 'utf-8')
|
||||||
|
entry[b'gid'] = bytes(str(self._gid), 'utf-8')
|
||||||
contents.append(entry)
|
contents.append(entry)
|
||||||
|
|
||||||
return contents
|
return contents
|
||||||
@@ -75,7 +82,7 @@ class ULzx(Archive):
|
|||||||
def list(self):
|
def list(self):
|
||||||
"""Output contents of the archive to stdout"""
|
"""Output contents of the archive to stdout"""
|
||||||
for entry in self._contents:
|
for entry in self._contents:
|
||||||
sys.stdout.write(self.ITEM % entry)
|
sys.stdout.buffer.write(self.ITEM % entry)
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
def run(self, dst):
|
def run(self, dst):
|
||||||
|
|||||||
Reference in New Issue
Block a user