def run(self): """Run the thread.""" try: while not self.stop.is_set(): if self.enable: should_run = False time_left = self.timeLeft() # Is self.force enable if self.force: should_run = True # check if interval has passed elif time_left.total_seconds() <= 0: should_run = True if should_run: if not self.silent: log.debug('Starting new thread: {name}', {'name': self.name}) self.action.run(self.force) self.lastRun = datetime.datetime.now() if self.force: self.force = False time.sleep(1) # exiting thread self.stop.clear() except Exception as e: exception_handler.handle(e)
def async_call(self, function): try: kwargs = self.request.arguments for arg, value in iteritems(kwargs): if len(value) == 1: kwargs[arg] = self.get_argument(arg) result = function(**kwargs) return result except Exception as e: exception_handler.handle(e)
def async_call(self, function): try: kwargs = self.request.arguments for arg, value in iteritems(kwargs): if len(value) == 1: kwargs[arg] = value[0] if isinstance(kwargs[arg], binary_type): kwargs[arg] = text_type(kwargs[arg], 'utf-8') result = function(**kwargs) return result except Exception as e: exception_handler.handle(e)
def write_ep_file(self, ep_obj): """ Generates and writes ep_obj's metadata under the given path with the given filename root. Uses the episode's name with the extension in _ep_nfo_extension. ep_obj: Episode object for which to create the metadata file_name_path: The file name to use for this metadata. Note that the extension will be automatically added based on _ep_nfo_extension. This should include an absolute path. Note that this method expects that _ep_data will return an ElementTree object. If your _ep_data returns data in another format you'll need to override this method. """ data = self._ep_data(ep_obj) if not data: return False nfo_file_path = self.get_episode_file_path(ep_obj) nfo_file_dir = os.path.dirname(nfo_file_path) if not (nfo_file_path and nfo_file_dir): log.debug( u'Unable to write episode nfo file because episode location is missing.' ) return False try: if not os.path.isdir(nfo_file_dir): log.debug( u'Metadata directory missing, creating it at {location}', {u'location': nfo_file_dir}) os.makedirs(nfo_file_dir) helpers.chmod_as_parent(nfo_file_dir) log.debug(u'Writing episode nfo file to {location}', {u'location': nfo_file_path}) nfo_file = io.open(nfo_file_path, u'wb') data.write(nfo_file, encoding=u'UTF-8') nfo_file.close() helpers.chmod_as_parent(nfo_file_path) except IOError as e: exception_handler.handle(e, u'Unable to write file to {location}', location=nfo_file_path) return False return True
def write_show_file(self, show_obj): """ Generates and writes show_obj's metadata under the given path to the filename given by get_show_file_path() show_obj: Series object for which to create the metadata path: An absolute or relative path where we should put the file. Note that the file name will be the default show_file_name. Note that this method expects that _show_data will return an ElementTree object. If your _show_data returns data in another format you'll need to override this method. """ data = self._show_data(show_obj) if not data: return False nfo_file_path = self.get_show_file_path(show_obj) nfo_file_dir = os.path.dirname(nfo_file_path) try: if not os.path.isdir(nfo_file_dir): log.debug( u'Metadata directory missing, creating it at {location}', {u'location': nfo_file_dir}) os.makedirs(nfo_file_dir) helpers.chmod_as_parent(nfo_file_dir) log.debug(u'Writing show nfo file to {location}', {u'location': nfo_file_path}) nfo_file = io.open(nfo_file_path, u'wb') data.write(nfo_file, encoding=u'UTF-8') nfo_file.close() helpers.chmod_as_parent(nfo_file_path) except IOError as e: exception_handler.handle(e, u'Unable to write file to {location}', location=nfo_file_path) return False return True
def _write_image(self, image_data, image_path, obj=None): """ Saves the data in image_data to the location image_path. Returns True/False to represent success or failure. image_data: binary image data to write to file image_path: file location to save the image to """ # don't bother overwriting it if os.path.isfile(image_path): log.debug(u'Image already exists, not downloading') return False image_dir = os.path.dirname(image_path) if not image_data: log.debug( u'Unable to retrieve image to save in {location}, skipping', {u'location': image_path}) return False try: if not os.path.isdir(image_dir): log.debug( u'Metadata directory missing, creating it at {location}', {u'location': image_path}) os.makedirs(image_dir) helpers.chmod_as_parent(image_dir) outFile = io.open(image_path, u'wb') outFile.write(image_data) outFile.close() helpers.chmod_as_parent(image_path) except IOError as e: exception_handler.handle(e, u'Unable to write image to {location}', location=image_path) return False return True
def run(self): """Run the thread.""" try: while not self.stop.is_set(): if self.enable: current_time = datetime.datetime.now() should_run = False # Is self.force enable if self.force: should_run = True # check if interval has passed elif current_time - self.lastRun >= self.cycleTime: # check if wanting to start around certain time taking interval into account if self.start_time is not None: hour_diff = current_time.time( ).hour - self.start_time.hour if not hour_diff < 0 and hour_diff < self.cycleTime.seconds // 3600: should_run = True else: # set lastRun to only check start_time after another cycleTime self.lastRun = current_time else: should_run = True if should_run: self.lastRun = current_time if not self.silent: log.debug(u'Starting new thread: {name}', {'name': self.name}) self.action.run(self.force) if self.force: self.force = False time.sleep(1) # exiting thread self.stop.clear() except Exception as e: exception_handler.handle(e)
def run(self): """Run the thread.""" try: while not self.stop.is_set(): if self.enable: current_time = datetime.datetime.now() should_run = False # Is self.force enable if self.force: should_run = True # check if interval has passed elif current_time - self.lastRun >= self.cycleTime: # check if wanting to start around certain time taking interval into account if self.start_time is not None: hour_diff = current_time.time().hour - self.start_time.hour if not hour_diff < 0 and hour_diff < self.cycleTime.seconds // 3600: should_run = True else: # set lastRun to only check start_time after another cycleTime self.lastRun = current_time else: should_run = True if should_run: self.lastRun = current_time if not self.silent: log.debug(u'Starting new thread: {name}', {'name': self.name}) self.action.run(self.force) if self.force: self.force = False time.sleep(1) # exiting thread self.stop.clear() except Exception as e: exception_handler.handle(e)