コード例 #1
0
ファイル: cli.py プロジェクト: jacebrowning/dropthebeat
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)
コード例 #2
0
ファイル: gui.py プロジェクト: jacebrowning/dropthebeat
    def __init__(self, master=None, root=None, home=None, name=None):
        ttk.Frame.__init__(self, master)

        # Load the root sharing directory
        self.root = root or share.find(home)

        # Load the user
        self.user = user.User(os.path.join(self.root, name)) if name else None
        try:
            self.user = self.user or user.get_current(self.root)
        except EnvironmentError:

            while True:

                msg = "Enter your name in the form 'First Last':"
                text = simpledialog.askstring("Create a User", msg)
                logging.debug("text: {}".format(repr(text)))
                name = text.strip(" '") if text else None
                if not name:
                    raise KeyboardInterrupt("no user specified")
                try:
                    self.user = user.User.new(self.root, name)
                except EnvironmentError:
                    existing = user.User(os.path.join(self.root, name))
                    msg = "Is this you:"
                    for info in existing.info:
                        msg += "\n\n'{}' on '{}'".format(info[1], info[0])
                    if not existing.info or \
                            messagebox.askyesno("Add to Existing User", msg):
                        self.user = user.User.add(self.root, name)
                        break
                else:
                    break

        # Create variables
        self.path_root = tk.StringVar(value=self.root)
        self.path_downloads = tk.StringVar(value=self.user.path_downloads)
        self.outgoing = []
        self.incoming = []

        # Initialize the GUI
        self.listbox_outgoing = None
        self.listbox_incoming = None
        frame = self.init(master)
        frame.pack(fill=tk.BOTH, expand=1)

        # Show the GUI
        master.deiconify()
        self.update()
コード例 #3
0
ファイル: test_user.py プロジェクト: jacebrowning/dropthebeat
 def test_get_current(self):
     """Verify the current user can be retrieved."""
     os.mkdir(os.path.join(self.root, "empty"))
     user = get_current(self.root)
     self.assertEqual(self.user, user)