<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array"/>
  <modified type="array">
    <modified>
      <diff>@@ -1,3 +1,4 @@
+*.tmproj
 *.pyc
 *.so
 *~</diff>
      <filename>.gitignore</filename>
    </modified>
    <modified>
      <diff>@@ -36,6 +36,11 @@ or parse a config file with:
     import tornado.options
     tornado.options.parse_config_file(&quot;/etc/server.conf&quot;)
     tornado.options.parse_command_line()
+    
+Config files - you can pass a config file in command line, or create one:
+
+    $python facebook.py --makeconfig=./facebook.conf
+    $python facebook.py --config=./facebook.conf
 
 Command line formats are what you would expect (&quot;--myoption=myvalue&quot;).
 Config files are just Python files. Global names become options, e.g.,
@@ -53,6 +58,7 @@ import logging
 import re
 import sys
 import time
+import os
 
 # For pretty log messages, if available
 try:
@@ -96,10 +102,11 @@ def define(name, default=None, type=str, help=None, metavar=None,
 
 def parse_command_line(args=None):
     &quot;&quot;&quot;Parses all options given on the command line.
-
+    
     We return all command line arguments that are not options as a list.
     &quot;&quot;&quot;
     if args is None: args = sys.argv
+    cmd_options = {}
     for i in xrange(1, len(args)):
         # All things after the last option are command line arguments
         if not args[i].startswith(&quot;-&quot;):
@@ -118,15 +125,27 @@ def parse_command_line(args=None):
                 value = &quot;true&quot;
             else:
                 raise Error('Option %r requires a value' % name)
+        cmd_options[name] = value
         option.parse(value)
+    
     if options.help:
         print_help()
         sys.exit(0)
-
+    
+    if options.config:
+        parse_config_file(options.config)
+        # command line override config file
+        for key in cmd_options.keys():
+            options[key].parse(cmd_options[key])
+    
+    if options.makeconfig:
+        print_config(options.makeconfig)
+        sys.exit(0)
+    
     # Set up log level and pretty console logging by default
     logging.getLogger().setLevel(getattr(logging, options.logging.upper()))
     enable_pretty_logging()
-
+    
     return []
 
 
@@ -134,10 +153,32 @@ def parse_config_file(path, overwrite=True):
     &quot;&quot;&quot;Parses and loads the Python config file at the given path.&quot;&quot;&quot;
     config = {}
     execfile(path, config, config)
-    for name in config:
-        if name in options:
-            options[name].set(config[name])
+    if config:
+        for name in config:
+            if name in options:
+                options[name].parse(config[name])
 
+def print_config(path=&quot;./app.conf&quot;):
+    &quot;&quot;&quot;Prints default config file to file&quot;&quot;&quot;
+    by_file = {}
+    file = open(path,'w')
+    for option in options.itervalues():
+        by_file.setdefault(option.file_name, []).append(option)
+    
+    out = &quot;&quot;
+    for filename, o in sorted(by_file.items()):
+        if filename: out += &quot;\n# --- %s ---\n&quot; % filename
+        o.sort(key=lambda option: option.name)
+        for option in o:
+            if option.name not in ['help','config','makeconfig']:
+                metavar = &quot;&quot;
+                if option.metavar:
+                    metavar = &quot;# &quot; + option.metavar
+                out += '#%s\n%s = &quot;%s&quot;  %s\n' %  (option.help, \
+                    option.name,option.default,metavar)
+    file.write(out)
+    file.close()
+    print(&quot;Config file created at %s&quot; % path)
 
 def print_help(file=sys.stdout):
     &quot;&quot;&quot;Prints all the command line options to stdout.&quot;&quot;&quot;
@@ -196,6 +237,7 @@ class _Option(object):
             datetime.timedelta: self._parse_timedelta,
             bool: self._parse_bool,
             str: self._parse_string,
+            int: self._parse_int
         }.get(self.type, self.type)
         if self.multiple:
             if self._value is None:
@@ -289,6 +331,9 @@ class _Option(object):
     def _parse_bool(self, value):
         return value.lower() not in (&quot;false&quot;, &quot;0&quot;, &quot;f&quot;)
 
+    def _parse_int(self, value):
+        return int(value)
+    
     def _parse_string(self, value):
         return value.decode(&quot;utf-8&quot;)
 
@@ -345,6 +390,9 @@ options = _Options.instance()
 
 
 # Default options
+define(&quot;makeconfig&quot;, type=str,default=None, 
+    help=&quot;write out config file such as app.conf&quot;)
+define(&quot;config&quot;, help=&quot;config file to load before command line options&quot;)
 define(&quot;help&quot;, type=bool, help=&quot;show this help information&quot;)
 define(&quot;logging&quot;, default=&quot;info&quot;, help=&quot;set the Python log level&quot;,
        metavar=&quot;info|warning|error&quot;)</diff>
      <filename>tornado/options.py</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>1cff257b13f71ae01d012f41788743126900bdf4</id>
    </parent>
  </parents>
  <author>
    <name>Aaron Raddon</name>
    <email>araddon@yahoo.com</email>
  </author>
  <url>http://github.com/araddon/tornado/commit/3e90852ec4059a9f625c4e162572b81b3d881abc</url>
  <id>3e90852ec4059a9f625c4e162572b81b3d881abc</id>
  <committed-date>2009-11-07T09:16:30-08:00</committed-date>
  <authored-date>2009-11-07T09:16:30-08:00</authored-date>
  <message>config options to create config files, and load one from command line</message>
  <tree>3914fd43a718a9e2f15c01fb2e0218ed1b43cafe</tree>
  <committer>
    <name>Aaron Raddon</name>
    <email>araddon@yahoo.com</email>
  </committer>
</commit>
