Beispiel #1
0
    def get_filename(self):
        """ """
        if self._filename:
            return self._filename

        self._filename = self.barcode.raw
        try:
            self._filename = self._filename_format % self.barcode.data
        except KeyError as ex:
            log.warning("Barcode does not contain %s which is required by file-format" % ex)
        except Exception as ex:
            log.error("%(type)s: %(msg)s" % {'type': type(ex).__name__, 'msg': ex.message, 'args': ex.args})
        return self._filename
Beispiel #2
0
    def process(self, file):
        if self.options.disable_output:
            log.debug("FileHandler has been disabled.")
            return

        log.info("Saving %(filename)s" % {'filename': file.get_filename()})
        full_path = self.options.output_path % file.barcode.data
        full_path = os.path.normpath(os.path.join(full_path, file.get_filename()))
        try:
            f = open(full_path, 'wb')
            file.write(f)
            f.close()
        except IOError as ex:
            log.error("%(type)s: %(msg)s" % {'type': type(ex).__name__, 'msg': ex.strerror, 'args': ex.args})
Beispiel #3
0
 def archive(self, src_file):
     log.info('Archiving  %(filename)s to Dropbox.' % {'filename': os.path.basename(src_file)})
     try:
         f = open(src_file, 'r')
         filename = os.path.join(self.options.dbx_archive, os.path.basename(src_file))
         try:
             meta_data = self.dbx.files_upload(f, filename, autorename=self.options.dbx_autorename)
         except ApiError as ex:
             log.error(ex)
         f.close()
     except IOError as ex:
         log.error("%(type)s: %(msg)s" % {'type': type(ex).__name__, 'msg': ex.message, 'args': ex.args})
     except Exception as ex:
         log.error("%(type)s: %(msg)s" % {'type': type(ex).__name__, 'msg': ex.message, 'args': ex.args})
         log.error(ex)
Beispiel #4
0
    def process(self, file):
        if self.options.url:
            log.info("Uploading %(filename)s to %(url)s" % {'filename': file.get_filename(), 'url': self.options.url})
            try:
                f = StringIO.StringIO()
                file.write(f)
                files = {'file': (os.path.basename(file.get_filename()), f.getvalue(), 'application/pdf', {})}
                log.debug(self.get_form_data(file))
                r = requests.post(self.options.url, data=self.get_form_data(file), files=files)

                if r.status_code == 200:
                    log.info("file uploaded!")
                else:
                    log.warning("Server responded with status code %s [%s]" % (r.status_code, r.text))

            except IOError as ex:
                log.error("%(type)s: %(msg)s" % {'type': type(ex).__name__, 'msg': ex.message, 'args': ex.args})
            except requests.exceptions.ConnectionError as ex:
                log.error("Could not contact server")
            except requests.exceptions.Timeout as ex:
                log.error("Request timed out")
            except Exception as ex:
                log.error("%(type)s: %(msg)s" % {'type': type(ex).__name__, 'msg': ex.message, 'args': ex.args})
Beispiel #5
0
    def process(self, file):
        log.info('Uploading %(filename)s to Dropbox.' % {'filename': file.get_filename()})

        try:
            f = StringIO.StringIO()
            file.write(f)
            f.seek(0)  # not sure why but dropbox would fail with out that, it shouldn't ne read at all.
            upload_path = self.options.dbx_path % file.barcode.data
            upload_path = os.path.normpath(os.path.join('/', upload_path, file.get_filename()))
            try:
                meta_data = self.dbx.files_upload(f, upload_path, autorename=self.options.dbx_autorename)
                log.info("File saved to Dropbox. REV: %s", meta_data.name)
            except ApiError as ex:
                log.error(ex)

        except IOError as ex:
            log.error("%(type)s: %(msg)s" % {'type': type(ex).__name__, 'msg': ex.message, 'args': ex.args})
        except Exception as ex:
            log.error("%(type)s: %(msg)s" % {'type': type(ex).__name__, 'msg': ex.message, 'args': ex.args})
Beispiel #6
0
 def archive(self, src_file):
     try:
         shutil.copy(src_file, self.options.archive_path)
     except Exception as ex:
         log.error(ex)