Add --serial option to main program of host controller
am: 18ee53c6f8

Change-Id: I7caf06817b516906afb09b577b8a065e8b2044c5
diff --git a/harnesses/host_controller/console.py b/harnesses/host_controller/console.py
index ebccdb4..dc399f4 100644
--- a/harnesses/host_controller/console.py
+++ b/harnesses/host_controller/console.py
@@ -160,6 +160,11 @@
         self.update_thread = None
         self.fetch_info = {}
 
+        if _ANDROID_SERIAL in os.environ:
+            self._serials = [os.environ[_ANDROID_SERIAL]]
+        else:
+            self._serials = []
+
         self.InitCommandModuleParsers()
         self.SetUpCommandProcessors()
 
@@ -231,14 +236,6 @@
 
         script_module = imp.load_source('script_module', script_file_path)
 
-        if _ANDROID_SERIAL in os.environ:
-            serial = os.environ[_ANDROID_SERIAL]
-        else:
-            serial = None
-
-        if serial:
-            self.onecmd("device --set_serial=%s" % serial)
-
         commands = script_module.EmitConsoleCommands()
         if commands:
             for command in commands:
@@ -1108,7 +1105,14 @@
             default=False,
             type=bool,
             help="Whether to lease jobs and execute them.")
-        self._serials = []
+
+    def SetSerials(self, serials):
+        """Sets the default serial numbers for flashing and testing.
+
+        Args:
+            serials: A list of strings, the serial numbers.
+        """
+        self._serials = serials
 
     def GetSerials(self):
         """Returns the serial numbers saved in the console.
@@ -1210,7 +1214,7 @@
         """Sets device info such as serial number."""
         args = self._device_parser.ParseLine(line)
         if args.set_serial:
-            self._serials = args.set_serial.split(",")
+            self.SetSerials(args.set_serial.split(","))
             print("serials: %s" % self._serials)
         if args.update:
             if args.host is None:
diff --git a/harnesses/host_controller/main.py b/harnesses/host_controller/main.py
index 0a5bb6c..7d6ef24 100644
--- a/harnesses/host_controller/main.py
+++ b/harnesses/host_controller/main.py
@@ -108,6 +108,11 @@
     parser.add_argument("--script",
                         default=None,
                         help="The path to a script file in .py format")
+    parser.add_argument("--serial",
+                        default=None,
+                        help="The default serial numbers for flashing and "
+                             "testing in the console. Multiple serial numbers "
+                             "are separated by comma.")
     parser.add_argument("--loop",
                         default=None,
                         metavar="INTERVAL",
@@ -182,6 +187,8 @@
     else:
         main_console = console.Console(vti_endpoint, tfc, pab, hosts)
         try:
+            if args.serial:
+                main_console.SetSerials(args.serial.split(","))
             if args.script:
                 if args.loop is None:
                     main_console.ProcessScript(args.script)