From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from lists.gentoo.org (pigeon.gentoo.org [208.92.234.80]) by finch.gentoo.org (Postfix) with ESMTP id 46DC11381F3 for ; Wed, 17 Jul 2013 23:20:02 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id BA263E0919; Wed, 17 Jul 2013 23:20:01 +0000 (UTC) Received: from smtp.gentoo.org (smtp.gentoo.org [140.211.166.183]) (using TLSv1 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by pigeon.gentoo.org (Postfix) with ESMTPS id 35622E0919 for ; Wed, 17 Jul 2013 23:20:01 +0000 (UTC) Received: from hornbill.gentoo.org (hornbill.gentoo.org [94.100.119.163]) (using TLSv1 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by smtp.gentoo.org (Postfix) with ESMTPS id 33602335E31 for ; Wed, 17 Jul 2013 23:20:00 +0000 (UTC) Received: from localhost.localdomain (localhost [127.0.0.1]) by hornbill.gentoo.org (Postfix) with ESMTP id CDE89E545F for ; Wed, 17 Jul 2013 23:19:58 +0000 (UTC) From: "Jauhien Piatlicki" To: gentoo-commits@lists.gentoo.org Content-Transfer-Encoding: 8bit Content-type: text/plain; charset=UTF-8 Reply-To: gentoo-dev@lists.gentoo.org, "Jauhien Piatlicki" Message-ID: <1374103176.f992111f9c194ded1401744745dc8708a50cfd23.jauhien@gentoo> Subject: [gentoo-commits] proj/g-sorcery:master commit in: gs_ctan/ X-VCS-Repository: proj/g-sorcery X-VCS-Files: gs_ctan/ctan_db.py X-VCS-Directories: gs_ctan/ X-VCS-Committer: jauhien X-VCS-Committer-Name: Jauhien Piatlicki X-VCS-Revision: f992111f9c194ded1401744745dc8708a50cfd23 X-VCS-Branch: master Date: Wed, 17 Jul 2013 23:19:58 +0000 (UTC) Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-commits@lists.gentoo.org X-Archives-Salt: 8fe0c333-75cf-4d2d-99f2-622d591688de X-Archives-Hash: 8e12f7113b738a576db26e420fa548e3 commit: f992111f9c194ded1401744745dc8708a50cfd23 Author: Jauhien Piatlicki (jauhien) gmail com> AuthorDate: Wed Jul 17 23:19:36 2013 +0000 Commit: Jauhien Piatlicki gmail com> CommitDate: Wed Jul 17 23:19:36 2013 +0000 URL: http://git.overlays.gentoo.org/gitweb/?p=proj/g-sorcery.git;a=commit;h=f992111f gs_ctan/ctan_db: parse_data implemented --- gs_ctan/ctan_db.py | 52 +++++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 47 insertions(+), 5 deletions(-) diff --git a/gs_ctan/ctan_db.py b/gs_ctan/ctan_db.py index 65ff4ba..adb6544 100644 --- a/gs_ctan/ctan_db.py +++ b/gs_ctan/ctan_db.py @@ -11,12 +11,10 @@ :license: GPL-2, see LICENSE for more details. """ +import itertools import os -from g_sorcery.compatibility import TemporaryDirectory -from g_sorcery.g_collections import Package from g_sorcery.package_db import PackageDB -from g_sorcery.fileutils import wget from g_sorcery.exceptions import SyncError class CtanDB(PackageDB): @@ -29,7 +27,51 @@ class CtanDB(PackageDB): def parse_data(self, data_f): data = data_f.read() - return data + + data = data.split("\n") + + #entries are separated by new lines + data = \ + [list(group) for key, group in itertools.groupby(data, bool) if key] + + #we need only Package entries + data = \ + [entry for entry in data if entry[1] == "category Package"] + + result = [] + + KEY = 0 + VALUE = 1 + FILES_LENGTH = len("files") + + for entry in data: + res_entry = {} + previous_key = "" + current_key = "" + for line in entry: + line = line.split(" ") + if line[KEY][-FILES_LENGTH:] == "files": + current_key = line[KEY] + res_entry[current_key] = {} + for value in line[VALUE:]: + key, val = value.split("=") + res_entry[current_key][key] = val + res_entry[current_key]["files"] = [] + elif not line[KEY]: + res_entry[current_key]["files"].append(" ".join(line[VALUE:])) + else: + if previous_key == line[KEY]: + res_entry[previous_key] += " " + " ".join(line[VALUE:]) + else: + res_entry[line[KEY]] = " ".join(line[VALUE:]) + previous_key = line[KEY] + current_key = "" + result.append(res_entry) + + return result def process_data(self, data): - print(data) + for entry in data["texlive.tlpdb"]: + for key, value in entry.items(): + print(key + ": " + str(value)) + print