Browse Source

add: movewin.process_kill(), add:fping

micha 1 year ago
parent
commit
5f3bc2bb73
5 changed files with 57 additions and 12 deletions
  1. 2 2
      LibreLightDesk.py
  2. 7 2
      _LibreLightDesk.py
  3. 2 2
      tksdl/config.py
  4. 9 0
      tool/fping.sh
  5. 37 6
      tool/movewin.py

+ 2 - 2
LibreLightDesk.py

@@ -18,10 +18,10 @@ _file_path=pathlib.Path(__file__)
 print("file:",_file_path)
 
 import tool.movewin as movewin
-count = movewin.search_process(_file_path)
+pids = movewin.search_process(_file_path)
 
 CAPTION = 'LibreLight Start XX'
-if count >= 2:
+if len(pids) >= 2:
     search = CAPTION[:]
     _ids = movewin.winfo(search)
     for _id in _ids:

+ 7 - 2
_LibreLightDesk.py

@@ -23,6 +23,7 @@ import subprocess
 import string
 import copy
 import traceback
+import tool.movewin as movewin
 
 rnd_id  = str(random.randint(100,900))
 rnd_id += " beta"
@@ -3049,7 +3050,8 @@ class LOAD_SHOW_AND_RESTAT():
         print("fork",[BASE_PATH,cmd,arg])
         if "--easy" in sys.argv:
             arg = "--easy"
-        #time.sleep(1)
+        
+        movewin.process_kill(BASE_PATH+"tksdl/")
         os.execl("/usr/bin/python3", BASE_PATH, cmd,arg)
         sys.exit()
                 
@@ -4601,7 +4603,8 @@ class WindowManager():
             self.create(name)
         
         w = self.windows[name]
-        print(" 2.1-",w,str(type(w)))
+        #def get_lineno():
+        print(" 2.1- ln",movewin.get_lineno(),w,str(type(w)))
         if type(w) is type(window_create_buffer):
             w.tk.attributes('-topmost',True)
             w.tk.attributes('-topmost',False)
@@ -5175,5 +5178,7 @@ if __run_main:
     try:
         window_manager.mainloop()
     finally:
+        BASE_PATH = "/opt/LibreLight/Xdesk/"
+        movewin.process_kill(BASE_PATH+"tksdl/")
         master.exit()
 

+ 2 - 2
tksdl/config.py

@@ -17,11 +17,11 @@ _file_path=pathlib.Path(__file__)
 print("file:",_file_path)
 
 import tool.movewin as movewin
-count = movewin.search_process(_file_path)
+pids = movewin.search_process(_file_path)
 
 CAPTION = 'LibreLight Start '
 
-if count >= 2:
+if len(pids) >= 2:
     search = CAPTION[:]
     _ids = movewin.winfo(search)
     for _id in _ids:

+ 9 - 0
tool/fping.sh

@@ -0,0 +1,9 @@
+
+
+#for ip in $(seq "%05g" 1 254); do
+for ip in $(seq 1 254); do
+    #echo $ip
+    sh -c "ping -c 1 192.168.2.$ip | grep 'bytes from '" &
+done
+
+sleep 10

+ 37 - 6
tool/movewin.py

@@ -40,10 +40,11 @@ def system(cmd):
     print(cmd)
     os.system(cmd)
 
-def search_process(_file_path):
+def search_process(_file_path,exact=1):
     print("search_process",_file_path)
     pids = psutil.pids()
     count = 0
+    out = []
     for pid in pids:
         p = psutil.Process(pid)
         ps = p.cmdline()
@@ -54,12 +55,42 @@ def search_process(_file_path):
         if "python" not in ps[0]:
             continue
 
-        #print(" ",[ps[1]])
-        if str(_file_path) == str(ps[1]):
-            print(ps)
-            count += 1
+        print(" ",[ps[1]])
+        print("exact_search",exact)
+        if exact:
+            if str(_file_path) == str(ps[1]):
+                print(ps)
+                count += 1
+                out.append(pid)
+        else:
+            if str(_file_path) in str(ps[1]):
+                print(ps)
+                count += 1
+                out.append(pid)
+
     print("search_process",count)
-    return count
+    return out
+
+def process_kill(path):
+    pids = search_process(path,exact=0)
+    for pid in pids:
+        print("process_kill:",pid)
+        p = psutil.Process(pid)   
+        #p.name()
+        #p.cmdline()
+        p.terminate()
+        p.wait()
+
+import inspect
+def get_lineno():
+  callerframerecord = inspect.stack()[1]    # 0 represents this line
+                                            # 1 represents line at caller
+  frame = callerframerecord[0]
+  info = inspect.getframeinfo(frame)
+  #print(info.filename)                      # __FILE__     -> Test.py
+  #print(info.function)                      # __FUNCTION__ -> Main
+  #print(info.lineno)                        # __LINE__     -> 13
+  return info.lineno
 
 if __name__ == "__main__":
     print("# python3 movewin.py window-title x y")