def _config_for_ini(self, projectconfig, aConfig): for k, (basepath, module) in aConfig.dirsIter(): paths = { 'module': module, 'reference': mozpath.normpath('%s/%s/locales/en-US/**' % (basepath, module)), 'l10n': mozpath.normpath('{l10n_base}/{locale}/%s/**' % module) } if module == 'mobile/android/base': paths['test'] = ['android-dtd'] projectconfig.add_paths(paths) for child in aConfig.children: self._config_for_ini(projectconfig, child)
def _config_for_ini(self, projectconfig, aConfig): for k, (basepath, module) in aConfig.dirsIter(): paths = { 'module': module, 'reference': mozpath.normpath('%s/%s/locales/en-US/**' % (basepath, module)), 'l10n': mozpath.normpath('{l10n_base}/{locale}/%s/**' % module) } if module == 'mobile/android/base': paths['test'] = ['android-dtd'] projectconfig.add_paths(paths) projectconfig.add_global_environment(l10n_base=self.l10nbase) for child in aConfig.children: self._config_for_ini(projectconfig, child)
def processIncludes(self, ctx): assert ctx.data is not None if 'includes' not in ctx.data: return for include in ctx.data['includes']: # resolve include['path'] against our root and env p = mozpath.normpath( expand( ctx.pc.root, include['path'], ctx.pc.environ ) ) try: child = self.parse( p, env=ctx.env, ignore_missing_includes=ctx.ignore_missing_includes ) except ConfigNotFound as e: if not ctx.ignore_missing_includes: raise (logging .getLogger('compare-locales.io') .error('%s: %s', e.strerror, e.filename)) continue ctx.pc.add_child(child)
def resolvepath(self, path): path = self.pc.expand(path, env=self.env) path = mozpath.join( mozpath.dirname(self.path), self.data.get('basepath', '.'), path) return mozpath.normpath(path)
def call_maybe_add_localization(self, node): self.issues.append({ 'msg': ('Calling {}.maybe_add_localization is not required').format( self.ctx_var), 'line': node.lineno }) args_msg = ('Expected arguments to {}.maybe_add_localization: ' 'str').format(self.ctx_var) if not self.check_arguments(node, ((ast.Str, ast.Name), )): raise BadContextAPIException(args_msg) path = node.args[0] if isinstance(path, ast.Str): path = path.s if isinstance(path, ast.Name): path = self.global_assigns.get(path.id) if not isinstance(path, six.string_types): self.issues.append({'msg': args_msg, 'line': node.args[0].lineno}) return if path != mozpath.normpath(path): self.issues.append({ 'msg': ('Argument to {}.maybe_add_localization needs to be a ' 'normalized path: "{}"').format(self.ctx_var, path), 'line': node.args[0].lineno }) else: self.sources.add(path)
def _walk(self, base): base = mozpath.normpath(base) root = self.mocks.find(base) if not root: return for tpl in root.walk(): yield tpl
def generic_visit(self, node): if isinstance(node, transforms.Source): src = node.path # Source needs paths to be normalized # https://bugzilla.mozilla.org/show_bug.cgi?id=1568199 if src != mozpath.normpath(src): self.issues.append( 'Source "{}" needs to be a normalized path'.format(src)) super(TransformsInspector, self).generic_visit(node)
def __init__(self, inipath, **kwargs): """Constructor for L10nConfigParsers inipath -- l10n.ini path Optional keyword arguments are fowarded to the inner ConfigParser as defaults. """ self.inipath = mozpath.normpath(inipath) # l10n.ini files can import other l10n.ini files, store the # corresponding L10nConfigParsers self.children = [] # we really only care about the l10n directories described in l10n.ini self.dirs = [] # optional defaults to be passed to the inner ConfigParser (unused?) self.defaults = kwargs
def _walk(self, base): base = mozpath.normpath(base) local_files = [ mozpath.split(mozpath.relpath(f, base)) for f in self.mocks if f.startswith(base) ] root = MockNode(base) for segs in local_files: node = root for n, seg in enumerate(segs[:-1]): if seg not in node.dirs: node.dirs[seg] = MockNode('/'.join([base] + segs[:n+1])) node = node.dirs[seg] node.files.append(segs[-1]) for tpl in root.walk(): yield tpl
def _processChild(self, ctx, field): assert ctx.data is not None if field not in ctx.data: return for child_config in ctx.data[field]: # resolve child_config['path'] against our root and env p = mozpath.normpath( expand(ctx.pc.root, child_config['path'], ctx.pc.environ)) try: child = self.parse( p, env=ctx.env, ignore_missing_includes=ctx.ignore_missing_includes) except ConfigNotFound as e: if not ctx.ignore_missing_includes: raise (logging.getLogger('compare-locales.io').error( '%s: %s', e.strerror, e.filename)) continue yield child
def processIncludes(self, ctx): assert ctx.data is not None if 'includes' not in ctx.data: return for include in ctx.data['includes']: # resolve include['path'] against our root and env p = mozpath.normpath( expand(ctx.pc.root, include['path'], ctx.pc.environ)) try: child = self.parse( p, env=ctx.env, ignore_missing_includes=ctx.ignore_missing_includes) except ConfigNotFound as e: if not ctx.ignore_missing_includes: raise (logging.getLogger('compare-locales.io').error( '%s: %s', e.strerror, e.filename)) continue ctx.pc.add_child(child)
def setUp(self): # Use tempdir as self.root, that's absolute on all platforms self.root = mozpath.normpath(tempfile.gettempdir())
def test_normpath(self): self.assertEqual( normpath(self.SEP.join(('foo', 'bar', 'baz', '..', 'qux'))), 'foo/bar/qux')
def test_normpath(self): self.assertEqual(normpath(self.SEP.join(('foo', 'bar', 'baz', '..', 'qux'))), 'foo/bar/qux')