# along with this program. If not, see <http://www.gnu.org/licenses/>.
# -*- mode: python; encoding: utf-8; -*-
import xml.dom.minidom
+import dirs
class Contribuinte:
def __init__(self, cpf):
+ irpf_dir = dirs.get_default_irpf_dir()
self.cpf = self._minimize_cpf(cpf)
if not self._validate_cpf(self.cpf):
raise RuntimeError("Invalid CPF: " + self.cpf)
+ self.cpf_file = irpf_dir.get_userdata_file("%s/%s.xml" % (self.cpf, self.cpf))
+ self.iddecl_file = irpf_dir.get_userdata_file("iddeclaracoes.xml")
self.declaracao = self._find_id()
- self.dados = xml.dom.minidom.parse("aplicacao/dados/%s/%s.xml" % (self.cpf, self.cpf))
+ self.dados = xml.dom.minidom.parse(self.cpf_file)
self.contribuinte = self.dados.getElementsByTagName("contribuinte")[0]
def _find_id(self):
cpf = self._normalize_cpf(self.cpf)
- self.declaracoes = xml.dom.minidom.parse("aplicacao/dados/iddeclaracoes.xml")
+ self.declaracoes = xml.dom.minidom.parse(self.iddecl_file)
for i in self.declaracoes.childNodes[0].childNodes:
if "cpf" in i.attributes.keys():
if i.attributes["cpf"].nodeValue == cpf:
return True
def save(self):
- self.dados.writexml(open("aplicacao/dados/%s/%s.xml" % (self.cpf, self.cpf), "w"))
- self.declaracoes.writexml(open("aplicacao/dados/iddeclaracoes.xml", "w"))
+ self.dados.writexml(open(self.cpf_file, "w"))
+ self.declaracoes.writexml(open(self.iddecl_file, "w"))
def _get_attr(self, el, attr):
if attr in el.attributes.keys():
return el.attributes[attr].nodeValue
--- /dev/null
+#
+# Copyright 2013 Thadeu Lima de Souza Cascardo <cascardo@cascardo.info>
+#
+# 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 <http://www.gnu.org/licenses/>.
+# -*- mode: python; encoding: utf-8; -*-
+
+import os
+
+class IRPFDir:
+ def __init__(self, resource_dir, userdata_dir):
+ self.resource_dir = resource_dir
+ self.userdata_dir = userdata_dir
+ def get_resource_dir(self):
+ return self.resource_dir
+ def get_userdata_dir(self):
+ return self.userdata_dir
+ def get_resource_file(self, file):
+ return self.get_resource_dir() + file
+ def get_userdata_file(self, file):
+ return self.get_userdata_dir() + file
+
+class IRPFDevelDir(IRPFDir):
+ def __init__(self):
+ self.resource_dir = "res/"
+ self.userdata_dir = "aplicacao/dados/"
+
+class IRPFInstallDir(IRPFDir):
+ def __init__(self):
+ self.resource_dir = "/usr/share/irpflivre/res/"
+ self.userdata_dir = os.path.expanduser("~/.irpflivre/aplicacao/dados/")
+
+default_irpf_dir = None
+
+def set_default_irpf_dir(dir):
+ default_irpf_dir = dir
+
+def get_default_irpf_dir():
+ global default_irpf_dir
+ if default_irpf_dir == None:
+ default_irpf_dir = IRPFDevelDir()
+ return default_irpf_dir
+
+# vim:tabstop=4:expandtab:smartindent
# along with this program. If not, see <http://www.gnu.org/licenses/>.
# -*- mode: python; encoding: utf-8; -*-
import xml.dom.minidom
+import dirs
class Municipios:
def __init__(self):
return None
def carregar_estado(self, UF):
+ irpf_dir = dirs.get_default_irpf_dir()
self.l = []
- self.xml = xml.dom.minidom.parse("res/%s.xml" % (UF,))
+ self.xml = xml.dom.minidom.parse(irpf_dir.get_resource_file("%s.xml" % (UF,)))
self._list()
def verify_cep(self, m, cep):
# along with this program. If not, see <http://www.gnu.org/licenses/>.
# -*- mode: python; encoding: utf-8; -*-
import xml.dom.minidom
+import dirs
class Ocupacoes:
def __init__(self):
- self.xml = xml.dom.minidom.parse("res/ocupacoesPrincipal.xml")
+ irpf_dir = dirs.get_default_irpf_dir()
+ self.xml = xml.dom.minidom.parse(irpf_dir.get_resource_file("ocupacoesPrincipal.xml"))
self.l = []
self.g = {}
self._list()