Flexget/Flexget — pull request #379 by gazpachoking (2014-11-15 22:20:08+00:00)
Title: Refactor client/daemon architecture

Goals:
- [ ] Only one process ever accesses the database
- [ ] All commands are proxied to a running daemon (currently only execute is)
- [ ] Client processes don't load/validate config
- [ ] Client processes don't load plugins
- [ ] User plugins load from config directory rather than hard coded to ~/.flexget/plugins

I'm not exactly sure how appropriate the Manager class is anymore for always being the main entry point. I'm thinking that client processes should not even instantiate a Manager. Here's my current thoughts on what happens when calling flexget executable:
- Run parse_known_args with an argparser that only has the base options configured.
- Find the specified config directory
- Start up logging
- Check for lock file

At this point, execution will split, based on whether there is a running daemon. (determined by checking lock file)

Case 1: (no lock file found)
- Instantiate a Manager class
- Manager will now be responsible for loading plugins
- Call some sort of `run_command` method of manager, where we pass the extra options not parsed in initial argparse pass

Case 2: (active lock file found, it isn't a daemon)
- Just quit with an error, you can't start 2 flexget processes at once

Case 3: (active lock file found, it's a daemon)
- Some sort of ipc method that proxies to the daemon Manager `run_command` method with our extra cli arguments
- All logs and stdout resulting from `run_command` get proxied back from daemon and displayed to client process

If we go with this plan, here are some things that need to happen:
- [ ] Separate lock file code from Manager
- [ ] Separate config finding code from Manager
- [ ] Move plugin loading into manager initialization
- [ ] Add run_command method to Manager, which takes the cli options (this includes the command and its options)
- [ ] Convert execute method of IPCClient to be a generic run_command

@paranoidi Any thoughts are appreciated, just trying to dump my ideas here now to get feedback.