backend/server/handlers/config_mgmt/rhn_config_management.py | 50 +++---
client/tools/rhncfg/config_client/rhncfgcli_elist.py | 86 -----------
client/tools/rhncfg/config_common/file_utils.py | 82 ++++++++++
3 files changed, 114 insertions(+), 104 deletions(-)
New commits:
commit ec990a25c6b0ce66dd0e515cd8d0f1d645f45912
Author: Miroslav Suchý <msuchy(a)redhat.com>
Date: Tue Dec 21 16:30:01 2010 +0100
634963 - print diffs for "rhncfg-manager diff-revisions" if we differ in
selinux context, ownership or attributes
diff --git a/backend/server/handlers/config_mgmt/rhn_config_management.py
b/backend/server/handlers/config_mgmt/rhn_config_management.py
index 985c6f8..6bd7e15 100644
--- a/backend/server/handlers/config_mgmt/rhn_config_management.py
+++ b/backend/server/handlers/config_mgmt/rhn_config_management.py
@@ -21,6 +21,9 @@ import os
from spacewalk.common import rhnFault, log_debug
import tempfile
from spacewalk.server import rhnSQL, configFilesHandler
+import sys
+sys.path.append("/usr/share/rhn")
+from config_common.file_utils import ostr_to_sym
class ConfigManagement(configFilesHandler.ConfigFilesHandler):
def __init__(self):
@@ -424,6 +427,24 @@ class ConfigManagement(configFilesHandler.ConfigFilesHandler):
return self._get_maximum_file_size()
+ def __attributes_differ(self, fsrc, fdst):
+ """ Returns true if acl, ownership, type or selinux context
differ. """
+ return (fsrc['filemode'] != fdst['filemode']) or
(fsrc['label'] != fdst['label']) or \
+ (fsrc['username'] != fdst['username']) or
(fsrc['groupname'] != fdst['groupname']) or \
+ (fsrc['selinux_ctx'] != fdst['selinux_ctx'])
+
+ def __header(self, path, fsrc, config_channel_src, fdst, config_channel_dst):
+ """ Returns diff like header for this two files.
"""
+ template = "--- %s\t%s\tattributes: %s %s %s %s\tconfig channel:
%s\trevision: %s"
+ first_row = template % (path, f_date(fsrc['modified']),
ostr_to_sym(fsrc['filemode'], fsrc['label']),
+ fsrc['username'], fsrc['groupname'],
fsrc['selinux_ctx'], config_channel_src,
+ fsrc['revision'],
+ )
+ second_row = template % (path, f_date(fdst['modified']),
ostr_to_sym(fdst['filemode'], fdst['label']),
+ fdst['username'], fdst['groupname'],
fdst['selinux_ctx'], config_channel_dst,
+ fdst['revision'],
+ )
+ return (first_row, second_row)
def management_diff(self, dict):
log_debug(1)
@@ -454,19 +475,13 @@ class ConfigManagement(configFilesHandler.ConfigFilesHandler):
% (path, fsrc['label'], \
config_channel_src, fdst['label'],
config_channel_dst),
explain=0)
- template = "--- %s\t%s\tconfig channel: %s\trevision: %s target: %s
\n"
if fsrc['label'] == 'symlink':
- if fsrc["symlink"] != fdst['symlink']:
- first_row = template % (
- path, f_date(fsrc['modified']), config_channel_src,
- fsrc['revision'], fsrc["symlink"],
- )
- second_row = template % (
- path, f_date(fdst['modified']), config_channel_dst,
- fdst['revision'], fdst["symlink"],
- )
- return first_row + second_row
+ if (fsrc["symlink"] != fdst['symlink']) or
self.__attributes_differ(fsrc, fdst):
+ (first_row, second_row) = self.__header(path, fsrc, config_channel_src,
fdst, config_channel_dst)
+ first_row += ' target: %s' % fsrc["symlink"]
+ second_row += ' target: %s' % fdst["symlink"]
+ return first_row + "\n" + second_row + "\n"
return ""
pipe = os.popen("/usr/bin/diff -u %s %s" % (fsrc['filename'],
@@ -484,17 +499,8 @@ class ConfigManagement(configFilesHandler.ConfigFilesHandler):
# Hmm, weird
return second_row + pipe.read()
- template = "--- %s\t%s\tconfig channel: %s\trevision: %s\n"
-
- first_row = template % (
- path, f_date(fsrc['modified']), config_channel_src,
- fsrc['revision'],
- )
- second_row = template % (
- path, f_date(fdst['modified']), config_channel_dst,
- fdst['revision'],
- )
- return first_row + second_row + pipe.read()
+ (first_row, second_row) = self.__header(path, fsrc, config_channel_src, fdst,
config_channel_dst)
+ return first_row + "\n" + second_row + '\n' + pipe.read()
def _get_file_revision(self, config_channel, revision, path):
if revision and not revision.isdigit():
commit b0320c911354e9d4f453ef1b9f143d4fc30fae3a
Author: Miroslav Suchý <msuchy(a)redhat.com>
Date: Tue Dec 21 13:10:30 2010 +0100
move function ostr_to_sym from rhncfgcli_elist to config_common/file_utils
diff --git a/client/tools/rhncfg/config_client/rhncfgcli_elist.py
b/client/tools/rhncfg/config_client/rhncfgcli_elist.py
index 6da4730..637c026 100755
--- a/client/tools/rhncfg/config_client/rhncfgcli_elist.py
+++ b/client/tools/rhncfg/config_client/rhncfgcli_elist.py
@@ -1,86 +1,8 @@
from config_common.rhn_log import log_debug, die
-import handler_base, base64, stat
-
-FILETYPE2CHAR = {
- 'file' : '-',
- 'directory' : 'd',
- 'symlink' : 'l',
- 'chardev' : 'c',
- 'blockdev' : 'b',
-}
+from config_common.file_utils import ostr_to_sym
+import handler_base, base64
class Handler(handler_base.HandlerBase):
- def ostr_to_sym(self, octstr, ftype):
- mode = int(str(octstr), 8)
-
- symstr = FILETYPE2CHAR.get(ftype, '?')
-
- if mode & stat.S_IRUSR:
- symstr += 'r'
- else:
- symstr += '-'
-
- if mode & stat.S_IWUSR:
- symstr += 'w'
- else:
- symstr += '-'
-
- if mode & stat.S_IXUSR:
- if mode & stat.S_ISUID:
- symstr += 's'
- else:
- symstr += 'x'
- else:
- if mode & stat.S_ISUID:
- symstr += 'S'
- else:
- symstr += '-'
-
- if mode & stat.S_IRGRP:
- symstr += 'r'
- else:
- symstr += '-'
-
- if mode & stat.S_IWGRP:
- symstr += 'w'
- else:
- symstr += '-'
-
- if mode & stat.S_IXGRP:
- if mode & stat.S_ISGID:
- symstr += 's'
- else:
- symstr += 'x'
- else:
- if mode & stat.S_ISGID:
- symstr += 'S'
- else:
- symstr += '-'
-
- if mode & stat.S_IROTH:
- symstr += 'r'
- else:
- symstr += '-'
-
- if mode & stat.S_IWOTH:
- symstr += 'w'
- else:
- symstr += '-'
-
- if mode & stat.S_IXOTH:
- if mode & stat.S_ISVTX:
- symstr += 't'
- else:
- symstr += 'x'
- else:
- if mode & stat.S_ISVTX:
- symstr += 'T'
- else:
- symstr += '-'
-
- return symstr
-
-
def run(self):
log_debug(2)
r = self.repository
@@ -106,13 +28,13 @@ class Handler(handler_base.HandlerBase):
fsize = '*' + str(len(finfo['file_contents']))
if finfo['filetype'] == 'symlink':
- permstr = self.ostr_to_sym('777', finfo['filetype'])
+ permstr = ostr_to_sym('777', finfo['filetype'])
dest = "%s -> %s" % (file[1], finfo['symlink'])
fsize = str(len(finfo['symlink']))
finfo['username'] = 'root'
finfo['groupname'] = 'root'
else:
- permstr = self.ostr_to_sym(finfo['filemode'],
finfo['filetype']) or ''
+ permstr = ostr_to_sym(finfo['filemode'],
finfo['filetype']) or ''
dest = file[1]
print "%10s %8s %-8s %10s %+3s %*s %s" % (permstr,
finfo['username'], finfo['groupname'], fsize, finfo['revision'],
maxlen, file[0], dest)
diff --git a/client/tools/rhncfg/config_common/file_utils.py
b/client/tools/rhncfg/config_common/file_utils.py
index a350a30..a129a0e 100644
--- a/client/tools/rhncfg/config_common/file_utils.py
+++ b/client/tools/rhncfg/config_common/file_utils.py
@@ -18,6 +18,7 @@ import os.path
import time
import tempfile
import base64
+import stat
try:
from selinux import lgetfilecon
except:
@@ -150,3 +151,84 @@ def maketemp(prefix=None, directory=None):
return filename, dirs_created, os.fdopen(fd, "w+")
+
+FILETYPE2CHAR = {
+ 'file' : '-',
+ 'directory' : 'd',
+ 'symlink' : 'l',
+ 'chardev' : 'c',
+ 'blockdev' : 'b',
+}
+
+def ostr_to_sym(octstr, ftype):
+ """ Convert filemode in octets (like '644') to string like
"ls -l" ("-rwxrw-rw-")
+ ftype is one of: file, directory, symlink, chardev, blockdev.
+ """
+ mode = int(str(octstr), 8)
+
+ symstr = FILETYPE2CHAR.get(ftype, '?')
+
+ if mode & stat.S_IRUSR:
+ symstr += 'r'
+ else:
+ symstr += '-'
+
+ if mode & stat.S_IWUSR:
+ symstr += 'w'
+ else:
+ symstr += '-'
+
+ if mode & stat.S_IXUSR:
+ if mode & stat.S_ISUID:
+ symstr += 's'
+ else:
+ symstr += 'x'
+ else:
+ if mode & stat.S_ISUID:
+ symstr += 'S'
+ else:
+ symstr += '-'
+
+ if mode & stat.S_IRGRP:
+ symstr += 'r'
+ else:
+ symstr += '-'
+
+ if mode & stat.S_IWGRP:
+ symstr += 'w'
+ else:
+ symstr += '-'
+
+ if mode & stat.S_IXGRP:
+ if mode & stat.S_ISGID:
+ symstr += 's'
+ else:
+ symstr += 'x'
+ else:
+ if mode & stat.S_ISGID:
+ symstr += 'S'
+ else:
+ symstr += '-'
+
+ if mode & stat.S_IROTH:
+ symstr += 'r'
+ else:
+ symstr += '-'
+
+ if mode & stat.S_IWOTH:
+ symstr += 'w'
+ else:
+ symstr += '-'
+
+ if mode & stat.S_IXOTH:
+ if mode & stat.S_ISVTX:
+ symstr += 't'
+ else:
+ symstr += 'x'
+ else:
+ if mode & stat.S_ISVTX:
+ symstr += 'T'
+ else:
+ symstr += '-'
+
+ return symstr