<commit_before>import os, sys, re

from io import BytesIO
from zipfile import ZipFile, ZIP_STORED, ZIP_DEFLATED

try:
    from cmp_listed_locales import cmp_listed_locales
except ImportError, ex:
    def cmp_listed_locales(dirname):
        print >>sys.stderr, "WARNING: did not compare locales (%s)" % ex

from path import path

jar_files = [
    "content/*",
    "content/*/*",
    "locale/*/*.dtd",
    "locale/*/*.properties",
    "skin/*.css",
    "skin/*.png"
    ]
xpi_files = [
    "install.rdf",
    "*.png",
    "LICENSE",
    "chrome/icons/default/*",
    "defaults/preferences/*",
    "lib/*.dll",
    "lib/*.so",
    "lib/SOURCES",
    "lib_unix/tray/export-versionscript",
    "lib_unix/tray/MakeFile",
    "lib_unix/tray/*.c",
    "lib_unix/tray/*.h",
    "lib_win/tray/*.c",
    "lib_win/tray/*.cpp",
    "lib_win/tray/*.h",
    "lib_win/tray/*.def",
    "lib_win/tray/*.rc",
    "lib_win/tray/*.sln",
    "lib_win/tray/*.vcproj",
    "modules/*"
    ]

class ZipOutFile(ZipFile):
    def __init__(self, zfile, method=None):
        self.zfile = zfile
        zfile.seek(0,0)
        ZipFile.__init__(self, zfile, "a", method or ZIP_STORED)
    def __enter__(self):
        return self
    def __exit__(self, type, value, traceback):
        self.close()
        self.zfile.seek(0,0)
        del self.zfile


def zip_files(out, file_list, basedir):
    with ZipOutFile(out) as zp:
        for f in file_list:
            for fe in basedir.glob(f):
                if fe.isdir():
                    continue
                oe = fe[len(basedir):]
                with open(fe, "rb") as fp:
                    zp.writestr(oe, fp.read())
                    print oe

def chromejar_line(line):
    pieces = re.split(r"\s+", line, 3)
    if pieces[0] in ["content"]:
        pieces[2] = pieces[2].replace("chrome/", "jar:chrome.jar!/")
    elif pieces[0] in ["skin", "locale"]:
        pieces[3] = pieces[3].replace("chrome/", "jar:chrome.jar!/")
    return " ".join(pieces)

def main():
    basedir = path(__file__).dirname()
    cmp_listed_locales(basedir)

    with BytesIO() as xpi:
        zip_files(xpi, xpi_files, basedir)
        with ZipOutFile(xpi) as zp:<commit_msg>Fix build script<commit_after>import os, sys, re

from io import BytesIO
from zipfile import ZipFile, ZIP_STORED, ZIP_DEFLATED

try:
    from cmp_listed_locales import cmp_listed_locales
except ImportError, ex:
    def cmp_listed_locales(dirname):
        print >>sys.stderr, "WARNING: did not compare locales (%s)" % ex

from path import path

jar_files = [
    "content/*",
    "content/*/*",
    "locale/*/*.dtd",
    "locale/*/*.properties",
    "skin/*.css",
    "skin/*.png"
    ]
xpi_files = [
    "install.rdf",
    "*.png",
    "LICENSE",
    "chrome/icons/default/*",
    "defaults/preferences/*",
    "lib/*.dll",
    "lib/*.so",
    "lib/SOURCES",
    "lib_unix/tray/export-versionscript",
    "lib_unix/tray/MakeFile",
    "lib_unix/tray/*.c",
    "lib_unix/tray/*.h",
    "lib_win/tray/*.c",
    "lib_win/tray/*.cpp",
    "lib_win/tray/*.h",
    "lib_win/tray/*.def",
    "lib_win/tray/*.rc",
    "lib_win/tray/*.sln",
    "lib_win/tray/*.vcproj",
    "modules/*"
    ]

class ZipOutFile(ZipFile):
    def __init__(self, zfile, method=None):
        self.zfile = zfile
        zfile.seek(0,0)
        ZipFile.__init__(self, zfile, "a", method or ZIP_STORED)
    def __enter__(self):
        return self
    def __exit__(self, type, value, traceback):
        self.close()
        self.zfile.seek(0,0)
        del self.zfile


def zip_files(out, file_list, basedir):
    with ZipOutFile(out) as zp:
        for f in file_list:
            for fe in basedir.glob(f):
                if fe.isdir():
                    continue
                oe = path(fe.replace("\\", "/"))[len(basedir):]
                with open(fe, "rb") as fp:
                    zp.writestr(oe, fp.read())
                    print fe

def chromejar_line(line):
    pieces = re.split(r"\s+", line, 3)
    if pieces[0] in ["content"]:
        pieces[2] = pieces[2].replace("chrome/", "jar:chrome.jar!/")
    elif pieces[0] in ["skin", "locale"]:
        pieces[3] = pieces[3].replace("chrome/", "jar:chrome.jar!/")
    return " ".join(pieces)

def main():
    basedir = path("./")
    cmp_listed_locales(basedir)

    with BytesIO() as xpi:
        zip_files(xpi, xpi_files, basedir)
        with ZipOutFile(xpi) as zp:
{'fraction_non_alphanumeric': 0.16560509554140126, 'fraction_numerical': 0.005004549590536852, 'mean_word_length': 2.3335860500379075, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, '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': '6084437', 'n_tokens_mistral': 1672, 'n_tokens_neox': 1623, 'n_words': 326}