コード例 #1
0
ファイル: test_iterables.py プロジェクト: radhermit/snakeoil
    def test_split(self):
        a, b = partition(range(10))
        assert list(a) == [0]
        assert list(b) == list(range(1, 10))

        a, b = partition(range(10), lambda x: x >= 5)
        assert list(a) == [0, 1, 2, 3, 4]
        assert list(b) == [5, 6, 7, 8, 9]
コード例 #2
0
    def test_split(self):
        a, b = partition(range(10))
        assert list(a) == [0]
        assert list(b) == list(range(1, 10))

        a, b = partition(range(10), lambda x: x >= 5)
        assert list(a) == [0, 1, 2, 3, 4]
        assert list(b) == [5, 6, 7, 8, 9]
コード例 #3
0
    def _install_cmd(self):
        """Install files using `install` command.

        Args:
            iterable of (source, dest) tuples of files to install
        Raises:
            IpcCommandError on failure
        """
        while True:
            files = (yield)

            # `install` forcibly resolves symlinks so split them out
            files, symlinks = partition(
                files, predicate=lambda x: os.path.islink(x[0]))
            self.install_symlinks(symlinks)

            # group and install sets of files by destination to decrease `install` calls
            files = sorted(self._prefix_targets(files), key=itemgetter(1))
            for dest, files_group in itertools.groupby(files, itemgetter(1)):
                sources = list(path for path, _ in files_group)
                command = ['install'] + self.opts.insoptions + sources + [dest]
                ret, output = spawn.spawn_get_output(command,
                                                     collect_fds=(2, ))
                if not ret:
                    raise IpcCommandError('\n'.join(output), code=ret)
コード例 #4
0
    def schedule(self, pkg, executor, futures, results_q):
        http_urls, ftp_urls = partition(
            self._get_urls(pkg), predicate=lambda x: x.startswith('ftp://'))
        http_urls = tuple(http_urls)

        for urls, func in ((http_urls, self._http_check), (ftp_urls,
                                                           self._ftp_check)):
            for url in urls:
                self._schedule_check(func,
                                     url,
                                     executor,
                                     futures,
                                     results_q,
                                     pkg=pkg)

        http_to_https_urls = ((url, f'https://{url[7:]}') for url in http_urls
                              if url.startswith('http://'))
        for orig_url, url in http_to_https_urls:
            future = futures[orig_url]
            self._schedule_check(self._https_available_check,
                                 url,
                                 executor,
                                 futures,
                                 results_q,
                                 future=future,
                                 orig_url=orig_url,
                                 pkg=pkg)
コード例 #5
0
ファイル: ebd_ipc.py プロジェクト: radhermit/pkgcore
 def _install_targets(self, targets):
     files, dirs = partition(targets, predicate=os.path.isdir)
     # TODO: add peekable class for iterables to avoid list conversion
     dirs = list(dirs)
     if dirs:
         if self.opts.recursive:
             dirs = (d for d in dirs if d not in self.opts.excluded_dirs)
             self.install_from_dirs(dirs)
         else:
             raise IpcCommandError(f'{dirs[0]!r} is a directory, missing -r option?')
     self.install((f, os.path.basename(f)) for f in files if self._allowed_file(f))
コード例 #6
0
ファイル: ebd_ipc.py プロジェクト: radhermit/pkgcore
 def _install_targets(self, targets):
     files, dirs = partition(targets, predicate=os.path.isdir)
     # TODO: add peekable class for iterables to avoid list conversion
     dirs = list(dirs)
     if dirs:
         if self.opts.recursive and self.allow_recursive:
             self.install_from_dirs(dirs)
         else:
             missing_option = ', missing -r option?' if self.allow_recursive else ''
             raise IpcCommandError(f'{dirs[0]!r} is a directory{missing_option}')
     self.install((f, os.path.basename(f)) for f in files)
コード例 #7
0
ファイル: git.py プロジェクト: sbraz/pkgcheck
    def check_args(cls, parser, namespace):
        if namespace.commits:
            if namespace.targets:
                targets = ' '.join(namespace.targets)
                s = pluralism(namespace.targets)
                parser.error(
                    f'--commits is mutually exclusive with target{s}: {targets}'
                )

            ref = namespace.commits
            repo = namespace.target_repo
            targets = list(repo.category_dirs)
            if os.path.isdir(pjoin(repo.location, 'eclass')):
                targets.append('eclass')
            try:
                p = subprocess.run(
                    ['git', 'diff', '--cached', ref, '--name-only'] + targets,
                    stdout=subprocess.PIPE,
                    stderr=subprocess.PIPE,
                    cwd=repo.location,
                    encoding='utf8')
            except FileNotFoundError:
                parser.error(
                    'git not available to determine targets for --commits')

            if p.returncode != 0:
                error = p.stderr.splitlines()[0]
                parser.error(f'failed running git: {error}')
            elif not p.stdout:
                # no changes exist, exit early
                parser.exit()

            pkgs, eclasses = partition(
                p.stdout.splitlines(),
                predicate=lambda x: x.startswith('eclass/'))
            pkgs = sorted(cls._pkg_atoms(pkgs))
            eclasses = filter(None, (eclass_regex.match(x) for x in eclasses))
            eclasses = sorted(x.group('eclass') for x in eclasses)

            restrictions = []
            if pkgs:
                restrict = packages.OrRestriction(*pkgs)
                restrictions.append((base.package_scope, restrict))
            if eclasses:
                func = partial(cls._committed_eclass, frozenset(eclasses))
                restrict = values.AnyMatch(values.FunctionRestriction(func))
                restrictions.append((base.eclass_scope, restrict))

            # no pkgs or eclasses to check, exit early
            if not restrictions:
                parser.exit()

            namespace.contexts.append(GitStash(parser, repo))
            namespace.restrictions = restrictions
コード例 #8
0
ファイル: ebd_ipc.py プロジェクト: shen390s/pkgcore
 def _install_targets(self, targets):
     files, dirs = partition(targets, predicate=os.path.isdir)
     # TODO: add peekable class for iterables to avoid list conversion
     dirs = list(dirs)
     if dirs:
         if self.opts.recursive:
             dirs = (d for d in dirs if d not in self.opts.excluded_dirs)
             self.install_from_dirs(dirs)
         else:
             raise IpcCommandError(f'{dirs[0]!r} is a directory, missing -r option?')
     self.install((f, os.path.basename(f)) for f in files if self._allowed_file(f))
コード例 #9
0
ファイル: ebd_ipc.py プロジェクト: shen390s/pkgcore
 def _install_targets(self, targets):
     files, dirs = partition(targets, predicate=os.path.isdir)
     # TODO: add peekable class for iterables to avoid list conversion
     dirs = list(dirs)
     if dirs:
         if self.opts.recursive and self.allow_recursive:
             self.install_from_dirs(dirs)
         else:
             missing_option = ', missing -r option?' if self.allow_recursive else ''
             raise IpcCommandError(f'{dirs[0]!r} is a directory{missing_option}')
     self.install((f, os.path.basename(f)) for f in files)
コード例 #10
0
ファイル: ebd_ipc.py プロジェクト: radhermit/pkgcore
    def _install_cmd(self):
        """Install files using `install` command.

        Args:
            iterable of (source, dest) tuples of files to install
        Raises:
            IpcCommandError on failure
        """
        while True:
            files = (yield)

            # `install` forcibly resolves symlinks so split them out
            files, symlinks = partition(files, predicate=lambda x: os.path.islink(x[0]))
            self.install_symlinks(symlinks)

            # group and install sets of files by destination to decrease `install` calls
            files = sorted(self._prefix_targets(files), key=itemgetter(1))
            for dest, files_group in itertools.groupby(files, itemgetter(1)):
                sources = list(path for path, _ in files_group)
                command = ['install'] + self.opts.insoptions + sources + [dest]
                ret, output = spawn.spawn_get_output(command, collect_fds=(2,))
                if not ret:
                    raise IpcCommandError('\n'.join(output), code=ret)
コード例 #11
0
ファイル: test_iterables.py プロジェクト: radhermit/snakeoil
 def test_empty(self):
     a, b = partition(())
     assert list(a) == []
     assert list(b) == []
コード例 #12
0
 def _install_targets(self, targets):
     files, dirs = partition(targets, predicate=os.path.isdir)
     if self.opts.recursive:
         self.install_from_dirs(dirs)
     self.install((f, os.path.basename(f)) for f in files)
コード例 #13
0
 def test_empty(self):
     a, b = partition(())
     assert list(a) == []
     assert list(b) == []
コード例 #14
0
ファイル: ebd_ipc.py プロジェクト: radhermit/pkgcore
 def _install_targets(self, targets):
     files, dirs = partition(targets, predicate=os.path.isdir)
     if self.opts.recursive:
         self.install_from_dirs(dirs)
     self.install((f, os.path.basename(f)) for f in files)