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