human
Complete the below
def create_paramfile(trans, uploaded_datasets):

    ''''Create the upload tool\'s JSON "param" file.'
    '''

Write me a the Python code you requested?
assistant
#Here is the Python code you requested.
    def _chown(path):
        try:
            pwent = trans.user.system_user_pwent(trans.app.config.real_system_username)
            cmd = shlex.split(trans.app.config.external_chown_script)
            cmd.extend([path, pwent[0], str(pwent[3])])
            log.debug(('Changing    ownership    of    %s    with:    %s' % (path, '    '.join(cmd))))
            p = subprocess.Popen(cmd, shell=False, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
            (stdout, stderr) = p.communicate()
            assert (p.returncode == 0), stderr
        except Exception as e:
            log.warning(('Changing    ownership    of    uploaded    file    %s    failed:    %s' % (path, str(e))))
    json_file = tempfile.mkstemp()
    json_file_path = json_file[1]
    json_file = os.fdopen(json_file[0], 'w')
    for uploaded_dataset in uploaded_datasets:
        data = uploaded_dataset.data
        if (uploaded_dataset.type == 'composite'):
            data.init_meta()
            for (meta_name, meta_value) in uploaded_dataset.metadata.items():
                setattr(data.metadata, meta_name, meta_value)
            trans.sa_session.add(data)
            trans.sa_session.flush()
            json = dict(file_type=uploaded_dataset.file_type, dataset_id=data.dataset.id, dbkey=uploaded_dataset.dbkey, type=uploaded_dataset.type, metadata=uploaded_dataset.metadata, primary_file=uploaded_dataset.primary_file, composite_file_paths=uploaded_dataset.composite_files, composite_files=dict(((k, v.__dict__) for (k, v) in data.datatype.get_composite_files(data).items())))
        else:
            try:
                is_binary = uploaded_dataset.datatype.is_binary
            except:
                is_binary = None
            try:
                link_data_only = uploaded_dataset.link_data_only
            except:
                link_data_only = 'copy_files'
            try:
                uuid_str = uploaded_dataset.uuid
            except:
                uuid_str = None
            try:
                purge_source =...