Exemplo n.º 1
0
def venv_package_status_site(venv: Venv, site: Path, req_spec: str) -> Do:
    ws = yield IO.delay(pkg_resources.WorkingSet, [site])
    req = yield IO.delay(pkg_resources.Requirement, req_spec)
    return Maybe.check(ws.by_key.get(req.key)).cata_strict(
        lambda a: VenvPackageExistent(venv, a),
        VenvPackageAbsent(venv),
    )
Exemplo n.º 2
0
def find_interpreter(spec: str) -> Do:
    path = Path(spec)
    exists = yield IO.delay(path.exists)
    venv = env.get('VIRTUAL_ENV').get_or_strict('[no venv]')
    yield (
        IO.pure(path)
        if exists else
        virtualenv_interpreter(venv, spec)
    )
Exemplo n.º 3
0
def build_venv(global_interpreter: Maybe[str], dir: Path, rplugin_interpreter: Maybe[str], name: str) -> Do:
    interpreter = yield python_interpreter(global_interpreter, rplugin_interpreter)
    retval, out, err = yield Subprocess.popen(str(interpreter), '-m', 'venv', str(dir), '--upgrade', timeout=30)
    success = retval == 0
    yield (
        IO.pure(cons_venv(dir, name))
        if success else
        IO.failed(f'creating venv for `{name}`: {err.join_lines}')
    )
Exemplo n.º 4
0
 def purge(self, cmd):
     days = cmd.args.head | 30
     self.log.info('Deleting releases older than {} days'.format(days))
     data = Map(self.client.put('release/purge', dict(days=days)))
     return IO.pure(
         purge_msg.format(data['monitors'], data['links'], data['releases'])
     )
Exemplo n.º 5
0
    def _lookup(self, data):
        def check(resp):
            return (IO.failed('no release found') if resp == -1 else IO.pure(
                (resp, self.rest)))

        return IO.delay(self.client.get, '{}_id'.format(self._type),
                        body=data) // check
Exemplo n.º 6
0
    def help(self, cmd):
        if self.doc:
            maxlen = len(max(self.doc.keys(), key=len))
            pad = lambda s: s.ljust(maxlen)

            def output():
                yield 'Available commands:'
                data = List.wrap(self.doc.items()).sort_by(_[0])
                for name, (param_desc, desc) in data:
                    yield ''
                    yield '{}    {}'.format(pad(name), param_desc)
                    yield '  {}'.format(desc)

            return IO.delay(output) / '\n'.join
        else:
            return IO.failed('no doc for client')
Exemplo n.º 7
0
def check_venv(base_dir: Path, plugin: Rplugin) -> Do:
    dir = base_dir / plugin.name
    pip = dir / 'bin' / 'pip'
    exists = yield IO.delay(pip.exists)
    return (
        venv_present(dir, plugin)
        if exists else
        VenvAbsent(plugin)
    )
Exemplo n.º 8
0
 def list_shows(self, cmd):
     regex = cmd.args.head | ''
     def output(matches):
         if matches:
             for id, description in matches:
                 i = ColorString('#{}'.format(id), term.green)
                 d = ColorString(description, term.yellow)
                 yield '{}: {}'.format(i, d)
         else:
             yield 'No matching show found.'
     return (IO.delay(self.client.get, 'show', body=dict(regex=regex)) /
             output / List.wrap)
Exemplo n.º 9
0
 def search(monitor) -> None:
     r = monitor['release']
     date = Try(datetime.strptime, r['airdate'], '%Y-%m-%d') | None
     release = Release(name=r['series'], season=r['season'], episode=r['episode'], search_name=r['search_name'],
                       airdate=date)
     query = cmd.rest.filter_not(_.empty) / _.join_tokens | release.search_query_no_res
     query1 = release.search_query_date if query == 'date' else query
     self.log.info(f'Searching torrent for "{release}" with query "{query1}"...')
     dl = TorrentDownloader([query1])
     res = Boolean(dl._search()).m(dl.search_results) / Lists.wrap // _.head
     return (
         res /
         (lambda l: cmd.put(data=(lambda i: Just(dict(url=l))), path=Just('link'))) |
         IO.failed('no search results')
     )
Exemplo n.º 10
0
 def hackage(
         self, a: HsHackageRplugin
 ) -> NS[CrmRibosome, GatherItem[Tuple[str, bool]]]:
     exe = cabal_rplugin_executable(self.rplugin)
     return NS.pure(GatherIO(IO.pure((self.rplugin.name, exe.is_file()))))
Exemplo n.º 11
0
 def check_error(response):
     if isinstance(response, dict) and 'error' in response:
         return IO.failed(response['error'])
     else:
         return IO.pure(response)
Exemplo n.º 12
0
 def data(self):
     return (self.spec // __.lmap(lambda a: IO.pure(
         (a, self.args.tail | List()))).left_or_map(self._lookup))
Exemplo n.º 13
0
 def io(i, body):
     return IO.delay(meth(self.client),
                     '{}/{}{}'.format(self._type, i, sub),
                     body=body)
Exemplo n.º 14
0
 def create_episode(self, cmd):
     series, season, episode = cmd.args
     data = dict(episode=episode)
     path = 'series/{}/seasons/{}/episodes'.format(series, season)
     return IO.delay(self.client.post, path, body=data)
Exemplo n.º 15
0
def which(name: str) -> Do:
    exe = yield IO.delay(shutil.which, name)
    return Path(exe)
Exemplo n.º 16
0
def pane_dir(pane: P) -> Do:
    ui_pane = yield TmuxIO.from_either(UiPane.e_for(pane))
    yield (ui_pane.cwd(pane) / TmuxIO.pure).get_or(lambda: TmuxIO.from_io(IO.delay(Path.cwd)))
Exemplo n.º 17
0
 def venv_absent(self, status: VenvAbsent) -> IO[Boolean]:
     return IO.pure(false)
Exemplo n.º 18
0
def venv_site(venv: Venv) -> Do:
    lib_dir = venv.meta.dir / 'lib'
    libs = yield IO.delay(lib_dir.glob, 'python3.?')
    lib = Lists.wrap(libs).head.to_either(f'no python dirs in {lib_dir}')
    return lib.map(lambda a: a / 'site-packages')
Exemplo n.º 19
0
def codegen(task: CodegenTask) -> Do:
    template_path = yield IO.delay(task.template.absolute)
    template_code = yield IO.delay(template_path.read_text)
    replaced = task.subs.fold_left(template_code)(
        lambda z, a: re.sub(a[0], a[1], z))
    return task.imports.cat(replaced).join_lines
Exemplo n.º 20
0
def virtualenv_interpreter(venv: str, executable: str) -> Do:
    path_s = yield IO.from_either(env.get('PATH'))
    path = Lists.split(path_s, ':')
    clean_path = path.filter_not(lambda a: a.startswith(venv))
    candidate = yield IO.delay(shutil.which, executable, path=clean_path.mk_string(':'))
    return Path(candidate)
Exemplo n.º 21
0
def create_dir(dir: Path) -> IO[None]:
    return IO.delay(dir.mkdir, parents=True, exist_ok=True)
Exemplo n.º 22
0
def remove_dir(dir: Path) -> Do:
    exists = yield IO.delay(dir.exists)
    yield IO.delay(shutil.rmtree, dir) if exists else IO.pure(None)
Exemplo n.º 23
0
 def dir(self, a: HsStackDirRplugin
         ) -> NS[CrmRibosome, GatherItem[Tuple[str, bool]]]:
     return NS.pure(GatherIO(IO.pure((self.rplugin.name, False))))
Exemplo n.º 24
0
def clear_cache() -> Do:
    yield IO.delay(shutil.rmtree, str(venvs_path), ignore_errors=True)
    yield create_dir(venvs_path)
Exemplo n.º 25
0
 def to_io(fa: 'TmuxIO[A]', tmux: Tmux) -> Do:
     result = yield IO.delay(fa.run, tmux)
     yield IO.from_either(result.to_either)
Exemplo n.º 26
0
 def check(resp):
     return (IO.failed('no release found') if resp == -1 else IO.pure(
         (resp, self.rest)))
Exemplo n.º 27
0
 def subfps(self, cmd):
     series, season, episode, subfps = cmd.args
     data = dict(subfps=subfps)
     path = 'series/{}/seasons/{}/episodes/{}'.format(
         series, season, episode)
     return IO.delay(self.client.put, path, body=data)
Exemplo n.º 28
0
def mkdir(path: Path) -> IO[None]:
    return IO.delay(path.mkdir, parents=True, exist_ok=True)
Exemplo n.º 29
0
def codegen_write(task: CodegenTask, outpath: Path) -> Do:
    code = yield codegen(task)
    yield IO.delay(outpath.write_text, code)
    return code
Exemplo n.º 30
0
def venv_package_status(venv: Venv, req: str) -> Do:
    site_e = yield venv_site(venv)
    yield site_e.cata(lambda a: IO.pure(VenvPackageAbsent(venv)),
                      lambda a: venv_package_status_site(venv, a, req))