From a95da60f7d33fb510506dff3110e156510437db6 Mon Sep 17 00:00:00 2001 From: Diane Trout Date: Sun, 30 Dec 2007 23:28:17 +0000 Subject: [PATCH] split rsync directory listing correctly ticket:5 My previous code was generating a too many values to unpack exception if there was a filename with spaces in it. --- gaworkflow/copier.py | 10 ++++++++-- test/test_copier.py | 15 +++++++++++++++ 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/gaworkflow/copier.py b/gaworkflow/copier.py index 9420208..f59eafb 100644 --- a/gaworkflow/copier.py +++ b/gaworkflow/copier.py @@ -32,13 +32,19 @@ class rsync(object): def list(self): """Get a directory listing""" - dirs_to_copy = [] args = copy.copy(self.cmd) args.append(self.source_base) logging.debug("Rsync cmd:" + " ".join(args)) short_process = subprocess.Popen(args, stdout=subprocess.PIPE) - direntries = [ x.split() for x in short_process.stdout ] + return self.list_parser(short_process.stdout) + + def list_filter(self, lines): + """ + parse rsync directory listing + """ + dirs_to_copy = [] + direntries = [ x[0:42].split() + [x[43:]] for x in lines ] for permissions, size, filedate, filetime, filename in direntries: if permissions[0] == 'd': # hey its a directory, the first step to being something we want to diff --git a/test/test_copier.py b/test/test_copier.py index 2cb92f0..a67df2e 100644 --- a/test/test_copier.py +++ b/test/test_copier.py @@ -42,6 +42,21 @@ notify_users: user3@example.fake self.failUnlessEqual(len(c.notify_users), 1) self.failUnlessEqual(c.notify_users[0], 'user3@example.fake') + def test_dirlist_filter(self): + """ + test our dir listing parser + """ + # everyone should have a root dir, and since we're not + # currently writing files... it should all be good + r = copier.rsync('/', '/', '/') + + listing = [ + '-rwxrw-r-- 123268 2007/12/29 17:39:31 2038EAAXX.rtf', + '-rwxrw-r-- 6 2007/12/29 15:10:29 New Text Document.txt', + ] + + result = r.list_filter(listing) + def suite(): return unittest.makeSuite(testCopier,'test') -- 2.30.2