Esempio n. 1
0
    def github_diff_link(self, upstream_fork, upstream_base):
        """Generates a GitHub compare link based on the attributes of this facade
        This method would be used when we have a last known pass of a given test
        We are making an assumption that the attributes of this facade are children of
        upstream_fork and upstream_base

        GitHub docs describing the compare view
        https://help.github.com/articles/comparing-commits-across-time/

        Args:
            upstream_fork (str): the fork you wish to compare against
            upstream_base (str): the branch or SHA you want to compare against

        Returns:
            str: The string containing the link to the relevant github compare view
        """
        try:
            # These variable names are the language used by GitHub
            base_fork = self._repo_fork
            base = self._git_sha
            head_fork = upstream_fork
            compare = upstream_base
            path = "/{}/{}/compare/{}...{}:{}".format(base_fork,
                                                      self._repo_name,
                                                      base,
                                                      head_fork,
                                                      compare)
            return urlunsplit((self._scheme, self._netloc, path, '', ''))
        except AttributeError:
            return 'Unknown'  # If we ask for the diff link and can't determine it we will supply 'Unknown'
Esempio n. 2
0
    def github_testlog_failure_link(self, test_log):
        """Generates a link to test case failure in GitHub
        The link generated by this method should highlight the line that caused the failure

        Args:
            test_log (ZigZagTestLog): the test log used to generate the link

        Returns:
            str: The string containing the link to the line that failed
        """
        try:
            base_dir = self._mediator.config_dict.get_config('path_to_test_exec_dir')
            base_dir = '/'.join([path for path in base_dir.split('/') if path])  # sanitize the path
            path = "/{fork}/{repo_name}/tree/{sha}/{base_dir}/{test_file}"
            path = path.format(fork=self._mediator.config_dict.get_config('test_fork'),
                               repo_name=self._mediator.config_dict.get_config('test_repo_name'),
                               sha=self._mediator.config_dict.get_config('test_commit'),
                               base_dir=base_dir,
                               test_file=test_log.test_file)
            failure_line_number = self._get_line_number_from_failure_output(test_log)
            line = failure_line_number or test_log.def_line_number or ''
            if line:
                line = "L{}".format(line)
            return urlunsplit(('https', 'github.com', path, '', line))
        except(AttributeError, ZigZagConfigError):
            pass  # If we ask for the failure link and can't determine it we should silently fail
Esempio n. 3
0
    def github_testlog_failure_link(self, test_log):
        """Generates a link to test case failure in GitHub
        The link generated by this method should highlight the line that caused the failure

        Args:
            test_log (ZigZagTestLog): the test log used to generate the link

        Returns:
            str: The string containing the link to the line that failed
        """
        try:
            if self._mediator.ci_environment == 'asc':
                # for Molecule repo of repos pattern
                path = "/{}/{}/tree/{}/molecule/{}/{}".format(
                    self._repo_fork, self._repo_name, self._git_sha,
                    self._molecule_scenario, test_log.test_file)
            elif self._mediator.ci_environment == 'mk8s':
                base_dir = 'tools/installer'  # this value is specific to mk8s and can not be derived from the XML
                path = "/{}/{}/tree/{}/{}/{}".format(self._repo_fork,
                                                     self._repo_name,
                                                     self._git_sha, base_dir,
                                                     test_log.test_file)
            failure_line_number = self._get_line_number_from_failure_output(
                test_log)
            line = failure_line_number or test_log.def_line_number or ''
            if line:
                line = "L{}".format(line)
            return urlunsplit((self._scheme, self._netloc, path, '', line))
        except AttributeError:
            pass  # If we ask for the failure link and can't determine it we should silently fail
Esempio n. 4
0
 def select_backend(self, request):
     """Replaces the scheme and netloc of the url with the backend"""
     if self.backend_iter is None:
         return
     next_backend = next(self.backend_iter)
     scheme, netloc = urlsplit(next_backend)[0:2]
     parsed = urlsplit(request._original_url)
     request.url = urlunsplit(parsed._replace(scheme=scheme, netloc=netloc))
Esempio n. 5
0
def add_split_url_params(parsed_url, new_params):
    split_url, params = parsed_url
    query = {}
    query.update(params)
    for key, value in new_params.items():
        query[key] = value

    return urlunsplit((split_url.scheme, split_url.netloc, split_url.path,
                       urlencode(query, doseq=True), split_url.fragment))
Esempio n. 6
0
def add_query_params(url, params):
    scheme, netloc, path, query_string, fragment = urlsplit(url)
    query_params = parse_qs(query_string)

    for name, value in iteritems(params):
        if value:
            query_params[name] = [value]

    new_query_string = urlencode(query_params, doseq=True)

    return urlunsplit((scheme, netloc, path, new_query_string, fragment))
Esempio n. 7
0
 def full_url(self):
     netloc = self.conn.host
     if self.conn.port:
         netloc += ':{}'.format(self.conn.port)
     return urlunsplit((
         self.pool.scheme,
         netloc,
         self.url,
         None,
         None,
     ))
Esempio n. 8
0
 def full_url(self):
     netloc = self.conn.host
     if self.conn.port:
         netloc += ':{}'.format(self.conn.port)
     return urlunsplit((
         self.pool.scheme,
         netloc,
         self.url,
         None,
         None,
     ))
Esempio n. 9
0
def get_scrape_url(tracker_url, info_hash):
    if 'announce' in tracker_url:
        v = urlsplit(tracker_url)
        result = urlunsplit([v.scheme, v.netloc, v.path.replace('announce', 'scrape'),
                             v.query, v.fragment])
    else:
        log.debug('`announce` not contained in tracker url, guessing scrape address.')
        result = tracker_url + '/scrape'

    result += '&' if '?' in result else '?'
    result += 'info_hash=%s' % quote(binascii.unhexlify(info_hash))
    return result
Esempio n. 10
0
def get_scrape_url(tracker_url, info_hash):
    if 'announce' in tracker_url:
        v = urlsplit(tracker_url)
        result = urlunsplit([v.scheme, v.netloc, v.path.replace('announce', 'scrape'),
                             v.query, v.fragment])
    else:
        log.debug('`announce` not contained in tracker url, guessing scrape address.')
        result = tracker_url + '/scrape'

    result += '&' if '?' in result else '?'
    result += 'info_hash=%s' % quote(binascii.unhexlify(info_hash))
    return result
Esempio n. 11
0
 def get_auth_from_url():
     """Moves basic authentication from url to username and password fields"""
     parts = list(parse.urlsplit(config['url']))
     split = parts[1].split('@')
     if len(split) > 1:
         auth = split[0].split(':')
         if len(auth) == 2:
             config['username'], config['password'] = auth[0], auth[1]
         else:
             log.warning('Invalid basic authentication in url: %s' % config['url'])
         parts[1] = split[1]
         config['url'] = parse.urlunsplit(parts)
Esempio n. 12
0
def stripUrlPassword(url):
    parts = list(urlsplit(url))
    parts[1] = _netloc_url_re.sub(':xxxx@', parts[1])
    return urlunsplit(parts)
Esempio n. 13
0
 def SerializeToString(self):
   url = (self.transport, self.host, self.path, self.query, self.fragment)
   return str(urlparse.urlunsplit(url))
Esempio n. 14
0
def extend_querystring_params(url, params):
    scheme, netloc, path, query, _ = urlsplit(url)
    orig_params = parse_qs(query)
    orig_params.update(params)
    query = urlencode(orig_params, True)
    return urlunsplit([scheme, netloc, path, query, ''])
Esempio n. 15
0
 def SerializeToHumanReadable(self):
   parts = (self.transport, self.host, self.path, self.query, self.fragment)
   return urlparse.urlunsplit(parts)
Esempio n. 16
0
 def __str__(self):
     import urllib.request, urllib.parse, urllib.error
     
     qs = urllib.parse.urlencode(self.qs, True)
     return urllib_parse.urlunsplit((self.scheme, self.netloc, self.script_root, qs, self.anchor))
Esempio n. 17
0
 def SerializeToHumanReadable(self):
   parts = (self.transport, self.host, self.path, self.query, self.fragment)
   return urlparse.urlunsplit(parts)
Esempio n. 18
0
def stripUrlPassword(url):
    parts = list(urlsplit(url))
    parts[1] = _netloc_url_re.sub(':xxxx@', parts[1])
    return urlunsplit(parts)