annotate Demo/rpc/mountclient.py @ 5817:48b94de85bf3 legacy-trunk

Extensive changes by AMK.
author Guido van Rossum <guido@python.org>
date Thu, 17 Jul 1997 16:29:42 +0000
parents f7a752fb7b73
children 3b45c04a4833
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1133
9add0e3e804a Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1 # Mount RPC client -- RFC 1094 (NFS), Appendix A
9add0e3e804a Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2
9add0e3e804a Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
3 # This module demonstrates how to write your own RPC client in Python.
9add0e3e804a Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
4 # Since there is no RPC compiler for Python (yet), you must first
9add0e3e804a Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
5 # create classes derived from Packer and Unpacker to handle the data
9add0e3e804a Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
6 # types for the server you want to interface to. You then write the
9add0e3e804a Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
7 # client class. If you want to support both the TCP and the UDP
9add0e3e804a Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
8 # version of a protocol, use multiple inheritance as shown below.
9add0e3e804a Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
9
9add0e3e804a Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
10
1136
e39309b9a0aa Add explicit auth call
Guido van Rossum <guido@python.org>
parents: 1133
diff changeset
11 import rpc
1133
9add0e3e804a Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
12 from rpc import Packer, Unpacker, TCPClient, UDPClient
9add0e3e804a Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
13
1154
e82ac452d551 Bind to reserved port if root; changed mkcred interface; added -t/-u option
Guido van Rossum <guido@python.org>
parents: 1149
diff changeset
14
e82ac452d551 Bind to reserved port if root; changed mkcred interface; added -t/-u option
Guido van Rossum <guido@python.org>
parents: 1149
diff changeset
15 # Program number and version for the mount protocol
1133
9add0e3e804a Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
16 MOUNTPROG = 100005
9add0e3e804a Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
17 MOUNTVERS = 1
9add0e3e804a Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
18
1154
e82ac452d551 Bind to reserved port if root; changed mkcred interface; added -t/-u option
Guido van Rossum <guido@python.org>
parents: 1149
diff changeset
19 # Size of the 'fhandle' opaque structure
1133
9add0e3e804a Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
20 FHSIZE = 32
9add0e3e804a Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
21
9add0e3e804a Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
22
9add0e3e804a Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
23 # Packer derived class for Mount protocol clients.
9add0e3e804a Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
24 # The only thing we need to pack beyond basic types is an 'fhandle'
9add0e3e804a Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
25
9add0e3e804a Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
26 class MountPacker(Packer):
9add0e3e804a Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
27
9add0e3e804a Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
28 def pack_fhandle(self, fhandle):
9add0e3e804a Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
29 self.pack_fopaque(FHSIZE, fhandle)
9add0e3e804a Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
30
9add0e3e804a Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
31
9add0e3e804a Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
32 # Unpacker derived class for Mount protocol clients.
9add0e3e804a Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
33 # The important types we need to unpack are fhandle, fhstatus,
9add0e3e804a Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
34 # mountlist and exportlist; mountstruct, exportstruct and groups are
9add0e3e804a Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
35 # used to unpack components of mountlist and exportlist and the
9add0e3e804a Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
36 # corresponding functions are passed as function argument to the
9add0e3e804a Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
37 # generic unpack_list function.
9add0e3e804a Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
38
9add0e3e804a Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
39 class MountUnpacker(Unpacker):
9add0e3e804a Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
40
9add0e3e804a Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
41 def unpack_fhandle(self):
9add0e3e804a Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
42 return self.unpack_fopaque(FHSIZE)
9add0e3e804a Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
43
9add0e3e804a Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
44 def unpack_fhstatus(self):
9add0e3e804a Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
45 status = self.unpack_uint()
9add0e3e804a Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
46 if status == 0:
9add0e3e804a Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
47 fh = self.unpack_fhandle()
9add0e3e804a Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
48 else:
9add0e3e804a Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
49 fh = None
9add0e3e804a Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
50 return status, fh
9add0e3e804a Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
51
9add0e3e804a Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
52 def unpack_mountlist(self):
9add0e3e804a Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
53 return self.unpack_list(self.unpack_mountstruct)
9add0e3e804a Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
54
9add0e3e804a Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
55 def unpack_mountstruct(self):
9add0e3e804a Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
56 hostname = self.unpack_string()
9add0e3e804a Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
57 directory = self.unpack_string()
9add0e3e804a Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
58 return (hostname, directory)
9add0e3e804a Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
59
9add0e3e804a Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
60 def unpack_exportlist(self):
9add0e3e804a Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
61 return self.unpack_list(self.unpack_exportstruct)
9add0e3e804a Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
62
9add0e3e804a Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
63 def unpack_exportstruct(self):
9add0e3e804a Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
64 filesys = self.unpack_string()
9add0e3e804a Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
65 groups = self.unpack_groups()
9add0e3e804a Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
66 return (filesys, groups)
9add0e3e804a Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
67
9add0e3e804a Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
68 def unpack_groups(self):
9add0e3e804a Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
69 return self.unpack_list(self.unpack_string)
9add0e3e804a Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
70
9add0e3e804a Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
71
9add0e3e804a Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
72 # These are the procedures specific to the Mount client class.
9add0e3e804a Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
73 # Think of this as a derived class of either TCPClient or UDPClient.
9add0e3e804a Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
74
9add0e3e804a Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
75 class PartialMountClient:
9add0e3e804a Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
76
1428
f7a752fb7b73 *** empty log message ***
Guido van Rossum <guido@python.org>
parents: 1160
diff changeset
77 # This method is called by Client.__init__ to initialize
1133
9add0e3e804a Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
78 # self.packer and self.unpacker
9add0e3e804a Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
79 def addpackers(self):
1428
f7a752fb7b73 *** empty log message ***
Guido van Rossum <guido@python.org>
parents: 1160
diff changeset
80 self.packer = MountPacker()
f7a752fb7b73 *** empty log message ***
Guido van Rossum <guido@python.org>
parents: 1160
diff changeset
81 self.unpacker = MountUnpacker('')
1133
9add0e3e804a Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
82
1428
f7a752fb7b73 *** empty log message ***
Guido van Rossum <guido@python.org>
parents: 1160
diff changeset
83 # This method is called by Client.__init__ to bind the socket
1154
e82ac452d551 Bind to reserved port if root; changed mkcred interface; added -t/-u option
Guido van Rossum <guido@python.org>
parents: 1149
diff changeset
84 # to a particular network interface and port. We use the
e82ac452d551 Bind to reserved port if root; changed mkcred interface; added -t/-u option
Guido van Rossum <guido@python.org>
parents: 1149
diff changeset
85 # default network interface, but if we're running as root,
e82ac452d551 Bind to reserved port if root; changed mkcred interface; added -t/-u option
Guido van Rossum <guido@python.org>
parents: 1149
diff changeset
86 # we want to bind to a reserved port
e82ac452d551 Bind to reserved port if root; changed mkcred interface; added -t/-u option
Guido van Rossum <guido@python.org>
parents: 1149
diff changeset
87 def bindsocket(self):
e82ac452d551 Bind to reserved port if root; changed mkcred interface; added -t/-u option
Guido van Rossum <guido@python.org>
parents: 1149
diff changeset
88 import os
1160
5244827dd423 Changed to use new make_call method
Guido van Rossum <guido@python.org>
parents: 1154
diff changeset
89 try:
5244827dd423 Changed to use new make_call method
Guido van Rossum <guido@python.org>
parents: 1154
diff changeset
90 uid = os.getuid()
5244827dd423 Changed to use new make_call method
Guido van Rossum <guido@python.org>
parents: 1154
diff changeset
91 except AttributeError:
5244827dd423 Changed to use new make_call method
Guido van Rossum <guido@python.org>
parents: 1154
diff changeset
92 uid = 1
5244827dd423 Changed to use new make_call method
Guido van Rossum <guido@python.org>
parents: 1154
diff changeset
93 if uid == 0:
1154
e82ac452d551 Bind to reserved port if root; changed mkcred interface; added -t/-u option
Guido van Rossum <guido@python.org>
parents: 1149
diff changeset
94 port = rpc.bindresvport(self.sock, '')
e82ac452d551 Bind to reserved port if root; changed mkcred interface; added -t/-u option
Guido van Rossum <guido@python.org>
parents: 1149
diff changeset
95 # 'port' is not used
e82ac452d551 Bind to reserved port if root; changed mkcred interface; added -t/-u option
Guido van Rossum <guido@python.org>
parents: 1149
diff changeset
96 else:
e82ac452d551 Bind to reserved port if root; changed mkcred interface; added -t/-u option
Guido van Rossum <guido@python.org>
parents: 1149
diff changeset
97 self.sock.bind(('', 0))
e82ac452d551 Bind to reserved port if root; changed mkcred interface; added -t/-u option
Guido van Rossum <guido@python.org>
parents: 1149
diff changeset
98
e82ac452d551 Bind to reserved port if root; changed mkcred interface; added -t/-u option
Guido van Rossum <guido@python.org>
parents: 1149
diff changeset
99 # This function is called to cough up a suitable
1136
e39309b9a0aa Add explicit auth call
Guido van Rossum <guido@python.org>
parents: 1133
diff changeset
100 # authentication object for a call to procedure 'proc'.
1154
e82ac452d551 Bind to reserved port if root; changed mkcred interface; added -t/-u option
Guido van Rossum <guido@python.org>
parents: 1149
diff changeset
101 def mkcred(self):
1136
e39309b9a0aa Add explicit auth call
Guido van Rossum <guido@python.org>
parents: 1133
diff changeset
102 if self.cred == None:
e39309b9a0aa Add explicit auth call
Guido van Rossum <guido@python.org>
parents: 1133
diff changeset
103 self.cred = rpc.AUTH_UNIX, rpc.make_auth_unix_default()
e39309b9a0aa Add explicit auth call
Guido van Rossum <guido@python.org>
parents: 1133
diff changeset
104 return self.cred
e39309b9a0aa Add explicit auth call
Guido van Rossum <guido@python.org>
parents: 1133
diff changeset
105
1133
9add0e3e804a Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
106 # The methods Mnt, Dump etc. each implement one Remote
1160
5244827dd423 Changed to use new make_call method
Guido van Rossum <guido@python.org>
parents: 1154
diff changeset
107 # Procedure Call. This is done by calling self.make_call()
5244827dd423 Changed to use new make_call method
Guido van Rossum <guido@python.org>
parents: 1154
diff changeset
108 # with as arguments:
5244827dd423 Changed to use new make_call method
Guido van Rossum <guido@python.org>
parents: 1154
diff changeset
109 #
5244827dd423 Changed to use new make_call method
Guido van Rossum <guido@python.org>
parents: 1154
diff changeset
110 # - the procedure number
5244827dd423 Changed to use new make_call method
Guido van Rossum <guido@python.org>
parents: 1154
diff changeset
111 # - the arguments (or None)
5244827dd423 Changed to use new make_call method
Guido van Rossum <guido@python.org>
parents: 1154
diff changeset
112 # - the "packer" function for the arguments (or None)
5244827dd423 Changed to use new make_call method
Guido van Rossum <guido@python.org>
parents: 1154
diff changeset
113 # - the "unpacker" function for the return value (or None)
5244827dd423 Changed to use new make_call method
Guido van Rossum <guido@python.org>
parents: 1154
diff changeset
114 #
5244827dd423 Changed to use new make_call method
Guido van Rossum <guido@python.org>
parents: 1154
diff changeset
115 # The packer and unpacker function, if not None, *must* be
5244827dd423 Changed to use new make_call method
Guido van Rossum <guido@python.org>
parents: 1154
diff changeset
116 # methods of self.packer and self.unpacker, respectively.
5244827dd423 Changed to use new make_call method
Guido van Rossum <guido@python.org>
parents: 1154
diff changeset
117 # A value of None means that there are no arguments or is no
5244827dd423 Changed to use new make_call method
Guido van Rossum <guido@python.org>
parents: 1154
diff changeset
118 # return value, respectively.
5244827dd423 Changed to use new make_call method
Guido van Rossum <guido@python.org>
parents: 1154
diff changeset
119 #
5244827dd423 Changed to use new make_call method
Guido van Rossum <guido@python.org>
parents: 1154
diff changeset
120 # The return value from make_call() is the return value from
5244827dd423 Changed to use new make_call method
Guido van Rossum <guido@python.org>
parents: 1154
diff changeset
121 # the remote procedure call, as unpacked by the "unpacker"
5244827dd423 Changed to use new make_call method
Guido van Rossum <guido@python.org>
parents: 1154
diff changeset
122 # function, or None if the unpacker function is None.
5244827dd423 Changed to use new make_call method
Guido van Rossum <guido@python.org>
parents: 1154
diff changeset
123 #
5244827dd423 Changed to use new make_call method
Guido van Rossum <guido@python.org>
parents: 1154
diff changeset
124 # (Even if you expect a result of None, you should still
5244827dd423 Changed to use new make_call method
Guido van Rossum <guido@python.org>
parents: 1154
diff changeset
125 # return the return value from make_call(), since this may be
5244827dd423 Changed to use new make_call method
Guido van Rossum <guido@python.org>
parents: 1154
diff changeset
126 # needed by a broadcasting version of the class.)
5244827dd423 Changed to use new make_call method
Guido van Rossum <guido@python.org>
parents: 1154
diff changeset
127 #
5244827dd423 Changed to use new make_call method
Guido van Rossum <guido@python.org>
parents: 1154
diff changeset
128 # If the call fails, make_call() raises an exception
5244827dd423 Changed to use new make_call method
Guido van Rossum <guido@python.org>
parents: 1154
diff changeset
129 # (this includes time-outs and invalid results).
5244827dd423 Changed to use new make_call method
Guido van Rossum <guido@python.org>
parents: 1154
diff changeset
130 #
5244827dd423 Changed to use new make_call method
Guido van Rossum <guido@python.org>
parents: 1154
diff changeset
131 # Note that (at least with the UDP protocol) there is no
5244827dd423 Changed to use new make_call method
Guido van Rossum <guido@python.org>
parents: 1154
diff changeset
132 # guarantee that a call is executed at most once. When you do
5244827dd423 Changed to use new make_call method
Guido van Rossum <guido@python.org>
parents: 1154
diff changeset
133 # get a reply, you know it has been executed at least once;
5244827dd423 Changed to use new make_call method
Guido van Rossum <guido@python.org>
parents: 1154
diff changeset
134 # when you don't get a reply, you know nothing.
1133
9add0e3e804a Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
135
9add0e3e804a Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
136 def Mnt(self, directory):
1160
5244827dd423 Changed to use new make_call method
Guido van Rossum <guido@python.org>
parents: 1154
diff changeset
137 return self.make_call(1, directory, \
5244827dd423 Changed to use new make_call method
Guido van Rossum <guido@python.org>
parents: 1154
diff changeset
138 self.packer.pack_string, \
5244827dd423 Changed to use new make_call method
Guido van Rossum <guido@python.org>
parents: 1154
diff changeset
139 self.unpacker.unpack_fhstatus)
1133
9add0e3e804a Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
140
9add0e3e804a Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
141 def Dump(self):
1160
5244827dd423 Changed to use new make_call method
Guido van Rossum <guido@python.org>
parents: 1154
diff changeset
142 return self.make_call(2, None, \
5244827dd423 Changed to use new make_call method
Guido van Rossum <guido@python.org>
parents: 1154
diff changeset
143 None, self.unpacker.unpack_mountlist)
1133
9add0e3e804a Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
144
9add0e3e804a Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
145 def Umnt(self, directory):
1160
5244827dd423 Changed to use new make_call method
Guido van Rossum <guido@python.org>
parents: 1154
diff changeset
146 return self.make_call(3, directory, \
5244827dd423 Changed to use new make_call method
Guido van Rossum <guido@python.org>
parents: 1154
diff changeset
147 self.packer.pack_string, None)
1133
9add0e3e804a Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
148
9add0e3e804a Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
149 def Umntall(self):
1160
5244827dd423 Changed to use new make_call method
Guido van Rossum <guido@python.org>
parents: 1154
diff changeset
150 return self.make_call(4, None, None, None)
1133
9add0e3e804a Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
151
9add0e3e804a Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
152 def Export(self):
1160
5244827dd423 Changed to use new make_call method
Guido van Rossum <guido@python.org>
parents: 1154
diff changeset
153 return self.make_call(5, None, \
5244827dd423 Changed to use new make_call method
Guido van Rossum <guido@python.org>
parents: 1154
diff changeset
154 None, self.unpacker.unpack_exportlist)
1133
9add0e3e804a Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
155
9add0e3e804a Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
156
9add0e3e804a Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
157 # We turn the partial Mount client into a full one for either protocol
9add0e3e804a Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
158 # by use of multiple inheritance. (In general, when class C has base
9add0e3e804a Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
159 # classes B1...Bn, if x is an instance of class C, methods of x are
9add0e3e804a Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
160 # searched first in C, then in B1, then in B2, ..., finally in Bn.)
9add0e3e804a Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
161
9add0e3e804a Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
162 class TCPMountClient(PartialMountClient, TCPClient):
9add0e3e804a Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
163
1428
f7a752fb7b73 *** empty log message ***
Guido van Rossum <guido@python.org>
parents: 1160
diff changeset
164 def __init__(self, host):
f7a752fb7b73 *** empty log message ***
Guido van Rossum <guido@python.org>
parents: 1160
diff changeset
165 TCPClient.__init__(self, host, MOUNTPROG, MOUNTVERS)
1133
9add0e3e804a Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
166
9add0e3e804a Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
167
9add0e3e804a Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
168 class UDPMountClient(PartialMountClient, UDPClient):
9add0e3e804a Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
169
1428
f7a752fb7b73 *** empty log message ***
Guido van Rossum <guido@python.org>
parents: 1160
diff changeset
170 def __init__(self, host):
f7a752fb7b73 *** empty log message ***
Guido van Rossum <guido@python.org>
parents: 1160
diff changeset
171 UDPClient.__init__(self, host, MOUNTPROG, MOUNTVERS)
1133
9add0e3e804a Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
172
9add0e3e804a Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
173
9add0e3e804a Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
174 # A little test program for the Mount client. This takes a host as
9add0e3e804a Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
175 # command line argument (default the local machine), prints its export
1154
e82ac452d551 Bind to reserved port if root; changed mkcred interface; added -t/-u option
Guido van Rossum <guido@python.org>
parents: 1149
diff changeset
176 # list, and attempts to mount and unmount each exported files system.
e82ac452d551 Bind to reserved port if root; changed mkcred interface; added -t/-u option
Guido van Rossum <guido@python.org>
parents: 1149
diff changeset
177 # An optional first argument of -t or -u specifies the protocol to use
e82ac452d551 Bind to reserved port if root; changed mkcred interface; added -t/-u option
Guido van Rossum <guido@python.org>
parents: 1149
diff changeset
178 # (TCP or UDP), default is UDP.
1133
9add0e3e804a Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
179
9add0e3e804a Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
180 def test():
9add0e3e804a Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
181 import sys
1154
e82ac452d551 Bind to reserved port if root; changed mkcred interface; added -t/-u option
Guido van Rossum <guido@python.org>
parents: 1149
diff changeset
182 if sys.argv[1:] and sys.argv[1] == '-t':
e82ac452d551 Bind to reserved port if root; changed mkcred interface; added -t/-u option
Guido van Rossum <guido@python.org>
parents: 1149
diff changeset
183 C = TCPMountClient
e82ac452d551 Bind to reserved port if root; changed mkcred interface; added -t/-u option
Guido van Rossum <guido@python.org>
parents: 1149
diff changeset
184 del sys.argv[1]
e82ac452d551 Bind to reserved port if root; changed mkcred interface; added -t/-u option
Guido van Rossum <guido@python.org>
parents: 1149
diff changeset
185 elif sys.argv[1:] and sys.argv[1] == '-u':
e82ac452d551 Bind to reserved port if root; changed mkcred interface; added -t/-u option
Guido van Rossum <guido@python.org>
parents: 1149
diff changeset
186 C = UDPMountClient
e82ac452d551 Bind to reserved port if root; changed mkcred interface; added -t/-u option
Guido van Rossum <guido@python.org>
parents: 1149
diff changeset
187 del sys.argv[1]
e82ac452d551 Bind to reserved port if root; changed mkcred interface; added -t/-u option
Guido van Rossum <guido@python.org>
parents: 1149
diff changeset
188 else:
e82ac452d551 Bind to reserved port if root; changed mkcred interface; added -t/-u option
Guido van Rossum <guido@python.org>
parents: 1149
diff changeset
189 C = UDPMountClient
1133
9add0e3e804a Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
190 if sys.argv[1:]: host = sys.argv[1]
9add0e3e804a Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
191 else: host = ''
1428
f7a752fb7b73 *** empty log message ***
Guido van Rossum <guido@python.org>
parents: 1160
diff changeset
192 mcl = C(host)
1133
9add0e3e804a Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
193 list = mcl.Export()
9add0e3e804a Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
194 for item in list:
9add0e3e804a Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
195 print item
9add0e3e804a Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
196 try:
9add0e3e804a Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
197 mcl.Mnt(item[0])
9add0e3e804a Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
198 except:
9add0e3e804a Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
199 print 'Sorry'
9add0e3e804a Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
200 continue
9add0e3e804a Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
201 mcl.Umnt(item[0])