コード例 #1
0
def main():
    """Execute entry function."""
    args = parser.parse_args()
    args_dict = vars(args)
    root_dir = args_dict['root'] if 'root' in args else None

    # If a root directory is specified, get the absolute path and
    # check if it exists. Abort if it doesn't exist!
    if root_dir:
        root_dir = os.path.abspath(root_dir)
        if not os.path.exists(root_dir):
            print("The specified directory doesn't exist!")
            sys.exit(1)
    # Default to home directory if no root is specified
    else:
        root_dir = os.path.expanduser('~')

    if args.stopdaemon:
        print_command_factory('STOPDAEMON')(vars(args), root_dir)
    elif args.nodaemon:
        daemon_factory(root_dir)()
    elif args.daemon:
        config_dir = os.path.join(root_dir, '.config/pueue')
        os.makedirs(config_dir, exist_ok=True)
        daemon = Daemonize(app='pueue', pid=os.path.join(config_dir, 'pueue.pid'),
                           action=daemon_factory(root_dir), chdir=root_dir)
        daemon.start()
    elif hasattr(args, 'func'):
        try:
            args.func(args_dict, root_dir)
        except EOFError:
            print('Apparently the daemon just died. Sorry for that :/')
    else:
        print('Invalid Command. Please check -h')
コード例 #2
0
status_subcommand.set_defaults(func=execute_status)

# Configuration
config_parser = subparsers.add_parser('config',
                                      help='Command for various configs.')

config_subparser = config_parser.add_subparsers(
    title='config subcommands', help='Subcommands to set various configs.')

# Configuration: Max process
max_processes_subcommand = config_subparser.add_parser(
    'maxProcesses', help='Set the amount of concurrent running processes.')
max_processes_subcommand.add_argument(
    'value', type=int, help="The amount of concurrent running processes.")
max_processes_subcommand.set_defaults(option='maxProcesses')
max_processes_subcommand.set_defaults(func=print_command_factory('config'))

# Show
show_subcommand = subparsers.add_parser(
    'show', help='Shows the output of the currently running process')
show_subcommand.add_argument(
    '-w',
    '--watch',
    action='store_true',
    help='Get live output in a curses session. Like tail -f.')
show_subcommand.set_defaults(func=execute_show)

# Logs
logs_subcommand = subparsers.add_parser(
    'log', help='Print the current log file to the command line.')
logs_subcommand.add_argument('-k',