]> git.phdru.name Git - extfs.d.git/blob - dummy
Feat(torrent): Try harder to guess encoding
[extfs.d.git] / dummy
1 #! /usr/bin/env python3
2 """Dummy VFS for Midnight Commander. Just for a test."""
3
4 __version__ = "1.1.0"
5 __author__ = "Oleg Broytman <phd@phdru.name>"
6 __copyright__ = "Copyright (C) 2004-2023 PhiloSoft Design"
7 __license__ = "GPL"
8
9
10 import sys
11
12
13 def log_error(msg):
14     sys.stderr.write(msg + '\n')
15
16
17 def error(msg):
18     log_error(msg + '\n')
19     sys.exit(1)
20
21
22 if len(sys.argv) < 2:
23     error("""\
24 It is not a program - it is a dummy VFS for Midnight Commander.
25 Put it in $HOME/.mc/extfs.d or /usr/lib/mc/extfs.""")
26
27
28 def mcdummy_list():
29     """List the entire VFS"""
30     # Ignore the VFS name (sys.argv[2])
31     # Emit a dummy listing
32     print("-r--r--r-- 1 user group 0 Jun 13 02:20 file0")
33     print("-r--r--r-- 1 user group 1 Jun 13 02:21 file1")
34     print("dr--r--r-- 1 user group 2 Jun 13 02:22 subdir")
35     print("-r--r--r-- 1 user group 3 Jun 13 02:23 subdir/file3")
36     print("-r--r--r-- 1 user group 4 Jun 13 02:23 subdir/file4")
37
38
39 def mcdummy_copyout():
40     """Extract a file from the VFS"""
41     # Ignore the VFS name (sys.argv[2])
42     dummy_filename = sys.argv[3]
43     real_filename = sys.argv[4]
44
45     real_file = open(real_filename, 'a')
46     real_file.write("Copy from %s\n" % dummy_filename)
47     real_file.write("Copy  to   %s\n" % real_filename)
48     real_file.close()
49
50
51 def mcdummy_copyin():
52     """Put a file to the VFS"""
53     # Ignore the VFS name (sys.argv[2])
54     dummy_filename = sys.argv[3]
55     real_filename = sys.argv[4]
56
57     real_file = open(real_filename + "-dummy.tmp", 'a')
58     real_file.write("Copy from %s\n" % real_filename)
59     real_file.write("Copy  to   %s\n" % dummy_filename)
60     real_file.close()
61
62
63 def mcdummy_rm():
64     """Remove a file from the VFS"""
65     # Ignore the VFS name (sys.argv[2])
66     dummy_filename = sys.argv[3]
67
68     real_file = open(".dummy.tmp", 'a')
69     real_file.write("Remove %s\n" % dummy_filename)
70     real_file.close()
71
72
73 def mcdummy_mkdir():
74     """Create a directory in the VFS"""
75     # Ignore the VFS name (sys.argv[2])
76     dummy_dirname = sys.argv[3]
77
78     real_file = open(".dummy.tmp", 'a')
79     real_file.write("Create %s\n" % dummy_dirname)
80     real_file.close()
81
82
83 def mcdummy_rmdir():
84     """Remove a directory from the VFS"""
85     # Ignore the VFS name (sys.argv[2])
86     dummy_dirname = sys.argv[3]
87
88     real_file = open(".dummy.tmp", 'a')
89     real_file.write("Remove %s\n" % dummy_dirname)
90     real_file.close()
91
92
93 g = globals()
94 command = sys.argv[1]
95 procname = "mcdummy_" + command
96
97 if procname not in g:
98     error("Unknown command %s" % command)
99
100 g[procname]()