Skip to content

Commit

Permalink
Fixed cli args parsing conflicting with conf file
Browse files Browse the repository at this point in the history
  • Loading branch information
gbrindisi committed Jul 18, 2012
1 parent c847417 commit bb851b4
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 12 deletions.
22 changes: 11 additions & 11 deletions wordpot.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,27 +10,27 @@
from wordpot import app
from wordpot.logger import *
from optparse import OptionParser
import os

def parse_options():
usage = "usage: %prog [options]"

parser = OptionParser(usage=usage)
parser.add_option('--host', dest='host', default='127.0.0.1', help='Host address')
parser.add_option('--port', dest='port', default='80', help='Port number')
parser.add_option('--title', dest='title', default='Random Ramblings', help='Blog title')
parser.add_option('--theme', dest='theme', default='twentyeleven', help='Default theme name')
parser.add_option('--ver', dest='version', default='2.8', help='Wordpress version')
parser.add_option('--host', dest='HOST', help='Host address')
parser.add_option('--port', dest='PORT', help='Port number')
parser.add_option('--title', dest='BLOGTITLE', help='Blog title')
parser.add_option('--theme', dest='THEME', help='Default theme name')
parser.add_option('--ver', dest='VERSION', help='Wordpress version')

(options, args) = parser.parse_args()

app.config['HOST'] = options.host
app.config['PORT'] = options.port
app.config['BLOGTITLE'] = options.title
app.config['THEME'] = options.theme
app.config['VERSION'] = options.version
for opt, val in options.__dict__.iteritems():
if val is not None:
app.config[opt] = val

# Import config from file
app.config.from_pyfile('../wordpot.conf')
conffile = os.path.join(os.path.dirname(__file__), '../wordpot.conf')
app.config.from_pyfile(conffile)

# Setup logging before execute the main
logging_setup()
Expand Down
4 changes: 3 additions & 1 deletion wordpot/logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from wordpot import app
import logging
import logging.handlers
import os

LOGGER = logging.getLogger('wordpot-logger')

Expand All @@ -11,7 +12,8 @@ def logging_setup():
formatter = logging.Formatter('%(asctime)s - %(message)s')

# File handler
fh = logging.handlers.RotatingFileHandler('logs/wordpot.log', 'a', 2097152, 10)
logfile = os.path.join(os.path.dirname(__file__), '../logs/wordpot.log')
fh = logging.handlers.RotatingFileHandler(logfile, 'a', 2097152, 10)
fh.setFormatter(formatter)

# Add handlers
Expand Down

0 comments on commit bb851b4

Please sign in to comment.