# Path: nappingcat/config.py
# def build_settings():
#     config = ConfigParser()
#     config.read([os.path.expanduser('~/nappingcat.conf'), '/etc/nappingcat.conf'])
#     return config
# 
# SECTION_NAME = 'kittyconfig' 
# 
# Path: nappingcat/auth.py
# def get_auth_backend_from_settings(settings):
#     settings_dict = dict(settings.items(config.SECTION_NAME))
#     module, target = settings_dict['auth'].rsplit('.',1)
#     module = import_module(module)
#     target = getattr(module,target)
#     return target(settings)
# 
# Path: nappingcat/util.py
# def import_class_from_module(name):
#     module_path, target = name.rsplit('.', 1)
#     module = import_module(module_path)
#     return getattr(module, target)


import optparse
import sys
from nappingcat.config import build_settings, SECTION_NAME
from nappingcat.auth import get_auth_backend_from_settings
from nappingcat.util import import_class_from_module

def main(name=None, key=None):
    name = sys.argv[1] if name is None else name
    key = sys.stdin.read() if key is None else key
    settings = build_settings()
    auth = get_auth_backend_from_settings(settings)
    pubkey_handler = dict(settings.items(SECTION_NAME)).get('public_key_handler', 'nappingcat.pubkey_handlers.AuthorizedKeysFile')
    pubkey_handler = import_class_from_module(pubkey_handler)()

    auth.add_user(name)
    auth.add_key_to_user(name, key)

# Path: nappingcat/config.py
# def build_settings():
#     config = ConfigParser()
#     config.read([os.path.expanduser('~/nappingcat.conf'), '/etc/nappingcat.conf'])
#     return config
# 
# SECTION_NAME = 'kittyconfig' 
# 
# Path: nappingcat/auth.py
# def get_auth_backend_from_settings(settings):
#     settings_dict = dict(settings.items(config.SECTION_NAME))
#     module, target = settings_dict['auth'].rsplit('.',1)
#     module = import_module(module)
#     target = getattr(module,target)
#     return target(settings)
# 
# Path: nappingcat/util.py
# def import_class_from_module(name):
#     module_path, target = name.rsplit('.', 1)
#     module = import_module(module_path)
#     return getattr(module, target)


# Path: nappingcat/contrib/auth/bin/nappingcat_createsuperuser.py
import optparse
import sys
from nappingcat.config import build_settings, SECTION_NAME
from nappingcat.auth import get_auth_backend_from_settings
from nappingcat.util import import_class_from_module


def main(name=None, key=None):
    name = sys.argv[1] if name is None else name
    key = sys.stdin.read() if key is None else key
    settings = build_settings()
    auth = get_auth_backend_from_settings(settings)
    pubkey_handler = dict(settings.items(SECTION_NAME)).get('public_key_handler', 'nappingcat.pubkey_handlers.AuthorizedKeysFile')
    pubkey_handler = import_class_from_module(pubkey_handler)()

    auth.add_user(name)
    auth.add_key_to_user(name, key)

    auth.add_permission(