52 lines
2.2 KiB
Python
52 lines
2.2 KiB
Python
"""Query or change only the Windows desktop FPS in the box's local POC config."""
|
|
import argparse
|
|
import subprocess
|
|
import sys
|
|
|
|
parser = argparse.ArgumentParser(description=__doc__)
|
|
parser.add_argument("--fps", type=int, choices=[30, 45, 60], required=True)
|
|
parser.add_argument("--apply", action="store_true")
|
|
args = parser.parse_args()
|
|
program = r'''
|
|
from pathlib import Path
|
|
from datetime import datetime
|
|
import json, os, shutil, stat, tempfile
|
|
path=Path.home()/'.config/vdi-terminal/desktops.json'
|
|
original=path.read_bytes()
|
|
data=json.loads(original)
|
|
matches=[d for d in data['desktops'] if d.get('id')=='desk-win10-01']
|
|
if len(matches)!=1 or matches[0].get('endpoint')!='192.168.1.70':
|
|
raise RuntimeError('Unexpected Windows desktop identity; inspect before changing')
|
|
desktop=matches[0]
|
|
before=desktop.get('fps')
|
|
backup=None
|
|
if __APPLY__:
|
|
backup=Path.home()/'vdi-terminal/backups'/('fps-'+datetime.now().strftime('%Y%m%d-%H%M%S-%f'))
|
|
backup.mkdir(parents=True)
|
|
shutil.copy2(path,backup/'desktops.json')
|
|
desktop['fps']=__FPS__
|
|
name=None
|
|
try:
|
|
with tempfile.NamedTemporaryFile(dir=path.parent,prefix='.desktops-',delete=False) as stream:
|
|
name=stream.name
|
|
stream.write((json.dumps(data,ensure_ascii=False,indent=2)+'\n').encode())
|
|
os.chmod(name,stat.S_IMODE(path.stat().st_mode))
|
|
if path.read_bytes()!=original:
|
|
raise RuntimeError('Desktop configuration changed concurrently; left it intact')
|
|
os.replace(name,path)
|
|
name=None
|
|
if json.loads(path.read_bytes())!=data:
|
|
raise RuntimeError('Desktop configuration read-back mismatch')
|
|
finally:
|
|
if name is not None: os.unlink(name)
|
|
print(json.dumps({'desktop':desktop['id'],'before':before,'fps':desktop['fps'],
|
|
'requested':__FPS__,'applied':__APPLY__,
|
|
'backup':str(backup) if backup else None}))
|
|
'''.replace("__FPS__", str(args.fps)).replace("__APPLY__", str(args.apply))
|
|
result = subprocess.run(["ssh", "-o", "ConnectTimeout=8", "armbian@192.168.1.188", "python3 -"],
|
|
input=program, capture_output=True, text=True, encoding="utf-8")
|
|
print(result.stdout, end="")
|
|
if result.stderr:
|
|
print(result.stderr, end="", file=sys.stderr)
|
|
sys.exit(result.returncode)
|