def fwGlobPath(fw, Path): Groups = [] Projects = [] Subjects = [] Sesions = [] Segments = Path.split('/') Containers = {} if (len(Segments) >= 0): Groups = [ Group for Group in fw.groups() if (globre.match(Segments[0], Group.id)) ] for Group in Groups: Containers[Group.id] = Group CurrentPath = [] if (len(Segments) > 1): Projects = {} for GroupPath, Group in Containers.items(): for Project in Group.projects(): if (globre.match(Segments[1], Project.label)): Projects['/'.join([GroupPath, Project.label])] = Project Containers = Projects if (len(Segments) > 2): Subjects = {} for ProjectPath, Project in Containers.items(): for Subject in Project.subjects(): if (globre.match(Segments[2], Subject.label)): Subjects['/'.join([ProjectPath, Subject.label])] = Subject Containers = Subjects if (len(Segments) > 3): Sessions = {} for SubjectPath, Subject in Containers.items(): for Session in Subject.sessions(): if (globre.match(Segments[3], Session.label)): Sessions['/'.join([SubjectPath, Session.label])] = Session Containers = Sessions if (len(Segments) > 4): Acquisitions = {} for SessionPath, Session in Containers.items(): for Acquisition in Session.acquisitions(): if (globre.match(Segments[3], Session.label)): Acquisitions['/'.join([SessionPath, Acquisition.label])] = Acquisition Containers = Acquisitions return (Containers)
def match_pattern(self,collection , context): for pattern in collection: if globre.match(pattern, context): log.debug( "Matched pattern {pattern} in path {path}".format( pattern=pattern, path=context) ) return True return False
def test_match(self): self.assertIsNotNone(globre.match('/foo/bar/**.ini', '/foo/bar/conf.ini')) self.assertIsNotNone(globre.match('/foo/bar/**.ini', '/foo/bar/a/b/c/conf.ini')) self.assertIsNone(globre.match('/foo/bar/**.ini', '/a/foo/bar/conf.ini')) self.assertIsNone(globre.match('/foo/bar/**.ini', '/foo/bar/conf.ini.txt')) self.assertIsNone(globre.match('/foo/bar/**.ini', '/foo/bar/conf.ini/zig.txt')) self.assertIsNone(globre.match('/foo/bar/**.ini', '/FOO/BAR/ZIP/CONF.INI')) self.assertIsNotNone(globre.match('/foo/bar/**.ini', '/FOO/BAR/ZIP/CONF.INI', flags=re.IGNORECASE))
def get_project_by_pattern(project_name): """Find YouTrack project name by GitLab project name.""" if _projects is None: read_projects() for pattern in _projects: if globre.match(pattern, project_name): return _projects[pattern] raise ValueError('Project name does not match any pattern!')
def is_excluded(self, node): ''' returns True if the node should be excluded ''' if self.excludes is not None: for exclude in self.excludes: if globre.match(exclude, node.root_path): log.debug("Matched exclude path [%s] to node [%s]", exclude, node.root_path) return True return False
def is_included(self, node): ''' returns True if the node should be included ''' if self.includes is not None: for include in self.includes: if globre.match(include, node.root_path): log.debug("Matched include path [%s] to node [%s]", include, node.root_path) return True else: return True
def test_sep_alternate(self): self.assertIsNotNone(globre.match('/foo/**.ini', '/foo/bar/conf.ini', sep='/')) self.assertIsNotNone(globre.match('\\\\foo\\\\**.ini', '\\foo\\bar\\conf.ini', sep='\\')) self.assertIsNotNone(globre.match(':foo:**.ini', ':foo:bar:conf.ini', sep=':')) self.assertIsNone(globre.match('/foo/*.ini', '/foo/bar/conf.ini', sep='/')) self.assertIsNone(globre.match('\\\\foo\\\\*.ini', '\\foo\\bar\\conf.ini', sep='\\')) self.assertIsNone(globre.match(':foo:*.ini', ':foo:bar:conf.ini', sep=':'))
def test_sep_default(self): self.assertIsNotNone(globre.match('/foo/**.ini', '/foo/bar/conf.ini')) self.assertIsNone(globre.match('/foo/**.ini', '\\foo\\bar\\conf.ini')) self.assertIsNotNone(globre.match(':foo:**.ini', ':foo:bar:conf.ini')) self.assertIsNone(globre.match('/foo/*.ini', '/foo/bar/conf.ini')) self.assertIsNone(globre.match('/foo/*.ini', '\\foo\\bar\\conf.ini')) self.assertIsNotNone(globre.match(':foo:*.ini', ':foo:bar:conf.ini'))
def is_excluded(self, node): ''' returns True if the node should be excluded if the are no exclude patterns then nothing is excluded any exclude pattern matching the root path will result in exclusion ''' if self.excludes is not None: for exclude in self.excludes: if globre.match(exclude, node.root_path): log.debug("Matched exclude path [%s] to node [%s]", exclude, node.root_path) return True return False
def is_included(self, node): ''' returns True if the node should be included. if there are no include patterns then everything is included any include patterns matching the root path will result in inclusion ''' if self.includes is not None: for include in self.includes: if globre.match(include, node.root_path): log.debug("Matched include path [%s] to node [%s]", include, node.root_path) return True else: return True
def test_match(self): self.assertIsNotNone( globre.match('/foo/bar/**.ini', '/foo/bar/conf.ini')) self.assertIsNotNone( globre.match('/foo/bar/**.ini', '/foo/bar/a/b/c/conf.ini')) self.assertIsNone( globre.match('/foo/bar/**.ini', '/a/foo/bar/conf.ini')) self.assertIsNone( globre.match('/foo/bar/**.ini', '/foo/bar/conf.ini.txt')) self.assertIsNone( globre.match('/foo/bar/**.ini', '/foo/bar/conf.ini/zig.txt')) self.assertIsNone( globre.match('/foo/bar/**.ini', '/FOO/BAR/ZIP/CONF.INI')) self.assertIsNotNone( globre.match('/foo/bar/**.ini', '/FOO/BAR/ZIP/CONF.INI', flags=re.IGNORECASE))
def test_sep_alternate(self): self.assertIsNotNone( globre.match('/foo/**.ini', '/foo/bar/conf.ini', sep='/')) self.assertIsNotNone( globre.match('\\\\foo\\\\**.ini', '\\foo\\bar\\conf.ini', sep='\\')) self.assertIsNotNone( globre.match(':foo:**.ini', ':foo:bar:conf.ini', sep=':')) self.assertIsNone( globre.match('/foo/*.ini', '/foo/bar/conf.ini', sep='/')) self.assertIsNone( globre.match('\\\\foo\\\\*.ini', '\\foo\\bar\\conf.ini', sep='\\')) self.assertIsNone( globre.match(':foo:*.ini', ':foo:bar:conf.ini', sep=':'))
def test_sep_multi(self): self.assertIsNotNone(globre.match('/foo/**.ini', '/foo/bar/conf.ini', sep='/\\')) self.assertIsNotNone(globre.match('/foo/**.ini', '\\foo\\bar\\conf.ini', sep='/\\')) self.assertIsNotNone(globre.match('/foo/**.ini', '/foo\\bar/conf.ini', sep='/\\')) self.assertIsNotNone(globre.match('\\\\foo\\\\**.ini', '\\foo\\bar\\conf.ini', sep='/\\')) self.assertIsNotNone(globre.match('\\\\foo\\\\**.ini', '/foo/bar/conf.ini', sep='/\\')) self.assertIsNotNone(globre.match('\\\\foo/**.ini', '\\foo\\bar\\conf.ini', sep='/\\')) self.assertIsNotNone(globre.match('\\\\foo/**.ini', '/foo\\bar/conf.ini', sep='/\\')) self.assertIsNone(globre.match('/foo/*.ini', '/foo/bar/conf.ini', sep='/\\')) self.assertIsNone(globre.match('/foo/*.ini', '\\foo\\bar\\conf.ini', sep='/\\')) self.assertIsNone(globre.match('/foo/*.ini', '/foo\\bar/conf.ini', sep='/\\')) self.assertIsNone(globre.match('\\\\foo\\\\*.ini', '\\foo\\bar\\conf.ini', sep='/\\')) self.assertIsNone(globre.match('\\\\foo\\\\*.ini', '/foo/bar/conf.ini', sep='/\\')) self.assertIsNone(globre.match('\\\\foo/*.ini', '\\foo\\bar\\conf.ini', sep='/\\')) self.assertIsNone(globre.match('\\\\foo/*.ini', '/foo\\bar/conf.ini', sep='/\\'))
def test_sep_multi(self): self.assertIsNotNone( globre.match('/foo/**.ini', '/foo/bar/conf.ini', sep='/\\')) self.assertIsNotNone( globre.match('/foo/**.ini', '\\foo\\bar\\conf.ini', sep='/\\')) self.assertIsNotNone( globre.match('/foo/**.ini', '/foo\\bar/conf.ini', sep='/\\')) self.assertIsNotNone( globre.match('\\\\foo\\\\**.ini', '\\foo\\bar\\conf.ini', sep='/\\')) self.assertIsNotNone( globre.match('\\\\foo\\\\**.ini', '/foo/bar/conf.ini', sep='/\\')) self.assertIsNotNone( globre.match('\\\\foo/**.ini', '\\foo\\bar\\conf.ini', sep='/\\')) self.assertIsNotNone( globre.match('\\\\foo/**.ini', '/foo\\bar/conf.ini', sep='/\\')) self.assertIsNone( globre.match('/foo/*.ini', '/foo/bar/conf.ini', sep='/\\')) self.assertIsNone( globre.match('/foo/*.ini', '\\foo\\bar\\conf.ini', sep='/\\')) self.assertIsNone( globre.match('/foo/*.ini', '/foo\\bar/conf.ini', sep='/\\')) self.assertIsNone( globre.match('\\\\foo\\\\*.ini', '\\foo\\bar\\conf.ini', sep='/\\')) self.assertIsNone( globre.match('\\\\foo\\\\*.ini', '/foo/bar/conf.ini', sep='/\\')) self.assertIsNone( globre.match('\\\\foo/*.ini', '\\foo\\bar\\conf.ini', sep='/\\')) self.assertIsNone( globre.match('\\\\foo/*.ini', '/foo\\bar/conf.ini', sep='/\\'))