<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def copy_resource(self, resource, targetdir):
 """Copies a resource file and returns the source path for monitoring"""

        final_path = resource.final_path()
        if final_path[0] == '/' or (':' in final_path) or ('?' in final_path):
            # Absolute path or URI: Do nothing
            return

        source_path = self.get_source_path(resource)

        if resource.resource_type == DIRECTORY_RESOURCE:
            for file_path in glob.iglob(os.path.join(source_path, '**'), recursive=True):
                if os.path.isdir(file_path):
                    continue
                rest_target_path = file_path[len(source_path)+1:]
                target_path = os.path.join(targetdir, final_path, rest_target_path)
                # Don't yield the result, we don't monitor these.
                self._copy_file(file_path, target_path)
        else:
            target_path = os.path.join(targetdir, final_path)
            yield self._copy_file(source_path, target_path)