Esempio n. 1
0
def load_classpath_resource(resource):
    """
    Uploads the classpath resource to the session's working directory.
    :param resource: to find on the classpath to copy
    :return: string
    """
    url = Thread.currentThread().contextClassLoader.getResource(resource)
    if url is None:
        raise Exception("Resource [%s] not found on classpath." % resource)

    return Resources.toString(url, Charset.defaultCharset())
 def upload_classpath_resource_to_work_dir(self, resource, executable=False):
     """
     Uploads the classpath resource to the session's working directory.
     :param resource: to find on the classpath to copy
     :param executable: True if the uploaded file should be made executable
     :return: com.xebialabs.overthere.OverthereFile
     """
     filename = posixpath.basename(resource)
     url = Thread.currentThread().contextClassLoader.getResource(resource)
     if url is None:
         raise Exception("Resource [%s] not found on classpath." % resource)
     target = self.work_dir_file(filename)
     outputstream = target.outputStream
     try:
         Resources.copy(url, outputstream)
     finally:
         outputstream.close()
     if executable:
         target.setExecutable(executable)
     return target