Skip to content

Commit

Permalink
revert: laylines only when moving
Browse files Browse the repository at this point in the history
  • Loading branch information
quantenschaum committed Jul 7, 2024
1 parent 2bcfc1e commit 6f7a6d9
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 26 deletions.
16 changes: 8 additions & 8 deletions server/avnav_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
# DEALINGS IN THE SOFTWARE.
#
# parts from this software (AIS decoding) are taken from the gpsd project
# so refer to this BSD licencse also (see ais.py) or omit ais.py
# so refer to this BSD licencse also (see ais.py) or omit ais.py
###############################################################################
import datetime
import logging.handlers
Expand Down Expand Up @@ -57,7 +57,7 @@ def avnavPrint(*args, **kwargs):
first=False
AVNLog.info(line)

builtins.print=avnavPrint
#builtins.print=avnavPrint

def sighandler(signal,frame):
AVNWorker.shutdownServer()
Expand Down Expand Up @@ -242,9 +242,9 @@ def main(argv):
if httpServer is not None and options.urlmap is not None:
urlmaps = options.urlmap if isinstance(options.urlmap,list) else [options.urlmap]
for urlmap in urlmaps:
for mapping in re.split("\s*,\s*",urlmap):
for mapping in re.split(r"\s*,\s*",urlmap):
try:
url,path=re.split("\s*=\s*",mapping,2)
url,path=re.split(r"\s*=\s*",mapping,2)
httpServer.pathmappings[url] = path
AVNLog.info("set url mapping %s=%s"%(url,path))
except:
Expand Down Expand Up @@ -307,9 +307,9 @@ def main(argv):
AVNLog.error("Exception in main %s",traceback.format_exc())
AVNLog.info("stopping")
sighandler(None, None)

if __name__ == "__main__":
main(sys.argv)



13 changes: 9 additions & 4 deletions server/avnav_store.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
# DEALINGS IN THE SOFTWARE.
#
# parts from this software (AIS decoding) are taken from the gpsd project
# so refer to this BSD licencse also (see ais.py) or omit ais.py
# so refer to this BSD licencse also (see ais.py) or omit ais.py
###############################################################################


Expand Down Expand Up @@ -55,6 +55,9 @@ def __init__(self,value,source=None,priority=0,keepAlways=False,record=None,time
self.keepAlways=keepAlways
self.record=record

def __str__(self):
return "DataEntry"+str({"v":self.value,"t":self.timestamp,"s":self.source,"k":self.keepAlways,"r":self.record})

class AisDataEntry(object):
def __init__(self,data,priority=0,timestamp=None):
self.value=data
Expand Down Expand Up @@ -107,6 +110,7 @@ def __isExpired(self, entry, now=None):
now=time.monotonic()
et = now - self.__expiryTime
return entry.timestamp < et

def __isAisExpired(self, aisEntry, now=None):
if now is None:
now=time.monotonic()
Expand Down Expand Up @@ -270,10 +274,11 @@ def getSingleValue(self,key,includeInfo=False):
rt=self.__list.get(key)
if rt is None:
return None
if self.__isExpired(rt):
return None
if type(rt.value) == dict:
return None
if self.__isExpired(rt):
del self.__list[key]
return None
if includeInfo:
return rt
return rt.value
Expand Down Expand Up @@ -445,7 +450,7 @@ def getRegisteredKeys(self):




def __str__(self):
rt="%s \n"%self.__class__.__name__
idx=0
Expand Down
16 changes: 8 additions & 8 deletions server/handler/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@
import sys
import re
import importlib
sys.path.insert(0,os.path.dirname(os.path.realpath(__file__)))
sys.path.insert(0, os.path.join(os.path.dirname(__file__),"..","..","libraries"))
__all__=[]
regexp="(.+)\.py(c?)$"
mdir=os.path.dirname(__file__)
sys.path.insert(0, os.path.dirname(os.path.realpath(__file__)))
sys.path.insert(0, os.path.join(os.path.dirname(__file__), "..", "..", "libraries"))
__all__ = []
regexp = r"(.+)\.py(c?)$"
mdir = os.path.dirname(__file__)
for entry in os.listdir(mdir):
if entry == '__init__.py':
continue
if os.path.isfile(os.path.join(mdir, entry)):
regexp_result = re.search(regexp, entry)
if regexp_result: # is a module file name
importlib.import_module("."+regexp_result.groups()[0],__package__)
regexp_result = re.search(regexp, entry)
if regexp_result: # is a module file name
importlib.import_module("." + regexp_result.groups()[0], __package__)
28 changes: 22 additions & 6 deletions server/handler/pluginhandler.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,8 @@
# DEALINGS IN THE SOFTWARE.
#
# parts from this software (AIS decoding) are taken from the gpsd project
# so refer to this BSD licencse also (see ais.py) or omit ais.py
# so refer to this BSD licencse also (see ais.py) or omit ais.py
###############################################################################
import imp
import inspect
import json
from typing import Dict, Any
Expand All @@ -48,11 +47,28 @@
URL_PREFIX= "/plugins"

'''
hide plugins if an environment variable with this prefix
hide plugins if an environment variable with this prefix
and the "normalized" plugin name is set
'''
ENV_PREFIX="AVNAV_HIDE_"

try:
from imp import load_source
except:
import importlib
def load_source(modname, filename):
# print("LOAD", modname, filename)
"https://stackoverflow.com/questions/76694726/replacing-imp-load-source-in-python-3-12"
loader = importlib.machinery.SourceFileLoader(modname, filename)
spec = importlib.util.spec_from_file_location(modname, filename, loader=loader)
module = importlib.util.module_from_spec(spec)
# The module is always executed and not cached in sys.modules.
# Uncomment the following line to cache the module.
# sys.modules[module.__name__] = module
loader.exec_module(module)
return module


class UserApp(object):
def __init__(self,url,icon,title):
self.url=url
Expand Down Expand Up @@ -159,7 +175,7 @@ def stop(self):


def getPrefixForItems(self):
return re.sub(".*\.","",self.prefix)
return re.sub(r".*\.","",self.prefix)

def log(self, str, *args):
AVNLog.info("%s",str % args)
Expand Down Expand Up @@ -461,7 +477,7 @@ def __init__(self,param):
AVNWorker.__init__(self, param)
self.queue=None
self.createdPlugins={}
self.createdApis={}
self.createdApis={}
self.startedThreads={}
self.pluginDirs={} #key: moduleName, Value: dir
self.configLock=threading.Lock()
Expand Down Expand Up @@ -654,7 +670,7 @@ def loadPluginFromDir(self, dir, name):
if not os.path.exists(moduleFile):
return None
try:
rt = imp.load_source(name, moduleFile)
rt = load_source(name, moduleFile)
AVNLog.info("loaded %s as %s", moduleFile, name)
return rt
except:
Expand Down

0 comments on commit 6f7a6d9

Please sign in to comment.