Advertisement
Guest User

Untitled

a guest
Jul 18th, 2019
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.27 KB | None | 0 0
  1. # coding: utf-8
  2.  
  3. import glob
  4. import os
  5. from ui.ui_progrressbar import Ui_progressbar_form
  6. from lib.bridge import Bridge
  7. from lib.config import ConfigIni
  8. from lib.export import ExportDBF
  9. from PyQt5.QtWidgets import QMainWindow, QMessageBox
  10. from PyQt5.QtCore import Qt
  11.  
  12.  
  13. class ViewExtrairDadosConcorrente(QMainWindow):
  14. def __init__(self, parent=None):
  15. super(ViewExtrairDadosConcorrente, self).__init__(parent)
  16.  
  17. self.ui_extrair = Ui_progressbar_form()
  18. self.ui_extrair.setupUi(self)
  19. self.bridge = Bridge()
  20. self.config = ConfigIni()
  21. self.export_dbf = ExportDBF()
  22.  
  23. self.range_max = 0
  24.  
  25. def create_child_window(self):
  26. self.setWindowFlags(Qt.Window | Qt.WindowCloseButtonHint)
  27. self.setWindowTitle("Extrair dados do concorrente")
  28. self.ui_extrair.info_label.setText("")
  29. self.range_max = len(self.bridge.instance_object.files_path)
  30. self.ui_extrair.progressBar.setValue(0)
  31. self.ui_extrair.iniciar_pushButton.clicked.connect(self.extract_files_concurrent)
  32. self.ui_extrair.fechar_pushButton.clicked.connect(self.close)
  33. self.show()
  34.  
  35. def extract_files_concurrent(self):
  36. files_csv_exists = glob.glob(self.config.path_extract_scd + r"*.csv")
  37. if files_csv_exists:
  38. qtdade_files_delete = len(files_csv_exists)
  39. self.range_max = qtdade_files_delete
  40. self.ui_extrair.progressBar.setRange(0, self.range_max)
  41. for i, file in enumerate(files_csv_exists):
  42. self.ui_extrair.info_label.setText(file)
  43. try:
  44. os.remove(file)
  45. self.ui_extrair.progressBar.setValue(i + 1)
  46. except PermissionError as error:
  47. error_message = "O arquivo está sendo usado por outro processo.n"
  48. "Arquivo: {} n"
  49. "Erro: {}".format(file, error)
  50. QMessageBox.warning(self, "Erro", error_message)
  51.  
  52. self.bridge.instance_object.export_files()
  53.  
  54. class Netspeed:
  55. def __init__(self):
  56. self.config = ConfigIni()
  57. # self.database = DataBase()
  58. self.export = ExportDBF()
  59. self._dbf_files = self.dbf_files
  60. self._files_path = self.files_path
  61.  
  62. # self.conn = conexao()
  63. # self.database = DataBase()
  64.  
  65. # self._module = self.module
  66.  
  67. @property
  68. def dbf_files(self):
  69. self._dbf_files = glob.glob(self.config.path_database_concorrente + r"*.dbf")
  70. return self._dbf_files
  71.  
  72. @property
  73. def files_path(self):
  74. """
  75. Propriedade que retorna os arquivos encontrados para conversão com o caminho completo.
  76. :return: Retorna uma lista com os caminho completo dos arquivos a serem copiados.
  77. """
  78.  
  79. files_list = []
  80. _files_path = {"socios": glob.glob(self.config.path_database_concorrente + r"netspeed" + "\SOCIOS.dbf"),
  81. "contador": glob.glob(self.config.path_database_concorrente + r"netspeed" + "\CONTADOR.dbf"),
  82. "unique": glob.glob(self.config.path_database_concorrente + r"netspeedfls" + "\FLARQDPT.dbf"),
  83. "folha_FLFU": glob.glob(self.config.path_database_concorrente + r"netspeedfls" + "\FLFU*.DBF"),
  84. "folha_FLSO": glob.glob(self.config.path_database_concorrente + r"netspeedfls" + "\FLSO*.DBF"),
  85. "folha_firebird": glob.glob(self.config.path_database_concorrente + r"netspeednetgdb" + "\"
  86. + "FOLHA.FDB"),
  87. "folha_interbase": glob.glob(self.config.path_database_concorrente + r"netspeednetgdb" + "\"
  88. + "FOLHA.GDB"),
  89. "escrita": glob.glob(self.config.path_database_concorrente + r"netspeedescrita" +
  90. "\FORCLI.DBF"),
  91. "contabil_HISTO": glob.glob(self.config.path_database_concorrente + r"netspeedctb" +
  92. "\HISTO*.dbf"),
  93. "contabil_PLANO": glob.glob(self.config.path_database_concorrente + r"netspeedctb" +
  94. "\PLANO*.dbf")}
  95.  
  96. for modules in _files_path:
  97. list_files_module = _files_path.get(modules)
  98. if list_files_module:
  99. for i, files_path in enumerate(list_files_module):
  100. files_list.append(files_path)
  101.  
  102. return files_list
  103.  
  104. def export_files(self):
  105. if self.dbf_files:
  106. for index, file_dbf in enumerate(self.dbf_files):
  107. file_name = file_dbf.split("\")[-1].split(".")[0]
  108.  
  109. table = DBF(file_dbf, ignore_missing_memofile=True, encoding="ANSI", parserclass=MyFieldParser)
  110.  
  111. path_csv_file_output = self.config.path_extract_scd + "\" + file_name + ".csv"
  112.  
  113. with open(path_csv_file_output, "w", newline='', encoding='utf-8') as csv_file:
  114. csv_writer = csv.writer(csv_file, delimiter='t')
  115. csv_writer.writerow(table.field_names)
  116. for record in table:
  117. csv_writer.writerow(record.values())
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement