def copy_data(data, dest, header=None, use_put=None): """ Copy data to a destination To aid in debugging, copy a file locally to verify the contents. Attempts to write the same data that would otherwise be sent remotely. :param data: data string to copy :param dest: destination path :param header: header info item to return :param use_put: dictionary of items for PUT method :return: nothing or header info if requested """ ret = None # PUT uses a filename instead of a list like POST if use_put: udata = data else: udata = urllib.urlencode(data) if utils.is_url(dest): ret = copy_remote(udata, dest, use_put) if header: return ret[header] else: if header: ret = dest + str(time.time()) # should be unique dest = ret + "/_task_result" copy_local(udata, dest, use_put) return ret
def copy_data(data, dest, header=None, use_put=None): """ Copy data to a destination To aid in debugging, copy a file locally to verify the contents. Attempts to write the same data that would otherwise be sent remotely. @param data: data string to copy @param dest: destination path @param header: header info item to return @param use_put: dictionary of items for PUT method :return: nothing or header info if requested """ ret = None # PUT uses a filename instead of a list like POST if use_put: udata = data else: udata = urllib.urlencode(data) if utils.is_url(dest): ret = copy_remote(udata, dest, use_put) if header: return ret[header] else: if header: ret = dest + str(time.time()) # should be unique dest = ret + "/_task_result" copy_local(udata, dest, use_put) return ret
def _get_package_name(self, url, regex): if not utils.is_url(url): if url.endswith('.tar.bz2'): testname = url.replace('.tar.bz2', '') testname = re.sub(r'(\d*)\.', '', testname) return (testname, testname) else: return ('', url) match = re.match(regex, url) if not match: return ('', url) group, filename = match.groups() # Generate the group prefix. group = re.sub(r'\W', '_', group) # Drop the extension to get the raw test name. testname = re.sub(r'\.tar\.bz2', '', filename) # Drop any random numbers at the end of the test name if any testname = re.sub(r'\.(\d*)', '', testname) return (group, testname)
def test_rejects_local_path_containing_url(self): self.assertFalse(utils.is_url("somedir/http://path/file"))
def test_rejects_relative_local_path(self): self.assertFalse(utils.is_url("somedir/somesubdir/file"))
def test_rejects_local_filename(self): self.assertFalse(utils.is_url("filename"))
def test_rejects_local_path(self): self.assertFalse(utils.is_url("/home/username/file"))
def test_accepts_ftp(self): self.assertTrue(utils.is_url("ftp://ftp.example.com"))
def test_accepts_http(self): self.assertTrue(utils.is_url("http://example.com"))