<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def process_stencil(cookbook, cookbook_name, template_pack, force_argument, stencil_set, stencil, written_files):
 """Process the stencil requested, writing any missing files as needed. The stencil named 'stencilset_name' should be one of templatepack's stencils. """

    # force can be passed on the command line or forced in a stencil's options
    force = force_argument or stencil['options'].get('force', False)

    stencil['files'] = stencil.get('files') or {}
    files = {
        # files.keys() are template paths, files.values() are target paths
        # {path to template: rendered target path, ... }
        os.path.join(stencil_set.path, tpl): os.path.join(cookbook.path, tgt)
        for tgt, tpl in stencil['files'].items()
    }

    stencil['partials'] = stencil.get('partials') or {}
    partials = {
        # files.keys() are template paths, files.values() are target paths
        # {path to template: rendered target path, ... }
        os.path.join(stencil_set.path, tpl): os.path.join(cookbook.path, tgt)
        for tgt, tpl in stencil['partials'].items()
    }

    stencil['binaries'] = stencil.get('binaries') or {}
    binaries = {
        # files.keys() are binary paths, files.values() are target paths
        # {path to binary: rendered target path, ... }
        os.path.join(stencil_set.path, tpl): os.path.join(cookbook.path, tgt)
        for tgt, tpl in stencil['binaries'].items()
    }

    template_map = _build_template_map(cookbook, cookbook_name, stencil)

    filetable = templating.render_templates(*files.keys(), **template_map)
    _render_templates(files, filetable, written_files, force)

    parttable = templating.render_templates(*partials.keys(), **template_map)
    _render_templates(partials, parttable, written_files, force, open_mode='a')

    # no templating needed for binaries, just pass off to the copy method
    _render_binaries(binaries, written_files)

    # merge metadata.rb dependencies
    stencil_metadata_deps = {'depends': stencil.get('dependencies', {})}
    stencil_metadata = book.MetadataRb.from_dict(stencil_metadata_deps)
    cookbook.metadata.merge(stencil_metadata)

    # merge Berksfile dependencies
    stencil_berks_deps = {'cookbook': stencil.get('berks_dependencies', {})}
    stencil_berks = book.Berksfile.from_dict(stencil_berks_deps)
    cookbook.berksfile.merge(stencil_berks)

    return cookbook