1 # vim:ts=4:sw=4:et:ai:sts=4
3 import os, subprocess, os.path
5 __all__ = ["python", "ssh_path"]
6 __all__ += ["rsh", "tcpdump_path", "sshd_path"]
7 __all__ += ["execute", "backticks"]
9 def find_bin(name, extra_path = None):
11 if "PATH" in os.environ:
12 search += os.environ["PATH"].split(":")
13 for pref in ("/", "/usr/", "/usr/local/"):
14 for d in ("bin", "sbin"):
15 search.append(pref + d)
21 os.stat(d + "/" + name)
24 if e.errno != os.errno.ENOENT:
28 def find_bin_or_die(name, extra_path = None):
31 raise RuntimeError(("Cannot find `%s' command, impossible to " +
35 ssh_path = find_bin_or_die("ssh")
36 python_path = find_bin_or_die("python")
39 rsh_path = find_bin("rsh")
40 tcpdump_path = find_bin("tcpdump")
41 sshd_path = find_bin("sshd")
44 # FIXME: create a global debug variable
45 #print "[pid %d]" % os.getpid(), " ".join(cmd)
46 null = open("/dev/null", "r+")
47 p = subprocess.Popen(cmd, stdout = null, stderr = subprocess.PIPE)
48 out, err = p.communicate()
50 raise RuntimeError("Error executing `%s': %s" % (" ".join(cmd), err))
53 p = subprocess.Popen(cmd, stdout = subprocess.PIPE,
54 stderr = subprocess.PIPE)
55 out, err = p.communicate()
57 raise RuntimeError("Error executing `%s': %s" % (" ".join(cmd), err))
60 def homepath(path, app='.nepi', mode = 0500):
61 home = os.environ.get('HOME')
63 home = os.path.join(os.sep, 'home', os.getlogin())
65 path = os.path.join(home, app, path)
66 dirname = os.path.dirname(path)
67 if not os.path.exists(dirname):