#######################################################################
# This file is part of Pyblosxom.
#
# Copyright (C) 2008-2011 by the Pyblosxom team.  See AUTHORS.
#
# Pyblosxom is distributed under the MIT license.  See the file
# LICENSE for distribution details.
#######################################################################

"""
This module holds commandline related stuff.  Installation
verification, blog creation, commandline argument parsing, ...
"""

import os
import os.path
import sys
import random
import time
from optparse import OptionParser

from Pyblosxom import __version__
from Pyblosxom.pyblosxom import Pyblosxom
from Pyblosxom.tools import run_callback, pwrap, pwrap_error
from Pyblosxom import plugin_utils

USAGE = "%prog [options] [command] [command-options]"
VERSION = "%prog " + __version__


def build_pyblosxom():
    """Imports config.py and builds an empty Pyblosxom object.
    """
    pwrap("Trying to import the config module....")
    try:
        from config import py as cfg
    except StandardError:
        h, t = os.path.split(sys.argv[0])
        script_name = t or h

        pwrap_error("ERROR: Cannot find your config.py file.  Please execute "
                    "%s in the directory with the config.py file in it or use "
                    "the --config flag.\n\n"
                    "See \"%s --help\" for more details." % (script_name,
                                                             script_name))
        return None

    return Pyblosxom(cfg, {})


def build_parser(usage):