def exc_desktop_call(self, meth, *args, **kwargs): if self._desktop is None: self._desktop = get_desktop() try: m = getattr(self._desktop.__class__, meth, None) if m is None: print('method %s not found in class %s'%(meth, self._desktop.__class__.__name__)) raise CommandError() return m(self._desktop, *args, **kwargs) except (WPStyleError, DesktopError) as e: print(e) raise CommandError()
def exc_call(self, method): try: score = method() print('image score: %d' % score) except DBImageError as e: print(str(e)) raise CommandError()
def config_call(self, func, *args): try: r = func(*args) return r except (ConfigError, ValueError) as e: print(str(e)) raise CommandError()
def get_wallpaper_image(self): try: db_images = DBImages() image = db_images.get_current_wallpaper_image() except DBImageError as e: print(e) raise CommandError() return image
def keep(self, period): '''Keep the wallpaper unchanged for a certain period of time. period: time period''' try: exp_period = self.keep_wallpaper(period) print('wallpaper will stick for next %s' % exp_period) except KeepError as e: print(str(e)) raise CommandError()
def add(self, frequency): '''Add schedule. frequency: time frequency for changing wallpaper''' scheduler = Scheduler() try: scheduler.set_frequency(frequency) except SchedulerError as e: print(str(e)) raise CommandError()
def player_list_error_wrapped(self, method, *args, **kwargs): try: return method(*args, **kwargs) except PlayerListError as e: print(e) raise CommandError() except AttributeError as e: # In case a command is sent to class Player and VLC is not running, the following error occurs: # <<'NoneType' object has no attribute 'xyz'.>> # This error is explicitly catched here to avoid crashing of the complete program. print("VLC player is not running.") return -1
def validate_input(self, regex, input, err_msg): #import pdb; pdb.set_trace() match = re.compile(regex).match(input) if match is None: print(err_msg) raise CommandError() return match #later #@common #def instance(self, id=1, all): '''Common arguments for subcommands dealing with multiple instances.
def favorite(self, unfavorite=False): '''Favorite current wallpaper image. unfavorite: remove current wallpaper image from favorites''' db_images = Images() try: if not unfavorite: db_images.favorite_wallpaper() print('favorited') else: db_images.unfavorite_wallpaper() print('removed from favorites') except DBImageError as e: print(str(e)) raise CommandError()
def change_wallpaper(self, params): exc = None for _ in range(0, self._repeat_count): try: wallpaper = Wallpaper(params=params) wallpaper.change() except WallpaperError as e: printer.printf('error', str(e)) exc = CommandError() sleep(self._repeat_delay) if exc is not None: raise exc
def dump(self): 'Print all the configuration settings.' settings = self.exc_call(self._config.get_all) for name, value in settings: printer.printf(name, str(value)) printer.printf('', '') try: sources = Sources() source_states = sources.get_all() except DBSourceError as e: print(e) raise CommandError() for name, enabled in source_states: printer.printf(name, 'enabled' if enabled else 'disabled')
def exc_call(self, method, *args): try: method(*args) except DBSourceError as e: print(e) raise CommandError()
def exc_call(self, method, *args, **kwargs): try: return method(*args, **kwargs) except ConfigError as e: print(e) raise CommandError()
def player_list_error_wrapped(self, method, *args, **kwargs): try: return method(*args, **kwargs) except PlayerListError as e: print(e) raise CommandError()