comparison bitsyblog/blogme.py @ 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 04866e5abb5a
comparison
equal deleted inserted replaced
45:c228832db770 46:66bfcceea3b4
75 if os.path.exists(options.config): 75 if os.path.exists(options.config):
76 config.read(options.config) 76 config.read(options.config)
77 77
78 # get default host, if available 78 # get default host, if available
79 if options.host: 79 if options.host:
80 if config.has_option('DEFAULTS', 'host'): 80 if not config.has_option('DEFAULTS', 'host'):
81 print "Make %s the default host? (Y/n): ", 81 _config['default'] = options.host
82 answer = raw_input()
83 if not anwer.lower().startswith('n'):
84 _config['default'] = options.host
85 else: 82 else:
86 if config.has_option('DEFAULTS', 'host'): 83 if config.has_option('DEFAULTS', 'host'):
87 options.host = config.get('DEFAULTS', 'host') 84 options.host = config.get('DEFAULTS', 'host')
88 else: 85 else:
89 print "Enter URL of host: ", 86 print "Enter URL of host: ",
90 host = raw_input() 87 options.host = raw_input()
91 _config['default'] = host 88 _config['default'] = options.host
92 89
93 # determine user name and password 90 # determine user name and password
94 fields = [ 'user', 'password' ] 91 fields = [ 'user', 'password' ]
95 for field in fields: 92 for field in fields:
96 if hasattr(options, field): 93 has_option = config.has_option(options.host, field)
97 if (not config.has_option(options.host, field)) or (config.get(options.host, field) != getattr(options, field)): 94
95 if getattr(options, field):
96 if (not has_option) or (config.get(options.host, field) != getattr(options, field)):
98 _config[field] = getattr(options, field) 97 _config[field] = getattr(options, field)
99 else: 98 else:
100 print "%s: " % field, 99 if has_option:
101 setattr(options, field, raw_input()) 100 setattr(options, field, config.get(options.host, field))
102 _config[field] = getattr(options, field) 101 else:
102 print "%s: " % field,
103 setattr(options, field, raw_input())
104 _config[field] = getattr(options, field)
103 105
104 # write the dotfile if it doesn't exist 106 # write the dotfile if it doesn't exist
105 if _config: 107 if _config:
106 if 'default' in _config: 108 if 'default' in _config:
107 if not config.has_section('DEFAULTS'): 109 if not config.has_section('DEFAULTS'):
110 if not config.has_section(options.host): 112 if not config.has_section(options.host):
111 config.add_section(options.host) 113 config.add_section(options.host)
112 for field in fields: 114 for field in fields:
113 if not config.has_option(options.host, field): 115 if not config.has_option(options.host, field):
114 config.set(options.host, field, getattr(options, field)) 116 config.set(options.host, field, getattr(options, field))
115 config.write() 117 config.write(file(options.config, 'w'))
116 118
117 # get the blog 119 # get the blog
118 if args: 120 if args:
119 msg = ' '.join(args) 121 msg = ' '.join(args)
120 else: 122 else: