<commit_before>#
# Copyright (c) 2006 rPath, Inc.
#
# All Rights Reserved
#

import os
import tempfile
import stat
import zipfile

from jobslave import buildtypes
from jobslave.imagegen import logCall
from jobslave.generators import constants
from jobslave.generators import raw_fs_image, bootable_image

from conary.lib import util, log

def ordToAscii(index):
    res = ''
    while index >= 0:
        modulus = index % 26
        res = chr(97 + modulus) + res
        index = (index - modulus) / 26 - 1
    return res

def sortMountPoints(mountDict):
    res = {}
    res['sda'] = '/boot' in mountDict and '/boot' or '/'
    index = 1
    for partition in sorted([x[0] for x in mountDict.iteritems() \
            if x[1][-1] == 'swap']):
        res['sd%s' % ordToAscii(index)] = partition
        index += 1
    for partition in sorted([x for x in mountDict if x not in res.values()]):
        res['sd%s' % ordToAscii(index)] = partition
        index += 1
    return res

class XenOVA(raw_fs_image.RawFsImage):
    templateName = 'ova.xml.in'
    suffix = '.xva.tar'

    @bootable_image.timeMe
    def createXVA(self, outfile, sizes):
        # Read in the stub file
        infile = file(os.path.join(constants.templateDir, self.templateName),
                      'rb')

        # Replace the @DELIMITED@ text with the appropriate values
        template = infile.read()
        infile.close()

        template = template.replace('@TITLE@', self.jobData['project']['name'])
        template = template.replace('@DESCRIPTION@',
            'Created by rPath rBuilder')
        template = template.replace('@MEMORY@', str(self.getBuildData('vmMemory') * 1024 * 1024))
        vbdLines = ''
        vdiLines = ''
        for label, mountPoint in self.mountLabels.iteritems():
            settings = {'label': label, 'diskSize': sizes[mountPoint]}
            vbdLine = '            <vbd device="%(label)s" function="root" ' \
                    'mode="w" vdi="vdi_%(label)s"/>\n'
            vbdLine %= settings
            vbdLines += vbdLine
            vdiLine = '    <vdi name="vdi_%(label)s" size="%(diskSize)d" '\
                    'source="file://%(label)s" type="dir-gzipped-chunks"/>\n'
            vdiLine %= settings
            vdiLines += vdiLine

        template = template.replace('@VDB_ENTRIES@', vbdLines[:-1])
        template = template.replace('@VDI_ENTRIES@', vdiLines[:-1])
        # write the file to the proper location
        ofile = file(outfile, 'wb')
        ofile.write(template)
        ofile.close()

    def write(self):
        topDir = os.path.join(constants.tmpDir, self.jobId)
        baseDir = os.path.join(topDir, self.basefilename)
        #util.rmtree(baseDir, ignore_errors = True)
        util.mkdirChain(baseDir)
        ovaPath = os.path.join(baseDir, 'ova.xml')
        imagePath = baseDir + '.ext3'
        outputDir = os.path.join(constants.finishedDir, self.UUID)
        util.mkdirChain(outputDir)<commit_msg>rebase xen_ova top directory to avoid name collisions with raw_filesystem<commit_after>#
# Copyright (c) 2006 rPath, Inc.
#
# All Rights Reserved
#

import os
import tempfile
import stat
import zipfile

from jobslave import buildtypes
from jobslave.imagegen import logCall
from jobslave.generators import constants
from jobslave.generators import raw_fs_image, bootable_image

from conary.lib import util, log

def ordToAscii(index):
    res = ''
    while index >= 0:
        modulus = index % 26
        res = chr(97 + modulus) + res
        index = (index - modulus) / 26 - 1
    return res

def sortMountPoints(mountDict):
    res = {}
    res['sda'] = '/boot' in mountDict and '/boot' or '/'
    index = 1
    for partition in sorted([x[0] for x in mountDict.iteritems() \
            if x[1][-1] == 'swap']):
        res['sd%s' % ordToAscii(index)] = partition
        index += 1
    for partition in sorted([x for x in mountDict if x not in res.values()]):
        res['sd%s' % ordToAscii(index)] = partition
        index += 1
    return res

class XenOVA(raw_fs_image.RawFsImage):
    templateName = 'ova.xml.in'
    suffix = '.xva.tar'

    @bootable_image.timeMe
    def createXVA(self, outfile, sizes):
        # Read in the stub file
        infile = file(os.path.join(constants.templateDir, self.templateName),
                      'rb')

        # Replace the @DELIMITED@ text with the appropriate values
        template = infile.read()
        infile.close()

        template = template.replace('@TITLE@', self.jobData['project']['name'])
        template = template.replace('@DESCRIPTION@',
            'Created by rPath rBuilder')
        template = template.replace('@MEMORY@', str(self.getBuildData('vmMemory') * 1024 * 1024))
        vbdLines = ''
        vdiLines = ''
        for label, mountPoint in self.mountLabels.iteritems():
            settings = {'label': label, 'diskSize': sizes[mountPoint]}
            vbdLine = '            <vbd device="%(label)s" function="root" ' \
                    'mode="w" vdi="vdi_%(label)s"/>\n'
            vbdLine %= settings
            vbdLines += vbdLine
            vdiLine = '    <vdi name="vdi_%(label)s" size="%(diskSize)d" '\
                    'source="file://%(label)s" type="dir-gzipped-chunks"/>\n'
            vdiLine %= settings
            vdiLines += vdiLine

        template = template.replace('@VDB_ENTRIES@', vbdLines[:-1])
        template = template.replace('@VDI_ENTRIES@', vdiLines[:-1])
        # write the file to the proper location
        ofile = file(outfile, 'wb')
        ofile.write(template)
        ofile.close()

    def write(self):
        topDir = os.path.join(self.workDir, 'ova_base')
        baseDir = os.path.join(topDir, self.basefilename)
        util.mkdirChain(baseDir)
        ovaPath = os.path.join(baseDir, 'ova.xml')
        outputDir = os.path.join(constants.finishedDir, self.UUID)
        util.mkdirChain(outputDir)
{'fraction_non_alphanumeric': 0.13028764805414553, 'fraction_numerical': 0.009644670050761422, 'mean_word_length': 2.4526869158878504, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 4}, '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': '3197059', 'n_tokens_mistral': 1917, 'n_tokens_neox': 1824, 'n_words': 450}