pywebexec 1.7.18__py3-none-any.whl → 1.8.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
pywebexec/pywebexec.py CHANGED
@@ -404,37 +404,42 @@ def get_output_file_path(command_id):
404
404
 
405
405
  def update_command_status(command_id, updates):
406
406
  status_file_path = get_status_file_path(command_id)
407
- status = read_command_status(command_id) or {}
407
+ status = read_command_status(command_id)
408
408
  status.update(updates)
409
+ status = status.copy()
409
410
  if status.get('status') != 'running':
410
411
  output_file_path = get_output_file_path(command_id)
411
412
  if os.path.exists(output_file_path):
412
413
  status['last_output_line'] = get_last_line(output_file_path, status.get('cols'), status.get('rows'))
413
- status_cache[command_id] = status
414
+ if 'last_read' in status:
415
+ del status['last_read']
414
416
  with open(status_file_path, 'w') as f:
415
417
  json.dump(status, f)
418
+ os.sync()
419
+ status_cache[command_id] = status
416
420
 
417
421
 
418
422
  def read_command_status(command_id):
419
423
  # Return cached status if available
420
- status_data = {}
421
- if command_id in status_cache:
422
- status_data = status_cache[command_id]
424
+ global status_cache
425
+ if not command_id in status_cache:
426
+ status_cache[command_id] = {}
427
+ status_data = status_cache[command_id]
423
428
  status = status_data.get('status')
424
429
  if status and status != "running":
425
430
  return status_data
426
- if command_id in status_cache and status_cache.get('last_read',0)>datetime.now().timestamp()-0.5:
431
+ if status_data.get('last_read',0)>datetime.now().timestamp()-0.5:
427
432
  return status_data
428
433
  status_file_path = get_status_file_path(command_id)
429
434
  if not os.path.exists(status_file_path):
430
- return None
435
+ return status_data
431
436
  with open(status_file_path, 'r') as f:
432
437
  try:
433
438
  status_data.update(json.load(f))
434
439
  except json.JSONDecodeError:
435
- return None
440
+ return status_data
436
441
  status_data['last_read'] = datetime.now().timestamp()
437
- status_cache[command_id] = status_data
442
+ #status_cache[command_id] = status_data
438
443
  return status_data
439
444
 
440
445
  def sigwinch_passthrough(sig, data):
@@ -466,7 +471,6 @@ def run_command(fromip, user, command, params, command_id, rows, cols):
466
471
  log_info(fromip, user, f'run_command {command_id}: {command_str(command, params)}')
467
472
  start_time = datetime.now(timezone.utc).isoformat()
468
473
  update_command_status(command_id, {
469
- 'status': 'running',
470
474
  'command': command,
471
475
  'params': params,
472
476
  'start_time': start_time,
@@ -493,7 +497,6 @@ def run_command(fromip, user, command, params, command_id, rows, cols):
493
497
  'status': 'aborted',
494
498
  'end_time': end_time,
495
499
  'exit_code': exit_code,
496
- 'user': user
497
500
  })
498
501
  log_info(fromip, user, f'run_command {command_id}: {command_str(command, params)}: command aborted')
499
502
  else:
@@ -503,7 +506,6 @@ def run_command(fromip, user, command, params, command_id, rows, cols):
503
506
  'status': 'success',
504
507
  'end_time': end_time,
505
508
  'exit_code': exit_code,
506
- 'user': user
507
509
  })
508
510
  log_info(fromip, user, f'run_command {command_id}: {command_str(command, params)}: completed successfully')
509
511
  else:
@@ -511,7 +513,6 @@ def run_command(fromip, user, command, params, command_id, rows, cols):
511
513
  'status': 'failed',
512
514
  'end_time': end_time,
513
515
  'exit_code': exit_code,
514
- 'user': user
515
516
  })
516
517
  log_info(fromip, user, f'run_command {command_id}: {command_str(command, params)}: exit code {exit_code}')
517
518
 
@@ -521,7 +522,6 @@ def run_command(fromip, user, command, params, command_id, rows, cols):
521
522
  'status': 'failed',
522
523
  'end_time': end_time,
523
524
  'exit_code': 1,
524
- 'user': user
525
525
  })
526
526
  with open(get_output_file_path(command_id), 'a') as output_file:
527
527
  output_file.write(str(e))
@@ -555,7 +555,6 @@ def read_commands():
555
555
  'last_update': datetime.now().timestamp(),
556
556
  'last_output_line': get_last_line(output_file_path, status.get('cols'), status.get('rows')),
557
557
  })
558
- status_cache[command_id] = status
559
558
  commands.append({
560
559
  'command_id': command_id,
561
560
  'status': status.get('status'),
@@ -733,13 +732,6 @@ def get_command_status(command_id):
733
732
  status = read_command_status(command_id)
734
733
  if not status:
735
734
  return jsonify({'error': 'Invalid command_id'}), 404
736
-
737
- # output_file_path = get_output_file_path(command_id)
738
- # if os.path.exists(output_file_path):
739
- # with open(output_file_path, 'r') as output_file:
740
- # output = output_file.read()
741
- # status['output'] = output
742
-
743
735
  return jsonify(status)
744
736
 
745
737
  @app.route('/')
@@ -759,11 +751,16 @@ def get_command_output(command_id):
759
751
  maxsize = int(request.args.get('maxsize', 10485760))
760
752
  output_file_path = get_output_file_path(command_id)
761
753
  if os.path.exists(output_file_path):
762
- with open(output_file_path, 'rb') as output_file:
763
- output_file.seek(offset)
764
- output = output_file.read().decode('utf-8', errors='replace')
765
- new_offset = output_file.tell()
766
- status_data = read_command_status(command_id) or {}
754
+ size = os.path.getsize(output_file_path)
755
+ if offset >= size:
756
+ output = ''
757
+ new_offset = offset
758
+ else:
759
+ with open(output_file_path, 'rb') as output_file:
760
+ output_file.seek(offset)
761
+ output = output_file.read().decode('utf-8', errors='replace')
762
+ new_offset = output_file.tell()
763
+ status_data = read_command_status(command_id)
767
764
  token = app.config.get("TOKEN_URL")
768
765
  token_param = f"&token={token}" if token else ""
769
766
  response = {
pywebexec/version.py CHANGED
@@ -17,5 +17,5 @@ __version__: str
17
17
  __version_tuple__: VERSION_TUPLE
18
18
  version_tuple: VERSION_TUPLE
19
19
 
20
- __version__ = version = '1.7.18'
21
- __version_tuple__ = version_tuple = (1, 7, 18)
20
+ __version__ = version = '1.8.0'
21
+ __version_tuple__ = version_tuple = (1, 8, 0)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.2
2
2
  Name: pywebexec
3
- Version: 1.7.18
3
+ Version: 1.8.0
4
4
  Summary: Simple Python HTTP Exec Server
5
5
  Home-page: https://github.com/joknarf/pywebexec
6
6
  Author: Franck Jouvanceau
@@ -1,7 +1,7 @@
1
1
  pywebexec/__init__.py,sha256=197fHJy0UDBwTTpGCGortZRr-w2kTaD7MxqdbVmTEi0,61
2
2
  pywebexec/host_ip.py,sha256=Ud_HTflWVQ8789aoQ2RZdT1wGI-ccvrwSWGz_c7T3TI,1241
3
- pywebexec/pywebexec.py,sha256=j52h1x4VgVLgDZ6hTX-QMt7UbmDtO0MHg2EnLcmvcGQ,32727
4
- pywebexec/version.py,sha256=atP_5XTod1UHdqP67s_f64V3lP30xwHn22VXn1ZEIgM,513
3
+ pywebexec/pywebexec.py,sha256=Pwsjq9VpM19l10-suEZ5nEXBv-LOaJNZy91ubuAkBos,32541
4
+ pywebexec/version.py,sha256=NlHLpXkNFmTH52K5-WhbSOpEjuVpHwg6f2tUr8gHTCY,511
5
5
  pywebexec/static/css/Consolas NF.ttf,sha256=DJEOzF0eqZ-kxu3Gs_VE8X0NJqiobBzmxWDGpdgGRxI,1313900
6
6
  pywebexec/static/css/style.css,sha256=fU-_eAk6Xy0L_GbH9rJBkeCFe5M2RYQA99cvRZ3pW9w,7934
7
7
  pywebexec/static/css/xterm.css,sha256=uo5phWaUiJgcz0DAzv46uoByLLbJLeetYosL1xf68rY,5559
@@ -36,9 +36,9 @@ pywebexec/static/js/xterm/xterm.js.map,sha256=Y7O2Pb-fIS7Z8AC1D5s04_aiW_Jf1f4mCf
36
36
  pywebexec/templates/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
37
37
  pywebexec/templates/index.html,sha256=KSdQYBdzWKP6v0ETZsMO_729aosGBAzJxAss8T5jCto,2953
38
38
  pywebexec/templates/popup.html,sha256=f5m4u8WKpkevL2mQamGqo4_y-rSuLOXGuNsezuUbniY,1508
39
- pywebexec-1.7.18.dist-info/LICENSE,sha256=gRJf0JPT_wsZJsUGlWPTS8Vypfl9vQ1qjp6sNbKykuA,1064
40
- pywebexec-1.7.18.dist-info/METADATA,sha256=uHZ987HDurDIzK2s6krXQHYXkpqjS91Z_uQiIaovs98,8147
41
- pywebexec-1.7.18.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
42
- pywebexec-1.7.18.dist-info/entry_points.txt,sha256=l52GBkPCXRkmlHfEyoVauyfBdg8o-CAtC8qQpOIjJK0,55
43
- pywebexec-1.7.18.dist-info/top_level.txt,sha256=vHoHyzngrfGdm_nM7Xn_5iLmaCrf10XO1EhldgNLEQ8,10
44
- pywebexec-1.7.18.dist-info/RECORD,,
39
+ pywebexec-1.8.0.dist-info/LICENSE,sha256=gRJf0JPT_wsZJsUGlWPTS8Vypfl9vQ1qjp6sNbKykuA,1064
40
+ pywebexec-1.8.0.dist-info/METADATA,sha256=BwYrBzm4blpnbGe0A1xwwobqIHCnIT211Jobsx9GpQg,8146
41
+ pywebexec-1.8.0.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
42
+ pywebexec-1.8.0.dist-info/entry_points.txt,sha256=l52GBkPCXRkmlHfEyoVauyfBdg8o-CAtC8qQpOIjJK0,55
43
+ pywebexec-1.8.0.dist-info/top_level.txt,sha256=vHoHyzngrfGdm_nM7Xn_5iLmaCrf10XO1EhldgNLEQ8,10
44
+ pywebexec-1.8.0.dist-info/RECORD,,