client/tools/rhncfg/config_client/rhncfgcli_diff.py | 24 ---
client/tools/rhncfg/config_client/rhncfgcli_get.py | 99 ++++------------
client/tools/rhncfg/config_client/rpc_cli_repository.py | 1
client/tools/rhncfg/config_common/file_utils.py | 52 ++++++--
client/tools/rhncfg/config_common/transactions.py | 2
client/tools/rhncfg/config_management/rhncfg_diff.py | 29 +---
6 files changed, 81 insertions(+), 126 deletions(-)
New commits:
commit 889764d2b3536c89b20774ca1259e5e8e3998e14
Author: Michael Mraka <michael.mraka(a)redhat.com>
Date: Wed Dec 22 14:46:52 2010 +0100
if file is excluded skip also deploy preparation
diff --git a/client/tools/rhncfg/config_client/rhncfgcli_get.py
b/client/tools/rhncfg/config_client/rhncfgcli_get.py
index 4fe7b7e..588b6e2 100644
--- a/client/tools/rhncfg/config_client/rhncfgcli_get.py
+++ b/client/tools/rhncfg/config_client/rhncfgcli_get.py
@@ -39,22 +39,22 @@ class Handler(handler_base.TopdirHandlerBase):
for path in self.get_valid_files():
- try:
- finfo = self.repository.get_file_info(path, auto_delete=0,
dest_directory=topdir)
- except cfg_exceptions.DirectoryEntryIsFile, e:
- print "Error: unable to deploy directory %s, as it is already a file
on disk" % (e[0], )
- continue
-
- if finfo is None:
- # File disappeared since we called the function
- continue
-
- (processed_path, file_info, dirs_created) = finfo
-
if excludes.has_key(path):
print "Excluding %s" % path
else:
try:
+ finfo = self.repository.get_file_info(path, auto_delete=0,
dest_directory=topdir)
+ except cfg_exceptions.DirectoryEntryIsFile, e:
+ print "Error: unable to deploy directory %s, as it is already a
file on disk" % (e[0], )
+ continue
+
+ if finfo is None:
+ # File disappeared since we called the function
+ continue
+
+ (processed_path, file_info, dirs_created) = finfo
+
+ try:
dep_trans.add_preprocessed(path, processed_path, file_info,
dirs_created)
except cfg_exceptions.UserNotFound, e:
print "Error: unable to deploy file %s, information on user
'%s' could not be found." % (path,e[0])
commit a3247233b25a902360871cf2188dababc549069e
Author: Michael Mraka <michael.mraka(a)redhat.com>
Date: Wed Dec 22 16:09:51 2010 +0100
even rhncfg-manager can use file_utils.diff instead of external diff command
diff --git a/client/tools/rhncfg/config_management/rhncfg_diff.py
b/client/tools/rhncfg/config_management/rhncfg_diff.py
index b1d7b42..fa0a75e 100644
--- a/client/tools/rhncfg/config_management/rhncfg_diff.py
+++ b/client/tools/rhncfg/config_management/rhncfg_diff.py
@@ -18,6 +18,7 @@ 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
class Handler(handler_base.HandlerBase):
_usage_options = "[options] file [ file ... ]"
@@ -118,27 +119,13 @@ class Handler(handler_base.HandlerBase):
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 ""
- # Test -u option to diff
- diffcmd = "/usr/bin/diff -u"
- pipe = os.popen("%s %s %s 2>/dev/null" % (diffcmd, temp_file,
local_file))
- pipe.read() # Read the output so GNU diff is happy
- ret = pipe.close()
- if ret == None: ret = 0
- ret = ret/256 # Return code in upper byte
- if ret == 2: # error in diff call
- diffcmd = "/usr/bin/diff -c"
-
- pipe = os.popen("%s %s %s" % (diffcmd, temp_file, local_file))
- first_row = pipe.readline()
- if not first_row:
+ diff_u = diff(temp_file, local_file)
+
+ diff_len = len(diff_u)
+ if diff_len == 0:
return ""
- elif first_row.startswith("---"):
- first_row = "--- %s\tconfig_channel: %s\trevision: %s\n" % (
- path, channel, info['revision']
- )
- elif first_row.startswith("***"):
- # This happens when we drop back to "diff -c"
- first_row = "*** %s\tconfig_channel: %s\trevision: %s\n" % (
+ elif diff_u[0].startswith("---"):
+ diff_u[0] = "--- %s\tconfig_channel: %s\trevision: %s\n" % (
path, channel, info['revision']
)
- return first_row + pipe.read()
+ return ''.join(diff_u)
commit a60d23a73c1e780e9c028d2ee23805fc5bf03c1e
Author: Michael Mraka <michael.mraka(a)redhat.com>
Date: Wed Dec 22 13:02:13 2010 +0100
use file_utils.diff instead of external diff command
diff --git a/client/tools/rhncfg/config_client/rhncfgcli_diff.py
b/client/tools/rhncfg/config_client/rhncfgcli_diff.py
index 83b8477..0e0a9ab 100644
--- a/client/tools/rhncfg/config_client/rhncfgcli_diff.py
+++ b/client/tools/rhncfg/config_client/rhncfgcli_diff.py
@@ -17,16 +17,13 @@ import sys
import os
import handler_base
+from config_common.file_utils import diff
class Handler(handler_base.HandlerBase):
_usage_options = handler_base.HandlerBase._usage_options + " [ files ...
]"
def _process_file(self, *args):
src, dst= args [:2]
type = args[3]
- # label for diff output. this lets 'patch -R' properly apply
- # a patch to update to known version and have proper lsdiff
- # output. also gets rid of /tmp/@blah in diff output.
- label = dst
if type == 'symlink':
#dst is a symlink, so just tell the user we're skipping the entry
@@ -35,21 +32,4 @@ class Handler(handler_base.HandlerBase):
if srclink != destlink:
print "Symbolic links differ. Channel: '%s' ->
'%s' System: '%s' -> '%s' " % (dst,srclink, dst,
destlink)
elif type == 'file':
- # if file isn't present, compare to /dev/null so we see the
- # whole thing in the diff
- if not os.access(dst, os.R_OK):
- dst = "/dev/null"
-
- # Test -L and -u options to diff
- diffcmd = "/usr/bin/diff -L %s -u" % (label,)
- dst = '"' + dst + '"'
- pipe = os.popen("%s %s %s 2>/dev/null" % (diffcmd, src, dst))
- pipe.read() # Read the output so GNU diff is happy
- ret = pipe.close()
- if ret == None: ret = 0
- ret = ret/256 # Return code in upper byte
- if ret == 2: # error in diff call
- diffcmd = "/usr/bin/diff -c"
-
- pipe = os.popen("%s %s %s" % (diffcmd, src, dst))
- sys.stdout.write(pipe.read())
+ sys.stdout.write(''.join(diff(src, dst, srcname=dst, dstname=dst)))
commit 1750b509e075bc0556115eacde215084371f6d71
Author: Michael Mraka <michael.mraka(a)redhat.com>
Date: Wed Dec 22 13:00:17 2010 +0100
use difflib instead of external diff command
diff --git a/client/tools/rhncfg/config_common/file_utils.py
b/client/tools/rhncfg/config_common/file_utils.py
index 5873bd5..399ddb7 100644
--- a/client/tools/rhncfg/config_common/file_utils.py
+++ b/client/tools/rhncfg/config_common/file_utils.py
@@ -17,6 +17,7 @@ import os
import time
import tempfile
import base64
+import difflib
try:
from selinux import lgetfilecon
except:
@@ -116,8 +117,7 @@ class FileProcessor:
else:
raise e
else:
- pipe = os.popen("/usr/bin/diff -u %s %s" % (path, temp_file))
- result = pipe.read()
+ result = ''.join(diff(path, temp_file))
os.unlink(temp_file)
return sectx_result + result
@@ -129,6 +129,32 @@ class FileProcessor:
raise Exception, "Missing key %s" % k
+def diff(src, dst, srcname=None, dstname=None):
+ def f_content(path, name):
+ if os.access(path, os.R_OK):
+ f = open(path, 'U')
+ content = f.readlines()
+ f.close()
+ f_time = time.ctime(os.stat(path).st_mtime)
+ if content and content[-1] and content[-1][-1] != "\n":
+ content[-1] += "\n"
+ else:
+ content = []
+ f_time = time.ctime(0)
+ if not name:
+ name = path
+ return (content, name, f_time)
+
+ (src_content, src_name, src_time) = f_content(src, srcname)
+ (dst_content, dst_name, dst_time) = f_content(dst, dstname)
+
+ diff_u = difflib.unified_diff(src_content, dst_content,
+ src_name, dst_name,
+ src_time, dst_time)
+ return list(diff_u)
+
+
+
def maketemp(prefix=None, directory=None, symlink=None):
"""Creates a temporary file (guaranteed to be new), using the
specified prefix.
commit 4828118420bea4b17aef1d52c4a41d7f834beb1a
Author: Michael Mraka <michael.mraka(a)redhat.com>
Date: Wed Dec 22 10:34:30 2010 +0100
made exception block more readable
diff --git a/client/tools/rhncfg/config_client/rhncfgcli_get.py
b/client/tools/rhncfg/config_client/rhncfgcli_get.py
index cc17a96..4fe7b7e 100644
--- a/client/tools/rhncfg/config_client/rhncfgcli_get.py
+++ b/client/tools/rhncfg/config_client/rhncfgcli_get.py
@@ -67,67 +67,25 @@ class Handler(handler_base.TopdirHandlerBase):
dep_trans.deploy()
#5/3/05 wregglej - 136415 added missing user exception stuff.
except cfg_exceptions.UserNotFound, e:
- try:
- dep_trans.rollback()
- except FailedRollback:
- pass
- #5/3/05 wregglej - 136415 Added exception handling for missing user.
- except cfg_exceptions.UserNotFound, f:
- pass
- #5/5/05 wregglej - 136415 Added exception handling for unknown group
- except cfg_exceptions.GroupNotFound, f:
- pass
- print "Error: unable to deploy file %s, information on user '%s'
could not be found." % (e[0], f[0])
-
+ self.try_rollback(dep_trans, "Error unable to deploy file, information
on user '%s' could not be found" % e[0])
except cfg_exceptions.GroupNotFound, e:
- try:
- dep_trans.rollback()
- except FailedRollback:
- pass
- #5/3/05 wregglej - 136415 Added exception handling for missing user.
- except cfg_exceptions.UserNotFound, f:
- pass
- #5/5/05 wregglej - 136415 Added exception handling for unknown group
- except cfg_exceptions.GroupNotFound, f:
- pass
- print "Error: unable to deploy file %s, information on group
'%s' could not be found." % (e[0], f[0])
-
+ self.try_rollback(dep_trans, "Error: unable to deploy file, information
on group '%s' could not be found" % e[0])
except cfg_exceptions.FileEntryIsDirectory, e:
- try:
- dep_trans.rollback()
- except FailedRollback:
- pass
- #5/3/05 wregglej - 136415 Added exception handling for missing user.
- except cfg_exceptions.UserNotFound, f:
- pass
- #5/5/05 wregglej - 136415 Added exception handling for missing group
- except cfg_exceptions.GroupNotFound, f:
- pass
-
- print "Error: unable to deploy file %s, as it is already a directory on
disk" % (e[0],)
+ self.try_rollback(dep_trans, "Error: unable to deploy file %s, as it is
already a directory on disk" % e[0])
except cfg_exceptions.DirectoryEntryIsFile, e:
- try:
- dep_trans.rollback()
- except FailedRollback:
- pass
- #5/3/05 wregglej - 136415 Added exception handling for missin user
- except cfg_exceptions.UserNotFound, f:
- pass
- #5/5/05 wregglej - 136415 Added exception handling for unknown group
- except cfg_exceptions.GroupNotFound, f:
- pass
- print "Error: unable to deploy directory %s, as it is already a file on
disk" % (e[0],)
+ self.try_rollback(dep_trans, "Error: unable to deploy directory %s, as
it is already a file on disk" % e[0])
except Exception:
try:
- dep_trans.rollback()
- except FailedRollback:
+ self.try_rollback(dep_trans, "Deploy failed, rollback
successful")
+ except:
print "Failed rollback"
- except cfg_exceptions.UserNotFound, f:
- print "Failed rollback due to missing user info"
- #5/5/05 wregglej - 136415 Added exception handling for unknown group
- except cfg_exceptions.GroupNotFound, f:
- pass
- raise
- else:
- print "Deploy failed, rollback successful"
raise
+
+ def try_rollback(self, dep_trans, msg):
+ try:
+ dep_trans.rollback()
+ except (FailedRollback,
+ cfg_exceptions.UserNotFound,
+ cfg_exceptions.GroupNotFound), f:
+ pass
+ print msg
commit 15fe38653e1d8287731959a5510c4ff7313c6a17
Author: Michael Mraka <michael.mraka(a)redhat.com>
Date: Wed Dec 22 14:15:39 2010 +0100
664677 - fixed directory deployment under --topdir
diff --git a/client/tools/rhncfg/config_client/rhncfgcli_get.py
b/client/tools/rhncfg/config_client/rhncfgcli_get.py
index d19bb5e..cc17a96 100644
--- a/client/tools/rhncfg/config_client/rhncfgcli_get.py
+++ b/client/tools/rhncfg/config_client/rhncfgcli_get.py
@@ -39,11 +39,8 @@ class Handler(handler_base.TopdirHandlerBase):
for path in self.get_valid_files():
- (directory, filename) = os.path.split(path)
- directory = os.path.normpath("%s%s%s" % (topdir, os.sep,
directory))
-
try:
- finfo = self.repository.get_file_info(path, auto_delete=0,
dest_directory=directory)
+ finfo = self.repository.get_file_info(path, auto_delete=0,
dest_directory=topdir)
except cfg_exceptions.DirectoryEntryIsFile, e:
print "Error: unable to deploy directory %s, as it is already a file
on disk" % (e[0], )
continue
diff --git a/client/tools/rhncfg/config_client/rpc_cli_repository.py
b/client/tools/rhncfg/config_client/rpc_cli_repository.py
index 0d5cc0d..055663a 100644
--- a/client/tools/rhncfg/config_client/rpc_cli_repository.py
+++ b/client/tools/rhncfg/config_client/rpc_cli_repository.py
@@ -79,6 +79,7 @@ class ClientRepository(repository.RPC_Repository):
# Older servers will not return directories; if filetype is missing,
# assume file
if result.get('filetype') == 'directory':
+ result['path'] = dest_directory + result['path']
if os.path.isfile(result['path']):
raise cfg_exceptions.DirectoryEntryIsFile(result['path'])
else:
diff --git a/client/tools/rhncfg/config_common/file_utils.py
b/client/tools/rhncfg/config_common/file_utils.py
index 88cdfcb..5873bd5 100644
--- a/client/tools/rhncfg/config_common/file_utils.py
+++ b/client/tools/rhncfg/config_common/file_utils.py
@@ -14,7 +14,6 @@
#
import os
-import os.path
import time
import tempfile
import base64
@@ -39,6 +38,9 @@ class FileProcessor:
def process(self, file_struct, directory=None, strict_ownership=1):
# Older servers will not return directories; if filetype is missing,
# assume file
+ if directory:
+ directory += os.path.split(file_struct['path'])[0]
+
if file_struct.get('filetype') == 'directory':
return directory, []
commit f6db743f85057d42ec06f82fb16fed72795cf423
Author: Michael Mraka <michael.mraka(a)redhat.com>
Date: Mon Dec 20 13:37:04 2010 +0100
664677 - fixed symlink deployment under --topdir
diff --git a/client/tools/rhncfg/config_common/file_utils.py
b/client/tools/rhncfg/config_common/file_utils.py
index b22e855..88cdfcb 100644
--- a/client/tools/rhncfg/config_common/file_utils.py
+++ b/client/tools/rhncfg/config_common/file_utils.py
@@ -46,10 +46,9 @@ class FileProcessor:
if not file_struct.has_key('symlink'):
raise Exception, "Missing key symlink"
- (dirname, filename) = os.path.split(file_struct['path'])
- temppath = ".rhn-cfg-tmp_%s_%s_%.8f" % (filename, os.getpid(),
time.time())
- os.symlink(file_struct['symlink'], temppath)
- return temppath, []
+ (fullpath, dirs_created, fh) = maketemp(prefix=".rhn-cfg-tmp",
+ directory=directory,
symlink=file_struct['symlink'])
+ return fullpath, dirs_created
for k in self.file_struct_fields.keys():
if not file_struct.has_key(k):
@@ -128,7 +127,7 @@ class FileProcessor:
raise Exception, "Missing key %s" % k
-def maketemp(prefix=None, directory=None):
+def maketemp(prefix=None, directory=None, symlink=None):
"""Creates a temporary file (guaranteed to be new), using the
specified prefix.
@@ -148,4 +147,11 @@ def maketemp(prefix=None, directory=None):
file_prefix = "%s-%s-" % (prefix, os.getpid())
(fd, filename) = tempfile.mkstemp(prefix=file_prefix, dir=directory)
- return filename, dirs_created, os.fdopen(fd, "w+")
+ if symlink:
+ os.unlink(filename)
+ os.symlink(symlink, filename)
+ open_file = None
+ else:
+ open_file = os.fdopen(fd, "w+")
+
+ return filename, dirs_created, open_file
diff --git a/client/tools/rhncfg/config_common/transactions.py
b/client/tools/rhncfg/config_common/transactions.py
index 9582277..2fbed4f 100644
--- a/client/tools/rhncfg/config_common/transactions.py
+++ b/client/tools/rhncfg/config_common/transactions.py
@@ -186,8 +186,6 @@ class DeployTransaction:
# assume file
if file_info.get('filetype') == 'directory':
self.dirs.append(file_info)
- elif file_info.get('filetype') == 'symlink':
- self.files.append(file_info)
else:
self._chown_chmod_chcon(processed_file_path, dest_path, file_info,
strict_ownership=strict_ownership)