Exemple #1
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
Exemple #2
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
Exemple #3
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
Exemple #4
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