Exemple #1
0
 def create(worktree: Path, store: Path):
     List.wrap(BASE_DIRECTORIES)\
         .smap(store.joinpath) %\
         __.mkdir(parents=True, exist_ok=True)
     DiskObjectStore.init(str(store / OBJECTDIR))
     repo = DulwichRepo(store, worktree)
     repo.refs.set_symbolic_ref(b'HEAD', _master_ref.encode())
     return repo
Exemple #2
0
 def _candidates(self):
     down = (
         self._no_cached_torrents_q
         .filter(ReleaseMonitor.downgrade_after > 0)
         .all()
     )
     caching = (
         self._no_cached_torrents_q
         .join(Torrent)
         .filter(Torrent.caching)
         .all()
     )
     return ((List.wrap(down) / Downgrade) +
             (List.wrap(caching) / CheckCaching))
Exemple #3
0
 def _search_kickass(self, query):
     from tek_utils.sharehoster import kickass
     search = kickass.Search(query).order(kickass.ORDER.SEED,
                                          kickass.ORDER.DESC)
     return List.wrap(
         SearchResultFactory.from_kickass(res)
         for res in itertools.islice(search, self._limit))
Exemple #4
0
 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)
Exemple #5
0
 def __init__(self, func, *a, **kw) -> None:
     assert callable(func), 'ComplexLambda: {} is not callable'.format(func)
     self.__func = func
     self.__args = List.wrap(a)
     self.__kwargs = kw
     self.__qualname__ = self.__func.__name__
     self.__annotations__ = {}
Exemple #6
0
 def filt(entry):
     paths = (
         List.wrap(entry.changes()) //
         (F(_.new.path) >> Maybe) /
         __.decode()
     )
     return paths.contains(relpath)
Exemple #7
0
 def parse(path: Path):
     with path.open() as f:
         try:
             return List.wrap(map(Map, json.loads(f.read())))
         except Exception as e:
             self.log.error('parse error in {}: {}'.format(path, e))
             return List()
Exemple #8
0
def _unite_word(args):
    first = List.wrap(args).lift(0)
    candidates = (
        first.to_list.join
        if first.exists(lambda a: isinstance(a, list))
        else first
    )
    return candidates / Map // __.get('word')
Exemple #9
0
 def filter(self) -> None:
     l = LazyList(range(30))
     l2 = l.filter(_ % 2 == 0)
     l2.strict.should.have.length_of(0)
     l3 = LazyList(range(30))
     l3[29]
     l4 = l3.filter(_ % 2 == 0)
     l4.strict.should.have.length_of(15)
     l4.drain.should.equal(List.wrap(range(0, 30, 2)))
Exemple #10
0
 def handle_show(show):
     season = List.wrap(self.tvdb.season(show.etvdb_id, num))
     if season:
         now = datetime.now().strftime('%F')
         aired = (season.filter(_['date'] < now).map(_['episode']).max)
         aired % L(self._releases.add_season)(
             show.canonical_name, num, _, search_name=show.search_name)
         return 'Done'
     else:
         return 'No such season: {} s{}'.format(show, num)
 def status(self):
     thresh = datetime_to_unix(datetime.now() -
                               timedelta(days=self._status_new_interval))
     done = List.wrap((self.filter_by(downloaded=True).filter(
         ReleaseMonitor.download_date_stamp > thresh)))
     not_cached = List.wrap((self.monitors.filter(
         ~ReleaseMonitor.downloaded).filter(~ReleaseMonitor.torrents.any(
             and_(Torrent.cached, ~Torrent.dead)))))
     caching, search = not_cached.split(__.caching_f())
     downloading = List.wrap(
         self.monitors.filter(ReleaseMonitor.downloading))
     failed = List.wrap(
         (self.monitors.filter(~ReleaseMonitor.downloaded).filter(
             ReleaseMonitor.failed_downloads > 0)))
     return Map(
         done=done / _.done_info,
         caching=caching / _.status_info,
         search=search / _.status_info,
         downloading=downloading / _.status_info,
         failed=failed / _.status_info,
     )
Exemple #12
0
    def effs(self, fa: F, *args):
        from amino.eff import Eff
        types = List.wrap(args)
        c = lambda a, b: Eff(fa, a, depth=b)
        with_depth = lambda d, t: c(t, d)
        types_only = lambda: c(types, depth=len(types))

        def try_depth(h, t):
            return with_depth(int(h), t) if isinstance(h,
                                                       int) else types_only()

        return types.detach_head.map2(try_depth) | types_only
Exemple #13
0
 def _safe_search(self, query):
     self.log.debug(
         'Search {} for {}: {}'.format(query.desc, self.requester,
                                       query.query))
     try:
         return List.wrap(self._search(query.query))
     except NoResultsError as e:
         self.log.debug('Error searching for torrent: {}'.format(e))
     except requests.RequestException as e:
         self.log.warning(
             'Connection failure in {} search'.format(self.search_engine))
     except lxml.etree.XMLSyntaxError as e:
         self.log.warning('Parse error in kickass results: {}'.format(e))
     return List()
Exemple #14
0
    def status(self):
        now = datetime.now().replace(hour=0, minute=0, second=0)
        thresh = now + timedelta(days=7)
        filt = and_(Show.next_episode_stamp >= datetime_to_unix(now),
                    Show.next_episode_stamp < datetime_to_unix(thresh))
        nxt = List.wrap(self.filter(filt))

        def info(s):
            return Map(id=s.id,
                       series=s.canonical_name,
                       episode=s.next_episode,
                       season=s.season,
                       airdate=s.next_episode_day)

        return Map(next=nxt / info)
Exemple #15
0
 def __init__(
         self,
         vim: NvimFacade,
         config_path: Path,
         plugins: List[str],
         bases: List[Path],
         type_bases: Map[Path, List[str]],
         initial_projects: Maybe[Projects]=Empty()
 ) -> None:
     self._config_path = config_path
     self._bases = bases
     self._type_bases = type_bases
     self._initial_projects = initial_projects
     core = 'proteome.plugins.core'
     ProteomeState.__init__(self, vim, List.wrap(cons(core, plugins)))
Exemple #16
0
 def _load_config(self) -> List[Map]:
     def parse(path: Path):
         with path.open() as f:
             try:
                 return List.wrap(map(Map, json.loads(f.read())))
             except Exception as e:
                 self.log.error('parse error in {}: {}'.format(path, e))
                 return List()
     if (self.config_path.is_dir()):
         return List.wrap(self.config_path.glob('*.json')) \
             .flat_map(parse)
     elif self.config_path.is_file():
         return parse(self.config_path)
     else:
         return List()
Exemple #17
0
 def __call__(self, params, skip=1):
     args = [str(self._path)] + list(map(str, params))
     try:
         result = subprocess.run(args,
                                 timeout=60,
                                 stdout=subprocess.PIPE,
                                 stderr=subprocess.PIPE,
                                 universal_newlines=True)
     except subprocess.SubprocessError as e:
         self.log.error('etvdb subprocess error: {}'.format(e))
     else:
         if result.returncode == 0:
             output = List.lines(result.stdout)
             return List.wrap(output[skip:])
         elif result.returncode == 1:
             cmd = ' '.join(args)
             output = List.lines(result.stderr)
             msg = 'etvdb returned {}:\n{}\n{}'
             self.log.error(msg.format(result.returncode, cmd, output))
Exemple #18
0
 def parents(self, commit):
     return List.wrap(commit.parents) / self.repo.get_object
Exemple #19
0
 def content(self):
     sel = self.data.selected
     return List.wrap(enumerate(self.data.commits[:sel + 20]))\
         .flat_smap(lambda i, a: a.browse_format(i == sel))
Exemple #20
0
    def __call_as_pre__(self, *a, **kw):
        def err():
            raise AnonError(self._call_as_pre_error.format(self))

        obj, a2 = List.wrap(a).detach_head.get_or_else(err)
        return self.__call_as_pre_member__(obj, a2)
Exemple #21
0
 def __init__(self, pre: 'AnonFunc', name: str, a, kw) -> None:
     super().__init__(pre, name)
     self.__args = List.wrap(a)
     self.__kw = kw
Exemple #22
0
 def search(hist):
     all = List.wrap(takewhile(_.commit.id != id, hist))
     return all.reversed
Exemple #23
0
 def result(self) -> Maybe[List]:
     return (Just(List.wrap(self._result.get_nowait()))
             if self.result_present else Empty())
Exemple #24
0
 def show(self):
     lines = self.data.projects.show(List.wrap(self.msg.names))
     header = List('Projects:')  # type: List[str]
     return Info('\n'.join(header + lines))
Exemple #25
0
 def go(show):
     services = self._json.get('services') / __.split(',') | ['all']
     s = List.wrap(services)
     r = List(show)
     return self._getd / __.explain_show(r, s) | self._no_getd
Exemple #26
0
 def _clone_repo_name(self, uri):
     return (
         List.wrap(uri.split('/'))
         .lift(-1) /
         F(re.sub, '\.git$', '')
     )
Exemple #27
0
 def go(release):
     services = self._json.get('services') / __.split(',') | ['all']
     s = List.wrap(services)
     r = List(release)
     return self._getd / __.explain_release(r, s) | self._no_getd
Exemple #28
0
 def groups(self) -> List[str]:
     return List.wrap(self.internal.groups())
Exemple #29
0
 def _create_mappings(self):
     List.wrap('jksprq').foreach(self._create_mapping)
     self._create_mapping('<cr>', to='%CR%')
Exemple #30
0
 def __init__(self, name, args, client, param_desc, desc) -> None:
     self.name = name
     self.args = List.wrap(args)
     self.client = client
     self.param_desc = param_desc
     self.desc = desc
Exemple #31
0
 def map(self, fa: List[A], f: Callable[[A], B]) -> List[B]:
     return List.wrap(map(f, fa))
Exemple #32
0
def callers(limit=20):
    stack = (List.wrap(
        inspect.stack()).filter_not(lambda a: 'amino' in a.filename))
    data = stack[:limit] / (lambda a: a[1:-2] + tuple(a[-2]))
    return ''.join(traceback.format_list(data))
Exemple #33
0
 def flat_map(self, fa: List[A], f: Callable[[A], List[B]]) -> List[B]:
     return List.wrap(flatten(map(f, fa)))
Exemple #34
0
 def __dispatch__(self, obj, a):
     sub_a, rest = self.__substitute__(self.__args, List.wrap(a))
     return obj(*sub_a, **self.__kw), rest
Exemple #35
0
 def with_index(self, fa: List[A]) -> List[Tuple[int, A]]:
     return List.wrap(enumerate(fa))
Exemple #36
0
 def __call(self, a, kw):
     sub_a, rest = self.__substitute__(self.__args, List.wrap(a))
     sub_kw = merge(self.__kwargs, kw)
     return self.__func(*sub_a, **sub_kw), rest
Exemple #37
0
 def filter(self, fa: List[A], f: Callable[[A], bool]):
     return List.wrap(filter(f, fa))
Exemple #38
0
 def __call__(self, obj, *a):
     result, rest = self.__call(obj, List.wrap(a))
     if not rest.empty:
         msg = 'extraneous arguments to {}: {}'
         raise AnonError(msg.format(self, rest.mk_string(',')))
     return result
Exemple #39
0
 def zip(self, fa: List[A], fb: List[B], *fs) -> List:
     return List.wrap(zip(fa, fb, *fs))
Exemple #40
0
def content(path: Path):
    return List.wrap(path.iterdir()) if path.is_dir() else List()
Exemple #41
0
 def __init__(self, f, stack, cause) -> None:
     self.f = f
     self.stack = List.wrap(stack)
     self.cause = cause
Exemple #42
0
 def _dyn_subs(self, item: ReleaseMonitor):
     return List.wrap(item.all_links)
Exemple #43
0
 def traverse(self):
     n = 3
     target = Just(List.wrap(range(n)))
     List.wrap(map(Just, range(n))).sequence(Maybe).should.equal(target)