Commits

Richo Healey  committed 694a609

Implment an args strategy

It will be the default if args are provided, if not it will be removed
from the strategy list.

It will update the cache, meaning if you know where you are with greater
accuracy than other strategies can provide, you have a way to
transparently teach doko where you are.

  • Participants
  • Parent commits e25120d
  • Branches strategies/args

Comments (0)

Files changed (1)

File doko/__init__.py

 class LocationServiceException(Exception):
     pass
 
+@location_strategy("args")
+def args_location(timeout=DEFAULT_TIMEOUT):
+    """
+    Fetch the current location from sys.argv
+    """
+
+    l = sys.argv[0].split(",")
+    if len(l) != 2:
+        raise LocationServiceException('Invalid argument for args strategy')
+    return Location(l[0], l[1], 'args')
 
 @location_strategy("cache")
 def cache_location(timeout=DEFAULT_TIMEOUT):
     parser = _create_option_parser()
     (options, args) = parser.parse_args(argv)
 
-    if args:
-        parser.print_help()
-        sys.exit(1)
+    sys.argv = args
 
     if options.strategy and options.strategy not in LOCATION_STRATEGIES:
         raise OptionValueError("%s is not a valid strategy" % options.strategy)
     if not (os.getenv("DOKO_CACHE") or options.cache):
         del LOCATION_STRATEGIES['cache']
 
+    if not (sys.argv):
+        del LOCATION_STRATEGIES['args']
+
     try:
         l = location(options.strategy, timeout=options.timeout,
                 force=options.force)