Ejemplo n.º 1
0
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
Ejemplo n.º 2
0
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
Ejemplo n.º 3
0
    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)
Ejemplo n.º 4
0
    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)
Ejemplo n.º 5
0
 def test_rejects_local_path_containing_url(self):
     self.assertFalse(utils.is_url("somedir/http://path/file"))
Ejemplo n.º 6
0
 def test_rejects_relative_local_path(self):
     self.assertFalse(utils.is_url("somedir/somesubdir/file"))
Ejemplo n.º 7
0
 def test_rejects_local_filename(self):
     self.assertFalse(utils.is_url("filename"))
Ejemplo n.º 8
0
 def test_rejects_local_path(self):
     self.assertFalse(utils.is_url("/home/username/file"))
Ejemplo n.º 9
0
 def test_accepts_ftp(self):
     self.assertTrue(utils.is_url("ftp://ftp.example.com"))
Ejemplo n.º 10
0
 def test_accepts_http(self):
     self.assertTrue(utils.is_url("http://example.com"))
Ejemplo n.º 11
0
 def test_rejects_local_path_containing_url(self):
     self.assertFalse(utils.is_url("somedir/http://path/file"))
Ejemplo n.º 12
0
 def test_rejects_relative_local_path(self):
     self.assertFalse(utils.is_url("somedir/somesubdir/file"))
Ejemplo n.º 13
0
 def test_rejects_local_filename(self):
     self.assertFalse(utils.is_url("filename"))
Ejemplo n.º 14
0
 def test_rejects_local_path(self):
     self.assertFalse(utils.is_url("/home/username/file"))
Ejemplo n.º 15
0
 def test_accepts_ftp(self):
     self.assertTrue(utils.is_url("ftp://ftp.example.com"))
Ejemplo n.º 16
0
 def test_accepts_http(self):
     self.assertTrue(utils.is_url("http://example.com"))