def consume_one_config(self, config_option): if os.path.exists(config_option) or utils.is_url(config_option): if os.path.exists(config_option): cfg = open(config_option, 'r') if utils.is_url(config_option): cfg = utils.urlopen(config_option) # read the file for line in cfg.readlines(): self.configs.append(line) else: self.configs.append(config_option)
def find_repository_host(job_path): ''' Find the machine holding the given logs and return a URL to the logs :param job_path: when this was a CGI script, this value came from the 'job' variable, which was usually composed of '/results/' + a path such as '1-autotest' or '1-autotest/status.log' :type job_path: str :returns: a tuple with three members: protocol (such as "http"), host (such as "foo.bar.com") and a path such as "/results/1-autotest" :rtype: tuple or None ''' site_repo_info = site_find_repository_host(job_path) if site_repo_info is not None: return site_repo_info results_repos = [RESULTS_HOST] for drone in DRONES.split(','): drone = drone.strip() if drone not in results_repos: results_repos.append(drone) if ARCHIVE_HOST and ARCHIVE_HOST not in results_repos: results_repos.append(ARCHIVE_HOST) for drone in results_repos: if drone == 'localhost': continue http_path = 'http://%s%s' % (drone, job_path) try: logging.info('Attempting to access the selected results URL: "%s"', http_path) utils.urlopen(http_path) return 'http', utils.normalize_hostname(drone), job_path except urllib2.URLError: logging.error('Failed to access the selected results URL. ' 'Reverting to usual results location') pass