Dev server: Support image hosting for factory install.

Adds two new command-line options to the dev server:

--factory_config <filename>: If set, images will be returned according
to the configuration set in the filename. The format of this is
documented by example in sample_factory_server.conf.

--validate_factory_config: If this is set along w/ the previous
option, the checksums in the factory config will be verified.

Review URL: http://codereview.chromium.org/1596016
diff --git a/devserver.py b/devserver.py
index 58bb628..20aac06 100644
--- a/devserver.py
+++ b/devserver.py
@@ -7,8 +7,8 @@
 import optparse
 import os
 import SimpleHTTPServer
-import web
 import sys
+import web
 
 global updater
 updater = None
@@ -47,19 +47,30 @@
   parser = optparse.OptionParser(usage)
   parser.add_option('-a', '--archive_dir', dest='archive_dir',
                     help='serve archived builds only.')
+  parser.add_option('--factory_config', dest='factory_config',
+                    help='Config file for serving images from factory floor.')
   parser.add_option('-t', action='store_true', dest='test_image')
   parser.add_option('-u', '--urlbase', dest='urlbase',
                     help='base URL, other than devserver, for update images.')
+  parser.add_option('--validate_factory_config', action="store_true",
+                    dest='validate_factory_config',
+                    help='Validate factory config file, then exit.')
   options, args = parser.parse_args()
   # clean up the args, due to httpserver's hardcoded use of sys.argv
   if options.archive_dir:
     sys.argv.remove('-a')
+    sys.argv.remove('--archive_dir')
     sys.argv.remove(options.archive_dir)
+  if options.factory_config:
+    sys.argv.remove('--factory_config')
+    sys.argv.remove(options.factory_config)
   if options.test_image:
     sys.argv.remove('-t')
   if options.urlbase:
     sys.argv.remove('-u')
     sys.argv.remove(options.urlbase)
+  if options.validate_factory_config:
+    sys.argv.remove('--validate_factory_config')
 
   root_dir = os.path.realpath('%s/../..' %
                               os.path.dirname(os.path.abspath(sys.argv[0])))
@@ -74,11 +85,16 @@
     os.system('mkdir -p %s' % static_dir)
   web.debug('Serving images from %s' % static_dir)
 
-  updater = autoupdate.Autoupdate(root_dir=root_dir,
-                                  static_dir=static_dir,
-                                  serve_only=options.archive_dir,
-                                  urlbase=options.urlbase,
-                                  test_image=options.test_image)
+  updater = autoupdate.Autoupdate(
+      root_dir=root_dir,
+      static_dir=static_dir,
+      serve_only=options.archive_dir,
+      urlbase=options.urlbase,
+      test_image=options.test_image,
+      factory_config_path=options.factory_config,
+      validate_factory_config=options.validate_factory_config)
+  if options.validate_factory_config:
+    sys.exit(0)
   urls = ('/', 'index',
           '/update', 'update',
           '/update/(.+)', 'update',