1
+ import os
1
2
import time
2
3
import threading
3
4
import traceback
@@ -342,6 +343,8 @@ def __init__(self, mpstate):
342
343
self .web = None
343
344
self .web_interface = 0
344
345
self .web_serverid = None
346
+
347
+ self .local_path = os .path .dirname (os .getcwd ())
345
348
print ("DroneAPI loaded" )
346
349
347
350
def __on_change (self , * args ):
@@ -434,7 +437,8 @@ def send_to_server(self, m):
434
437
pass
435
438
436
439
def thread_remove (self , t ):
437
- del self .threads [t .thread_num ]
440
+ if t .thread_num in self .threads .keys ():
441
+ del self .threads [t .thread_num ]
438
442
439
443
def thread_add (self , t ):
440
444
self .threads [t .thread_num ] = t
@@ -445,7 +449,8 @@ def cmd_list(self):
445
449
print str (t )
446
450
447
451
def cmd_kill (self , n ):
448
- self .threads [n ].kill ()
452
+ if self .threads [n ].isAlive ():
453
+ self .threads [n ].kill ()
449
454
450
455
def get_connection (self ):
451
456
return self .api
@@ -529,10 +534,22 @@ def cmd_api(self, args):
529
534
# Just kill the youngest
530
535
self .cmd_kill (max (self .threads .keys ))
531
536
elif args [0 ] == "start" :
532
- if len (args ) != 2 :
533
- print ("usage: api load <filename>" )
537
+ if len (args ) < 2 :
538
+ print ("usage: api start <filename> <local_path:optional >" )
534
539
return
535
- g = { "local_connect" : self .get_connection }
540
+
541
+ g = {
542
+ "local_connect" : self .get_connection ,
543
+ "local_path" : self .local_path
544
+ }
545
+
546
+ # define local_path in target file
547
+ # this helps to add context to apps
548
+ # that need to load external resources
549
+ # w/o relative paths
550
+ if len (args ) == 3 :
551
+ g ["local_path" ] = args [2 ]
552
+
536
553
APIThread (self , lambda : execfile (args [1 ], g ), args [1 ])
537
554
else :
538
555
print ("Invalid api subcommand" )
0 commit comments