Package config_client :: Module rhncfgcli_diff
[hide private]
[frames] | no frames]

Source Code for Module config_client.rhncfgcli_diff

 1  # 
 2  # Copyright (c) 2008--2017 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  import os 
18   
19  import handler_base 
20  from config_common.file_utils import diff 
21  from config_common.local_config import get as get_config 
22   
23 -class Handler(handler_base.HandlerBase):
24 _options_table = [ 25 handler_base.HandlerBase._option_class( 26 '-d', '--diff-secure-files', dest='display_diff', 27 action="store_true", default=False, 28 help="Force diff to display the diff for secure files.", 29 ) 30 ] 31 _usage_options = handler_base.HandlerBase._usage_options + " [ files ... ]"
32 - def _process_file(self, *args):
33 src, dst= args [:2] 34 type = args[3] 35 file_info = args[4] 36 37 if type == 'symlink': 38 if not os.path.exists(dst): 39 print("Symbolic link '%s' is missing" % dst) 40 return 41 42 if not os.path.islink(dst): 43 print("Path '%s' is not a symbolic link" % dst) 44 return 45 46 #dst is a symlink, so just tell the user we're skipping the entry 47 srclink = os.readlink(src) 48 destlink = os.readlink(dst) 49 if srclink != destlink: 50 print("Symbolic links differ. Channel: '%s' -> '%s' System: '%s' -> '%s' " % (dst,srclink, dst, destlink)) 51 elif type == 'file': 52 if 'is_binary' in file_info and file_info['is_binary'] == 'Y': 53 src_content = dst_content = None 54 content_differs = False 55 src_file = open(src, 'rb') 56 src_content = src_file.read() 57 src_file.close() 58 if os.access(dst, os.R_OK): 59 dst_file = open(dst, 'rb') 60 dst_content = dst_file.read() 61 dst_file.close() 62 else: 63 print("File %s that is not readable. Re-deployment of configuration file is recommended." % dst) 64 return 65 if len(src_content) != len(dst_content): 66 content_differs = True 67 else: 68 for i in range(len(src_content)): 69 if src_content[i] != dst_content[i]: 70 content_differs = True 71 break 72 if content_differs: 73 sys.stdout.write("Binary file %s differs.\n" % (dst)) 74 else: 75 sys.stdout.write(''.join(diff(src, dst, srcname=dst, dstname=dst, 76 display_diff= 77 (self.options.display_diff or get_config('display_diff')))))
78