Пример #1
0
 def testUnion(self):
     paths = []
     for i in xrange(10):
         paths.append(gc.Path("/foo", i))
     f = gc.union(gc.largest_export_versions(3), gc.mod_export_version(3))
     self.assertEqual(f(paths), [
         gc.Path("/foo", 0),
         gc.Path("/foo", 3),
         gc.Path("/foo", 6),
         gc.Path("/foo", 7),
         gc.Path("/foo", 8),
         gc.Path("/foo", 9)
     ])
Пример #2
0
def get_most_recent_export(export_dir_base):
    """Locate the most recent SavedModel export in a directory of many exports.

  This method assumes that SavedModel subdirectories are named as a timestamp
  (seconds from epoch), as produced by get_timestamped_export_dir().

  Args:
    export_dir_base: A base directory containing multiple timestamped
                     directories.

  Returns:
    A gc.Path, with is just a namedtuple of (path, export_version).
  """
    select_filter = gc.largest_export_versions(1)
    results = select_filter(
        gc.get_paths(export_dir_base, parser=_export_version_parser))
    return next(iter(results or []), None)
Пример #3
0
def garbage_collect_exports(export_dir_base, exports_to_keep):
    """Deletes older exports, retaining only a given number of the most recent.

  Export subdirectories are assumed to be named with monotonically increasing
  integers; the most recent are taken to be those with the largest values.

  Args:
    export_dir_base: the base directory under which each export is in a
      versioned subdirectory.
    exports_to_keep: the number of recent exports to retain.
  """
    if exports_to_keep is None:
        return

    keep_filter = gc.largest_export_versions(exports_to_keep)
    delete_filter = gc.negation(keep_filter)
    for p in delete_filter(
            gc.get_paths(export_dir_base, parser=_export_version_parser)):
        try:
            gfile.DeleteRecursively(p.path)
        except errors_impl.NotFoundError as e:
            logging.warn('Can not delete %s recursively: %s', p.path, e)
Пример #4
0
 def testLargestExportVersionsDoesNotDeleteZeroFolder(self):
     paths = [gc.Path("/foo", 0), gc.Path("/foo", 3)]
     newest = gc.largest_export_versions(2)
     n = newest(paths)
     self.assertEqual(n, [gc.Path("/foo", 0), gc.Path("/foo", 3)])
Пример #5
0
 def testLargestExportVersions(self):
     paths = [gc.Path("/foo", 8), gc.Path("/foo", 9), gc.Path("/foo", 10)]
     newest = gc.largest_export_versions(2)
     n = newest(paths)
     self.assertEqual(n, [gc.Path("/foo", 9), gc.Path("/foo", 10)])