1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 import os
17 import sys
18 from config_common import handler_base, utils
19 from config_common.rhn_log import log_debug, die
20
21 try:
22 import xmlrpclib
23 except ImportError:
24 import xmlrpc.client as xmlrpclib
25
26 -class Handler(handler_base.HandlerBase):
27 _usage_options = "[options] file [ file ... ]"
28
29 _options_table = handler_base.HandlerBase._options_table + [
30 handler_base.HandlerBase._option_class(
31 '-c', '--channel', action="store",
32 help="Remove files from this config channel",
33 ),
34 handler_base.HandlerBase._option_class(
35 '-t', '--topdir', action="store",
36 help="Make all files relative to this string",
37 ),
38 ]
39
41 log_debug(2)
42 r = self.repository
43
44 if len(self.args) == 0:
45 die(0, "No files supplied (use --help for help)")
46
47 channel = self.options.channel
48
49 if not channel:
50 die(6, "Config channel not specified")
51
52 r = self.repository
53 if not r.config_channel_exists(channel):
54 die(6, "Error: config channel %s does not exist" % channel)
55
56 files = [utils.normalize_path(x) for x in self.args]
57
58 files_to_remove = []
59 if self.options.topdir:
60 if not os.path.isdir(self.options.topdir):
61 die(8, "--topdir specified, but `%s' not a directory" %
62 self.options.topdir)
63 for f in files:
64 if not f.startswith(self.options.topdir):
65 die(8, "--topdir %s specified, but file `%s' doesn't comply"
66 % (self.options.topdir, f))
67 files_to_remove.append((f, f[len(self.options.topdir):]))
68 else:
69 for f in files:
70 files_to_remove.append((f, f))
71
72 print("Removing from config channel %s" % channel)
73 for (local_file, remote_file) in files_to_remove:
74 try:
75 r.remove_file(channel, remote_file)
76 except xmlrpclib.Fault:
77 e = sys.exc_info()[1]
78 if e.faultCode == -4011:
79 print("%s does not exist" % remote_file)
80 continue
81 raise
82 else:
83 print("%s removed" % remote_file)
84