From 0b93e487df31e15d903f1dcebf475f761085696d Mon Sep 17 00:00:00 2001 From: Thadeu Lima de Souza Cascardo Date: Sun, 23 Mar 2014 16:29:00 -0300 Subject: [PATCH] =?utf8?q?Introduz=20classe=20tipos=20para=20ocupa=C3=A7?= =?utf8?q?=C3=B5es,=20tipo=20de=20bens,=20etc.?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- src/tipos.py | 62 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 src/tipos.py diff --git a/src/tipos.py b/src/tipos.py new file mode 100644 index 0000000..c236554 --- /dev/null +++ b/src/tipos.py @@ -0,0 +1,62 @@ +# coding=utf-8 +# +# Copyright 2013 Thadeu Lima de Souza Cascardo +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . +# -*- mode: python; encoding: utf-8; -*- + +import xml.dom.minidom +import dirs + +class Tipos: + def __init__(self, fname, cols, group = -1): + irpf_dir = dirs.get_default_irpf_dir() + self.xml = xml.dom.minidom.parse(irpf_dir.get_resource_file(fname)) + self.l = [] + self.g = {} + self.cols = cols + self.group = group + self._list() + if group >= 0: + self._group() + + def _list(self): + for i in self.xml.getElementsByTagName("ITEM"): + if self.cols[-1] in i.attributes.keys(): + item = [] + for j in self.cols: + item.append(i.attributes[j].nodeValue) + self.l.append(item) + + def list(self): + return self.l + + def _group(self): + for i in self.l: + if i[self.group] not in self.g: + self.g[i[self.group]] = [] + self.g[i[self.group]].append(i) + + def groups(self): + if group < 0: + return None + return self.g + + def get_by_code(self, code): + for i in self.l: + if i[0] == code: + return i + return None + +# vim:tabstop=4:expandtab:smartindent -- 2.20.1