Beispiel #1
0
def releaserdf(fp, **kw):
    """ Preprocesses install.rdf for release mode """

    with Reset(fp):
        rdf = XML(fp.read())
    node = rdf.getElementsByTagNameNS(NS_EM, 'version')[0].childNodes[0]
    if not re.match(r"^[\d.]+$", node.data):
        raise ValueError("Invalid release version: {}".format(node.data))

    return releasify(fp, **kw)
Beispiel #2
0
def betardf(fp, **kw):
    """ Preprocess install.rdf for beta mode """

    with Reset(fp):
        rdf = XML(fp.read())
    node = rdf.getElementsByTagNameNS(NS_EM, 'version')[0].firstChild
    if not re.match(r"^\d\.\db\d+$", node.data):
        raise ValueError("Invalid beta version: {}".format(node.data))

    return set_uurl(releasify(fp, **kw), **kw)
Beispiel #3
0
def releaserdf(fp, **kw):
    """ Preprocesses install.rdf for release mode """

    with Reset(fp):
        rdf = XML(fp.read())
    node = rdf.getElementsByTagNameNS(NS_EM, 'version')[0].childNodes[0]
    if not re.match(r"^[\d.]+$", node.data) and not kw.get("force"):
        raise ValueError("Invalid release version: {}".format(node.data))

    return releasify(fp, **kw)
Beispiel #4
0
def betardf(fp, **kw):
    """ Preprocess install.rdf for beta mode """

    with Reset(fp):
        rdf = XML(fp.read())
    node = rdf.getElementsByTagNameNS(NS_EM, 'version')[0].firstChild
    if not re.match(r"^\d\.\db\d+$", node.data):
        raise ValueError("Invalid beta version: {}".format(node.data))

    return set_uurl(releasify(fp, **kw), **kw)
Beispiel #5
0
def releasify(fp, **kw):
    with Reset(fp):
        rdf = XML(fp.read())
    node = rdf.getElementsByTagNameNS(NS_EM, "id")[0].childNodes[0]
    node.data = RELEASE_ID

    io = BytesIO()
    with Reset(io):
        print >> io, rdf.toxml(encoding="utf-8")
    rdf.unlink()
    return io
Beispiel #6
0
def releasify(fp, **kw):
    with Reset(fp):
        rdf = XML(fp.read())
    node = rdf.getElementsByTagNameNS(NS_EM, "id")[0].childNodes[0]
    node.data = RELEASE_ID

    io = BytesIO()
    with Reset(io):
        print >> io, rdf.toxml(encoding="utf-8")
    rdf.unlink()
    return io
Beispiel #7
0
def devrdf(fp, **kw):
    """ Preprocesses install.rdf for default mode """

    rdf = XML(fp.read())
    node = rdf.getElementsByTagNameNS(NS_EM, 'name')[0].childNodes[0]
    node.data += " *unofficial developer build*"

    io = BytesIO()
    with Reset(io):
        print >> io, rdf.toxml(encoding="utf-8")
    rdf.unlink()
    return io
Beispiel #8
0
def devrdf(fp, **kw):
    """ Preprocesses install.rdf for default mode """

    rdf = XML(fp.read())
    node = rdf.getElementsByTagNameNS(NS_EM, 'name')[0].childNodes[0]
    node.data += " *unofficial developer build*"

    io = BytesIO()
    with Reset(io):
        print >> io, rdf.toxml(encoding="utf-8")
    rdf.unlink()
    return io
Beispiel #9
0
def releasify(fp, **kw):
    """ Decorator: Transform into release version """
    kw = kw
    with Reset(fp):
        rdf = XML(fp.read())
    node = rdf.getElementsByTagNameNS(NS_EM, "id")[0].childNodes[0]
    node.data = RELEASE_ID

    io = BytesIO()
    with Reset(io):
        io.write(rdf.toxml(encoding="utf-8"))
        io.truncate()
    rdf.unlink()
    return io
Beispiel #10
0
def releasify(fp, **kw):
    """ Decorator: Transform into release version """
    kw = kw
    with Reset(fp):
        rdf = XML(fp.read())
    node = rdf.getElementsByTagNameNS(NS_EM, "id")[0].childNodes[0]
    node.data = RELEASE_ID

    io = BytesIO()
    with Reset(io):
        io.write(rdf.toxml(encoding="utf-8"))
        io.truncate()
    rdf.unlink()
    return io
Beispiel #11
0
def set_uurl(fp, **kw):
    """ Set the updateURL """

    with Reset(fp):
        rdf = XML(fp.read())

    node = rdf.getElementsByTagNameNS(NS_EM, 'aboutURL')[0]
    u = rdf.createElementNS(NS_EM, 'em:updateURL')
    u.appendChild(rdf.createTextNode(kw.get("updateurl")))
    node.parentNode.insertBefore(u, node)
    node.parentNode.insertBefore(rdf.createTextNode('\n\t\t'), node)

    io = BytesIO()
    with Reset(io):
        print >> io, rdf.toxml(encoding="utf-8")
    rdf.unlink()
    return io
Beispiel #12
0
def set_uurl(fp, **kw):
    """ Set the updateURL """

    with Reset(fp):
        rdf = XML(fp.read())

    node = rdf.getElementsByTagNameNS(NS_EM, 'aboutURL')[0]
    u = rdf.createElementNS(NS_EM, 'em:updateURL')
    u.appendChild(rdf.createTextNode(kw.get("updateurl")))
    node.parentNode.insertBefore(u, node)
    node.parentNode.insertBefore(rdf.createTextNode('\n\t\t'), node)

    io = BytesIO()
    with Reset(io):
        print >> io, rdf.toxml(encoding="utf-8")
    rdf.unlink()
    return io
Beispiel #13
0
def nightlyrdf(fp, **kw):
    """ Preprocesses install.rdf for nightly mode """

    rdf = XML(fp.read())
    # update the version
    node = rdf.getElementsByTagNameNS(NS_EM, 'version')[0].childNodes[0]
    node.data += strftime(".%Y%m%d.%Hh%Mm%Ss")
    # a new name
    node = rdf.getElementsByTagNameNS(NS_EM, 'name')[0].childNodes[0]
    node.data += " *nightly*"

    io = BytesIO()
    with Reset(io):
        print >> io, rdf.toxml(encoding="utf-8")
    rdf.unlink()
    return set_uurl(io, **kw)
Beispiel #14
0
def nightlyrdf(fp, **kw):
    """ Preprocesses install.rdf for nightly mode """

    rdf = XML(fp.read())
    # update the version
    node = rdf.getElementsByTagNameNS(NS_EM, 'version')[0].childNodes[0]
    node.data += strftime(".%Y%m%d.%Hh%Mm%Ss")
    # a new name
    node = rdf.getElementsByTagNameNS(NS_EM, 'name')[0].childNodes[0]
    node.data += " *nightly*"

    io = BytesIO()
    with Reset(io):
        print >> io, rdf.toxml(encoding="utf-8")
    rdf.unlink()
    return set_uurl(io, **kw)
Beispiel #15
0
def localize(fp, **kw):
    """ Generate em:localized """
    kw = kw

    def sort(f):
        if "en-US" in f["locale"]:
            return 0, f["locale"]
        return 1, f["locale"]

    def get_locale_strings():
        locales = list()
        for f in sorted(files("chrome/locale/*/description.properties")):
            locale = dict(locale=(f.split("/", 3)[2],))
            with open(f, "r", encoding="utf-8") as lp:
                for l in lp:
                    l = l.strip()
                    if not l or l.startswith("#"):
                        continue
                    k, v = l.split("=", 1)
                    k = k.split(".")
                    k = k[-2] if len(k[-1]) < 3 else k[-1]
                    if not k or not v:
                        continue
                    if k not in locale:
                        locale[k] = list()
                    locale[k] += v,
            locales += locale,
        return locales

    locales = get_locale_strings()

    with Reset(fp):
        rdf = XML(fp.read())

    # kill old localized
    for e in rdf.getElementsByTagNameNS(NS_EM, "localized"):
        e.parentNode.removeChild(e)

    def mapkey(k):
        v = list()
        for e in rdf.getElementsByTagNameNS(NS_EM, k):
            v += e.firstChild.data,
        return k, v

    keys = ("locale", "name", "description", "creator", "homepageURL",
            "developer", "translator", "contributor")
    baseprops = dict(mapkey(k) for k in keys)

    def add_props():
        parent = rdf.getElementsByTagNameNS(NS_EM, "id")[0].parentNode
        for props in sorted(locales, key=sort):
            node = rdf.createElementNS(NS_EM, "em:localized")
            desc = rdf.createElementNS(NS_RDF, "Description")
            for k in keys:
                vals = props.get(k, baseprops.get(k, list()))
                for v in vals:
                    n = rdf.createElementNS(NS_EM, "em:" + k)
                    n.appendChild(rdf.createTextNode(v))
                    desc.appendChild(n)
            parent.appendChild(rdf.createTextNode("\n\t\t"))
            node.appendChild(desc)
            parent.appendChild(node)
        parent.appendChild(rdf.createTextNode("\n\t"))

    add_props()

    io = BytesIO()
    with Reset(io):
        io.write(rdf.toxml(encoding="utf-8"))
        io.truncate()
    rdf.unlink()
    return io
Beispiel #16
0
    install = XML('install.rdf')
except:
    with open('install.rdf', 'rb') as f:
        lines = f.readlines()[1:]
        install = XMLString('\n'.join(lines))
    
for e in install.getElementsByTagName('em:localized'):
    e.parentNode.removeChild(e)

baseprops = PropDict()
for p in BASEPROPS:
    for e in install.getElementsByTagName('em:' + p):
        baseprops.add(e.tagName[3:], e.firstChild.data)
    
document = XMLString("""<?xml version="1.0"?>
<locales xmlns="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:em="http://www.mozilla.org/2004/em-rdf#">
</locales>""")

def getFiles():
    for f in glob('*/*/*/description.properties'):
        yield f
    for f in glob('*/*/*/localized.properties'):
        yield f

for f in getFiles():
    locale = basename(dirname(f))
    props = parseProps(f)
    if not props:
        continue
    props.add('locale', locale)
    props.mergene(baseprops)
Beispiel #17
0
def localize(fp, **kw):
    """ Generate em:localized """
    def sort(f):
        if "en-US" in f["locale"]:
            return 0, f["locale"]
        return 1, f["locale"]

    locales = list()
    for f in sorted(files("chrome/locale/*/description.properties")):
        locale = dict(locale=(f.split("/", 3)[2], ))
        with open(f, "rb") as lp:
            for l in lp:
                l = unicode(l, "utf-8").strip()
                if not l or l.startswith("#"):
                    continue
                k, v = l.split("=", 1)
                k = k.split(".")
                k = k[-2] if len(k[-1]) < 3 else k[-1]
                if not k or not v:
                    continue
                if k not in locale:
                    locale[k] = list()
                locale[k] += v,
        locales += locale,

    with Reset(fp):
        rdf = XML(fp.read())

    # kill old localized
    for e in rdf.getElementsByTagNameNS(NS_EM, "localized"):
        e.parentNode.removeChild(e)

    def mapkey(k):
        v = list()
        for e in rdf.getElementsByTagNameNS(NS_EM, k):
            v += e.firstChild.data,
        return k, v

    keys = ("locale", "name", "description", "creator", "homepageURL",
            "developer", "translator", "contributor")
    baseprops = dict(mapkey(k) for k in keys)

    parent = rdf.getElementsByTagNameNS(NS_EM, "id")[0].parentNode
    for props in sorted(locales, key=sort):
        node = rdf.createElementNS(NS_EM, "em:localized")
        desc = rdf.createElementNS(NS_RDF, "Description")
        for k in keys:
            vals = props.get(k, baseprops.get(k, list()))
            for v in vals:
                n = rdf.createElementNS(NS_EM, "em:" + k)
                n.appendChild(rdf.createTextNode(v))
                desc.appendChild(n)
        parent.appendChild(rdf.createTextNode("\n\t\t"))
        node.appendChild(desc)
        parent.appendChild(node)
    parent.appendChild(rdf.createTextNode("\n\t"))

    io = BytesIO()
    with Reset(io):
        print >> io, rdf.toxml(encoding="utf-8")
        rdf.unlink()
    return io