def parse_weekday(text, warn=True): clean_text = str(text).strip().casefold() try: return WeekdayTranslator.get_number_by_name(clean_text) except KeyError: log.warning(f"Cannot parse weekday '{text}'.", warn) return None
def _load_data_from_spec(self, text): try: return yaml.load(text, Loader=yaml.BaseLoader) except Exception as e: log.warning(f"Failed to load temporary meetings from '{text}'") log.exception(e) return None
def parse_time(text, warn=True): clean_text = text.strip().casefold() for f in _time_formats: with suppress(ValueError): return datetime.datetime.strptime(clean_text, f).time() log.warning(f"Cannot parse time '{text}'.", warn) return None
def try_to_add_action(data): action_class = get_action_class(data) if not action_class: log.warning(f"Unknown action '{data}'.") else: _try_to_add_action_for_known_class( action_class, data )
def _do_apply(self, data): try: self._apply(data) except KeyError as e: log.warning(f"Failed to apply action '{data}'," f" missing attribute '{e}'.") except Exception as e: log.warning(f"Failed to apply action '{data}'.") log.exception(e) finally: return data
def _try_to_add_action_for_known_class(action_class, data): try: action = action_class.create(data) except Exception as e: name = action_class.name log.warning(f"Cannot add {name} action '{data}'.") log.warning(str(e)) else: action.set_conditions_from_dict(data) _actions.append( lambda d, level: action.apply(d, level) )
def apply_action(self, entry): """Try to apply action and log errors.""" call = self._determine_action(entry) try: call(entry) except KeyError as e: log.warning( f"Failed to apply action '{entry}'," f" missing attribute {e}." ) except Exception as e: log.warning(f"Failed to apply action '{entry}'.") log.exception(e)
def create_shortcut(desktop=True, startmenu=True): filename = f"meety-{icon_resolution()}.{icon_extension()}" icon_path = resources.get_icon_path(filename) log.debug(f"Creating shortcut with icon '{icon_path}'.") try: msg = create_shortcut_via_pyshortcuts(icon_path, desktop, startmenu) except ImportError: log.warning("Module 'pyshortcuts' is not available!") msg = try_to_copy_desktop_file(filename) if msg is True: _running.update_shortcut_database() return msg
def parse(cls, interval_cls, text, warn=True): if text is None: return None clean_text = io.datetime.prepare_list_of_ranges(text) ranges = utils.list_of_ranges(clean_text) intervals = [] for r in ranges: try: interval = interval_cls.parse(r, warn) except ValueError: log.warning(f"Cannot parse '{r}' in '{text}'.", warn) else: if interval and interval.is_valid: intervals.append(interval) return intervals or None
def _load_data_from_file(self, filename): """Try to load data from YAML file, return empty dictionary on failure. """ try: with open(filename) as file: return yaml.load(file, Loader=yaml.BaseLoader) except FileNotFoundError as e: self._loaded_paths.fail_on(filename, "does not exist") log.warning(f"Meeting file '{filename}' does not exist.") log.exception(e, warn=False) return None except Exception as e: self._loaded_paths.fail_on(filename, "failed to parse") log.warning(f"Failed to load meetings from '{filename}'") log.exception(e) return None
def _load(self): status = "FAILED" config = {} try: with open(self._path) as cfile: config = yaml.load(cfile, Loader=yaml.BaseLoader) assert isinstance(config, dict) except FileNotFoundError: if self._required: log.warning(f"Cannot find configuration '{self.description}'.") else: log.warning(f"No configuration '{self.description}'.") except Exception as e: log.warning(f"Cannot read {self.description} configuration.") log.exception(e) else: status = "successful" finally: log.info(f"Load configuration '{self.description}': {status}") return config
def _log_files_to_consider(self, files): if not files: log.warning("No YAML files to consider!") else: log.info("Will consider the following YAML files:") log.info("\n".join([f" - {f}" for f in files]))
DESCRIPTION = """Meety - quickly start online meetings from YAML.""" SYSTEM = platform.system() _running = None log.debug(f"Your system is '{SYSTEM}'") if SYSTEM == "Linux": from meety.system import linux _running = linux elif SYSTEM == "Darwin": from meety.system import darwin _running = darwin elif SYSTEM == "Windows": from meety.system import windows _running = windows else: log.warning(f"System '{SYSTEM}' is unknown.") def icon_resolution(): return _running.icon_resolution def icon_extension(): return _running.icon_extension def desktop_extension(): return _running.desktop_extension def desktop_path(filename):