|
1 # |
|
2 # Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
3 # All rights reserved. |
|
4 # This component and the accompanying materials are made available |
|
5 # under the terms of "Eclipse Public License v1.0" |
|
6 # which accompanies this distribution, and is available |
|
7 # at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 # |
|
9 # Initial Contributors: |
|
10 # Nokia Corporation - initial contribution. |
|
11 # |
|
12 # Contributors: |
|
13 # |
|
14 # Description: |
|
15 # |
|
16 |
|
17 import os |
|
18 import sys |
|
19 import fnmatch |
|
20 import re |
|
21 import logging |
|
22 |
|
23 |
|
24 def get_subactions(path,pattern): |
|
25 """ Find out the cone subscripts that are present in the ROOT_PATH """ |
|
26 subacts = ActionContainer() |
|
27 for file in os.listdir(path): |
|
28 if fnmatch.fnmatch(file, pattern): |
|
29 sact = SubAction(file,pattern) |
|
30 subacts[sact.name] = sact |
|
31 return subacts |
|
32 |
|
33 def get_log_level(level): |
|
34 """ |
|
35 Change the given user input log level to logging categorisation |
|
36 """ |
|
37 if level == 0 : return logging.NOTSET |
|
38 elif level == 1 : return logging.CRITICAL |
|
39 elif level == 2 : return logging.ERROR |
|
40 elif level == 3 : return logging.WARNING |
|
41 elif level == 4 : return logging.INFO |
|
42 elif level == 5 : return logging.DEBUG |
|
43 else : return logging.NOTSET |
|
44 |
|
45 class ActionContainer(object): |
|
46 def __init__(self): |
|
47 self._actions = {} |
|
48 |
|
49 def __len__(self): |
|
50 return len(self._actions) |
|
51 |
|
52 def __getitem__(self, key): |
|
53 return self._actions[key] |
|
54 |
|
55 def __setitem__( self, key, value): |
|
56 self._actions[key] = value |
|
57 |
|
58 def __delitem__( self, key): |
|
59 del self._actions[key] |
|
60 |
|
61 def __iter__( self): |
|
62 return self._actions.__iter__() |
|
63 |
|
64 class SubAction(object): |
|
65 def __init__(self, scriptname, pattern): |
|
66 self._scriptname = scriptname |
|
67 self._pattern = pattern |
|
68 |
|
69 @property |
|
70 def name(self): |
|
71 """ translate the pattern """ |
|
72 pattern = fnmatch.translate(self._pattern).replace('.*', '(.*)') |
|
73 m = re.match(pattern, self._scriptname) |
|
74 return m.group(1) |
|
75 |
|
76 def run(self): |
|
77 module = __import__(self._scriptname.replace('.py','')) |
|
78 module.main() |