1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 import re
21 import os
22 import sys
23 import logging
24 import fileutils
25 import archive
26
27
28 logger = logging.getLogger("archive.selectors")
29
30
32 """ A selector that selects files based on other criteria.
33
34 It is similar to the Ant file selector objects in design. This one selects files
35 based on whether the root-most Distribution.Policy.S60 file matches the given value.
36 """
37
38 - def __init__(self, policy_files, value, ignoremissingpolicyfiles=False):
39 """ Initialization. """
40 self._negate = False
41 self.values = [v.strip() for v in value.split() if v.strip()!=""]
42 self._policy_files = policy_files
43 self._ignoremissingpolicyfiles = ignoremissingpolicyfiles
44
46 if value.startswith('!'):
47 return (value[1:], True)
48 return (value, False)
49
51 """ Determines if the path is selected by this selector. """
52 current_dir = os.path.abspath(os.path.dirname(path))
53 logger.debug('is_selected: current dir = ' + current_dir + ' ' + str(os.path.exists(current_dir)))
54 result = False
55 policy_file = None
56
57 for filename in self._policy_files:
58
59 if sys.platform != 'win32':
60 for f in os.listdir(current_dir):
61 if f.lower() == filename.lower():
62 policy_file = os.path.join(current_dir, f)
63 break
64 elif os.path.exists(os.path.join(current_dir, filename)):
65 policy_file = os.path.join(current_dir, filename)
66 logger.debug('Using Policy file: ' + policy_file)
67 break
68
69 policy_value = None
70 if policy_file is None:
71 if not self._ignoremissingpolicyfiles:
72 logger.error("POLICY_ERROR: Policy file not found under '%s' using names [%s]" % (current_dir, ", ".join(self._policy_files)))
73 policy_value = archive.mappers.MISSING_POLICY
74 else:
75 try:
76 policy_value = fileutils.read_policy_content(policy_file)
77 except Exception:
78 logger.warning('POLICY_ERROR: Exception thrown parsing policy file: ' + policy_file)
79 policy_value = archive.mappers.MISSING_POLICY
80
81 for value in self.values:
82 (val, negate) = self.get_value_and_negate(value)
83 logger.debug('Policy value: ' + str(policy_value) + ' ' + val)
84 if (not negate and policy_value == val) or (negate and policy_value != val):
85 return True
86 return False
87
88
90 """ A selector that selects files based on other criteria.
91
92 It is similar to the Ant file selector objects in design. This one selects files
93 based on whether the root-most distribution.policy file matches the given value.
94 """
95
96 - def __init__(self, policy_files, value):
97 """ Initialization. """
98 self._negate = False
99 self.values = [v.strip() for v in value.split() if v.strip()!=""]
100 self._policy_files = policy_files
101
102
104 if value.startswith('!'):
105 return (value[1:], True)
106 return (value, False)
107
109 """ Determines if the path is selected by this selector. """
110 current_dir = os.path.abspath(os.path.dirname(path))
111 logger.debug('is_selected: current dir = ' + current_dir + ' ' + str(os.path.exists(current_dir)))
112 result = False
113 policy_file = None
114
115 for filename in self._policy_files:
116 if sys.platform != 'win32':
117 for f in os.listdir(current_dir):
118 if f.lower() == filename.lower():
119 policy_file = os.path.join(current_dir, f)
120 logger.debug('Using Policy file: ' + policy_file)
121 break
122 elif os.path.exists(os.path.join(current_dir, filename)):
123 policy_file = os.path.join(current_dir, filename)
124 logger.debug('Using Policy file: ' + policy_file)
125 break
126
127 policy_value = None
128 if policy_file is None:
129 logger.error("POLICY_ERROR: Policy file not found under '%s' using names [%s]" % (current_dir, ", ".join(self._policy_files)))
130 policy_value = archive.mappers.MISSING_POLICY
131 else:
132 try:
133 policy_value = fileutils.read_symbian_policy_content(policy_file)
134 except Exception:
135 logger.warning('POLICY_ERROR: Exception thrown parsing policy file: ' + policy_file)
136 policy_value = archive.mappers.MISSING_POLICY
137
138 for value in self.values:
139 (val, negate) = self.get_value_and_negate(value)
140 logger.debug('Policy value: ' + str(policy_value) + ' ' + val)
141 if (not negate and policy_value == val) or (negate and policy_value != val):
142 return True
143 return False
144
145 SELECTORS = {'policy': lambda config: DistributionPolicySelector(config.get_list('policy.filenames', ['Distribution.Policy.S60']), config['policy.value']),
146 'symbian.policy': lambda config: SymbianPolicySelector(config.get_list('policy.filenames', ['distribution.policy']), config['policy.value']),
147 'distribution.policy.s60': lambda config: DistributionPolicySelector(['Distribution.Policy.S60'], config['distribution.policy.s60'], config['ignore.missing.policyfiles'] == 'true'),
148 }
149
151 if not 'ignore.missing.policyfiles' in config:
152 config['ignore.missing.policyfiles'] = 'false'
153 return SELECTORS[name](config)
154