Added regexp support in rsync_ls*

Change-Id: I71c51518acdc17fa1552a84ac5892c6084cbc0f6
diff --git a/rsync_client.py b/rsync_client.py
index 05991f9..e9e569b 100644
--- a/rsync_client.py
+++ b/rsync_client.py
@@ -4,6 +4,7 @@
 
 import datetime
 import os
+import re
 import subprocess
 import tempfile
 
@@ -114,23 +115,32 @@
         cmd = 'rsync {opts} {extra} {source} {dest}'.format(**(locals()))
         return self._shell(cmd)
 
-    def rsync_ls(self, dirname=None):
+    def _rsync_ls(self, dirname=None, pattern=r'.*', opts=''):
         if dirname is None:
             dirname = '{}/'.format(self.root_path)
         dest = '{}/{}'.format(self.url, dirname)
-        opts = '-l'
         extra = self.rsync_extra_params + ' --no-v'
         exitcode, out, err = self._do_rsync(dest=dest, opts=opts, extra=extra)
-        out = [_ for _ in out.splitlines() if _.split()[-1] != '.']
+        regexp = re.compile(pattern)
+        out = [_ for _ in out.splitlines()
+               if (_.split()[-1] != '.') and
+               (regexp.match(_.split()[-1]) is not None)]
         return exitcode, out, err
 
-    def rsync_ls_dirs(self, dirname):
-        exitcode, out, err = self.rsync_ls(dirname)
+    def rsync_ls(self, dirname, pattern=r'.*'):
+        exitcode, out, err = self._rsync_ls(dirname, pattern=pattern)
+        out = [_.split()[-1] for _ in out]
+        return exitcode, out, err
+
+    def rsync_ls_dirs(self, dirname, pattern=r'.*'):
+        exitcode, out, err = self._rsync_ls(dirname, pattern=pattern)
         out = [_.split()[-1] for _ in out if _.startswith('d')]
         return exitcode, out, err
 
-    def rsync_ls_symlinks(self, dirname):
-        exitcode, out, err = self.rsync_ls(dirname)
+    def rsync_ls_symlinks(self, dirname, pattern=r'.*'):
+        exitcode, out, err = self._rsync_ls(dirname,
+                                            pattern=pattern,
+                                            opts='-l')
         out = [_.split()[-3:] for _ in out if _.startswith('l')]
         out = [[_[0], _[-1]] for _ in out]
         return exitcode, out, err