コード例 #1
0
ファイル: ImportR85ERZCentral.py プロジェクト: dio4/vista_1
    def processRespFile(self, fileName):
        """Импортирует указанный файл

        :param fileName: имя файла для импорта (R|D)<SS><DD><YY><NNNN>.(oms|xml) (описание имени см в `parseFileName`)
        :return: True, если импорт файла прошел успешно, False в ином случа
        :raise: Exception("архив пуст"), если архив пуст
        """
        docFile = None
        try:
            if zipfile.is_zipfile(fileName):
                zipFile = zipfile.ZipFile(fileName, 'r')
                zipItems = zipFile.namelist()
                if not zipItems:
                    raise Exception(u'zip-архив "%s" пуст' % fileName)
                docFile = zipFile.open(zipItems[0])
            else:
                docFile = open(fileName, 'r')

            self.processRespDocument(CXMLHelper.loadDocument(QtCore.QString(docFile.read().decode(self.encoding))))


        except Exception, e:
            self.logger().warning(u'Не удалось импортировать файл "%s" (%s)' % (fileName, e.message))
            self.onException()
            return False
コード例 #2
0
    def processFile(self, fileName):
        docFile = None
        try:
            isOk, sourceType, sourceInfis, destType, destInfis, year, month, number = self.parseFileName(fileName)
            if not isOk:
                return False

            if not zipfile.is_zipfile(fileName):
                raise Exception(u'Файл %s не является zip-архивом' % fileName)

            zipFile = zipfile.ZipFile(fileName, 'r')
            zipItems = zipFile.namelist()
            if not zipItems:
                raise Exception(u'Zip-архив "%s" пуст' % fileName)
            zipItem = next((item for item in zipItems if not item.startswith('L')), None)
            if zipItem is None:
                raise Exception(u'Необходимый файл в zip-архиве не найден' % fileName)

            docFile = zipFile.open(zipItem)

            self.processDocument(CXMLHelper.loadDocument(QtCore.QString(docFile.read().decode(self.encoding))), sourceInfis)
        except Exception, e:
            self.logger().warning(u'Не удалось провести импорт (%s)' % e.message)
            self.onException()
            return False
コード例 #3
0
ファイル: RCExchange.py プロジェクト: dio4/vista_1
    def openZip(self, zipFileName):
        if not zipfile.is_zipfile(forceString(zipFileName)):
            QtGui.qApp.processEvents()
            return False

        archive = zipfile.ZipFile(forceString(zipFileName), "r")
        names = archive.namelist()
        for fileName in names:
            docFile = archive.read(fileName)
            self.documents[fileName] = CXMLHelper.loadDocument(docFile)
コード例 #4
0
    def processFile(self, fileName, accInfo):
        """Импортирует указанный файл

        :param fileName: имя файла для импорта (A)<SS><DD><YY><NNNN>.(oms|xml) (описание имени см в `parseFileName`)
        :return: True, если импорт файла прошел успешно, False в ином случа
        :raise: Exception("архив пуст"), если архив пуст
        """
        docFile = None
        try:
            isOk, destInfis, sourceInfis, year, number = self.parseFileName(
                fileName)
            if destInfis[:2] != self._orgInfis[:2]:
                self.logger().info(
                    u'Пропуск обработки файла "%s": территория назначения (%s) не соответствует текущей (%s)'
                    % (fileName, destInfis, self._orgInfis))
                return False

            if zipfile.is_zipfile(fileName):
                zipFile = zipfile.ZipFile(fileName, 'r')
                zipItems = zipFile.namelist()
                if not zipItems:
                    raise Exception(u'oms-архив "%s" пуст' % fileName)
                docFile = zipFile.open(zipItems[0])
            else:
                docFile = open(fileName, 'r')

            self.processDocument(
                CXMLHelper.loadDocument(
                    QtCore.QString(docFile.read().decode(self.encoding))),
                sourceInfis, year, accInfo)

            self.logger().info(u'Импорт окончен %s\nОбновлено записей: %s' %
                               (QtCore.QTime.currentTime().toString('hh:mm'),
                                accInfo['countUpdate']))

        except Exception, e:
            self.logger().warning(u'Не удалось импортировать файл "%s" (%s)' %
                                  (fileName, e.message))
            self.onException()
            return False