|
@@ -2,7 +2,9 @@
|
|
|
|
|
|
import os
|
|
|
import sys
|
|
|
-import termux_log_location
|
|
|
+import termux_log_location as tll
|
|
|
+
|
|
|
+LAST_YAML_SYMLINK_NAME = 'last.yml'
|
|
|
|
|
|
|
|
|
def symlink(src, dst, force=False):
|
|
@@ -11,15 +13,27 @@ def symlink(src, dst, force=False):
|
|
|
os.symlink(src=src, dst=dst)
|
|
|
|
|
|
|
|
|
-def compute(target_dir_path):
|
|
|
- cur = termux_log_location.Position.from_termux_location()
|
|
|
- if cur:
|
|
|
- cur_path = cur.save_yaml(target_dir_path)
|
|
|
- symlink(
|
|
|
- src=os.path.relpath(cur_path, start=target_dir_path),
|
|
|
- dst=os.path.join(target_dir_path, 'last.yml'),
|
|
|
- force=True,
|
|
|
+def load_last(target_dir_path):
|
|
|
+ last_path = os.path.join(target_dir_path, LAST_YAML_SYMLINK_NAME)
|
|
|
+ if os.path.exists(last_path):
|
|
|
+ return tll.Position.load_yaml(
|
|
|
+ path=os.path.realpath(last_path),
|
|
|
)
|
|
|
+ else:
|
|
|
+ return None
|
|
|
+
|
|
|
+
|
|
|
+def compute(target_dir_path, distance_threshold_metres):
|
|
|
+ cur = tll.Position.from_termux_location()
|
|
|
+ if cur:
|
|
|
+ last = load_last(target_dir_path)
|
|
|
+ if not last or tll.Position.haversine_distance_metres(last, cur) > distance_threshold_metres:
|
|
|
+ cur_path = cur.save_yaml(target_dir_path)
|
|
|
+ symlink(
|
|
|
+ src=os.path.relpath(cur_path, start=target_dir_path),
|
|
|
+ dst=os.path.join(target_dir_path, LAST_YAML_SYMLINK_NAME),
|
|
|
+ force=True,
|
|
|
+ )
|
|
|
|
|
|
|
|
|
def _init_argparser():
|
|
@@ -31,6 +45,13 @@ def _init_argparser():
|
|
|
dest='target_dir_path',
|
|
|
default='.',
|
|
|
)
|
|
|
+ argparser.add_argument(
|
|
|
+ '--distance-threshold',
|
|
|
+ metavar='METRES',
|
|
|
+ dest='distance_threshold_metres',
|
|
|
+ default=0,
|
|
|
+ type=float,
|
|
|
+ )
|
|
|
return argparser
|
|
|
|
|
|
|