pywebexec 1.4.14__py3-none-any.whl → 1.4.15__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
@@ -13,7 +13,7 @@ import time
13
13
  import shlex
14
14
  from gunicorn.app.base import Application
15
15
  import ipaddress
16
- from socket import gethostname, gethostbyname_ex, gethostbyaddr, inet_aton, inet_ntoa
16
+ from socket import socket, gethostname, gethostbyname_ex, gethostbyaddr, inet_aton, inet_ntoa, AF_INET, SOCK_STREAM
17
17
  import ssl
18
18
  import re
19
19
  import pwd
@@ -255,10 +255,15 @@ def daemon_d(action, pidfilepath, silent=False, hostname=None, args=None):
255
255
  if pidfile.is_locked():
256
256
  pid = pidfile.read_pid()
257
257
  print(f"Stopping server pid {pid}")
258
- try:
259
- os.kill(pid, signal.SIGINT)
260
- except:
261
- return False
258
+ n = 20
259
+ while n > 0:
260
+ try:
261
+ os.kill(pid, signal.SIGINT)
262
+ time.sleep(0.25)
263
+ n -= 1
264
+ except ProcessLookupError:
265
+ return True
266
+ print("Failed to stop server", file=sys.stderr)
262
267
  return True
263
268
  elif action == "status":
264
269
  status = pidfile.is_locked()
@@ -291,12 +296,14 @@ def start_term(command_id):
291
296
  os.chdir(CWD)
292
297
  start_time = datetime.now().isoformat()
293
298
  user = pwd.getpwuid(os.getuid())[0]
299
+ print(f"Starting terminal session for {user} : {command_id}")
294
300
  update_command_status(command_id, 'running', command="term", params=[user,os.ttyname(sys.stdout.fileno())], start_time=start_time, user=user)
295
301
  output_file_path = get_output_file_path(command_id)
296
302
  res = script(output_file_path)
297
303
  end_time = datetime.now().isoformat()
298
304
  update_command_status(command_id, status="success", end_time=end_time, exit_code=res)
299
- return command_id
305
+ print("Terminal session ended")
306
+ return res
300
307
 
301
308
 
302
309
  def print_urls(command_id=None):
@@ -313,6 +320,11 @@ def print_urls(command_id=None):
313
320
  print(f"{protocol}://{ip}:{args.port}{url_params}")
314
321
 
315
322
 
323
+ def is_port_in_use(address, port):
324
+ with socket(AF_INET, SOCK_STREAM) as s:
325
+ return s.connect_ex((address, port)) == 0
326
+
327
+
316
328
  def parseargs():
317
329
  global app, args, COMMAND_STATUS_DIR, hostname, ip
318
330
 
@@ -359,8 +371,8 @@ def parseargs():
359
371
  os.mkdir(COMMAND_STATUS_DIR, mode=0o700)
360
372
  if args.action == "term":
361
373
  COMMAND_STATUS_DIR = f"{os.getcwd()}/{COMMAND_STATUS_DIR}"
362
- start_term(str(uuid.uuid4()))
363
- sys.exit(0)
374
+ sys.exit(start_term(str(uuid.uuid4())))
375
+
364
376
  (hostname, ip) = resolve(gethostname()) if args.listen == '0.0.0.0' else resolve(args.listen)
365
377
 
366
378
  if args.tokenurl:
@@ -389,9 +401,6 @@ def parseargs():
389
401
  app.config['USER'] = None
390
402
  app.config['PASSWORD'] = None
391
403
 
392
- if args.action != 'stop':
393
- print("Starting server:")
394
- print_urls()
395
404
  return args
396
405
 
397
406
  def get_status_file_path(command_id):
@@ -711,6 +720,16 @@ def popup(command_id):
711
720
  def main():
712
721
  global COMMAND_STATUS_DIR
713
722
  basef = f"{CONFDIR}/pywebexec_{args.listen}:{args.port}"
723
+ if args.action == "restart":
724
+ daemon_d('stop', pidfilepath=basef)
725
+ args.action = "start"
726
+ port_used = is_port_in_use(args.listen, args.port)
727
+ if args.action != "stop":
728
+ print("Starting server:")
729
+ print_urls()
730
+ if args.action != "stop" and port_used:
731
+ print(f"Error: port {args.port} already in use", file=sys.stderr)
732
+ return 1
714
733
  if args.action == "shareterm":
715
734
  COMMAND_STATUS_DIR = f"{os.getcwd()}/{COMMAND_STATUS_DIR}"
716
735
  with open(basef + ".log", "ab+") as log:
@@ -718,13 +737,11 @@ def main():
718
737
  command_id = str(uuid.uuid4())
719
738
  print_urls(command_id)
720
739
  res = start_term(command_id)
740
+ print("Stopping server")
721
741
  time.sleep(1)
722
742
  pywebexec.terminate()
723
- sys.exit()
743
+ sys.exit(res)
724
744
 
725
- if args.action == "restart":
726
- daemon_d('stop', pidfilepath=basef)
727
- args.action = "start"
728
745
  if args.action == "start":
729
746
  return start_gunicorn(daemonized=True, baselog=basef)
730
747
  if args.action:
pywebexec/version.py CHANGED
@@ -12,5 +12,5 @@ __version__: str
12
12
  __version_tuple__: VERSION_TUPLE
13
13
  version_tuple: VERSION_TUPLE
14
14
 
15
- __version__ = version = '1.4.14'
16
- __version_tuple__ = version_tuple = (1, 4, 14)
15
+ __version__ = version = '1.4.15'
16
+ __version_tuple__ = version_tuple = (1, 4, 15)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.2
2
2
  Name: pywebexec
3
- Version: 1.4.14
3
+ Version: 1.4.15
4
4
  Summary: Simple Python HTTP Exec Server
5
5
  Home-page: https://github.com/joknarf/pywebexec
6
6
  Author: Franck Jouvanceau
@@ -1,6 +1,6 @@
1
1
  pywebexec/__init__.py,sha256=4spIsVaF8RJt8S58AG_wWoORRNkws9Iwqprj27C3ljM,99
2
- pywebexec/pywebexec.py,sha256=-wnb1KGTGKHRZUipcvZMwb8yQkidkhs_J_jMR6f84o4,27419
3
- pywebexec/version.py,sha256=LXsHxD5FW3f8CmcjK3voP4WqE9lpQQNN_tpUuI6VMfI,413
2
+ pywebexec/pywebexec.py,sha256=KDvV9_Gbp016p_3clO_-b59j0fSyk4nbPNJK1ehfKsc,28102
3
+ pywebexec/version.py,sha256=GV6XwJnZtaCHeM6MpSSHX9ZtGIZAtVvtA-5uewZQic0,413
4
4
  pywebexec/static/css/Consolas NF.ttf,sha256=DJEOzF0eqZ-kxu3Gs_VE8X0NJqiobBzmxWDGpdgGRxI,1313900
5
5
  pywebexec/static/css/style.css,sha256=cGJHPFj23SQ_bFpesfUaFA3VFxhXtpRUOL_zzx3x_X8,5726
6
6
  pywebexec/static/css/xterm.css,sha256=gy8_LGA7Q61DUf8ElwFQzHqHMBQnbbEmpgZcbdgeSHI,5383
@@ -23,9 +23,9 @@ pywebexec/static/js/xterm/xterm.js,sha256=Bzka76jZwEhVt_LlS0e0qMw7ryGa1p5qfxFyeo
23
23
  pywebexec/templates/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
24
24
  pywebexec/templates/index.html,sha256=DYtT555wSNhnFtzzHhPMWJireynCJNnAuTytpoORQeE,2321
25
25
  pywebexec/templates/popup.html,sha256=T6_tAOUoA58sA1oxB5pb8i42RenoMdCsH8T86Gccb6Q,945
26
- pywebexec-1.4.14.dist-info/LICENSE,sha256=gRJf0JPT_wsZJsUGlWPTS8Vypfl9vQ1qjp6sNbKykuA,1064
27
- pywebexec-1.4.14.dist-info/METADATA,sha256=70sAlcFCe8Lx83npHf3snGV36Ez3OPtfVISxo9IrfaE,7801
28
- pywebexec-1.4.14.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
29
- pywebexec-1.4.14.dist-info/entry_points.txt,sha256=l52GBkPCXRkmlHfEyoVauyfBdg8o-CAtC8qQpOIjJK0,55
30
- pywebexec-1.4.14.dist-info/top_level.txt,sha256=vHoHyzngrfGdm_nM7Xn_5iLmaCrf10XO1EhldgNLEQ8,10
31
- pywebexec-1.4.14.dist-info/RECORD,,
26
+ pywebexec-1.4.15.dist-info/LICENSE,sha256=gRJf0JPT_wsZJsUGlWPTS8Vypfl9vQ1qjp6sNbKykuA,1064
27
+ pywebexec-1.4.15.dist-info/METADATA,sha256=kak3uf5US-34yqqjx7GsyY_tW1AiUF9yJMDSs5n6TLY,7801
28
+ pywebexec-1.4.15.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
29
+ pywebexec-1.4.15.dist-info/entry_points.txt,sha256=l52GBkPCXRkmlHfEyoVauyfBdg8o-CAtC8qQpOIjJK0,55
30
+ pywebexec-1.4.15.dist-info/top_level.txt,sha256=vHoHyzngrfGdm_nM7Xn_5iLmaCrf10XO1EhldgNLEQ8,10
31
+ pywebexec-1.4.15.dist-info/RECORD,,