Skip to content

Commit

Permalink
Added fahctl command line client control script. #119
Browse files Browse the repository at this point in the history
  • Loading branch information
jcoffland committed Aug 19, 2024
1 parent 709d454 commit 6d889a4
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 1 deletion.
3 changes: 2 additions & 1 deletion SConstruct
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ if 'package' in COMMAND_LINE_TARGETS:
icons = ['images/fahlogo.png'],

documents = docs,
programs = [str(client[0])],
programs = [str(client[0]), 'scripts/fahctl'],
desktop_menu = ['build/install/lin/fah-client.desktop'],
changelog = 'CHANGELOG.md',
systemd = ['build/install/lin/fah-client.service'],
Expand All @@ -185,6 +185,7 @@ if 'package' in COMMAND_LINE_TARGETS:
deb_depends = 'ca-certificates',
deb_conflicts = 'FAHClient, fahclient',
deb_replaces = 'FAHClient, fahclient',
deb_suggests = 'python3-websocket',
deb_pre_depends = 'adduser, procps',
deb_priority = 'optional',

Expand Down
49 changes: 49 additions & 0 deletions scripts/fahctl
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#!/usr/bin/env python3

import sys
import argparse
import json

try:
from websocket import create_connection
except Exception as e:
print('Missing python3-websocket library', file = sys.stderr)
sys.exit(1)


# Parse args
epilog = '''\
Examples:
fahctl fold
fahctl finish
fahctl pause
'''

parser = argparse.ArgumentParser(
'Folding@home v8 Client command line control',
formatter_class = argparse.RawDescriptionHelpFormatter, epilog = epilog)

parser.add_argument('command', choices = ['fold', 'pause', 'finish', 'state'],
help = 'The command to send to the client')
parser.add_argument('group', nargs = '?',
help = 'Optional target resource group')
parser.add_argument('--address', default = '127.0.0.1:7396',
help = 'Client address')

args = parser.parse_args()


# Connect
ws = create_connection('ws://%s/api/websocket' % args.address)


# Send command
if args.command == 'state': print(ws.recv())
else:
msg = dict(cmd = 'state', state = args.command)
if args.group is not None: msg['group'] = args.group
ws.send(json.dumps(msg))


# Close
ws.close()

0 comments on commit 6d889a4

Please sign in to comment.