'Find all sample files (files in the repository with the special .sample extension)
in the reversed repository manifest up to ctx.  Copy each discovered file to dir and
return the list of filenames.  If a .sample file was added in a changeset and then
deleted in a later changeset, it will be returned in the deleted_sample_files list.
The caller will set the value of app.config.tool_data_path to dir in order to load
the tools and generate metadata for them.'

def get_list_of_copied_sample_files(self, repo, ctx, dir):

    deleted_sample_files = []
    sample_files = []
    for changeset in hg_util.reversed_upper_bounded_changelog(repo, ctx):
        changeset_ctx = repo.changectx(changeset)
        for ctx_file in changeset_ctx.files():
            ctx_file_name = basic_util.strip_path(ctx_file)
            if (ctx_file_name.endswith('.sample') and (ctx_file_name not in sample_files)):
                fctx = hg_util.get_file_context_from_ctx(changeset_ctx, ctx_file)
                if (fctx in ['DELETED']):
                    if (ctx_file_name not in deleted_sample_files):
                        deleted_sample_files.append(ctx_file_name)
                else:
                    sample_files.append(ctx_file_name)
                    tmp_ctx_file_name = os.path.join(dir, ctx_file_name.replace('.sample', ''))
                    fh = open(tmp_ctx_file_name, 'wb')
                    fh.write(fctx.data())
                    fh.close()
    return (sample_files, deleted_sample_files)
