Exemplo n.º 1
0
    def __init__(self, configFile, git, script):
        self.configFile = configFile
        self.configuration = Configuration().loadJsonFile(configFile)

        if not "license" in self.configuration:
            self.configuration["license"] = None

        # Compile the patterns for future use
        for p in self.configuration["patterns"]:
            if "commentEnd" not in p:
                p["commentEnd"] = ""

            if "prolog" not in p:
                p["prolog"] = []

            p["include"] = PathSpec(map(GitWildMatchPattern, p["include"]))

            if "exclude" in p:
                p["exclude"] = PathSpec(map(GitWildMatchPattern, p["exclude"]))

        self.git = git
        self.python = sys.executable
        self.script = script

        # Change to the git repository directory
        Out, Err, Code = self.git("rev-parse", "--show-toplevel")
        Result = Out.splitlines()
        self.repoDir = Result[0]

        os.chdir(self.repoDir)

        self.header = Header(self.git, self.configuration["copyright"],
                             self.configuration["license"])

        return
Exemplo n.º 2
0
def _load_ignore(at_path, parent_spec, ignores):
    ignore_file = at_path / ".gitignore"
    if not ignore_file.exists():
        return parent_spec
    lines = ignore_file.read_text().split(os.linesep)
    spec = PathSpec.from_lines("gitwildmatch", lines)
    spec = PathSpec(parent_spec.patterns + spec.patterns)
    ignores[at_path] = spec
    return spec
Exemplo n.º 3
0
    def extract_bower_zipfile(self, zip_file, dest, expected_version=None):
        bower_json = None
        root = None
        deps_installed = []
        for info in zip_file.infolist():
            if PurePath(info.filename).name == "bower.json":
                with zip_file.open(info) as f:
                    bower_json = json.load(f)
                    root = str(PurePath(info.filename).parent)
                break
        version = bower_json["version"]
        if expected_version is not None:
            expected_version = Bower.clean_semver(expected_version)
            if not semver.match(version, expected_version):
                click.secho("error: versions do not match ({} =/= {})".format(
                    version, expected_version))
                raise InvalidPackageError
        if "dependencies" in bower_json:
            for package, version in bower_json["dependencies"].items():
                url = Bower.get_package_url(package)
                deps_installed.extend(
                    self.get_bower_package(url, dest=dest, version=version))
        ignore_patterns = [GitIgnorePattern(ig) for ig in bower_json["ignore"]]
        path_spec = PathSpec(ignore_patterns)
        namelist = [
            path for path in zip_file.namelist()
            if PurePath(path).parts[0] == root
        ]
        ignored = list(path_spec.match_files(namelist))
        for path in namelist:
            dest_path = PurePath(bower_json["name"], *PurePath(path).parts[1:])

            if path in ignored:
                continue

            for path in ignored:
                for parent in PurePath(path):
                    if parent in ignored:
                        continue

            if path.endswith("/"):
                if list(path_spec.match_files([str(dest_path)])):
                    ignored.append(PurePath(path))
                elif not (dest / dest_path).is_dir():
                    (dest / dest_path).mkdir(parents=True)
            else:
                target_path = dest / dest_path.parent / dest_path.name
                source = zip_file.open(path)
                target = target_path.open("wb")
                with source, target:
                    shutil.copyfileobj(source, target)
        deps_installed.append((bower_json["name"], bower_json["version"]))
        return deps_installed
Exemplo n.º 4
0
    def _add_spec_excludes_to_build_ignore_patterns(build_root,
                                                    build_ignore_patterns=None,
                                                    spec_excludes=None):
        if not build_ignore_patterns:
            build_ignore_patterns = PathSpec.from_lines(GitIgnorePattern, [])

        patterns = list(build_ignore_patterns.patterns)
        patterns.extend(
            PathSpec.from_lines(
                GitIgnorePattern,
                BuildFile._spec_excludes_to_gitignore_syntax(
                    build_root, spec_excludes)).patterns)
        return PathSpec(patterns)
Exemplo n.º 5
0
def _gitignore_iterdir(path: Path, spec: Patterns) -> Iterator[Path]:

    try:
        with (path / ".gitignore").open("r", encoding="utf-8") as fr:
            patterns = list(fr)

        cpatterns = list(map(GitWildMatchPattern, patterns)) + spec.patterns
        spec = PathSpec(cpatterns)

    except FileNotFoundError:
        pass

    for item in path.iterdir():
        if not spec.match_file(item):
            if item.is_file():
                yield item
            elif item.is_dir():
                yield from _gitignore_iterdir(item, spec)
Exemplo n.º 6
0
def gitignore_iterdir(path: Path, defaultignore: Sequence[str] = [".git"]) -> Iterator[Path]:

    spec = PathSpec(map(GitWildMatchPattern, defaultignore))
    return _gitignore_iterdir(path, spec)