changeset 46:66bfcceea3b4

improvements to blogme....it works except for a mysterious conncection reset by peer error"
author k0s <k0scist@gmail.com>
date Tue, 24 Nov 2009 20:44:49 -0500
parents c228832db770
children f2b8204237dc
files bitsyblog/blogme.py
diffstat 1 files changed, 15 insertions(+), 13 deletions(-) [+]
line wrap: on
line diff
--- a/bitsyblog/blogme.py	Tue Nov 24 19:20:47 2009 -0500
+++ b/bitsyblog/blogme.py	Tue Nov 24 20:44:49 2009 -0500
@@ -77,29 +77,31 @@
 
     # get default host, if available
     if options.host:
-        if config.has_option('DEFAULTS', 'host'):
-            print "Make %s the default host? (Y/n): ",
-            answer = raw_input()
-            if not anwer.lower().startswith('n'):
-                _config['default'] = options.host
+        if not config.has_option('DEFAULTS', 'host'):
+            _config['default'] = options.host
     else:
         if config.has_option('DEFAULTS', 'host'):
             options.host = config.get('DEFAULTS', 'host')
         else:
             print "Enter URL of host: ",
-            host = raw_input()
-            _config['default'] = host
+            options.host = raw_input()
+            _config['default'] = options.host
 
     # determine user name and password
     fields = [ 'user', 'password' ]
     for field in fields:
-        if hasattr(options, field):
-            if (not config.has_option(options.host, field)) or (config.get(options.host, field) != getattr(options, field)):
+        has_option = config.has_option(options.host, field) 
+
+        if getattr(options, field):
+            if (not has_option) or (config.get(options.host, field) != getattr(options, field)):
                 _config[field] = getattr(options, field)
         else:
-            print "%s: " % field, 
-            setattr(options, field, raw_input())
-            _config[field] = getattr(options, field)
+            if has_option:
+                setattr(options, field, config.get(options.host, field))
+            else:
+                print "%s: " % field, 
+                setattr(options, field, raw_input())
+                _config[field] = getattr(options, field)
 
     # write the dotfile if it doesn't exist
     if _config:
@@ -112,7 +114,7 @@
         for field in fields:
             if not config.has_option(options.host, field):
                 config.set(options.host, field, getattr(options, field))
-        config.write()
+        config.write(file(options.config, 'w'))
 
     # get the blog
     if args: