b4d4d844fd
Signed-off-by: Thomas Klaehn <thomas.klaehn@u-blox.com>
63 lines
1.5 KiB
Python
63 lines
1.5 KiB
Python
import argparse
|
|
import sys
|
|
import threading
|
|
import time
|
|
|
|
from watchdog.observers import Observer
|
|
|
|
from gpx2html import Gpx2Html
|
|
from input_observer import InputObserver
|
|
|
|
def parse_args():
|
|
'''Shell argument parser.'''
|
|
parser = argparse.ArgumentParser()
|
|
parser.add_argument('infolder', help='Specify the in folder.')
|
|
parser.add_argument('outfolder', help='Specify the out folder.')
|
|
return parser.parse_args()
|
|
|
|
class myLoop(threading.Thread):
|
|
def __init__(self, infolder, outfolder):
|
|
super(myLoop, self).__init__()
|
|
self.run_condition = True
|
|
self.infolder = infolder
|
|
self.outfolder = outfolder
|
|
self.observer = Observer()
|
|
self.in_obs = InputObserver(patterns=["*.gpx"])
|
|
|
|
def run(self):
|
|
gpx2html = Gpx2Html(self.infolder, self.outfolder)
|
|
gpx2html.process()
|
|
|
|
self.observer.schedule(self.in_obs, self.infolder)
|
|
self.observer.start()
|
|
while self.run_condition is True:
|
|
new_file = self.in_obs.get_new_file()
|
|
if new_file:
|
|
gpx2html.process()
|
|
print "processed"
|
|
|
|
def stop(self):
|
|
self.run_condition = False
|
|
self.in_obs.stop()
|
|
self.observer.stop()
|
|
self.observer.join()
|
|
|
|
|
|
def main():
|
|
args = parse_args()
|
|
|
|
my_loop = myLoop(args.infolder, args.outfolder)
|
|
my_loop.start()
|
|
|
|
try:
|
|
while True:
|
|
time.sleep(1)
|
|
except KeyboardInterrupt:
|
|
my_loop.stop()
|
|
my_loop.join()
|
|
return 0
|
|
|
|
|
|
if __name__ == '__main__':
|
|
sys.exit(main())
|