-#! /usr/bin/env python
+#! /usr/bin/env python3
"""Dummy VFS for Midnight Commander. Just for a test."""
-__version__ = "1.0.3"
+__version__ = "1.1.0"
__author__ = "Oleg Broytman <phd@phdru.name>"
-__copyright__ = "Copyright (C) 2004-2013 PhiloSoft Design"
+__copyright__ = "Copyright (C) 2004-2023 PhiloSoft Design"
__license__ = "GPL"
import sys
+
def log_error(msg):
- sys.stderr.write(msg + '\n')
+ sys.stderr.write(msg + '\n')
+
def error(msg):
- log_error(msg + '\n')
- sys.exit(1)
+ log_error(msg + '\n')
+ sys.exit(1)
if len(sys.argv) < 2:
- error("""\
+ error("""\
It is not a program - it is a dummy VFS for Midnight Commander.
Put it in $HOME/.mc/extfs.d or /usr/lib/mc/extfs.""")
def mcdummy_list():
- """List the entire VFS"""
- # Ignore the VFS name (sys.argv[2])
- # Emit a dummy listing
- print "-r--r--r-- 1 user group 0 Jun 13 02:20 file0"
- print "-r--r--r-- 1 user group 1 Jun 13 02:21 file1"
- print "dr--r--r-- 1 user group 2 Jun 13 02:22 subdir"
- print "-r--r--r-- 1 user group 3 Jun 13 02:23 subdir/file3"
- print "-r--r--r-- 1 user group 4 Jun 13 02:23 subdir/file4"
+ """List the entire VFS"""
+ # Ignore the VFS name (sys.argv[2])
+ # Emit a dummy listing
+ print("-r--r--r-- 1 user group 0 Jun 13 02:20 file0")
+ print("-r--r--r-- 1 user group 1 Jun 13 02:21 file1")
+ print("dr--r--r-- 1 user group 2 Jun 13 02:22 subdir")
+ print("-r--r--r-- 1 user group 3 Jun 13 02:23 subdir/file3")
+ print("-r--r--r-- 1 user group 4 Jun 13 02:23 subdir/file4")
def mcdummy_copyout():
- """Extract a file from the VFS"""
- # Ignore the VFS name (sys.argv[2])
- dummy_filename = sys.argv[3]
- real_filename = sys.argv[4]
+ """Extract a file from the VFS"""
+ # Ignore the VFS name (sys.argv[2])
+ dummy_filename = sys.argv[3]
+ real_filename = sys.argv[4]
- real_file = open(real_filename, 'a')
- real_file.write("Copy from %s\n" % dummy_filename)
- real_file.write("Copy to %s\n" % real_filename)
- real_file.close()
+ real_file = open(real_filename, 'a')
+ real_file.write("Copy from %s\n" % dummy_filename)
+ real_file.write("Copy to %s\n" % real_filename)
+ real_file.close()
def mcdummy_copyin():
- """Put a file to the VFS"""
- # Ignore the VFS name (sys.argv[2])
- dummy_filename = sys.argv[3]
- real_filename = sys.argv[4]
+ """Put a file to the VFS"""
+ # Ignore the VFS name (sys.argv[2])
+ dummy_filename = sys.argv[3]
+ real_filename = sys.argv[4]
- real_file = open(real_filename + "-dummy.tmp", 'a')
- real_file.write("Copy from %s\n" % real_filename)
- real_file.write("Copy to %s\n" % dummy_filename)
- real_file.close()
+ real_file = open(real_filename + "-dummy.tmp", 'a')
+ real_file.write("Copy from %s\n" % real_filename)
+ real_file.write("Copy to %s\n" % dummy_filename)
+ real_file.close()
def mcdummy_rm():
- """Remove a file from the VFS"""
- # Ignore the VFS name (sys.argv[2])
- dummy_filename = sys.argv[3]
+ """Remove a file from the VFS"""
+ # Ignore the VFS name (sys.argv[2])
+ dummy_filename = sys.argv[3]
- real_file = open(".dummy.tmp", 'a')
- real_file.write("Remove %s\n" % dummy_filename)
- real_file.close()
+ real_file = open(".dummy.tmp", 'a')
+ real_file.write("Remove %s\n" % dummy_filename)
+ real_file.close()
def mcdummy_mkdir():
- """Create a directory in the VFS"""
- # Ignore the VFS name (sys.argv[2])
- dummy_dirname = sys.argv[3]
+ """Create a directory in the VFS"""
+ # Ignore the VFS name (sys.argv[2])
+ dummy_dirname = sys.argv[3]
- real_file = open(".dummy.tmp", 'a')
- real_file.write("Create %s\n" % dummy_dirname)
- real_file.close()
+ real_file = open(".dummy.tmp", 'a')
+ real_file.write("Create %s\n" % dummy_dirname)
+ real_file.close()
def mcdummy_rmdir():
- """Remove a directory from the VFS"""
- # Ignore the VFS name (sys.argv[2])
- dummy_dirname = sys.argv[3]
+ """Remove a directory from the VFS"""
+ # Ignore the VFS name (sys.argv[2])
+ dummy_dirname = sys.argv[3]
- real_file = open(".dummy.tmp", 'a')
- real_file.write("Remove %s\n" % dummy_dirname)
- real_file.close()
+ real_file = open(".dummy.tmp", 'a')
+ real_file.write("Remove %s\n" % dummy_dirname)
+ real_file.close()
g = globals()
command = sys.argv[1]
procname = "mcdummy_" + command
-if not g.has_key(procname):
- error("Unknown command %s" % command)
+if procname not in g:
+ error("Unknown command %s" % command)
g[procname]()
# OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
# PERFORMANCE OF THIS SOFTWARE.
+from functools import partial
import re
-def tokenize(text, match=re.compile("([idel])|(\d+):|(-?\d+)").match):
+
+def tokenize(text, match=re.compile("([idel])|(\\d+):|(-?\\d+)").match):
i = 0
while i < len(text):
m = match(text, i)
else:
yield s
-def decode_item(next, token):
+
+def decode_item(next_, token):
if token == "i":
# integer: "i" value "e"
- data = int(next())
- if next() != "e":
+ data = int(next_())
+ if next_() != "e":
raise ValueError
elif token == "s":
# string: "s" value (virtual tokens)
- data = next()
+ data = next_()
elif token == "l" or token == "d":
# container: "l" (or "d") values "e"
data = []
- tok = next()
+ tok = next_()
while tok != "e":
- data.append(decode_item(next, tok))
- tok = next()
+ data.append(decode_item(next_, tok))
+ try:
+ tok = next_()
+ except StopIteration:
+ break
if token == "d":
data = dict(zip(data[0::2], data[1::2]))
else:
raise ValueError
return data
+
def decode(text):
try:
src = tokenize(text)
- data = decode_item(src.next, src.next())
- for token in src: # look for more tokens
+ data = decode_item(partial(next, src), next(src))
+ for token in src: # look for more tokens
raise SyntaxError("trailing junk")
except (AttributeError, ValueError, StopIteration):
raise SyntaxError("syntax error")
-#! /usr/bin/env python
+#! /usr/bin/env python3
"""Torrent Virtual FileSystem for Midnight Commander
The script requires Midnight Commander 3.1+
"""
-__version__ = "1.2.4"
+__version__ = "1.3.0"
__author__ = "Oleg Broytman <phd@phdru.name>"
-__copyright__ = "Copyright (C) 2010-2018 PhiloSoft Design"
+__copyright__ = "Copyright (C) 2010-2023 PhiloSoft Design"
__license__ = "GPL"
# Get the default charset.
try:
lcAll = locale.getdefaultlocale()
- except locale.Error, err:
- print >>sys.stderr, "WARNING:", err
+ except locale.Error as err:
+ print("WARNING:", err, file=sys.stderr)
lcAll = []
if len(lcAll) == 2:
else:
try:
default_encoding = locale.getpreferredencoding()
- except locale.Error, err:
- print >>sys.stderr, "WARNING:", err
+ except locale.Error as err:
+ print("WARNING:", err, file=sys.stderr)
default_encoding = sys.getdefaultencoding()
else:
default_encoding = sys.getdefaultencoding()
dt = decode_datetime(getmtime(sys.argv[2]))
for name in sorted(dirs):
- print "dr-xr-xr-x 1 user group 0 %s %s" % (dt, name)
+ print("dr-xr-xr-x 1 user group 0 %s %s" % (dt, name))
for name, size in sorted(paths):
- print "-r--r--r-- 1 user group %d %s %s" % (size, dt, name)
+ print("-r--r--r-- 1 user group %d %s %s" % (size, dt, name))
def mctorrent_copyout():
data = torrent_file.read()
torrent_file.close()
return decode(data)
- except IOError, error_str:
+ except IOError as error_str:
torrent_error(error_str)
def decode_announce_list(announce):
- return '\n'.join(l[0] for l in announce if l)
+ return '\n'.join(a[0] for a in announce if a)
command = sys.argv[1]
g[procname]()
except SystemExit:
raise
-except:
+except Exception:
logger.exception("Error during run")
-#! /usr/bin/env python
+#! /usr/bin/env python3
"""XML Virtual FileSystem for Midnight Commander
The script requires Midnight Commander 3.1+
"""
-__version__ = "1.1.5"
+__version__ = "1.2.0"
__author__ = "Oleg Broytman <phd@phdru.name>"
-__copyright__ = "Copyright (C) 2013-2015 PhiloSoft Design"
+__copyright__ = "Copyright (C) 2013-2023 PhiloSoft Design"
__license__ = "GPL"
# Can be None for default choice, 'lxml', 'elementtree' or 'minidom'.
from time import localtime
import xml.dom.minidom
-try:
- import xml.etree.ElementTree as ET
-except ImportError:
- pass
-else:
- use_elementtree = True
+if sys.version_info[0] == 2:
+ try:
+ import xml.etree.ElementTree as ET
+ except ImportError:
+ pass
+ else:
+ use_elementtree = True
try:
import lxml.etree as etree
# Get the default charset.
try:
lcAll = locale.getdefaultlocale()
- except locale.Error, err:
- print >>sys.stderr, "WARNING:", err
+ except locale.Error as err:
+ print("WARNING:", err, file=sys.stderr)
lcAll = []
if len(lcAll) == 2:
else:
try:
default_encoding = locale.getpreferredencoding()
- except locale.Error, err:
- print >>sys.stderr, "WARNING:", err
+ except locale.Error as err:
+ print("WARNING:", err, file=sys.stderr)
default_encoding = sys.getdefaultencoding()
else:
default_encoding = sys.getdefaultencoding()
root_comments = self.get_root_comments()
if root_comments:
- print "-r--r--r-- 1 user group %d %s text" % (
- len(root_comments), self.xml_file_dt)
+ print("-r--r--r-- 1 user group %d %s text" % (
+ len(root_comments), self.xml_file_dt))
self._list(self.getroot())
else:
subpath = '%s %s' % (template % n, tag)
subpath_encoded = subpath.encode(default_encoding, "replace")
- print "dr-xr-xr-x 1 user group 0 %s %s" % (
- self.xml_file_dt, subpath_encoded)
+ print("dr-xr-xr-x 1 user group 0 %s %s" % (
+ self.xml_file_dt, subpath_encoded))
if self.getattrs(element):
attr_text = self.attrs2text(element)
- print "-r--r--r-- 1 user group %d %s %s/attributes" % (
- len(attr_text), self.xml_file_dt, subpath_encoded)
+ print("-r--r--r-- 1 user group %d %s %s/attributes" % (
+ len(attr_text), self.xml_file_dt, subpath_encoded))
if self.supports_namespaces and self.has_ns(element):
ns_text = self.ns2text(element)
- print "-r--r--r-- 1 user group %d %s %s/namespaces" % (
- len(ns_text), self.xml_file_dt, subpath_encoded)
+ print("-r--r--r-- 1 user group %d %s %s/namespaces" % (
+ len(ns_text), self.xml_file_dt, subpath_encoded))
text = self.collect_text(element)
if text:
- print "-r--r--r-- 1 user group %d %s %s/text" % (
- len(text), self.xml_file_dt, subpath_encoded)
+ print("-r--r--r-- 1 user group %d %s %s/text" % (
+ len(text), self.xml_file_dt, subpath_encoded))
self._list(element, subpath)
def get_tag_node(self, node, i):
g[procname]()
except SystemExit:
raise
-except:
+except Exception:
logger.exception("Error during run")