#61 Fix copying when compose path ends with slash
Merged 6 years ago by lsedlar. Opened 6 years ago by lsedlar.
lsedlar/compose-utils fix-partial-copy  into  master

@@ -28,17 +28,18 @@ 

              continue

  

          if not arches or (variant_arches & arches) == variant_arches:

-             paths.extend(_collect_variant(compose, variant, dest, arch=None))

+             paths.extend(_collect_variant(compose, variant, arch=None))

          else:

              for arch in variant_arches:

                  if arch not in arches:

                      continue

-                 paths.extend(_collect_variant(compose, variant, dest, arch=arch))

+                 paths.extend(_collect_variant(compose, variant, arch=arch))

  

+     compose_path = compose.compose_path.rstrip('/')

      paths = _reduce(compose, paths)

      for parent, children in paths.iteritems():

          sources = sorted([os.path.join(parent, child) for child in children])

-         destination = os.path.join(dest, parent.replace(compose.compose_path, '').lstrip('/'))

+         destination = os.path.join(dest, parent.replace(compose_path, '').lstrip('/'))

          _run_rsync(sources, destination, dry_run=dry_run, opts=rsync_opts)

  

      if not dry_run:
@@ -58,7 +59,7 @@ 

          shortcuts.run(cmd, stdout=True)

  

  

- def _collect_variant(compose, variant, dest, arch=None):

+ def _collect_variant(compose, variant, arch=None):

      """Find all paths in a variant that should be copied.

      If arch is not specified, that means all paths, otherwise only paths

      defined for the arch will be copied.

file modified
+3 -2
@@ -11,9 +11,10 @@ 

      return pth

  

  

- def get_compose(ident):

+ def get_compose(ident, path=None):

      """Load a test compose and return the Compose instance."""

-     return productmd.compose.Compose(get_compose_path(ident))

+     path = path or get_compose_path(ident)

+     return productmd.compose.Compose(path)

  

  

  def get_fixture(filename):

file modified
+13 -1
@@ -9,7 +9,7 @@ 

  

  from compose_utils import copy_compose

  

- from .helpers import get_compose

+ from .helpers import get_compose, get_compose_path

  

  

  class ChangelogTest(unittest.TestCase):
@@ -41,6 +41,18 @@ 

          self.assertComposeId()

  

      @mock.patch('kobo.shortcuts.run')

+     def test_copy_full_variant_from_explicit_path(self, mock_run):

+         self.compose = get_compose(get_compose_path('DP-1.0-20160315.t.0') + '/compose/')

+         copy_compose(self.compose, self.dest, variants=['Server'], arches=[])

+         self.assertItemsEqual(

+             mock_run.mock_calls,

+             [mock.call(['rsync', '-avHh',

+                         os.path.join(self.compose.compose_path, 'Server'),

+                         self.dest],

+                        stdout=True)])

+         self.assertComposeId()

+ 

+     @mock.patch('kobo.shortcuts.run')

      def test_copy_to_missing_dir(self, mock_run):

          self.dest = os.path.join(self.dest, 'missing', 'directory') + '/'

          copy_compose(self.compose, self.dest, variants=[], arches=[])