patches/moovida-04-pidof.diff
author yippi
Thu, 06 Aug 2009 16:30:48 +0000
changeset 2038 26b5a7e5fb68
child 3062 2a7bf2823c88
permissions -rw-r--r--
2009-08-05 Brian Cameron <[email protected]> * base-specs/moovida.spec, patches/moovida-04-pidof.diff: Add back reworked patch - it is still needed.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2038
26b5a7e5fb68 2009-08-05 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
     1
--- elisa-1.0.6/elisa/core/utils/misc.py-orig	2009-08-06 11:25:58.307494000 -0500
26b5a7e5fb68 2009-08-05 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
     2
+++ elisa-1.0.6/elisa/core/utils/misc.py	2009-08-06 11:26:55.181318000 -0500
26b5a7e5fb68 2009-08-05 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
     3
@@ -25,6 +25,7 @@ reasonnably small.
26b5a7e5fb68 2009-08-05 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
     4
 import platform
26b5a7e5fb68 2009-08-05 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
     5
 import os, re
26b5a7e5fb68 2009-08-05 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
     6
 import subprocess
26b5a7e5fb68 2009-08-05 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
     7
+import threading
26b5a7e5fb68 2009-08-05 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
     8
 
26b5a7e5fb68 2009-08-05 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
     9
 from twisted.trial.unittest import SkipTest
26b5a7e5fb68 2009-08-05 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
    10
 
26b5a7e5fb68 2009-08-05 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
    11
@@ -209,17 +210,30 @@ def get_os_name():
26b5a7e5fb68 2009-08-05 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
    12
     else:
26b5a7e5fb68 2009-08-05 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
    13
         return platform.system().lower()
26b5a7e5fb68 2009-08-05 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
    14
 
26b5a7e5fb68 2009-08-05 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
    15
-def linux_pidof(program_name):
26b5a7e5fb68 2009-08-05 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
    16
+def unix_pidof(program_name):
26b5a7e5fb68 2009-08-05 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
    17
     """
26b5a7e5fb68 2009-08-05 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
    18
-    Get the Linux process id of the given program name. Because
26b5a7e5fb68 2009-08-05 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
    19
+    Get the UNIX process id of the given program name. Because
26b5a7e5fb68 2009-08-05 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
    20
     multiple processes can exist, we return a list of the pids.
26b5a7e5fb68 2009-08-05 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
    21
 
26b5a7e5fb68 2009-08-05 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
    22
     @rtype: C{list} of C{int}
26b5a7e5fb68 2009-08-05 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
    23
     @returns: the list of running pids of given program name
26b5a7e5fb68 2009-08-05 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
    24
     """
26b5a7e5fb68 2009-08-05 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
    25
-    output = subprocess.Popen(["pidof", program_name],
26b5a7e5fb68 2009-08-05 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
    26
-                              stderr=subprocess.STDOUT,
26b5a7e5fb68 2009-08-05 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
    27
-                              stdout=subprocess.PIPE).communicate()[0]
26b5a7e5fb68 2009-08-05 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
    28
+    try:
26b5a7e5fb68 2009-08-05 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
    29
+        lock = threading.Lock()
26b5a7e5fb68 2009-08-05 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
    30
+        lock.acquire()
26b5a7e5fb68 2009-08-05 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
    31
+        if platform.system() == 'SunOS':
26b5a7e5fb68 2009-08-05 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
    32
+            output = subprocess.Popen(["/bin/sh", "-c", "/usr/bin/pgrep -u `whoami` %s" % program_name],
26b5a7e5fb68 2009-08-05 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
    33
+                                      stderr=subprocess.STDOUT,
26b5a7e5fb68 2009-08-05 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
    34
+                                      stdout=subprocess.PIPE,
26b5a7e5fb68 2009-08-05 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
    35
+                                      close_fds=True).communicate()[0]
26b5a7e5fb68 2009-08-05 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
    36
+        else:
26b5a7e5fb68 2009-08-05 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
    37
+            output = subprocess.Popen(["pidof", program_name],
26b5a7e5fb68 2009-08-05 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
    38
+                                      stderr=subprocess.STDOUT,
26b5a7e5fb68 2009-08-05 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
    39
+                                      stdout=subprocess.PIPE,
26b5a7e5fb68 2009-08-05 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
    40
+                                      close_fds=True).communicate()[0]
26b5a7e5fb68 2009-08-05 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
    41
+    finally:
26b5a7e5fb68 2009-08-05 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
    42
+        lock.release()
26b5a7e5fb68 2009-08-05 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
    43
+
26b5a7e5fb68 2009-08-05 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
    44
     return [int(pid) for pid in output.split()]
26b5a7e5fb68 2009-08-05 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
    45
 
26b5a7e5fb68 2009-08-05 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
    46
 def get_user_desktop_name():
26b5a7e5fb68 2009-08-05 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
    47
@@ -255,7 +269,7 @@ def get_user_desktop_name():
26b5a7e5fb68 2009-08-05 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
    48
                          'xfwm4': 'xfce',
26b5a7e5fb68 2009-08-05 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
    49
                          }
26b5a7e5fb68 2009-08-05 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
    50
                 for prog, name in progs.iteritems():
26b5a7e5fb68 2009-08-05 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
    51
-                    if linux_pidof(prog) != []:
26b5a7e5fb68 2009-08-05 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
    52
+                    if unix_pidof(prog) != []:
26b5a7e5fb68 2009-08-05 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
    53
                         desktop_name = name
26b5a7e5fb68 2009-08-05 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
    54
                         break
26b5a7e5fb68 2009-08-05 Brian Cameron <[email protected]>
yippi
parents:
diff changeset
    55
             if desktop_name is None: