COIN-OR::LEMON - Graph Library

source: lemon-tutorial/scripts/chg-len.py @ 33:598cd0b266d3

Last change on this file since 33:598cd0b266d3 was 17:0b3b26cd1cea, checked in by Alpar Juttner <alpar@…>, 16 years ago

Better build system

  • configure script added
  • demo/*.cc are now compiled (the executables are in demo/build)
  • version number appears in the doc and automatically updates
  • the cross reference to the lemon doc can be relocated (e.g. to a local copy of the doc)
  • some repo reorganization has taken place
  • better .hgignore
  • Property exe set to *
File size: 1007 bytes
Line 
1#! /usr/bin/env python
2
3import sys
4import os
5
6if len(sys.argv)>1 and sys.argv[1] in ["-h","--help"]:
7    print """
8This utility just prints the length of the longest path
9in the revision graph from revison 0 to the current one.
10"""
11    exit(0)
12plist = os.popen("HGRCPATH='' hg parents --template='{rev}\n'").readlines()
13if len(plist)>1:
14    print "You are in the process of merging"
15    exit(1)
16PAR = int(plist[0])
17
18f = os.popen("HGRCPATH='' hg log -r 0:tip --template='{rev} {parents}\n'").\
19    readlines()
20REV = -1
21lengths=[]
22for l in f:
23    REV+=1
24    s = l.split()
25    rev = int(s[0])
26    if REV != rev:
27        print "Something is seriously wrong"
28        exit(1)
29    if len(s) == 1:
30        par1 = par2 = rev - 1
31    elif len(s) == 2:
32        par1 = par2 = int(s[1].split(":")[0])
33    else:
34        par1 = int(s[1].split(":")[0])
35        par2 = int(s[2].split(":")[0])
36    if rev == 0:
37        lengths.append(0)
38    else:
39        lengths.append(max(lengths[par1],lengths[par2])+1)
40print lengths[PAR]
Note: See TracBrowser for help on using the repository browser.