'Constructor.
:param fname: a shortcut allowing to instantiate :class:`configmanager`
from Python code without resorting to environment
variable'

def __init__(self, fname=None):

    self.options = {'admin_passwd': 'admin', 'csv_internal_sep': ',', 'publisher_warranty_url': 'http://services.openerp.com/publisher-warranty/', 'reportgz': False, 'root_path': None}
    self.blacklist_for_save = set(['publisher_warranty_url', 'load_language', 'root_path', 'init', 'save', 'config', 'update', 'stop_after_init', 'dev_mode', 'shell_interface'])
    self.casts = {}
    self.misc = {}
    self.config_file = fname
    self._LOGLEVELS = dict([(getattr(loglevels, ('LOG_%s' % x)), getattr(logging, x)) for x in ('CRITICAL', 'ERROR', 'WARNING', 'INFO', 'DEBUG', 'NOTSET')])
    version = ('%s    %s' % (release.description, release.version))
    self.parser = parser = optparse.OptionParser(version=version, option_class=MyOption)
    group = optparse.OptionGroup(parser, 'Common    options')
    group.add_option('-c', '--config', dest='config', help='specify    alternate    config    file')
    group.add_option('-s', '--save', action='store_true', dest='save', default=False, help='save    configuration    to    ~/.odoorc    (or    to    ~/.openerp_serverrc    if    it    exists)')
    group.add_option('-i', '--init', dest='init', help='install    one    or    more    modules    (comma-separated    list,    use    "all"    for    all    modules),    requires    -d')
    group.add_option('-u', '--update', dest='update', help='update    one    or    more    modules    (comma-separated    list,    use    "all"    for    all    modules).    Requires    -d.')
    group.add_option('--without-demo', dest='without_demo', help='disable    loading    demo    data    for    modules    to    be    installed    (comma-separated,    use    "all"    for    all    modules).    Requires    -d    and    -i.    Default    is    %default', my_default=False)
    group.add_option('-P', '--import-partial', dest='import_partial', my_default='', help='Use    this    for    big    data    importation,    if    it    crashes    you    will    be    able    to    continue    at    the    current    state.    Provide    a    filename    to    store    intermediate    importation    states.')
    group.add_option('--pidfile', dest='pidfile', help='file    where    the    server    pid    will    be    stored')
    group.add_option('--addons-path', dest='addons_path', help='specify    additional    addons    paths    (separated    by    commas).', action='callback', callback=self._check_addons_path, nargs=1, type='string')
    group.add_option('--load', dest='server_wide_modules', help='Comma-separated    list    of    server-wide    modules.', my_default='web,web_kanban')
    group.add_option('-D', '--data-dir', dest='data_dir', my_default=_get_default_datadir(), help='Directory    where    to    store    Odoo    data')
    parser.add_option_group(group)
    group = optparse.OptionGroup(parser, 'XML-RPC    Configuration')
    group.add_option('--xmlrpc-interface', dest='xmlrpc_interface', my_default='', help='Specify    the    TCP    IP    address    for    the    XML-RPC    protocol.    The    empty    string    binds    to    all    interfaces.')
    group.add_option('--xmlrpc-port', dest='xmlrpc_port', my_default=8069, help='specify    the    TCP    port    for    the    XML-RPC    protocol', type='int')
    group.add_option('--no-xmlrpc', dest='xmlrpc', action='store_false', my_default=True, help='disable    the    XML-RPC    protocol')
    group.add_option('--proxy-mode', dest='proxy_mode', action='store_true', my_default=False, help='Enable    correct    behavior    when    behind    a    reverse    proxy')
    group.add_option('--longpolling-port', dest='longpolling_port', my_default=8072, help='specify    the    TCP    port    for    longpolling    requests', type='int')
    parser.add_option_group(group)
    group = optparse.OptionGroup(parser, 'Web    interface    Configuration')
    group.add_option('--db-filter', dest='dbfilter', my_default='.*', help='Filter    listed    database', metavar='REGEXP')
    parser.add_option_group(group)
    group = optparse.OptionGroup(parser, 'Testing    Configuration')
    group.add_option('--test-file', dest='test_file', my_default=False, help='Launch    a    python    or    YML    test    file.')
    group.add_option('--test-report-directory', dest='test_report_directory', my_default=False, help='If    set,    will    save    sample    of    all    reports    in    this    directory.')
    group.add_option('--test-enable', action='store_true', dest='test_enable', my_default=False, help='Enable    YAML    and    unit    tests.')
    group.add_option('--test-commit', action='store_true', dest='test_commit', my_default=False, help='Commit    database    changes    performed    by    YAML    or    XML    tests.')
    parser.add_option_group(group)
    group = optparse.OptionGroup(parser, 'Logging    Configuration')
    group.add_option('--logfile', dest='logfile', help='file    where    the    server    log    will    be    stored')
    group.add_option('--logrotate', dest='logrotate', action='store_true', my_default=False, help='enable    logfile    rotation')
    group.add_option('--syslog', action='store_true', dest='syslog', my_default=False, help='Send    the    log    to    the    syslog    server')
    group.add_option('--log-handler', action='append', default=[], my_default=DEFAULT_LOG_HANDLER, metavar='PREFIX:LEVEL', help='setup    a    handler    at    LEVEL    for    a    given    PREFIX.    An    empty    PREFIX    indicates    the    root    logger.    This    option    can    be    repeated.    Example:    "odoo.orm:DEBUG"    or    "werkzeug:CRITICAL"    (default:    ":INFO")')
    group.add_option('--log-request', action='append_const', dest='log_handler', const='odoo.http.rpc.request:DEBUG', help='shortcut    for    --log-handler=odoo.http.rpc.request:DEBUG')
    group.add_option('--log-response', action='append_const', dest='log_handler', const='odoo.http.rpc.response:DEBUG', help='shortcut    for    --log-handler=odoo.http.rpc.response:DEBUG')
    group.add_option('--log-web', action='append_const', dest='log_handler', const='odoo.http:DEBUG', help='shortcut    for    --log-handler=odoo.http:DEBUG')
    group.add_option('--log-sql', action='append_const', dest='log_handler', const='odoo.sql_db:DEBUG', help='shortcut    for    --log-handler=odoo.sql_db:DEBUG')
    group.add_option('--log-db', dest='log_db', help='Logging    database', my_default=False)
    group.add_option('--log-db-level', dest='log_db_level', my_default='warning', help='Logging    database    level')
    levels = ['info', 'debug_rpc', 'warn', 'test', 'critical', 'debug_sql', 'error', 'debug', 'debug_rpc_answer', 'notset']
    group.add_option('--log-level', dest='log_level', type='choice', choices=levels, my_default='info', help=('specify    the    level    of    the    logging.    Accepted    values:    %s.' % (levels,)))
    parser.add_option_group(group)
    group = optparse.OptionGroup(parser, 'SMTP    Configuration')
    group.add_option('--email-from', dest='email_from', my_default=False, help='specify    the    SMTP    email    address    for    sending    email')
    group.add_option('--smtp', dest='smtp_server', my_default='localhost', help='specify    the    SMTP    server    for    sending    email')
    group.add_option('--smtp-port', dest='smtp_port', my_default=25, help='specify    the    SMTP    port', type='int')
    group.add_option('--smtp-ssl', dest='smtp_ssl', action='store_true', my_default=False, help='if    passed,    SMTP    connections    will    be    encrypted    with    SSL    (STARTTLS)')
    group.add_option('--smtp-user', dest='smtp_user', my_default=False, help='specify    the    SMTP    username    for    sending    email')
    group.add_option('--smtp-password', dest='smtp_password', my_default=False, help='specify    the    SMTP    password    for    sending    email')
    parser.add_option_group(group)
    group = optparse.OptionGroup(parser, 'Database    related    options')
    group.add_option('-d', '--database', dest='db_name', my_default=False, help='specify    the    database    name')
    group.add_option('-r', '--db_user', dest='db_user', my_default=False, help='specify    the    database    user    name')
    group.add_option('-w', '--db_password', dest='db_password', my_default=False, help='specify    the    database    password')
    group.add_option('--pg_path', dest='pg_path', help='specify    the    pg    executable    path')
    group.add_option('--db_host', dest='db_host', my_default=False, help='specify    the    database    host')
    group.add_option('--db_port', dest='db_port', my_default=False, help='specify    the    database    port', type='int')
    group.add_option('--db_maxconn', dest='db_maxconn', type='int', my_default=64, help='specify    the    the    maximum    number    of    physical    connections    to    posgresql')
    group.add_option('--db-template', dest='db_template', my_default='template1', help='specify    a    custom    database    template    to    create    a    new    database')
    parser.add_option_group(group)
    group = optparse.OptionGroup(parser, 'Internationalisation    options', "Use    these    options    to    translate    Odoo    to    another    language.See    i18n    section    of    the    user    manual.    Option    '-d'    is    mandatory.Option    '-l'    is    mandatory    in    case    of    importation")
    group.add_option('--load-language', dest='load_language', help='specifies    the    languages    for    the    translations    you    want    to    be    loaded')
    group.add_option('-l', '--language', dest='language', help='specify    the    language    of    the    translation    file.    Use    it    with    --i18n-export    or    --i18n-import')
    group.add_option('--i18n-export', dest='translate_out', help='export    all    sentences    to    be    translated    to    a    CSV    file,    a    PO    file    or    a    TGZ    archive    and    exit')
    group.add_option('--i18n-import', dest='translate_in', help="import    a    CSV    or    a    PO    file    with    translations    and    exit.    The    '-l'    option    is    required.")
    group.add_option('--i18n-overwrite', dest='overwrite_existing_translations', action='store_true', my_default=False, help='overwrites    existing    translation    terms    on    updating    a    module    or    importing    a    CSV    or    a    PO    file.')
    group.add_option('--modules', dest='translate_modules', help='specify    modules    to    export.    Use    in    combination    with    --i18n-export')
    parser.add_option_group(group)
    security = optparse.OptionGroup(parser, 'Security-related    options')
    security.add_option('--no-database-list', action='store_false', dest='list_db', my_default=True, help='disable    the    ability    to    return    the    list    of    databases')
    parser.add_option_group(security)
    group = optparse.OptionGroup(parser, 'Advanced    options')
    group.add_option('--dev', dest='dev_mode', type='string', help='Enable    developer    mode.    Param:    List    of    options    separated    by    comma.    Options    :    all,    [pudb|wdb|ipdb|pdb],    reload,    qweb,    werkzeug,    xml')
    group.add_option('--shell-interface', dest='shell_interface', type='string', help='Specify    a    preferred    REPL    to    use    in    shell    mode.    Supported    REPLs    are:    [ipython|ptpython|bpython|python]')
    group.add_option('--stop-after-init', action='store_true', dest='stop_after_init', my_default=False, help='stop    the    server    after    its    initialization')
    group.add_option('--osv-memory-count-limit', dest='osv_memory_count_limit', my_default=False, help='Force    a    limit    on    the    maximum    number    of    records    kept    in    the    virtual    osv_memory    tables.    The    default    is    False,    which    means    no    count-based    limit.', type='int')
    group.add_option('--osv-memory-age-limit', dest='osv_memory_age_limit', my_default=1.0, help='Force    a    limit    on    the    maximum    age    of    records    kept    in    the    virtual    osv_memory    tables.    This    is    a    decimal    value    expressed    in    hours,    and    the    default    is    1    hour.', type='float')
    group.add_option('--max-cron-threads', dest='max_cron_threads', my_default=2, help='Maximum    number    of    threads    processing    concurrently    cron    jobs    (default    2).', type='int')
    group.add_option('--unaccent', dest='unaccent', my_default=False, action='store_true', help='Use    the    unaccent    function    provided    by    the    database    when    available.')
    group.add_option('--geoip-db', dest='geoip_database', my_default='/usr/share/GeoIP/GeoLiteCity.dat', help='Absolute    path    to    the    GeoIP    database    file.')
    parser.add_option_group(group)
    if (os.name == 'posix'):
        group = optparse.OptionGroup(parser, 'Multiprocessing    options')
        group.add_option('--workers', dest='workers', my_default=0, help='Specify    the    number    of    workers,    0    disable    prefork    mode.', type='int')
        group.add_option('--limit-memory-soft', dest='limit_memory_soft', my_default=((2048 * 1024) * 1024), help='Maximum    allowed    virtual    memory    per    worker,    when    reached    the    worker    be    reset    after    the    current    request    (default    671088640    aka    640MB).', type='int')
        group.add_option('--limit-memory-hard', dest='limit_memory_hard', my_default=((2560 * 1024) * 1024), help='Maximum    allowed    virtual    memory    per    worker,    when    reached,    any    memory    allocation    will    fail    (default    805306368    aka    768MB).', type='int')
        group.add_option('--limit-time-cpu', dest='limit_time_cpu', my_default=60, help='Maximum    allowed    CPU    time    per    request    (default    60).', type='int')
        group.add_option('--limit-time-real', dest='limit_time_real', my_default=120, help='Maximum    allowed    Real    time    per    request    (default    120).', type='int')
        group.add_option('--limit-time-real-cron', dest='limit_time_real_cron', my_default=(-1), help='Maximum    allowed    Real    time    per    cron    job.    (default:    --limit-time-real).    Set    to    0    for    no    limit.    ', type='int')
        group.add_option('--limit-request', dest='limit_request', my_default=8192, help='Maximum    number    of    request    to    be    processed    per    worker    (default    8192).', type='int')
        parser.add_option_group(group)
    for group in parser.option_groups:
        for option in group.option_list:
            if (option.dest not in self.options):
                self.options[option.dest] = option.my_default
                self.casts[option.dest] = option
    self._parse_config()
