-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdummy
executable file
·100 lines (70 loc) · 2.43 KB
/
dummy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#! /usr/bin/env python3
"""Dummy VFS for Midnight Commander. Just for a test."""
__version__ = "1.1.0"
__author__ = "Oleg Broytman <[email protected]>"
__copyright__ = "Copyright (C) 2004-2023 PhiloSoft Design"
__license__ = "GPL"
import sys
def log_error(msg):
sys.stderr.write(msg + '\n')
def error(msg):
log_error(msg + '\n')
sys.exit(1)
if len(sys.argv) < 2:
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 0 0 0 Jun 13 02:20 file0")
print("-r--r--r-- 1 0 0 1 Jun 13 02:21 file1")
print("dr--r--r-- 1 0 0 2 Jun 13 02:22 subdir")
print("-r--r--r-- 1 0 0 3 Jun 13 02:23 subdir/file3")
print("-r--r--r-- 1 0 0 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]
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]
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]
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]
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]
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 procname not in g:
error("Unknown command %s" % command)
g[procname]()