2 # Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
4 # Licensed under the Apache License, Version 2.0 (the "License");
5 # you may not use this file except in compliance with the License.
6 # You may obtain a copy of the License at
8 # http://www.apache.org/licenses/LICENSE-2.0
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS,
12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 # See the License for the specific language governing permissions and
14 # limitations under the License.
23 return len(f.readlines())
26 # short description (string or None)
27 # long decsription (array of strings or None)
29 def parseDescr(lines):
31 return (None, None, False)
33 if re.match( r"!!!options!!!", lines[0] ):
39 if len(linesRest) == 0:
40 return(None,None,optStop)
41 short = linesRest[0].rstrip()
43 for l in linesRest[1:]:
45 if re.search( r"\S", ll ):
50 return (short, long, optStop)
52 # RETURNS a tree with nodes like: (
54 # short description (string or None)
55 # long decsription (array of strings or None)
57 # list of subdirs (child nodes like this one)
63 with open( path+'/DESCRIPTION' ) as f:
64 short, long, optStop = parseDescr( f.readlines() )
69 for fname in os.listdir(path):
70 if fname != '.git' and os.path.isdir(path+'/'+fname):
71 subdir = parseDir(path+'/'+fname)
74 (dummy0, dummy1, dummy2, subLines, dummy4) = subdir
77 if os.path.isfile(path+'/'+fname) \
78 and not os.path.islink(path+'/'+fname):
79 cntLines += countLines(path+'/'+fname)
81 return path, short, long, cntLines, dirs
83 ##### PRINT AS a sort of CSV delimited by '|'
85 # indent is a number (0..)
86 def printTabSub(tree,indent):
87 path, short, long, loc, subdirs = tree
88 p = re.sub(r"^\./", '', path)
89 m = re.search(r"/([^/]*$)", p)
90 if m != None: p = m.groups()[0]
92 print '%s%s|%d|' % (" "*indent, p, loc)
94 print '%s%s|%d|%s' % (" "*indent, p, loc, short)
96 printTabSub(dir, indent+1)
101 def printTabWoMain(tree):
102 path, short, long, loc, dirs = tree