-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathhgccutils.py
More file actions
66 lines (55 loc) · 1.77 KB
/
hgccutils.py
File metadata and controls
66 lines (55 loc) · 1.77 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
def swapSuffix(suffix, path):
splitter = path.split(".")[:-1]
splitter.append(suffix)
return ".".join(splitter)
def rebaseFolder(path, srcDir, dstDir):
folder, fname = os.path.split(path)
newBaseFolder = folder.replace(srcDir,dstDir)
return os.path.join(newBaseFolder, fname)
def addPrefix(prefix, path):
import os
splitPath = os.path.split(path)
if len(splitPath) == 2:
return os.path.join(splitPath[0], prefix + splitPath[1])
else:
return prefix + path
def addPrefixAndRebase(prefix, path, newBase):
import os
newPath = addPrefix(prefix, path)
folder, name = os.path.split(newPath)
return os.path.join(newBase, name)
def delete(files):
import traceback
import os
os.system("rm -f %s" % (" ".join(files)))
def getProcTreeHelper(mypid, arr):
mypid = str(mypid)
import configlib
info = configlib.getoutput("ps axo pid,ppid,comm")
for line in info.splitlines():
args = line.strip().split()
if args[0] == mypid:
arr.append(" ".join(args[2:]))
getProcTreeHelper(args[1], arr)
break
def getProcTree():
import os
arr = []
getProcTreeHelper(os.getpid(), arr)
return arr
def getProcName():
import os
import configlib
import sys
pid = int(os.getppid())
runCmds = configlib.getoutput("ps -p %d" % pid).splitlines()[-1].split()
runCmds = runCmds[3:]
firstCmd = runCmds[0].lstrip("-")
if firstCmd in ("/bin/sh", "sh", "bash", "/bin/bash", "tcsh", "/bin/tcsh", "zsh", "/bin/zsh"):
if len(runCmds) > 1: #it might just be bash
firstCmd = runCmds[1]
cmd = os.path.split(firstCmd)[-1]
return cmd
def cleanFlag(flag):
from hgccvars import includeDir, execPrefix, prefix
return flag.replace("${includedir}", includeDir).replace("${exec_prefix}", execPrefix).replace("${prefix}",prefix).strip()