1234567891011121314151617181920212223242526272829303132333435363738394041 |
- '''
- Created on 13 Jul 2022 @author: vnc-console
- '''
- import subprocess as sp
- import os
- java_exec = 'C:/Users/DECEL/dist/jre6/bin/javaw.exe'
- duk_path = "F:/DECEL/dist/DUKIntegrator.jar"
- key_type = 'aladdin'
- pin = '61103989'
- command = '{} -jar {} {} {} {}'
- dst = 'f:/DECEL/TEST_100/{}'
- valid = 'Validare fara erori'
- sign_error = 'Eroare semnare PDF'
- files = list(filter(lambda f: f.endswith('.xml') or f.endswith('.xml'.upper()), os.listdir(os.getcwd())))
- # print(files)
- def validate(file: str, mode: str='-v', type_: str='D100', sign: bool=False, move: bool=True) -> str:
- global command
- if sign:
- mode = '-s'
- command = '{} -jar {} {} {} {} "" 0 "" {} {} {}'
- proc = sp.run(command.format(java_exec, duk_path, mode, type_, file, output, pin, key_type), capture_output=True, text=True, shell=True)
- print(proc.stdout)
- return proc.stdout, sign, move
- else:
- proc = sp.run(command.format(java_exec, duk_path, mode, type_, file), capture_output=True, text=True, shell=True)
- print(proc.stdout)
- return proc.stdout, sign, move
- if __name__ == '__main__':
- for file in files:
- output = file[:-4] + '_semnat.pdf'
- std_out, signed, moved = validate(file, mode='-v', type_='D100', sign=True, move=True)
- if valid in std_out:
- os.remove(file + '.err.txt')
- if signed and moved:
- if sign_error not in std_out:
- os.rename(file, dst.format(file))
|