1
+ """
2
+ Copyright (c) 2016-2020 ARM Limited. All rights reserved.
3
+
4
+ SPDX-License-Identifier: Apache-2.0
5
+
6
+ Licensed under the Apache License, Version 2.0 (the "License");
7
+ you may not use this file except in compliance with the License.
8
+ You may obtain a copy of the License at
9
+
10
+ http://www.apache.org/licenses/LICENSE-2.0
11
+
12
+ Unless required by applicable law or agreed to in writing, software
13
+ distributed under the License is distributed on an "AS IS" BASIS,
14
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ See the License for the specific language governing permissions and
16
+ limitations
17
+ """
18
+
19
+ from pathlib import Path
20
+ import glob
21
+ import os .path
22
+ import sys
23
+
24
+ level2_set = set ()
25
+ dup_set = set ()
26
+
27
+
28
+ def main ():
29
+ for filepath in Path ('.' ).rglob ('main.cpp' ):
30
+ level2dir = os .path .basename (os .path .dirname (filepath ))
31
+ level1dir = os .path .basename (os .path .dirname (os .path .dirname (filepath )))
32
+ level0dir = os .path .dirname (os .path .dirname (os .path .dirname (filepath )))
33
+
34
+ # check if length of folder name less then 34
35
+ if len (level2dir ) > 34 :
36
+ sys .stderr .write ("ERROR: Snippet '{}' length of {} is {} exceed the requirement of 34" .format (filepath ,level2dir ,len (level2dir )))
37
+ sys .exit (1 )
38
+
39
+ # check if folder level less than 2
40
+ if level1dir == '' :
41
+ sys .stderr .write ("ERROR: Snippet '{}' has only one level of folder, but 2 is required" .format (filepath ))
42
+ sys .exit (1 )
43
+
44
+ # check if folder level more than 2
45
+ if level0dir != '' :
46
+ sys .stderr .write ("ERROR: Snippet '{}' has more than two level of folders, but 2 is required" .format (filepath ))
47
+ sys .exit (1 )
48
+
49
+ if level2dir not in level2_set :
50
+ level2_set .add (level2dir )
51
+ else :
52
+ dup_set .add (level2dir )
53
+
54
+ # check duplicated level2 folder names
55
+ if len (dup_set ) > 0 :
56
+ for filepath in Path ('.' ).rglob ('main.cpp' ):
57
+ level2dir = os .path .basename (os .path .dirname (filepath ))
58
+ if level2dir in dup_set :
59
+ sys .stderr .write ("ERROR level2 name '{}' in path '{}' is has a duplicated with others" .format (level2dir ,filepath ))
60
+ sys .exit (1 )
61
+
62
+
63
+ print ("All checks PASSED" )
64
+
65
+
66
+ if __name__ == "__main__" :
67
+ main ()
0 commit comments