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)
def export_qip(pack, target_file): log.debug("export to qip started...%s", target_file) content = [] for icon in pack.icons: content.append(",".join(icon.text) + "\n") zip_file = ZipFile(target_file, "w") zip_file.writestr(os.path.join(pack.name, "Animated", "_define.ini"), "".join(content)) for icon in pack.icons: zip_file.write(os.path.join(config.temp_dir, icon.image), os.path.join(pack.name, "Animated", icon.image)) zip_file.close() log.debug("export to qip finished")
def export_kopete(pack, target_file): log.debug("export to kopete started...%s", target_file) pack_document = getDOMImplementation(config.dom_impl).createDocument(None, "icondef", None) meta_element = pack_document.createElement("meta") if pack.name: name_element = pack_document.createElement("name") name_element.appendChild(pack_document.createTextNode(pack.name)) meta_element.appendChild(name_element) pack_document.documentElement.appendChild(meta_element) for icon in pack.icons: icon_element = pack_document.createElement("icon") image_element = pack_document.createElement("object") image_element.setAttribute("mime", "image/gif") icon_element.appendChild(image_element) image_text = pack_document.createTextNode(icon.image) image_element.appendChild(image_text) for text in icon.text: text_element = pack_document.createElement("text") icon_element.appendChild(text_element) text_text = pack_document.createTextNode(text) text_element.appendChild(text_text) pack_document.documentElement.appendChild(icon_element) content = "" try: import cStringIO as StringIO stream=StringIO.StringIO() from xml.dom.ext import PrettyPrint PrettyPrint(pack_document, stream) content = stream.getvalue() except ImportError: content = pack_document.toxml() zip_file = ZipFile(target_file, "w") zip_file.writestr(os.path.join(pack.name, "icondef.xml"), content) for icon in pack.icons: zip_file.write(os.path.join(config.temp_dir, icon.image), os.path.join(pack.name, icon.image)) zip_file.close() log.debug("export to kopete finished")
def export_pidgin(pack, target_file): log.debug("export to pidgin started...%s", target_file) content = ["Name=%s\n" % pack.name] if pack.author: content.append("Author=%s\n" % pack.author) if pack.icon: content.append("Icon=%s\n" % pack.icon) content.append("[default]\n") for icon in pack.icons: # escaping '\' for i, text in enumerate(ifilter(lambda text: "\\" in text, icon.text)): icon.text[i] = text.replace("\\", "\\\\") # escaping ' ' for i, text in enumerate(ifilter(lambda text: " " in text, icon.text)): # TODO may be bad icon.text[i] = text.replace(" ","\\ ") full_text = icon.image + " " + " ".join(icon.text) + "\n" content.append(full_text) zip_file = ZipFile(target_file, "w") zip_file.writestr(os.path.join(pack.name, "theme"), "".join(content)) for icon in pack.icons: zip_file.write(os.path.join(config.temp_dir, icon.image), os.path.join(pack.name, icon.image)) zip_file.close() log.debug("export to pidgin finished")
def import_pidgin_dir(target_dir): log.debug("import from pidgin dir started...%s", target_dir) pack = _import_pidgin(target_dir, _read_content_from_file) log.debug("import from pidgin dir finished") return pack
def import_pidgin_zip(target_file): log.debug("import from pidgin zip started...%s", target_file) pack = _import_pidgin(target_file, _read_content_from_zip) log.debug("import from pidgin zip finished") return pack
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
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
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)) for text in xml_icon.getElementsByTagName("text"): icon.add_text(str(text.firstChild.data)) log.debug(" importing image : %s ", icon.image) try: image_content = _read_content_from_zip(target_file, icon.image) fout = open(os.path.join(config.temp_dir, icon.image), "wb") fout.write(image_content) fout.close() except IOError, (errno, strerror): log.warn("error during loading image : " + strerror + " -> skipping") pack.add_icon(icon) log.debug("import from kopete jisp finished")