Exemple #1
0
    def setup(self):
        log.debug('%s Setup' % self.__class__.__name__)
        self.dbx_key = self.options.dbx_key
        self.dbx_secret = self.options.dbx_secret
        self.dbx_token = self.get_token()

        try:
            self.dbx = dropbox.Dropbox(self.dbx_token)
            self.dbx_user = self.dbx.users_get_current_account()
            log.info(self.dbx_user.name.display_name)
        except AuthError as ex:
            log.warning('Dropbox Auth Error')
Exemple #2
0
    def parse(self):
        """ """
        new_file = None
        for pdf_page in self.pdf_file.pages:
            page = Page(page=pdf_page)

            if page.is_efos:
                new_file = self.new_file(page.get_barcode())
                log.info("Creating page %s" % new_file.get_filename())
            elif new_file:
                new_file.add(page)
                log.debug("Adding page to %s" % new_file.get_filename())
Exemple #3
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})
Exemple #4
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)
Exemple #5
0
 def delete(self):
     """ """
     # # After Parsing, Archive and Delete
     # if self.options.archive:
     #     archive_filename = os.path.join(self.options.archive, self.filename.replace(self.options.watch, "")[1:])
     #     if self.options.delete:
     #         log.info("Archiving file %s to %s" % (self.filename, archive_filename))
     #         log.info("Removing file %s" % (self.filename,))
     #         os.rename(self.filename, archive_filename)
     #     else:
     #         log.info("Archiving file %s to %s" % (self.filename, archive_filename))
     #         shutil.copy(self.filename, archive_filename)
     if self.options.delete:
         if os.path.exists(self.filename):
             os.remove(self.filename)
             log.info("Removing file %s" % (self.filename,))
Exemple #6
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})
Exemple #7
0
    def setup(self):
        log.debug('%s Setup' % self.__class__.__name__)

        if not os.path.isabs(self.options.output_path):
            self.options.output_path = os.path.join(self.options.watch, self.options.output_path)

        if not os.path.isabs(self.options.archive_path):
            self.options.archive_path = os.path.join(self.options.watch, self.options.archive_path)

        if not self.options.disable_output:
            if not os.path.isdir(self.options.output_path):
                log.debug("Creating output directory %s.", self.options.output_path)
                os.makedirs(self.options.output_path)
            log.info("Output directory: %s" % self.options.output_path)

        if self.options.archive:
            if not os.path.isdir(self.options.archive_path):
                log.debug("Creating archive directory %s.", self.options.archive_path)
                os.makedirs(self.options.archive_path)
            log.info("Archive directory: %s" % self.options.archive_path)
Exemple #8
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})