Package glue :: Module utils
[hide private]
[frames] | no frames]

Source Code for Module glue.utils

 1  # Copyright (C) 2010  Peter Couvares 
 2  # 
 3  # This program is free software; you can redistribute it and/or modify it 
 4  # under the terms of the GNU General Public License as published by the 
 5  # Free Software Foundation; either version 2 of the License, or (at your 
 6  # option) any later version. 
 7  # 
 8  # This program is distributed in the hope that it will be useful, but 
 9  # WITHOUT ANY WARRANTY; without even the implied warranty of 
10  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General 
11  # Public License for more details. 
12  # 
13  # You should have received a copy of the GNU General Public License along 
14  # with this program; if not, write to the Free Software Foundation, Inc., 
15  # 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA. 
16   
17   
18  import os 
19  import errno 
20   
21   
22  """ 
23  Check for pid existence efficiently and reliably.  (Using the null 
24  signal is faster and more unix-portable than looking in /proc). 
25   
26  Inspired by Larz Wirzenius 
27  <http://stackoverflow.com/questions/1005972> 
28  """ 
29 -def pid_exists(pid):
30 """ Returns true if the given pid exists, false otherwise. """ 31 try: 32 # signal 0 is harmless and can be safely used to probe pid existence 33 # faster and more unix-portable than looking in /proc 34 os.kill(pid, 0) 35 except OSError as e: 36 # "permission denied" proves existence; otherwise, no such pid 37 return e.errno == errno.EPERM 38 else: 39 return True
40 41 42 """ 43 Performs the equivalent of "mkdir -p", creating any intermediate 44 directories needed to create the leaf directory -- but unlike 45 os.makedirs(), produces no error if the path already exists. 46 47 Inspired by Christos Georgiou 48 <http://stackoverflow.com/questions/600268/mkdir-p-functionality-in-python> 49 """
50 -def mkdir_p(path):
51 try: 52 os.makedirs(path) 53 except OSError as exc: 54 if exc.errno == errno.EEXIST: 55 pass 56 else: raise 57 return path
58