Aarch64: Replace macro __x86_64__ with generic macro __LP64__
[platform/framework/web/wrt-plugins-common.git] / dir-struct.py
1 #!/usr/bin/env python
2 # Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
3 #
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
7 #
8 #        http://www.apache.org/licenses/LICENSE-2.0
9 #
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.
15 #
16
17 import os
18 import re
19
20
21 def countLines(path):
22     with open(path) as f:
23         return len(f.readlines())
24
25 # RETURNS: (
26 #    short description (string or None)
27 #    long decsription (array of strings or None)
28 #    options: stop
29 def parseDescr(lines):
30     if len(lines) == 0:
31         return (None, None, False)
32     linesRest = None
33     if re.match( r"!!!options!!!", lines[0] ):
34         optStop = True
35         linesRest = lines[1:]
36     else:
37         optStop = False
38         linesRest = lines
39     if len(linesRest) == 0:
40         return(None,None,optStop)
41     short = linesRest[0].rstrip()
42     long = []
43     for l in linesRest[1:]:
44         ll = l.rstrip()
45         if re.search( r"\S", ll ):
46             long.append( ll )
47     if len(long) == 0:
48         long = None
49
50     return (short, long, optStop)
51
52 # RETURNS a tree with nodes like: (
53 #    path (string)
54 #    short description (string or None)
55 #    long decsription (array of strings or None)
56 #    LOC (integer)
57 #    list of subdirs (child nodes like this one)
58 def parseDir(path):
59     short = None
60     long = None
61     optStop = False
62     try:
63         with open( path+'/DESCRIPTION' ) as f:
64             short, long, optStop = parseDescr( f.readlines() )
65     except IOError:
66         pass
67     dirs = []
68     cntLines = 0
69     for fname in os.listdir(path):
70         if fname != '.git' and os.path.isdir(path+'/'+fname):
71             subdir = parseDir(path+'/'+fname)
72             if optStop == False:
73                 dirs.append(subdir)
74             (dummy0, dummy1, dummy2, subLines, dummy4) = subdir
75             cntLines += subLines
76
77         if os.path.isfile(path+'/'+fname) \
78         and not os.path.islink(path+'/'+fname):
79             cntLines += countLines(path+'/'+fname)
80
81     return path, short, long, cntLines, dirs
82
83 ##### PRINT AS a sort of CSV delimited by '|'
84
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]
91     if short == None:
92         print '%s%s|%d|' % ("        "*indent, p, loc)
93     else:
94         print '%s%s|%d|%s' % ("        "*indent, p, loc, short)
95     for dir in subdirs:
96         printTabSub(dir, indent+1)
97
98 def printTab(tree):
99     printTabSub(tree,0)
100
101 def printTabWoMain(tree):
102     path, short, long, loc, dirs = tree
103     for dir in dirs:
104         printTabSub(dir, 0)
105
106
107 ##### MAIN
108
109 tree = parseDir('.')
110 printTabWoMain(tree)
111