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

Source Code for Module config_management.rhncfg_diff_revisions

 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 sys 
17   
18  from config_common import handler_base, cfg_exceptions 
19  from config_common.rhn_log import log_debug, die 
20   
21 -class Handler(handler_base.HandlerBase):
22 _usage_options = "[options] file" 23 _options_table = [ 24 handler_base.HandlerBase._option_class( 25 '-c', '--channel', action="append", 26 help="Use this config channel", 27 ), 28 handler_base.HandlerBase._option_class( 29 '-r', '--revision', action="append", 30 help="Use this revision", 31 ), 32 ]
33 - def run(self):
34 log_debug(2) 35 r = self.repository 36 37 if len(self.args) != 1: 38 die(3, "One file needs to be specified") 39 40 path = self.args[0] 41 42 channel_dst = None 43 ns_count = len(self.options.channel or []) 44 if ns_count == 0: 45 die(3, "At least one config channel has to be specified") 46 47 channel_src = self.options.channel[0] 48 if ns_count > 2: 49 die(3, "At most two config channels can be specified") 50 51 if not r.config_channel_exists(channel_src): 52 die(4, "Source config channel %s does not exist" % channel_src) 53 54 if ns_count == 2: 55 channel_dst = self.options.channel[1] 56 57 if not r.config_channel_exists(channel_dst): 58 die(4, "Config channel %s does not exist" % channel_dst) 59 60 revision_dst = None 61 rev_count = len(self.options.revision or []) 62 if rev_count == 0: 63 die(3, "At least one revision has to be specified") 64 65 revision_src = self.options.revision[0] 66 if rev_count > 2: 67 die(3, "At most two revisions can be specified") 68 69 if rev_count == 2: 70 revision_dst = self.options.revision[1] 71 72 try: 73 result = r.diff_file_revisions(path, channel_src, 74 revision_src, channel_dst, revision_dst) 75 except cfg_exceptions.RepositoryFileMissingError: 76 e = sys.exc_info()[1] 77 die(2, e[0]) 78 except cfg_exceptions.BinaryFileDiffError: 79 e = sys.exc_info()[1] 80 die(3, e[0]) 81 82 sys.stdout.write(result)
83