Cambio en métido join de utilidades
This commit is contained in:
parent
2f30bba8b4
commit
63c08d3a42
|
@ -10,10 +10,10 @@ def main(args):
|
||||||
return
|
return
|
||||||
|
|
||||||
if args.dir_trabajo:
|
if args.dir_trabajo:
|
||||||
entrada = util.join(args.dir_trabajo, 'entrada')
|
entrada = util.validar_dir(args.dir_trabajo, 'entrada')
|
||||||
generados = util.join(args.dir_trabajo, 'generados')
|
generados = util.validar_dir(args.dir_trabajo, 'generados')
|
||||||
por_timbrar = util.join(args.dir_trabajo, 'por_timbrar')
|
por_timbrar = util.validar_dir(args.dir_trabajo, 'por_timbrar')
|
||||||
timbrados = util.join(args.dir_trabajo, 'timbrados')
|
timbrados = util.validar_dir(args.dir_trabajo, 'timbrados')
|
||||||
else:
|
else:
|
||||||
entrada = args.dir_entrada
|
entrada = args.dir_entrada
|
||||||
generados = args.dir_generados
|
generados = args.dir_generados
|
||||||
|
|
|
@ -34,13 +34,20 @@ NS_CFDI = {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
def validar_dir(base, name):
|
||||||
|
path = _join(base, name)
|
||||||
|
if not _exists(path):
|
||||||
|
os.makedirs(path)
|
||||||
|
return path
|
||||||
|
|
||||||
|
|
||||||
def _exists(path):
|
def _exists(path):
|
||||||
if not path:
|
if not path:
|
||||||
return False
|
return False
|
||||||
return Path(path).exists()
|
return Path(path).exists()
|
||||||
|
|
||||||
|
|
||||||
def join(*paths):
|
def _join(*paths):
|
||||||
return str(Path(paths[0]).joinpath(*paths[1:]))
|
return str(Path(paths[0]).joinpath(*paths[1:]))
|
||||||
|
|
||||||
|
|
||||||
|
@ -349,9 +356,9 @@ def _validate_args_validar_cert(args):
|
||||||
log.error(msg)
|
log.error(msg)
|
||||||
return False, data
|
return False, data
|
||||||
|
|
||||||
path_cer = join(path_cert, f'{name}.cer')
|
path_cer = _join(path_cert, f'{name}.cer')
|
||||||
path_key = join(path_cert, f'{name}.key')
|
path_key = _join(path_cert, f'{name}.key')
|
||||||
path_enc = join(path_cert, f'{name}.enc')
|
path_enc = _join(path_cert, f'{name}.enc')
|
||||||
|
|
||||||
if not _exists(path_cer):
|
if not _exists(path_cer):
|
||||||
msg = f'No se encontró el archivo CER en: {path_cer}'
|
msg = f'No se encontró el archivo CER en: {path_cer}'
|
||||||
|
@ -428,14 +435,14 @@ def make(source, target):
|
||||||
|
|
||||||
def _stamp(path, target):
|
def _stamp(path, target):
|
||||||
current_path = os.path.dirname(__file__)
|
current_path = os.path.dirname(__file__)
|
||||||
path_cer = join(current_path, 'certificados')
|
path_cer = _join(current_path, 'certificados')
|
||||||
path_xslt = join(current_path, 'xslt', 'cadena.xslt')
|
path_xslt = _join(current_path, 'xslt', 'cadena.xslt')
|
||||||
doc = ET.parse(path)
|
doc = ET.parse(path)
|
||||||
|
|
||||||
for pac in PACs.keys():
|
for pac in PACs.keys():
|
||||||
xslt = open(path_xslt, 'rb')
|
xslt = open(path_xslt, 'rb')
|
||||||
cer = read_file(join(path_cer, f'{pac}.cer'))
|
cer = read_file(_join(path_cer, f'{pac}.cer'))
|
||||||
key = read_file(join(path_cer, f'{pac}.enc'))
|
key = read_file(_join(path_cer, f'{pac}.enc'))
|
||||||
cert = SATCertificate(cer, key)
|
cert = SATCertificate(cer, key)
|
||||||
# ~ print(cert)
|
# ~ print(cert)
|
||||||
|
|
||||||
|
@ -512,17 +519,13 @@ def read_file(path):
|
||||||
return data
|
return data
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def get_files(path, ext='xml'):
|
def get_files(path, ext='xml'):
|
||||||
docs = []
|
docs = []
|
||||||
for folder, _, files in os.walk(path):
|
for folder, _, files in os.walk(path):
|
||||||
pattern = re.compile('\.{}'.format(ext), re.IGNORECASE)
|
pattern = re.compile('\.{}'.format(ext), re.IGNORECASE)
|
||||||
docs += [join(folder,f) for f in files if pattern.search(f)]
|
docs += [_join(folder,f) for f in files if pattern.search(f)]
|
||||||
return tuple(docs)
|
return tuple(docs)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def _replace_ext(path, ext):
|
def _replace_ext(path, ext):
|
||||||
return str(Path(path).with_suffix(ext))
|
return str(Path(path).with_suffix(ext))
|
||||||
|
|
Loading…
Reference in New Issue