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}') )
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') )
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')
def check_error(response): if isinstance(response, dict) and 'error' in response: return IO.failed(response['error']) else: return IO.pure(response)
def check(resp): return (IO.failed('no release found') if resp == -1 else IO.pure( (resp, self.rest)))
def _data_path(self): tpl = 'show/{name}' form = lambda a: IO.pure(tpl.format(**a)) return self._data_spec // __.cata(IO.failed(self._arg_error), form)
def _data_path(self): tpl = 'release/{show}/{season}/{episode}' form = lambda a: IO.pure(tpl.format(**a)) return self._data_spec // __.cata(IO.failed(self._arg_error), form)