xentaur
changeset 10:f7fa09a390ed
Работаем с файлами напрямую
author | igor |
---|---|
date | Thu Aug 30 14:45:50 2007 +0300 (2007-08-30) |
parents | 3d837efe2d1c |
children | 1ede117a35ec |
files | xentaur.py |
line diff
1.1 --- a/xentaur.py Fri Aug 17 16:23:42 2007 +0300 1.2 +++ b/xentaur.py Thu Aug 30 14:45:50 2007 +0300 1.3 @@ -11,6 +11,17 @@ 1.4 1.5 screenrc=os.environ['HOME']+"/.screenrc_xentaur" 1.6 1.7 +def run(program, *args): 1.8 + pid = os.fork() 1.9 + if not pid: 1.10 + os.execvp(program, (program,) + args) 1.11 + return os.wait()[0] 1.12 + 1.13 +def run_command(line): 1.14 + #cmds=line.split() 1.15 + #run(cmds[0],*cmds[1:]) 1.16 + run("/bin/sh", "-c", line) 1.17 + 1.18 def create_bridges_script(): 1.19 unbound_bridges=bridges 1.20 create_unbound_bridges="\n".join(map(lambda x: "sudo /usr/sbin/brctl show | awk '{print $1}' | grep -q "+x+" || sudo /usr/sbin/brctl addbr "+x, unbound_bridges)) 1.21 @@ -42,16 +53,16 @@ 1.22 screenlist="\n".join(screens) 1.23 1.24 #hardstatus string "\%{gk}\%c \%{yk}\%M\%d \%{wk}\%?\%-Lw\%?\%{bw}\%n*\%f\%t\%?(\%u)\%?\%{wk}\%?\%+Lw\%?" 1.25 - print """ 1.26 - 1.27 -cat <<SCREENRC > screenrc 1.28 + 1.29 + f=open("screenrc", "w"); 1.30 + f.write(""" 1.31 hardstatus on 1.32 hardstatus alwayslastline 1.33 1.34 screen -t console 0 bash 1.35 -%(screenlist)s 1.36 -SCREENRC 1.37 -""" % { 'screenlist' : screenlist } 1.38 +%s 1.39 +""" % (screenlist)) 1.40 + f.close() 1.41 1.42 def graph_node(node): 1.43 i=0 1.44 @@ -99,8 +110,8 @@ 1.45 'networklist' : networklist, 1.46 } 1.47 1.48 - print """ 1.49 - cat <<'GRAPH' > xenomips.dot 1.50 + f = open("xenomips.dot", "w"); 1.51 + f.write (""" 1.52 graph G { 1.53 edge [len=1.25]; 1.54 splines=true; 1.55 @@ -127,9 +138,9 @@ 1.56 %(linklist)s 1.57 1.58 }; 1.59 -GRAPH 1.60 - neato -Tpng -o xenomips.png xenomips.dot 1.61 -""" % graph_dot 1.62 +""" % graph_dot) 1.63 + f.close() 1.64 + run_command("neato -Tpng -o xenomips.png xenomips.dot ") 1.65 1.66 def start_all(): 1.67 create_bridges_script() 1.68 @@ -159,16 +170,6 @@ 1.69 1.70 #----------------------------------------------------------------------- 1.71 1.72 -def run(program, *args): 1.73 - pid = os.fork() 1.74 - if not pid: 1.75 - os.execvp(program, (program,) + args) 1.76 - return os.wait()[0] 1.77 - 1.78 -def run_command(line): 1.79 - #cmds=line.split() 1.80 - #run(cmds[0],*cmds[1:]) 1.81 - run("/bin/sh", "-c", line) 1.82 1.83 def add_domain(name,type): 1.84 domains.append(name)