Package config_management :: Module rhncfg_remove
[hide private]
[frames] | no frames]

Source Code for Module config_management.rhncfg_remove

 1  # 
 2  # Copyright (c) 2008--2016 Red Hat, Inc. 
 3  # 
 4  # This software is licensed to you under the GNU General Public License, 
 5  # version 2 (GPLv2). There is NO WARRANTY for this software, express or 
 6  # implied, including the implied warranties of MERCHANTABILITY or FITNESS 
 7  # FOR A PARTICULAR PURPOSE. You should have received a copy of GPLv2 
 8  # along with this software; if not, see 
 9  # http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt. 
10  # 
11  # Red Hat trademarks are not licensed under GPLv2. No permission is 
12  # granted to use or replicate Red Hat trademarks that are incorporated 
13  # in this software or its documentation. 
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: # python2 
22      import xmlrpclib 
23  except ImportError: # python3 
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
40 - def run(self):
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