def createWorkdir(self, contents): workdir = self.graph.target.git.workdir locales = set() includes = [] for tpath, content_list in contents.items(): try: b_content = merge_channels(tpath, content_list) except MergeNotSupportedError: b_content = content_list[0] if tpath.endswith("l10n.toml"): try: data = toml.loads(b_content) if 'locales' in data: locales.update(data['locales']) includes.append(tpath) except Exception as e: print(e) pass tpath = mozpath.join(workdir, tpath) tdir = mozpath.dirname(tpath) if not os.path.isdir(tdir): os.makedirs(tdir) with open(tpath, "wb") as fh: fh.write(b_content) self.ensureL10nToml(workdir, locales, includes)
def loadConfigs(self): """Entry point to load the l10n.ini file this Parser refers to. This implementation uses synchronous loads, subclasses might overload this behaviour. If you do, make sure to pass a file-like object to onLoadConfig. """ cp = ConfigParser(self.defaults) cp.read(self.inipath) depth = self.getDepth(cp) self.base = mozpath.join(mozpath.dirname(self.inipath), depth) # create child loaders for any other l10n.ini files to be included try: for title, path in cp.items('includes'): # skip default items if title in self.defaults: continue # add child config parser self.addChild(title, path, cp) except NoSectionError: pass # try to load the "dirs" defined in the "compare" section try: self.dirs.extend(cp.get('compare', 'dirs').split()) except (NoOptionError, NoSectionError): pass # try to set "all_path" and "all_url" try: self.all_path = mozpath.join(self.base, cp.get('general', 'all')) except (NoOptionError, NoSectionError): self.all_path = None return cp
def isfile(self, path): dirname = mozpath.dirname(path) if dirname: node = self.find(dirname) else: node = self return node and mozpath.basename(path) in node.files
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 set_root(self, basepath): if self.path is None: self.root = None return self.root = mozpath.abspath( mozpath.join(mozpath.dirname(self.path), basepath) )
def set_root(self, basepath): if self.path is None: self.root = None return self.root = mozpath.abspath( mozpath.join(mozpath.dirname(self.path), basepath) )
def loadConfigs(self): """Entry point to load the l10n.ini file this Parser refers to. This implementation uses synchronous loads, subclasses might overload this behaviour. If you do, make sure to pass a file-like object to onLoadConfig. """ cp = ConfigParser(self.defaults) cp.read(self.inipath) depth = self.getDepth(cp) self.base = mozpath.join(mozpath.dirname(self.inipath), depth) # create child loaders for any other l10n.ini files to be included try: for title, path in cp.items('includes'): # skip default items if title in self.defaults: continue # add child config parser self.addChild(title, path, cp) except NoSectionError: pass # try to load the "dirs" defined in the "compare" section try: self.dirs.extend(cp.get('compare', 'dirs').split()) except (NoOptionError, NoSectionError): pass # try to set "all_path" and "all_url" try: self.all_path = mozpath.join(self.base, cp.get('general', 'all')) except (NoOptionError, NoSectionError): self.all_path = None return cp
def createWorkdir(self, contents): workdir = self.graph.target.git.workdir for tpath, content_list in contents.items(): try: b_content = merge_channels(tpath, content_list) except MergeNotSupportedError: b_content = content_list[0] tpath = mozpath.join(workdir, tpath) tdir = mozpath.dirname(tpath) if not os.path.isdir(tdir): os.makedirs(tdir) with open(tpath, "wb") as fh: fh.write(b_content) self.ensureL10nToml(workdir)
def getFilters(self): '''Get the test functions from this ConfigParser and all children. Only works with synchronous loads, used by compare-locales, which is local anyway. ''' filter_path = mozpath.join(mozpath.dirname(self.inipath), 'filter.py') try: local = {} execfile(filter_path, {}, local) if 'test' in local and callable(local['test']): filters = [local['test']] else: filters = [] except BaseException: # we really want to handle EVERYTHING here filters = [] for c in self.children: filters += c.getFilters() return filters
def getFilters(self): '''Get the test functions from this ConfigParser and all children. Only works with synchronous loads, used by compare-locales, which is local anyway. ''' filter_path = mozpath.join(mozpath.dirname(self.inipath), 'filter.py') try: local = {} with open(filter_path) as f: exec(compile(f.read(), filter_path, 'exec'), {}, local) if 'test' in local and callable(local['test']): filters = [local['test']] else: filters = [] except BaseException: # we really want to handle EVERYTHING here filters = [] for c in self.children: filters += c.getFilters() return filters
def create_merge_dir(self, merge_file): outdir = mozpath.dirname(merge_file) if not os.path.isdir(outdir): os.makedirs(outdir)
def create_merge_dir(self, merge_file): outdir = mozpath.dirname(merge_file) if not os.path.isdir(outdir): os.makedirs(outdir)
def test_dirname(self): self.assertEqual(dirname('foo/bar/baz'), 'foo/bar') self.assertEqual(dirname('foo/bar'), 'foo') self.assertEqual(dirname('foo'), '') self.assertEqual(dirname('foo/bar/'), 'foo/bar')
def test_dirname(self): self.assertEqual(dirname('foo/bar/baz'), 'foo/bar') self.assertEqual(dirname('foo/bar'), 'foo') self.assertEqual(dirname('foo'), '') self.assertEqual(dirname('foo/bar/'), 'foo/bar')