📄 m2m.py
字号:
# m2m (master to master graph)# Copyright (C) 2001, 2003 Carlo Perassi <carlo@linux.it># # This program is free software; you can redistribute it and/or modify# it under the terms of the GNU General Public License as published by the# Free Software Foundation; either version 2, or (at your option) any later# version.# # This program is distributed in the hope that it will be useful, but# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTIBILITY# or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License# for more details.## You should have received a copy of the GNU General Public License# along with this program; if not, write to the Free Software# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA#!/usr/bin/python2.1import os, popen2, string# getCommandOutput by Brent Burley - Brent.Burley@disney.com# http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/52296def getCommandOutput(command): child = os.popen(command) data = child.read() err = child.close() if err: raise RuntimeError, '%s failed w/ exit code %d' % (command, err) return dataTARGET = "Master"T_GREP = "as "T__URL = "http://www.advogato.org/person/"cmd0 = "curl " + T__URLcmd1 = cmd0 + " | grep " + "\"" + TARGET + "\" | awk -F \">\" '{ print $3 }'"cmd2 = cmd1 + " | awk -F \"<\" '{ print $1 }' | sort"bb = string.split(getCommandOutput(cmd2), "\n")graph_file = open("guru.gml", "w")graph_file.write("graph [\n")graph_file.write(" directed 1\n")graph_file.write(" version 2\n")k = 1for i in range(0, len(bb) - 1): graph_file.write(" node [\n") graph_file.write(" id " + `i + 1` + "\n") graph_file.write(" label \"" + bb[i] + "\"\n") graph_file.write(" ]\n")for i in range(0, len(bb) - 1): cmd1 = cmd0 + bb[i] + "/ | grep \"^<li>" + bb[i] + "\"" cmd2 = cmd1 + " | grep \"" + T_GREP + TARGET + "\"" cmd3 = cmd2 + " | awk -F \"\\\">\" '{ print $2 }'" cmd4 = cmd3 + " | awk -F \"<\" '{ print $1 }' | sort" cc = string.split(getCommandOutput(cmd4), "\n") provv = [] provv.extend(bb) provv.extend(cc) for k in range(0, len(cc) - 1): if provv.count(cc[k]) == 1: cc[k] = " " provv = [] for k in range(0, len(cc) - 1): if cc[k] != " ": provv.append(cc[k]) cc = [] cc.extend(provv) for j in range(0, len(cc) - 1): graph_file.write(" edge [\n") graph_file.write(" source " + `i + 1` + "\n") graph_file.write(" target " + `bb.index(cc[j]) + 1` + "\n") graph_file.write(" id " + `k` + "\n") graph_file.write(" label \"\"\n") graph_file.write(" graphics [\n") graph_file.write(" Line [\n") graph_file.write(" ]\n") graph_file.write(" ]\n") graph_file.write(" ]\n") k = k + 1graph_file.write("]\n")graph_file.close()
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -