validator.py 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. '''
  2. Created on 13 Jul 2022 @author: vnc-console
  3. '''
  4. import subprocess as sp
  5. import os
  6. java_exec = 'C:/Users/DECEL/dist/jre6/bin/javaw.exe'
  7. duk_path = "F:/DECEL/dist/DUKIntegrator.jar"
  8. key_type = 'aladdin'
  9. pin = '61103989'
  10. command = '{} -jar {} {} {} {}'
  11. dst = 'f:/DECEL/TEST_100/{}'
  12. valid = 'Validare fara erori'
  13. sign_error = 'Eroare semnare PDF'
  14. files = list(filter(lambda f: f.endswith('.xml') or f.endswith('.xml'.upper()), os.listdir(os.getcwd())))
  15. # print(files)
  16. def validate(file: str, mode: str='-v', type_: str='D100', sign: bool=False, move: bool=True) -> str:
  17. global command
  18. if sign:
  19. mode = '-s'
  20. command = '{} -jar {} {} {} {} "" 0 "" {} {} {}'
  21. proc = sp.run(command.format(java_exec, duk_path, mode, type_, file, output, pin, key_type), capture_output=True, text=True, shell=True)
  22. print(proc.stdout)
  23. return proc.stdout, sign, move
  24. else:
  25. proc = sp.run(command.format(java_exec, duk_path, mode, type_, file), capture_output=True, text=True, shell=True)
  26. print(proc.stdout)
  27. return proc.stdout, sign, move
  28. if __name__ == '__main__':
  29. for file in files:
  30. output = file[:-4] + '_semnat.pdf'
  31. std_out, signed, moved = validate(file, mode='-v', type_='D100', sign=True, move=True)
  32. if valid in std_out:
  33. os.remove(file + '.err.txt')
  34. if signed and moved:
  35. if sign_error not in std_out:
  36. os.rename(file, dst.format(file))