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