human
Complete this python program:
def get_config(argv, cwd=None):
assistant
#Here is the Python code you requested.

    """Read sys.argv and parse out repository of migrations and database url.
    >>> import os
    >>> from ConfigParser import SafeConfigParser
    >>> from tempfile import mkdtemp
    >>> config_dir = mkdtemp()
    >>> os.makedirs(os.path.join(config_dir, \config\))
    >>> def write_ini(path, property, value):
    ...     p = SafeConfigParser()
    ...     p.add_section(\app:main\)
    ...     p.set(\app:main\, property, value)
    ...     with open(os.path.join(config_dir, \config\, path), \w\) as f: p.write(f)
    >>> write_ini(\tool_shed.ini\, \database_connection\, \sqlite:///pg/testdb1\)
    >>> config = get_config([\manage_db.py\, \tool_shed\], cwd=config_dir)
    >>> config[\repo\]
    \lib/galaxy/webapps/tool_shed/model/migrate\
    >>> config[\db_url\]
    \sqlite:///pg/testdb1\
    >>> write_ini(\galaxy.ini\, \database_file\, \moo.sqlite\)
    >>> config = get_config([\manage_db.py\], cwd=config_dir)
    >>> config[\db_url\]
    \sqlite:///moo.sqlite?isolation_level=IMMEDIATE\
    >>> config[\repo\]
    \lib/galaxy/model/migrate\
    """
    if (argv and (argv[(-1)] in DATABASE)):
        database = argv.pop()
    else:
        database = 'galaxy'
    database_defaults = DATABASE[database]
    default = database_defaults.get('config_file', DEFAULT_CONFIG_FILE)
    old_default = database_defaults.get('old_config_file')
    config_file = read_config_file_arg(argv, default, old_default, cwd=cwd)
    repo = database_defaults['repo']
    config_prefix = database_defaults.get('config_prefix', DEFAULT_CONFIG_PREFIX)
    config_override = database_defaults.get('config_override', 'GALAXY_CONFIG_')
    default_sqlite_file = database_defaults['default_sqlite_file']
    properties = load_app_properties(ini_file=config_file, config_prefix=config_override)
    if (('%sdatabase_connection' % config_prefix) in properties):
        db_url = properties[('%sdatabase_connection' % config_prefix)]
    elif (('%sdatabase_file' % config_prefix) in properties):
        database_file = properties[('%sdatabase_file' % config_prefix)]
        db_url = ('sqlite:///%s?isolation_level=IMMEDIATE' % database_file)
    else:
        db_url = ('sqlite:///%s?isolation_level=IMMEDIATE' % default_sqlite_file)
    return dict(db_url=db_url, repo=repo, config_file=config_file, database=database)