<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:

def freeze(name=None, force=False, **kwargs):
    '''
    Save the list of package and repos in a freeze file.

    As this module is build on top of the pkg module, the user can
    send extra attributes to the underlying pkg module via kwargs.
    This function will call ``pkg.list_pkgs`` and ``pkg.list_repos``,
    and any additional arguments will be passed through to those
    functions.

    name
        Name of the frozen state. Optional.

    force
        If true, overwrite the state. Optional.

    CLI Example:

    .. code-block:: bash

        salt '*' freezer.freeze
        salt '*' freezer.freeze pre_install
        salt '*' freezer.freeze force=True root=/chroot

    '''
    states_path = _states_path()

    try:
        os.makedirs(states_path)
    except OSError as e:
        msg = 'Error when trying to create the freezer storage %s: %s'
        log.error(msg, states_path, e)
        raise CommandExecutionError(msg % (states_path, e))

    if status(name) and not force:
        raise CommandExecutionError('The state is already present. Use '
                                    'force parameter to overwrite.')
    safe_kwargs = clean_kwargs(**kwargs)
    pkgs = __salt__['pkg.list_pkgs'](**safe_kwargs)
    repos = __salt__['pkg.list_repos'](**safe_kwargs)
    for name, content in zip(_paths(name), (pkgs, repos)):
        with fopen(name, 'w') as fp:
            json.dump(content, fp)
    return True