#6041: sdist and register now use the check command. No more duplicate code for metadata checking
diff --git a/Lib/distutils/command/sdist.py b/Lib/distutils/command/sdist.py
index ab0ada1..c21f391 100644
--- a/Lib/distutils/command/sdist.py
+++ b/Lib/distutils/command/sdist.py
@@ -8,6 +8,8 @@
 import sys
 from types import *
 from glob import glob
+from warnings import warn
+
 from distutils.core import Command
 from distutils import dir_util, dep_util, file_util, archive_util
 from distutils.text_file import TextFile
@@ -34,6 +36,12 @@
 
     description = "create a source distribution (tarball, zip file, etc.)"
 
+    def checking_metadata(self):
+        """Callable used for the check sub-command.
+
+        Placed here so user_options can view it"""
+        return self.metadata_check
+
     user_options = [
         ('template=', 't',
          "name of manifest template file [default: MANIFEST.in]"),
@@ -63,11 +71,14 @@
         ('dist-dir=', 'd',
          "directory to put the source distribution archive(s) in "
          "[default: dist]"),
+        ('medata-check', None,
+         "Ensure that all required elements of meta-data "
+         "are supplied. Warn if any missing. [default]"),
         ]
 
     boolean_options = ['use-defaults', 'prune',
                        'manifest-only', 'force-manifest',
-                       'keep-temp']
+                       'keep-temp', 'metadata-check']
 
     help_options = [
         ('help-formats', None,
@@ -80,6 +91,8 @@
     default_format = {'posix': 'gztar',
                       'nt': 'zip' }
 
+    sub_commands = [('check', checking_metadata)]
+
     def initialize_options(self):
         # 'template' and 'manifest' are, respectively, the names of
         # the manifest template and manifest file.
@@ -99,6 +112,7 @@
         self.dist_dir = None
 
         self.archive_files = None
+        self.metadata_check = 1
 
     def finalize_options(self):
         if self.manifest is None:
@@ -128,9 +142,9 @@
         # manifest
         self.filelist = FileList()
 
-        # Ensure that all required meta-data is given; warn if not (but
-        # don't die, it's not *that* serious!)
-        self.check_metadata()
+        # Run sub commands
+        for cmd_name in self.get_sub_commands():
+            self.run_command(cmd_name)
 
         # Do whatever it takes to get the list of files to process
         # (process the manifest template, read an existing manifest,
@@ -146,34 +160,12 @@
         self.make_distribution()
 
     def check_metadata(self):
-        """Ensure that all required elements of meta-data (name, version,
-        URL, (author and author_email) or (maintainer and
-        maintainer_email)) are supplied by the Distribution object; warn if
-        any are missing.
-        """
-        metadata = self.distribution.metadata
-
-        missing = []
-        for attr in ('name', 'version', 'url'):
-            if not (hasattr(metadata, attr) and getattr(metadata, attr)):
-                missing.append(attr)
-
-        if missing:
-            self.warn("missing required meta-data: " +
-                      string.join(missing, ", "))
-
-        if metadata.author:
-            if not metadata.author_email:
-                self.warn("missing meta-data: if 'author' supplied, " +
-                          "'author_email' must be supplied too")
-        elif metadata.maintainer:
-            if not metadata.maintainer_email:
-                self.warn("missing meta-data: if 'maintainer' supplied, " +
-                          "'maintainer_email' must be supplied too")
-        else:
-            self.warn("missing meta-data: either (author and author_email) " +
-                      "or (maintainer and maintainer_email) " +
-                      "must be supplied")
+        """Deprecated API."""
+        warn("distutils.command.sdist.check_metadata is deprecated, \
+              use the check command instead", PendingDeprecationWarning)
+        check = self.distribution.get_command_obj('check')
+        check.ensure_finalized()
+        check.run()
 
     def get_file_list(self):
         """Figure out the list of files to include in the source