Beispiel #1
0
    def resolve_symlinks(self, path):
        """Resolve any symlinks in the path."""
        # Resolve symlinks first
        real_path = path_separator(os.path.realpath(os.path.join(self.path, path)))
        repository_path = path_separator(os.path.realpath(self.path))

        if not real_path.startswith(repository_path):
            raise ValueError("Too many symlinks or link outside tree")

        return real_path[len(repository_path) :].lstrip("/")
Beispiel #2
0
    def resolve_symlinks(self, path):
        """
        Resolves any symlinks in the path.
        """
        # Resolve symlinks first
        real_path = path_separator(os.path.realpath(os.path.join(self.path, path)))
        repository_path = path_separator(os.path.realpath(self.path))

        if not real_path.startswith(repository_path):
            raise ValueError("Too many symlinks or link outside tree")

        return real_path[len(repository_path) :].lstrip("/")
Beispiel #3
0
    def matches(self):
        """Return matched files together with match groups and mask."""
        result = []
        base = os.path.realpath(self.path)
        for root, dummy, filenames in os.walk(self.path, followlinks=True):
            for filename in filenames:
                fullname = os.path.join(root, filename)

                # Skip files outside our root
                if not os.path.realpath(fullname).startswith(base):
                    continue

                # Calculate relative path
                path = path_separator(os.path.relpath(fullname, self.path))

                # Check match against our regexp
                matches = self.path_match.match(path)
                if not matches:
                    continue

                # Check langauge regexp
                if not self.language_match.match(matches.group('language')):
                    continue

                # Calculate file mask for match
                mask = '{}*{}'.format(
                    path[:matches.start('language')],
                    path[matches.end('language'):],
                )
                result.append((path, matches.groupdict(), mask))

        return result
Beispiel #4
0
    def matches(self):
        """Return matched files together with match groups and mask."""
        result = []
        base = os.path.realpath(self.path)
        for root, dummy, filenames in os.walk(self.path, followlinks=True):
            for filename in filenames:
                fullname = os.path.join(root, filename)

                # Skip files outside our root
                if not os.path.realpath(fullname).startswith(base):
                    continue

                # Calculate relative path
                path = path_separator(os.path.relpath(fullname, self.path))

                # Check match against our regexp
                matches = self.path_match.match(path)
                if not matches:
                    continue

                # Check language regexp
                if not self.language_match.match(matches.group('language')):
                    continue

                # Calculate file mask for match
                mask = '{}*{}'.format(
                    path[:matches.start('language')],
                    path[matches.end('language'):],
                )
                result.append((path, matches.groupdict(), mask))

        return result
Beispiel #5
0
 def get_matching_files(self, repo):
     '''
     Returns relative path of matched files.
     '''
     matches = glob(os.path.join(repo, self.filemask))
     return [
         path_separator(f.replace(repo, '')).strip('/') for f in matches
     ]
Beispiel #6
0
 def get_matching_files(self, repo):
     '''
     Returns relative path of matched files.
     '''
     matches = glob(os.path.join(repo, self.filemask))
     return [
         path_separator(f.replace(repo, '')).strip('/') for f in matches
     ]
Beispiel #7
0
    def matches(self):
        """Return matched files together with match groups and mask."""
        result = []
        base = os.path.realpath(self.path)
        for root, dirnames, filenames in os.walk(self.path, followlinks=True):
            for filename in chain(filenames, dirnames):
                fullname = os.path.join(root, filename)

                # Skip files outside our root
                if not os.path.realpath(fullname).startswith(base):
                    continue

                # Calculate relative path
                path = path_separator(os.path.relpath(fullname, self.path))

                # Check match against our regexp
                matches = self.path_match.match(path)
                if not matches:
                    continue

                # Check language regexp
                if not self.language_match.match(matches.group('language')):
                    continue

                # Calculate file mask for match
                replacements = [
                    (matches.start('language'), matches.end('language'))
                ]
                for group in matches.groupdict().keys():
                    if group.startswith('_language_'):
                        replacements.append(
                            (matches.start(group), matches.end(group))
                        )
                maskparts = []
                maskpath = path
                for start, end in sorted(replacements, reverse=True):
                    maskparts.append(maskpath[end:])
                    maskpath = maskpath[:start]
                maskparts.append(maskpath)

                mask = '*'.join(reversed(maskparts))

                result.append((path, matches.groupdict(), mask))

        return result
Beispiel #8
0
    def matches(self):
        """Return matched files together with match groups and mask."""
        result = []
        base = os.path.realpath(self.path)
        for root, dirnames, filenames in os.walk(self.path, followlinks=True):
            for filename in chain(filenames, dirnames):
                fullname = os.path.join(root, filename)

                # Skip files outside our root
                if not os.path.realpath(fullname).startswith(base):
                    continue

                # Calculate relative path
                path = path_separator(os.path.relpath(fullname, self.path))

                # Check match against our regexp
                matches = self.path_match.match(path)
                if not matches:
                    continue

                # Check language regexp
                if not self.language_match.match(matches.group('language')):
                    continue

                # Calculate file mask for match
                replacements = [
                    (matches.start('language'), matches.end('language'))
                ]
                for group in matches.groupdict().keys():
                    if group.startswith('_language_'):
                        replacements.append(
                            (matches.start(group), matches.end(group))
                        )
                maskparts = []
                maskpath = path
                for start, end in sorted(replacements, reverse=True):
                    maskparts.append(maskpath[end:])
                    maskpath = maskpath[:start]
                maskparts.append(maskpath)

                mask = '*'.join(reversed(maskparts))

                result.append((path, matches.groupdict(), mask))

        return result