コード例 #1
0
ファイル: Tearer.py プロジェクト: prebuilder/prebuilder.py
    def __call__(self, fileName: Path) -> bool:
        filesUnmatched = []
        filesOwn = []
        for p in self.paths:
            if isNestedIn(p, fileName):
                if self.debug:
                    print("self.isDir == fileName.is_dir()",
                          self.isDir == fileName.is_dir(),
                          "self.isDir", self.isDir, "fileName.is_dir()",
                          fileName.is_dir(), fileName)

                if not self.isDir:
                    if not fileName.is_dir():
                        name2Match = fileName.name
                    else:
                        continue
                else:
                    p = relativePath(fileName, p)
                    name2Match = p.parts[0]

                if self.matchers:
                    for m in self.matchers:
                        if self.debug:
                            print(
                                "(" + repr(m) + ").search(" +
                                repr(name2Match) + ")", m.search(name2Match))
                        if m.search(name2Match):
                            return True
                else:
                    return True
        return False
コード例 #2
0
    def _internal(self, srcPath, srcRelative, pkg, childPkg):
        if self.dst is not None:
            dst = self.dst
        else:
            dst = srcRelative

        if self.ignoreMissing:
            if not srcPath.exists():
                warn("Missing file/dir " + repr(srcPath) +
                     " is ignored by action " + repr(self))
                return

        intoDir = (dst.is_dir() and not srcPath.is_dir())

        if intoDir:
            dstPath = childPkg.nest(dst)
            dstPath.mkdir(parents=True, exist_ok=True)
            dstFilePathStr = relativePath(dstPath / srcPath.name,
                                          childPkg.root)
            childPkg.copy(
                srcPath, dstFilePathStr,
                {dstFilePathStr: pkg.filesTracker.hashsums[srcRelative]})
        else:
            childPkg.copy(srcPath, dst,
                          {dst: pkg.filesTracker.hashsums[srcRelative]})
コード例 #3
0
    def __call__(
        self, targets: typing.Iterable[DownloadTarget]
    ) -> typing.Iterable[DownloadTarget]:
        if not targets:
            return
        args = []

        cwdP = Path(
            ".").absolute()  # https://github.com/aria2/aria2/issues/1137

        needPassMetalink = False

        targets = sorted(targets, key=lambda t: not bool(t.metalink))
        needPassMetalink = bool(targets[0].metalink)

        if not needPassMetalink:
            for t in targets:
                uris = t.uris
                if not isinstance(uris, str):
                    uris = "\t".join(uris)
                args += [uris, linesep]

                if t.fsPath:
                    args += [
                        " ", "out=",
                        str(relativePath(t.fsPath, cwdP)), linesep
                    ]

            config = "".join(args)

            print(repr(config))

            with MempipedPathRead(config) as pipe:
                self.aria2c(**{"input-file": pipe})
        else:
            from ..Metalink import Metalink

            tIt = iter(targets)
            m = Metalink(next(tIt))

            for t in tIt:
                m += Metalink(t)

            with MempipedPathRead(str(m)) as pipe:
                self.aria2c(**{"metalink-file": pipe})
コード例 #4
0
    def _internal(self, srcPath, srcRelative, pkg, childPkg):
        if self.dst is not None:
            dst = self.dst
        else:
            dst = srcRelative

        intoDir = (dst.is_dir() and not srcPath.is_dir())

        rt = childPkg.nest(
            self.relativeTo) if self.relativeTo is not None else None

        if intoDir:
            dstPath = childPkg.nest(dst)
            dstPath.mkdir(parents=True, exist_ok=True)
            dstFilePathStr = relativePath(dstPath / srcPath.name,
                                          childPkg.root)
            childPkg.symlink(childPkg.nest(srcRelative), dstFilePathStr, rt)
        else:
            childPkg.symlink(childPkg.nest(srcRelative), dst, rt)
コード例 #5
0
 def __call__(self, pkg, childPkg):
     srcPath = pkg.nest(self.src)
     if self.isGlob:
         if self.globAllowed:
             globExpr = str(srcPath)
             globbed = sorted(glob(globExpr))
             if not globbed:
                 if not self.ignoreMissing:
                     raise ValueError("Nothing has been globbed", globExpr,
                                      self)
                 else:
                     warn("Nothing has been globbed: " + repr(globExpr) +
                          " " + repr(self))
                     return
             for p in globbed:
                 p = Path(p)
                 self._internal(
                     p, VPath(relativePath(p, pkg.root)), pkg, childPkg
                 )  # nesting is checked in PackageInstallData module
         else:
             raise PermissionError(
                 "Glob expressions are not allowed for this action", self)
     else:
         self._internal(srcPath, self.src, pkg, childPkg)