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

Source Code for Module config_management.rhncfg_get

  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  import tempfile 
 19   
 20  from config_common import handler_base, utils, cfg_exceptions 
 21  from config_common.rhn_log import log_debug, die 
 22  from config_common.transactions import DeployTransaction, FailedRollback 
 23  from spacewalk.common.usix import raise_with_tb 
 24   
 25   
26 -def deploying_mesg_callback(path):
27 print("Deploying %s" % path)
28 29
30 -class Handler(handler_base.HandlerBase):
31 _usage_options = "[options] file [ file ... ]" 32 33 _options_table = handler_base.HandlerBase._options_table + [ 34 handler_base.HandlerBase._option_class( 35 '-c', '--channel', action="store", 36 help="Get file(s) from this config channel", 37 ), 38 handler_base.HandlerBase._option_class( 39 '-t', '--topdir', action="store", 40 help="Make all files relative to this string", 41 ), 42 handler_base.HandlerBase._option_class( 43 '-r', '--revision', action="store", 44 help="Get this file revision", 45 ), 46 ] 47
48 - def run(self):
49 log_debug(2) 50 r = self.repository 51 52 channel = self.options.channel 53 if not channel: 54 die(6, "Config channel not specified") 55 56 topdir = self.options.topdir 57 if topdir: 58 if not os.path.isdir(self.options.topdir): 59 die(8, "--topdir specified, but `%s' not a directory" % 60 self.options.topdir) 61 62 if not self.args: 63 die(7, "No files specified") 64 65 revision = self.options.revision 66 if revision: 67 if len(self.args) > 1: 68 die(9, "--revision specified with multiple files") 69 70 dep_trans = None 71 72 if topdir: 73 dep_trans = DeployTransaction(transaction_root=topdir) 74 dep_trans.deploy_callback(deploying_mesg_callback) 75 76 for f in self.args: 77 try: 78 directory = topdir or tempfile.gettempdir() 79 80 #5/11/05 wregglej - 157066 dirs_created is returned from get_file_info. 81 (temp_file, info, dirs_created) = r.get_file_info(channel, f, revision=revision, 82 auto_delete=0, dest_directory=directory) 83 84 except cfg_exceptions.RepositoryFileMissingError: 85 if revision is not None: 86 die(2, "Error: file %s (revision %s) not in config " 87 "channel %s" % (f, revision, channel)) 88 else: 89 die(2, "Error: file %s not in config channel %s" % 90 (f, channel)) 91 92 if topdir: 93 #5/11/05 wregglej - 157066 dirs_created now gets passed into add_preprocessed. 94 dep_trans.add_preprocessed(f, temp_file, info, dirs_created, strict_ownership=0) 95 continue 96 elif info.get('filetype') == 'symlink': 97 print("%s -> %s" % (info['path'], info['symlink'])) 98 continue 99 elif info.get('filetype') == 'directory': 100 print("%s is a directory entry, nothing to get" % info['path']) 101 continue 102 else: 103 print(open(temp_file).read()) 104 os.unlink(temp_file) 105 106 if topdir: 107 try: 108 dep_trans.deploy() 109 except Exception: 110 try: 111 dep_trans.rollback() 112 except FailedRollback: 113 raise_with_tb(FailedRollback("FAILED ROLLBACK: "), sys.exc_info()[2]) 114 #5/3/05 wregglej - 136415 Added exception stuff for missing user info. 115 except cfg_exceptions.UserNotFound: 116 raise 117 #5/5/05 wregglej - 136415 Added exception handling for unknown group. 118 except cfg_exceptions.GroupNotFound: 119 raise 120 else: 121 raise_with_tb(Exception("Deploy failed, rollback successful: "), sys.exc_info()[2])
122