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