<commit_before>#
# Copyright (c) 2010 rPath, Inc.
#
# All rights reserved.
#

import os
import robj
import time
from robj.lib import xutil
from xobj import xobj


class WigBackendClient(object):
    """Client for interfacing directly to a Windows Build Service."""

    def __init__(self, url):
        self.api = robj.connect(url, logging=False, maxClients=1)
        self.image = None

    def createJob(self):
        # Create image resource
        self.api.images.append({'createdBy': 'nobody'})
        self.image = self.api.images[-1]

    def startJob(self):
        # Initiate job
        self.image.imageJob = self.dataFromObject({
            'type': 'image',
            'createdBy': 'nobody',
            }, tag='job', method='POST')

        return self.image.imageJob

    def watchJob(self):
        """Yield status updates until the image job is done."""
        job = self.image.imageJob
        last = None
        while True:
            next = (job.status, job.message, int(job.progress))
            if last != next:
                last = next
                yield next
            if job.status not in ('Queued', 'Running'):
                break
            time.sleep(1)
            job.refresh(force=True)

    def getJobUrl(self):
        return self.image.imageJob.id

    def getResults(self):
        """Return a file handle to the result image."""
        results = self.image.imageJob.resultResource
        if not results.resultFiles.resultFile:
            raise RuntimeError("No files in job result")

        for resFile, resXobj in zip(results.resultFiles,
                results.resultFiles.resultFile):
            name = resXobj.path
            if resFile.type == 'iso':
                # Prefer ISO to WIM
                break

        size = int(resFile.size)
        fobj = resFile.path<commit_msg>WIG: fix case where the result has only one file (e.g. WIM output) (RBL-7838)<commit_after>#
# Copyright (c) 2010 rPath, Inc.
#
# All rights reserved.
#

import os
import robj
import time
from robj.lib import xutil
from xobj import xobj


class WigBackendClient(object):
    """Client for interfacing directly to a Windows Build Service."""

    def __init__(self, url):
        self.api = robj.connect(url, logging=False, maxClients=1)
        self.image = None

    def createJob(self):
        # Create image resource
        self.api.images.append({'createdBy': 'nobody'})
        self.image = self.api.images[-1]

    def startJob(self):
        # Initiate job
        self.image.imageJob = self.dataFromObject({
            'type': 'image',
            'createdBy': 'nobody',
            }, tag='job', method='POST')

        return self.image.imageJob

    def watchJob(self):
        """Yield status updates until the image job is done."""
        job = self.image.imageJob
        last = None
        while True:
            next = (job.status, job.message, int(job.progress))
            if last != next:
                last = next
                yield next
            if job.status not in ('Queued', 'Running'):
                break
            time.sleep(1)
            job.refresh(force=True)

    def getJobUrl(self):
        return self.image.imageJob.id

    def getResults(self):
        """Return a file handle to the result image."""
        results = self.image.imageJob.resultResource
        if not results.resultFiles.resultFile:
            raise RuntimeError("No files in job result")

        xobjList = results.resultFiles.resultFile
        if not isinstance(xobjList, list):
            xobjList = [xobjList]

        for resFile, resXobj in zip(results.resultFiles, xobjList):
            name = resXobj.path
            if resFile.type == 'iso':
                # Prefer ISO to WIM
                break

        size = int(resFile.size)
        fobj = resFile.path
{'fraction_non_alphanumeric': 0.10348413936557463, 'fraction_numerical': 0.0046801872074883, 'mean_word_length': 1.945635528330781, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1528747', 'n_tokens_mistral': 1112, 'n_tokens_neox': 1068, 'n_words': 316}