def test_flush_wallpapers(self): testdir = os.path.join(os.path.expanduser("~"), '.WAKEUPDOLORES') setupUtils.make_dir(testdir) test_dir_to_delete = os.path.join(testdir, 'tobedeleted') setupUtils.make_dir(test_dir_to_delete) utils.flush_wallpapers(testdir) self.assertEqual(os.listdir(testdir), []) shutil.rmtree(testdir)
def main(): """Main method of the UIP.""" wallpaper = Wallpaper() settingsParser = ParseSettings() settings = settingsParser.settings pid_file = os.path.join(HOME_DIR, 'daemon-uip.pid') auto_flush(settings) if settings['error']: print("\nWRONG USAGE OF FLAGS, see --help") settingsParser.show_help() exit_UIP() if settings['service']: if 'start' == str(settings['service']): with Daemonizer() as (is_setup, daemonizer): if is_setup: print("UIP will now run as a serice.") try: daemonizer(pid_file) except SystemExit: print("UIP service already, running " "Close previous app by running UIP --service stop") sys.exit(0) elif 'stop' == str(settings['service']): exit_UIP() else: print('Wrong option for service flag see --help') print("Hey this is UIP! you can use it to download" " images from reddit and also to schedule the setting of these" " images as your desktop wallpaper." " \nPress ctrl-c to exit") if settings['offline']: print("You have choosen to run UIP in offline mode.") if settings['flush']: flush_wallpapers(settings['pics-folder']) if not settings['offline']: print("UIP will now connect to internet and download images" " from reddit and unsplash.") if settings['ui']: from uiplib.gui.mainGui import MainWindow app = MainWindow(settings, wallpaper) app.run() exit_UIP() else: try: scheduler_object = Scheduler( settings['offline'], settings['pics-folder'], settings['timeout'], settings['website'], settings['no-of-images'], not (settings['service'] or settings['ui']), wallpaper) while True: # To keep the program from closing. time.sleep(15) except KeyboardInterrupt: exit_UIP()
def flush(self): """Method to flush all images.""" ask = messagebox.askquestion("Flush!", "Are You Sure? This will empty" " the contents in your pics folder", icon='warning') if ask == 'yes': flush_wallpapers(self.settings['pics-folder']) if active_count() < 2: download_thread = Thread(target=download, args=(self.settings['website'], self.settings['pics-folder'], self.settings['no-of-images']), kwargs={'appObj': self}, daemon=True) download_thread.start() self.update_ui() else: print("Not Flushing!")
def test_flush_wallpapers_raise_exception(self): testdir = os.path.join(os.path.expanduser("~"), '.WAKEUPDOLORES') utils.flush_wallpapers(testdir) self.assertEqual(os.path.isdir(testdir), False)