Skip to content

Commit

Permalink
chg: dev: move old directory support to serv_run, update daemon script
Browse files Browse the repository at this point in the history
Signed-off-by: Stephen L Arnold <nerdboy@gentoo.org>
  • Loading branch information
sarnold committed Oct 18, 2022
1 parent 9dc39a8 commit ef45f10
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 3 deletions.
3 changes: 0 additions & 3 deletions pyserv/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
"""

import logging
import os
import sys
import threading
from functools import partial
Expand Down Expand Up @@ -98,8 +97,6 @@ def __init__(self, iface, port, directory):

def run(self):
"""Start main server thread"""
if sys.version_info < (3, 7):
os.chdir(self.directory)
self.server.serve_forever()

def stop(self):
Expand Down
7 changes: 7 additions & 0 deletions pyserv/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
"""

import logging
import os
import sys
from pathlib import Path

from . import GetServer
from .settings import DEBUG, DOCROOT
Expand Down Expand Up @@ -33,13 +35,18 @@ def serv_run(iface='', port=8080, directory=DOCROOT): # pragma: no cover
:param iface: server listen interface
:param port: server listen port
"""
start_dir = Path.cwd()
path_diff = start_dir.name != Path(directory).name
if sys.version_info < (3, 7) and path_diff:
os.chdir(directory)
httpd = serv_init(iface, port, directory)
logging.info('Starting HTTP SERVER at %s:%s', iface, port)
try:
httpd.start()
httpd.join()
except KeyboardInterrupt:
httpd.stop()
os.chdir(start_dir)
print("\nExiting ...")


Expand Down
3 changes: 3 additions & 0 deletions scripts/httpdaemon
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ Http daemon script using pyserv (see settings.py for env vars).

import argparse
import logging
import os
import sys
from pathlib import Path

Expand Down Expand Up @@ -41,6 +42,8 @@ class ServDaemon(Daemon):
Daemon needs a run method. In this case we need to instantiate
our GetServer obj here, ie, *after* the Daemon object.
"""
if sys.version_info < (3, 7):
os.chdir(DOCROOT)
self.servd = GetServer(IFACE, PORT, DOCROOT)
self.servd.start()

Expand Down

0 comments on commit ef45f10

Please sign in to comment.