def run(self): # We set up the paths every time since the user could have switched # since last time. self._setuser() if self.user: inboxfiles = gripe.listdir(self.inbox) for f in inboxfiles: logger.debug("ScanInbox: Found file %s", f) gripe.rename(os.path.join(self.inbox, f), os.path.join(self.queue, f)) self.addfile(os.path.join(gripe.root_dir(), self.queue, f))
def run(self): # We set up the paths every time since the user could have switched # since last time. self._setuser() if self.user: inbox_files = gripe.listdir(self.inbox) for f in inbox_files: if f.endswith(".fit"): logger.debug("ScanInbox: Found file %s", f) gripe.rename(os.path.join(self.inbox, f), os.path.join(self.queue, f)) self.addfile(os.path.join(gripe.root_dir(), self.queue, f))
def handle(self): logger.debug("ImportFile: Importing file %s", self.filename) self.started("Importing file %s" % self.filename) try: f = os.path.basename(self.filename) parser = self.get_parser() if not parser: logger.warning("No parser registered for %s", f) return parser.set_athlete(self.user) parser.set_logger(self.thread) q = ImportedFITFile.query('"filename" =', f, parent = self.user) fitfile = q.get() if not fitfile: fitfile = ImportedFITFile(parent = self.user) fitfile.filename = f fitfile.status = False fitfile.put() try: parser.parse() except sweattrails.device.exceptions.SessionExistsError: # Ignore if the file was generated by the ANT download. # Otherwise complain. if "-st-antfs" not in self.filename: raise # Move file to 'done' directory if it was in the queue before: if os.path.basename(os.path.dirname(self.filename)) == "queue": gripe.rename(os.path.join(self.queue, f), os.path.join(self.done, f)) # Set file to completed in the log: with gripe.db.Tx.begin(): fitfile.status = True fitfile.put() self.finished("File %s successfully imported" % self.filename) except sweattrails.device.exceptions.FileImportError as ie: logger.exception("Exception importing file") self.error("Importing file %s" % self.filename, ie.message) raise
def handle(self): logger.debug("ImportFile: Importing file %s", self.filename) f = os.path.basename(self.filename) parser = sweattrails.device.get_parser(self.filename) if not parser: logger.warning("No parser registered for %s", f) return parser.set_athlete(self.user) parser.set_logger(self) q = ImportedFITFile.query('"filename" =', f, parent=self.user) fit_file = q.get() dest = self.rejected try: if not fit_file: fit_file = ImportedFITFile(parent=self.user) fit_file.filename = f fit_file.status = False fit_file.put() try: parser.parse() except sweattrails.device.exceptions.SessionExistsError: # Ignore if the file was generated by the ANT download. # Otherwise complain. if "-st-antfs" not in self.filename: raise dest = self.done QCoreApplication.instance().refresh.emit(None) except Exception: traceback.print_exc() logger.exception("Exception importing file '%s'", f) finally: if os.path.basename(os.path.dirname(self.filename)) == "queue": gripe.rename(os.path.join(self.queue, f), os.path.join(dest, f)) # Set file to completed in the log: with gripe.db.Tx.begin(): fit_file.status = True fit_file.put()