<commit_before># Copyright (C) 2010,2011  <NAME> <<EMAIL>>

# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation;
# version 2.1 of the License.

# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# Lesser General Public License for more details.

# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA

import random
import re
import os
import libxml2
import shutil

import Guest
import ozutil
import OzException

def get_windows_arch(tdl_arch):
    arch = tdl_arch
    if arch == "x86_64":
        arch = "amd64"
    return arch

class Windows2000andXPand2003(Guest.CDGuest):
    def __init__(self, tdl, config, auto):
        Guest.CDGuest.__init__(self, tdl.name, tdl.distro, tdl.update, tdl.arch,
                               tdl.installtype, 'rtl8139', "localtime", "usb",
                               None, config)

        self.tdl = tdl

        if self.tdl.update == "2000" and self.tdl.arch != "i386":
            raise OzException.OzException("Windows 2000 only supports i386 architecture")
        if self.tdl.key is None:
            raise OzException.OzException("A key is required when installing Windows 2000, XP, or 2003")

        self.siffile = auto
        if self.siffile is None:
            self.siffile = ozutil.generate_full_auto_path("windows-" + self.tdl.update + "-jeos.sif")

        self.url = self.check_url(self.tdl, iso=True, url=False)

        self.winarch = get_windows_arch(self.tdl.arch)

    def generate_new_iso(self):
        self.log.debug("Generating new ISO")
        Guest.subprocess_check_output(["mkisofs", "-b", "cdboot/boot.bin",
                                       "-no-emul-boot", "-boot-load-seg",
                                       "1984", "-boot-load-size", "4",
                                       "-iso-level", "2", "-J", "-l", "-D",
                                       "-N", "-joliet-long",
                                       "-relaxed-filenames", "-v", "-v",
                                       "-V", "Custom",
                                       "-o", self.output_iso, self.iso_contents])

    def modify_iso(self):
        os.mkdir(os.path.join(self.iso_contents, "cdboot"))
        self.geteltorito(self.orig_iso, os.path.join(self.iso_contents,
                                                     "cdboot", "boot.bin"))

        computername = "OZ" + str(random.randrange(1, 900000))

        f = open(self.siffile, "r")
        lines = f.readlines()
        f.close()

        for index, line in enumerate(lines):
            if re.match(" *ProductKey", line):
                lines[index] = "    ProductKey=" + self.tdl.key + "\n"
            elif re.match(" *ProductID", line):
                lines[index] = "    ProductID=" + self.tdl.key + "\n"
            elif re.match(" *ComputerName", line):
                lines[index] = "    ComputerName=" + computername + "\n"

        f = open(os.path.join(self.iso_contents, self.winarch, "winnt.sif"),
                 "w")
        f.writelines(lines)
        f.close()

    def generate_install_media(self, force_download=False):
        self.log.info("Generating install media")

        if not force_download and os.access(self.modified_iso_cache, os.F_OK):
            self.log.info("Using cached modified media")
            shutil.copyfile(self.modified_iso_cache, self.output_iso)<commit_msg>Use xreadlines() in Windows 2003 modify_iso.<commit_after># Copyright (C) 2010,2011  <NAME> <<EMAIL>>

# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation;
# version 2.1 of the License.

# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# Lesser General Public License for more details.

# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA

import random
import re
import os
import libxml2
import shutil

import Guest
import ozutil
import OzException

def get_windows_arch(tdl_arch):
    arch = tdl_arch
    if arch == "x86_64":
        arch = "amd64"
    return arch

class Windows2000andXPand2003(Guest.CDGuest):
    def __init__(self, tdl, config, auto):
        Guest.CDGuest.__init__(self, tdl.name, tdl.distro, tdl.update, tdl.arch,
                               tdl.installtype, 'rtl8139', "localtime", "usb",
                               None, config)

        self.tdl = tdl

        if self.tdl.update == "2000" and self.tdl.arch != "i386":
            raise OzException.OzException("Windows 2000 only supports i386 architecture")
        if self.tdl.key is None:
            raise OzException.OzException("A key is required when installing Windows 2000, XP, or 2003")

        self.siffile = auto
        if self.siffile is None:
            self.siffile = ozutil.generate_full_auto_path("windows-" + self.tdl.update + "-jeos.sif")

        self.url = self.check_url(self.tdl, iso=True, url=False)

        self.winarch = get_windows_arch(self.tdl.arch)

    def generate_new_iso(self):
        self.log.debug("Generating new ISO")
        Guest.subprocess_check_output(["mkisofs", "-b", "cdboot/boot.bin",
                                       "-no-emul-boot", "-boot-load-seg",
                                       "1984", "-boot-load-size", "4",
                                       "-iso-level", "2", "-J", "-l", "-D",
                                       "-N", "-joliet-long",
                                       "-relaxed-filenames", "-v", "-v",
                                       "-V", "Custom",
                                       "-o", self.output_iso, self.iso_contents])

    def modify_iso(self):
        os.mkdir(os.path.join(self.iso_contents, "cdboot"))
        self.geteltorito(self.orig_iso, os.path.join(self.iso_contents,
                                                     "cdboot", "boot.bin"))

        computername = "OZ" + str(random.randrange(1, 900000))

        infile = open(self.siffile, 'r')
        outfile = open(os.path.join(self.iso_contents, self.winarch,
                                    "winnt.sif"), 'w')

        for line in infile.xreadlines():
            if re.match(" *ProductKey", line):
                outfile.write("    ProductKey=" + self.tdl.key + "\n")
            elif re.match(" *ProductID", line):
                outfile.write("    ProductID=" + self.tdl.key + "\n")
            elif re.match(" *ComputerName", line):
                outfile.write("    ComputerName=" + computername + "\n")
            else:
                outfile.write(line)

        infile.close()
        outfile.close()

    def generate_install_media(self, force_download=False):
        self.log.info("Generating install media")

        if not force_download and os.access(self.modified_iso_cache, os.F_OK):
            self.log.info("Using cached modified media")
            shutil.copyfile(self.modified_iso_cache, self.output_iso)
{'fraction_non_alphanumeric': 0.11391076115485564, 'fraction_numerical': 0.02020997375328084, 'mean_word_length': 2.009873617693523, 'pattern_counts': {'":': 4, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 2}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 23, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5645173', 'n_tokens_mistral': 2354, 'n_tokens_neox': 2151, 'n_words': 614}