Misc s/func/certmaster/ replacements
[certmaster.git] / certmaster / overlord / cmd_modules / copyfile.py
1 """
2 copyfile command line
3
4 Copyright 2007, Red Hat, Inc
5 see AUTHORS
6
7 This software may be freely redistributed under the terms of the GNU
8 general public license.
9
10 You should have received a copy of the GNU General Public License
11 along with this program; if not, write to the Free Software
12 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
13 """
14
15
16 import optparse
17 import os
18 import pprint
19 import stat
20 import xmlrpclib
21
22 from func.overlord import command
23 from func.overlord import client
24
25 DEFAULT_PORT = 51234
26
27 class CopyFile(client.command.Command):
28 name = "copyfile"
29 usage = "copy a file to a client"
30
31
32 def addOptions(self):
33 self.parser.add_option("-f", "--file", dest="filename",
34 action="store")
35 self.parser.add_option("", "--remotepath", dest="remotepath",
36 action="store")
37 self.parser.add_option("", "--force", dest="force",
38 action="store_true")
39 self.parser.add_option("-v", "--verbose", dest="verbose",
40 action="store_true")
41 self.parser.add_option("-p", "--port", dest="port")
42
43 def handleOptions(self, options):
44 self.port = DEFAULT_PORT
45 if self.options.port:
46 self.port = self.options.port
47
48
49 def do(self, args):
50 self.server_spec = self.parentCommand.server_spec
51
52 client_obj = client.Client(self.server_spec,
53 port=self.port,
54 interactive=False,
55 verbose=self.options.verbose,
56 config=self.config)
57
58
59 try:
60 fb = open(self.options.filename, "r").read()
61 except IOError, e:
62 print "Unable to open file: %s: %s" % (self.options.filename, e)
63 return
64
65 st = os.stat(self.options.filename)
66 mode = stat.S_IMODE(st.st_mode)
67 uid = st.st_uid
68 gid = st.st_gid
69
70
71 data = xmlrpclib.Binary(fb)
72 results = client_obj.run("copyfile", "copyfile", [self.options.remotepath, data,
73 mode, uid, gid])