2 # Copyright (c) 2012 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
84 ### ##### PRINT AS TEXT
86 ### def printTextSub(path,indent,withLongDesc):
87 ### short, long, dirs, loc = parseDir(path)
89 ### p = re.sub(r"^\./", '', path)
90 ### print '%s%s -- ' % (indent, p)
92 ### p = re.sub(r"^\./", '', path)
93 ### print '%s%s -- %s' % (indent, p, short)
98 ### print '%s%s' % (indent+' ',line)
101 ### printTextSub(path+'/'+dir, indent+' ', withLongDesc)
103 ### def printText(path,withLongDesc):
104 ### printTextSub(path,'',withLongDesc)
106 ### def printTextWoMain(path,withLongDesc):
107 ### short, long, dirs, loc = parseDir(path)
109 ### printTextSub(path+'/'+dir, '', withLongDesc)
112 ##### PRINT AS a sort of CSV delimited by '|'
114 # indent is a number (0..)
115 def printTabSub(tree,indent):
116 path, short, long, loc, subdirs = tree
117 p = re.sub(r"^\./", '', path)
118 m = re.search(r"/([^/]*$)", p)
119 if m != None: p = m.groups()[0]
121 print '%s%s|%d|' % (" "*indent, p, loc)
123 print '%s%s|%d|%s' % (" "*indent, p, loc, short)
125 printTabSub(dir, indent+1)
130 def printTabWoMain(tree):
131 path, short, long, loc, dirs = tree