Ejemplo n.º 1
0
def import_qip_dir(target_dir):
    log.debug("import from qip dir started...%s", target_dir)
    # TODO add validation
    pack_dir = os.path.join(target_dir, "Animated")
    pack = Pack()
    pack.name = pack_dir.rpartition(os.sep)[0].rpartition(os.sep)[2]
    log.debug(" pack name : %s", pack.name)
    content = _read_content_from_file(pack_dir, "_define.ini")
    images = filter(lambda item: item.endswith(".gif"), os.listdir(pack_dir))
    images.sort()
    for line, image_entry in zip(content.splitlines(), images):
        log.debug(" line : %s, image : %s", line, image_entry)
        icon = Icon(line.split(","), image_entry.rpartition(os.sep)[2])
        log.debug(" text : %s, image : %s", icon.text, icon.image)
        log.debug(" importing image : %s, from entry : %s", icon.image, image_entry) 
        image_content = _read_content_from_file(pack_dir, image_entry)
        fout = open(os.path.join(config.temp_dir, icon.image),  "wb")
        fout.write(image_content)
        fout.close()
        pack.add_icon(icon)
    log.debug("import from qip dir finished")
    return pack
Ejemplo n.º 2
0
def import_qip_zip(target_file):
    log.debug("import from qip zip started...%s", target_file)
    # TODO add validation
    zip_file = ZipFile(target_file, "r")
    define_entry = filter(lambda item: item.endswith("_define.ini"), zip_file.namelist())[0]
    content = zip_file.read(define_entry)
    pack = Pack()
    pack.name = define_entry.partition("/")[0]
    log.debug(" pack name : %s", pack.name)
    images = filter(lambda item: item.endswith(".gif"), zip_file.namelist())
    images.sort()
    for line, image_entry in zip(content.splitlines(), images):
        log.debug(" line : %s, image : %s", line, image_entry)
        icon = Icon(line.split(","), image_entry.rpartition("/")[2])
        log.debug(" text : %s, image : %s", icon.text, icon.image)
        log.debug(" importing image : %s, from entry : %s", icon.image, image_entry) 
        image_content = zip_file.read(image_entry)
        fout = open(os.path.join(config.temp_dir, icon.image),  "wb")
        fout.write(image_content)
        fout.close()
        pack.add_icon(icon)
    log.debug("import from qip zip finished") 
    return pack
Ejemplo n.º 3
0
import os
from itertools import ifilter
from zipfile import ZipFile, is_zipfile
from qsmile.core.model import Pack,  Icon
import qsmile.core.config as config
from qsmile.core.util import timing, log

@timing
def import_kopete(target_file):
    log.debug("import from kopete jisp started...%s", target_file)
    try:
        content = _read_content_from_zip(target_file, "icondef.xml")
    except IOError, (errno, strerror):
        log.warn("import from kopete failed : %s", strerror)
        raise ImportPackError("Error during importing : " + strerror)
    pack = Pack()
    try:
        from xml.dom.ext.reader import PyExpat
        dom = PyExpat.Reader().fromString(content)
    except ImportError:
        from xml.dom.minidom import parseString
        dom = parseString(content)
    xml_meta = dom.getElementsByTagName("meta")
    if xml_meta:
        xml_name = xml_meta[0].getElementsByTagName("name")
        if xml_name:
            pack.name = str(xml_name[0].firstChild.data)
            log.debug(" pack name : %s",  pack.name)
    xml_icons = dom.getElementsByTagName("icon")
    for xml_icon in xml_icons:
        icon = Icon([], str(xml_icon.getElementsByTagName("object")[0].firstChild.data))