def _run(args, cwd, err): # pylint: disable=W0613 """Process arguments and run the main program. @param args: Namespace of CLI arguments @param cwd: current working directory @param err: function to call for CLI errors """ # Run the GUI if args.gui: logging.info("launching the GUI...") return gui.run(args) # Find the sharing directory root = args.root or share.find() # Create a new user and exit if args.new: return _new(args.new, root) # Get the current user if args.test: this = user.User(os.path.join(root, args.test)) else: this = user.get_current(root) this.cleanup() # Delete user and exit if args.delete: this.delete() print("deleted: {}".format(this)) return True # Display incoming, share a song, and/or display outgoing and exit if any((args.incoming, args.share, args.outgoing)): if args.incoming: logging.info("displaying incoming songs...") for song in this.incoming: print("incoming: {}".format(song)) if args.share: path = os.path.abspath(args.share) song = this.recommend(path, args.users) print("shared: {}".format(path)) if args.outgoing: logging.info("displaying outgoing songs...") for song in this.outgoing: print("outgoing: {}".format(song)) return True # Run the command-line interface loop logging.info("starting the main loop...") return _loop(this, args.daemon, not args.no_log)
def test_import(self): """Verify tkinter import errors are handled.""" sys.modules['tkinter'] = Mock(side_effect=ImportError) imp.reload(gui) self.assertFalse(gui.run(Mock())) self.assertIsInstance(gui.tk, Mock)