backend/server/configFilesHandler.py | 6 ++
client/tools/rhncfg/config_management/rhncfg_diff.py | 51 ++++++++++++++-----
2 files changed, 45 insertions(+), 12 deletions(-)
New commits:
commit 46f7967afb14981095af1621d7d735c6d02d0c42
Author: Miroslav Suchý <msuchy(a)redhat.com>
Date: Mon Jan 3 15:14:13 2011 +0100
634963 - indicate change in selinux, ownership or file mode (even if diff is empty)
diff --git a/client/tools/rhncfg/config_management/rhncfg_diff.py
b/client/tools/rhncfg/config_management/rhncfg_diff.py
index 87de1d4..d4fafb1 100644
--- a/client/tools/rhncfg/config_management/rhncfg_diff.py
+++ b/client/tools/rhncfg/config_management/rhncfg_diff.py
@@ -103,6 +103,13 @@ class Handler(handler_base.HandlerBase):
sys.stdout.write(
self.diff_file(channel, remote_file, local_file, revision))
+ def __attributes_differ(self, fsrc, fdst):
+ """ Returns true if acl, ownership, type or selinux context
differ.
+ fsrc is config file retrieved from xmlrpc, fdst is output of
make_stat_info()
+ """
+ return (fsrc['filemode'] != fdst['mode']) or \
+ (fsrc['username'] != fdst['user']) or
(fsrc['groupname'] != fdst['group']) or \
+ (fsrc['selinux_ctx'] != fdst['selinux_ctx'])
def diff_file(self, channel, path, local_file, revision):
r = self.repository
@@ -137,7 +144,7 @@ class Handler(handler_base.HandlerBase):
pass
file_stat = os.lstat(local_file)
local_info = r.make_stat_info(local_file, file_stat)
- if not first_row:
+ if not first_row and not self.__attributes_differ(info, local_info)
return ""
else:
template = "--- %s\t%s\tattributes: %s %s %s %s\tconfig channel:
%s\trevision: %s"
commit 3f70bb8be722ef230b75d8ef40c1399362f6e7e0
Author: Miroslav Suchý <msuchy(a)redhat.com>
Date: Mon Jan 3 14:57:30 2011 +0100
do not fail if diff do not differ
addressing:
Traceback (most recent call last):
File "/usr/bin/rhncfg-manager", line 46, in ?
sys.exit(Main().main() or 0)
File "/usr/share/rhn/config_common/rhn_main.py", line 187, in main
handler.run()
File "/usr/share/rhn/config_management/rhncfg_diff.py", line 103, in run
sys.stdout.write(
File "/usr/share/rhn/config_management/rhncfg_diff.py", line 134, in
diff_file
first_row = diff.next()
StopIteration
diff --git a/client/tools/rhncfg/config_management/rhncfg_diff.py
b/client/tools/rhncfg/config_management/rhncfg_diff.py
index 9bf4fe2..87de1d4 100644
--- a/client/tools/rhncfg/config_management/rhncfg_diff.py
+++ b/client/tools/rhncfg/config_management/rhncfg_diff.py
@@ -129,8 +129,12 @@ class Handler(handler_base.HandlerBase):
fromlines = info['file_contents'].splitlines(1)
tolines = open(local_file, 'r').readlines()
diff_output = difflib.unified_diff(fromlines, tolines, info['path'],
local_file)
- first_row = diff_output.next()
- second_row = diff_output.next()
+ first_row = second_row = ''
+ try:
+ first_row = diff_output.next()
+ second_row = diff_output.next()
+ except StopIteration:
+ pass
file_stat = os.lstat(local_file)
local_info = r.make_stat_info(local_file, file_stat)
if not first_row:
commit ec168cb800568729a58104979dd39624ef1d7971
Author: Miroslav Suchý <msuchy(a)redhat.com>
Date: Mon Jan 3 14:48:54 2011 +0100
do diff directly in memory
current workflow is:
get from xmlrpclib, save to disk, read from disk, do diff.
Saving to disk is really not needed
diff --git a/client/tools/rhncfg/config_management/rhncfg_diff.py
b/client/tools/rhncfg/config_management/rhncfg_diff.py
index fa0a75e..9bf4fe2 100644
--- a/client/tools/rhncfg/config_management/rhncfg_diff.py
+++ b/client/tools/rhncfg/config_management/rhncfg_diff.py
@@ -13,12 +13,15 @@
# in this software or its documentation.
#
+import base64
+from datetime import datetime
+import difflib
import os
import sys
from config_common import handler_base, utils, cfg_exceptions
from config_common.rhn_log import log_debug, die
-from config_common.file_utils import diff
+from config_common.file_utils import diff, f_date, ostr_to_sym
class Handler(handler_base.HandlerBase):
_usage_options = "[options] file [ file ... ]"
@@ -104,8 +107,12 @@ class Handler(handler_base.HandlerBase):
def diff_file(self, channel, path, local_file, revision):
r = self.repository
try:
- #5/11/05 wregglej - 157066 dirs_created is returned by get_file_info, now.
- temp_file, info, dirs_created = r.get_file_info(channel, path,
revision=revision)
+ info = r.get_raw_file_info(channel, path, revision)
+ if info.has_key('encoding') and info['file_contents']:
+ if info['encoding'] == 'base64':
+ info['file_contents'] =
base64.decodestring(info['file_contents'])
+ else:
+ die(9, 'Error: unknow encoding %s' %
info['encoding'])
except cfg_exceptions.RepositoryFileMissingError:
die(2, "Error: no such file %s (revision %s) in config channel %s"
% (path, revision, channel))
@@ -118,14 +125,23 @@ class Handler(handler_base.HandlerBase):
dest_link = os.readlink(local_file)
if src_link != os.readlink(local_file):
return "Symbolic links differ. Channel: '%s' ->
'%s' System: '%s' -> '%s' \n " % (path,src_link, path,
dest_link)
- return ""
- diff_u = diff(temp_file, local_file)
-
- diff_len = len(diff_u)
- if diff_len == 0:
return ""
- elif diff_u[0].startswith("---"):
- diff_u[0] = "--- %s\tconfig_channel: %s\trevision: %s\n" % (
- path, channel, info['revision']
+ fromlines = info['file_contents'].splitlines(1)
+ tolines = open(local_file, 'r').readlines()
+ diff_output = difflib.unified_diff(fromlines, tolines, info['path'],
local_file)
+ first_row = diff_output.next()
+ second_row = diff_output.next()
+ file_stat = os.lstat(local_file)
+ local_info = r.make_stat_info(local_file, file_stat)
+ if not first_row:
+ return ""
+ else:
+ template = "--- %s\t%s\tattributes: %s %s %s %s\tconfig channel:
%s\trevision: %s"
+ first_row = template % (path, str(info['modified']),
ostr_to_sym(info['filemode'], info['filetype']),
+ info['username'], info['groupname'],
info['selinux_ctx'], channel,
+ info['revision'],
+ )
+ second_row = template % (local_file,
f_date(datetime.fromtimestamp(local_info['mtime'])),
ostr_to_sym(local_info['mode'], 'file'),
+ local_info['user'], local_info['group'],
local_info['selinux_ctx'], 'local file', None
)
- return ''.join(diff_u)
+ return first_row + '\n' + second_row + '\n' +
''.join(list(diff_output))
commit 5a29f20605409ad19f430f736bbc73a962fe1027
Author: Miroslav Suchý <msuchy(a)redhat.com>
Date: Mon Jan 3 14:14:04 2011 +0100
send with config file, its modified time
one may wonder, why I used that str() function? I will tell you:
That is because of RHEL5 and its python 2.4, where has xmlrpclib.DateTime nearly 0
functionality.
diff --git a/backend/server/configFilesHandler.py b/backend/server/configFilesHandler.py
index c79751a..6497811 100644
--- a/backend/server/configFilesHandler.py
+++ b/backend/server/configFilesHandler.py
@@ -18,6 +18,7 @@
import base64
import os
+import xmlrpclib
from spacewalk.common import rhnFault, rhnException, log_debug, CFG, rhnFlags
from spacewalk.common.checksum import getStringChecksum
@@ -531,6 +532,10 @@ def format_file_results(row, server=None):
if client_caps and client_caps.has_key('configfiles.base64_enc'):
encoding = 'base64'
contents = base64.encodestring(contents)
+ if row['modified']:
+ m_date = xmlrpclib.DateTime(str(row['modified']))
+ else:
+ m_date = ''
return {
'path' : row['path'],
@@ -548,4 +553,5 @@ def format_file_results(row, server=None):
'encoding' : encoding or '',
'filetype' : row['label'],
'selinux_ctx' : row['selinux_ctx'] or '',
+ 'modified' : m_date,
}