Added command --add-platform

This command does the same as mtreplay -a but at the end also adds a
folder for the test cases in the tests directory with a platform.props
file pointing to the newly created platform in mttools/platforms.

BUG=chromium:353779
TEST=None

Change-Id: I528ef689a01f6433a04031d9ea3b4a5175b23209
Reviewed-on: https://chromium-review.googlesource.com/194990
Reviewed-by: Andrew de los Reyes <adlr@chromium.org>
Tested-by: Dennis Kempin <denniskempin@chromium.org>
Commit-Queue: Dennis Kempin <denniskempin@chromium.org>
diff --git a/framework/src/main.py b/framework/src/main.py
index 1d3f786..8bc32e6 100644
--- a/framework/src/main.py
+++ b/framework/src/main.py
@@ -15,7 +15,7 @@
 import sys
 
 from mtedit import MTEdit
-from mtlib.log import Log
+from mtlib import Log, PlatformDatabase
 
 from table import Table
 from test_case import TestCase
@@ -224,6 +224,15 @@
   if case:
     print "Test \"" + case.name + "\" created"
 
+def AddPlatform(ip):
+  name = PlatformDatabase.RegisterPlatformFromDevice(ip)
+  if not name:
+    return
+  dirname = os.path.join(os.environ["TESTS_DIR"], name)
+  propsfile = os.path.join(dirname, "platform.props")
+  os.mkdir(dirname)
+  open(propsfile, "w").write("{\"platform\": \"%s\"}" % name)
+  print " ", propsfile
 
 def Main():
   """
@@ -287,11 +296,18 @@
   parser.add_option("--slow",
                     dest="slow", action="store_true", default=False,
                     help="(use with --robot) Force slow movement.")
+  parser.add_option("--add-platform",
+                    dest="add_platform", default=None,
+                    help="add platform from IP address of remote device.")
 
   (options, args) = parser.parse_args()
   options.download = False  # For compatibility with mtedit
   options.screenshot = False  # For compatibility with mtedit
 
+  if options.add_platform:
+    AddPlatform(options.add_platform)
+    return
+
   if len(args) == 0:
     test_name = "all"
   elif len(args) == 1: