示例#1
0
    def configure(self, gconfig={}, **options):
        """
        Reconfigures the scheduler with the given options. Can only be done
        when the scheduler isn't running.
        """
        if self.running:
            raise SchedulerAlreadyRunningError

        # Set general options
        config = combine_opts(gconfig, 'gosa.common.components.scheduler.',
                              options)
        self.misfire_grace_time = int(config.pop('misfire_grace_time', 1))
        self.coalesce = asbool(config.pop('coalesce', True))
        self.daemonic = asbool(config.pop('daemonic', True))

        # Configure the thread pool
        if 'threadpool' in config:
            self._threadpool = maybe_ref(config['threadpool'])
        else:
            threadpool_opts = combine_opts(config, 'threadpool.')
            self._threadpool = ThreadPool(**threadpool_opts)

        # Configure job stores
        jobstore_opts = combine_opts(config, 'jobstore.')
        jobstores = {}
        for key, value in jobstore_opts.items():
            store_name, option = key.split('.', 1)
            opts_dict = jobstores.setdefault(store_name, {})
            opts_dict[option] = value

        for alias, opts in jobstores.items():
            classname = opts.pop('class')
            cls = maybe_ref(classname)
            jobstore = cls(**opts)
            self.add_jobstore(jobstore, alias, True)
示例#2
0
 def __init__(self, isifile):
     self.ada = []
     self.cp = []
     self.ko = 0
     while True:
         try:
             while True:
                 try:
                     self.apk = isifile
                     self.fs = open(self.apk).read().splitlines()
                     break
                 except Exception as e:
                     print("\n[!] Error : %s" % (e))
                     continue
             self.fl = []
             os.system('rm -rf pass.txt')
             os.system('rm -rf passangka.txt')
             tambah_pass()
             tambah_pass_angka()
             for i in self.fs:
                 try:
                     self.fl.append({
                         "id": i.split("•")[0],
                         "pw": password(i.split("•")[1])
                     })
                 except:
                     continue
         except Exception as e:
             print("\n[!] Error : %s" % (e))
         started()
         ThreadPool(35).map(self.mbasic, self.fl)
         os.remove(self.apk)
         exit()
示例#3
0
def get_text(
    files=[
        root_path('data', fname) for fname in listdir(root_path('data'))
        if fname.endswith('.txt')
    ]
) -> bytearray:
    log.debug(f'[loading] text from {len(files)} files')
    texts: bytearray = bytearray()
    lock = Lock()

    def read_file(path: str):
        start_file = time()
        fname = relpath(path)
        with open(path, mode='rb') as f:
            log.debug(f'[loading] text from file {fname}')
            try:
                txt = f.read()
                lock.acquire()
                texts.extend(txt)
                texts.extend(b'\n\n')
                lock.release()
            except Exception as e:
                log.warning(str(e))
        log.debug(
            f'[finished] reading from {fname} (read {getsizeof(texts[-1]) / 1e6:4.2f}MB in {time() - start_file:4.2f}s)'
        )

    with ThreadPool(max_workers=NO_CPUS,
                    thread_name_prefix='get_text') as pool:
        for task in [pool.submit(fn=read_file, path=p) for p in files]:
            task.result()
    return texts
示例#4
0
def check_proxies():
    """
    checks all the parsed proxies - all the types
    :return: None
    """
    global proxy_list, _checked, _host_ip
    if __name__ == "__main__":
        opts.judge = _choose_from_enum(Judge, "Please select a proxy judge:")
    _host_ip = get_external_ip()
    with ThreadPool(max_workers=opts.proxy_check_threads) as pool:
        for proxy_type in ProxyType:
            if len(proxy_list.dict[proxy_type]) == 0:
                continue
            futures = {pool.submit(test_proxy, proxy): proxy for proxy in proxy_list.dict[proxy_type]}
            # for proxy in proxy_list.dict[proxy_type]:
            #     pool.submit(test_proxy, proxy).add_done_callback(proxy_on_checked)
            if opts.show_progress:
                print(f"\nCurrently checking {proxy_type.name} proxies:")
            for future in as_completed(futures):
                proxy_on_checked(future, len(pool._threads))
            proxy_list.dict[proxy_type] = _checked
            _checked = []
            proxy_list.update_size()
    if opts.show_progress:
        print()
示例#5
0
def generate(seed=b'That day',
             n=6,
             max_len=(1000 * 5),
             show_metrics=True) -> Generator[bytes, None, None]:
    start = time()
    tokens: List[bytes] = [m.group(0) for m in list(chunk(seed))[-n:]]
    no_tokens = len(tokens)
    succ = np.array([0 for _ in range(n + 1)], dtype='uint32')
    ps: Dict[bytes, float] = get_chunk_ps()
    chunks: ndarray = np.array(list(ps.keys()))
    chunk_ps: ndarray = np.array(list(ps.values()))

    with ThreadPool(max_workers=NO_CPUS,
                    thread_name_prefix='markov/w') as pool:
        lookup = ChainMap(*[
            task.result() for task in
            [pool.submit(fn=get_nchunks_ps, n=i) for i in range(n, 0, -1)]
        ])
    yield seed

    # token generation
    while no_tokens * AVG_CHUNK_LEN < max_len:
        found = False
        for m in range(n, 0, -1):
            ngram = tuple(tokens[-m:])
            maybe_ps: Optional[Dict[bytes, float]] = lookup.get(ngram, None)
            if maybe_ps is not None and len(maybe_ps) > 1:
                found = True
                succ[m] += 1
                next_chunk: bytes = choice(
                    a=list(maybe_ps.keys()),
                    p=list(maybe_ps.values()),
                )
                yield next_chunk
                tokens.append(next_chunk)
                tokens = tokens[-n:]
                break
        if not found:
            succ[0] += 1
            next_chunk = choice(a=chunks, p=chunk_ps)
            yield next_chunk
            tokens.append(next_chunk)
            tokens = tokens[-n:]
        no_tokens += 1

    if show_metrics:
        # metrics
        log.info('-' * (1 + 6 + 15 + 2))
        log.info('%9s%s' % (' ', 'METRICS'))
        log.info('-' * (1 + 6 + 15 + 2))
        log.info('%-1s %-6s %-15s' % ('#', 'PROB', 'NO EXAMPLES'))
        log.info('%-1s %-6s %-15s' % ('-' * 1, '-' * 6, '-' * 15))
        no_gen_tokens: int = sum(succ)
        for i in range(n, -1, -1):
            log.info('%-1d %-6.4f %-15d' %
                     (i, succ[i] / no_gen_tokens, succ[i]))

    log.debug(f'[finished] generating text (took {time() - start:4.2f}s)')
示例#6
0
def _get_pool(pool_type: Type, max_workers: int) -> Pool:
    if pool_type == ThreadPool:
        pool = ThreadPool(max_workers)
        setattr(pool, "imap", pool.map)
        return pool
    elif pool_type == Pool:
        pool = Pool(max_workers, mp_context=get_context("spawn"))
        setattr(pool, "imap", pool.map)
        return pool
    else:
        raise TypeError(f"Unknown pool type: {pool_type}")
示例#7
0
def generate(seed=b'That day', n=6, max_len=(1000 * 5), show_metrics=True) -> Generator[int, None, None]:
    start = time()
    txt: bytearray = bytearray(seed[-n:])
    succ: ndarray = np.array([0 for _ in range(n + 1)], dtype='uint32')
    ps: ndarray = get_char_ps()
    char_idx: ndarray = np.arange(128, dtype='ubyte')

    with ThreadPool(max_workers=NO_CPUS, thread_name_prefix='markov/c') as pool:
        lookup = ChainMap(*[
            task.result() for task in [
                pool.submit(fn=get_nchar_ps, n=(i + 1))
                for i in range(n, 0, -1)]])

    for byte in seed:
        yield byte

    while max_len > 0:
        max_len -= 1
        found = False
        for m in range(n, 0, -1):
            maybe_ps: Optional[Dict[bytes, float]] = \
                    lookup.get(bytes(txt[-m:]), None)
            if maybe_ps is not None and len(maybe_ps) > 1:
                succ[m] += 1
                next_char = choice(
                    a=tuple(maybe_ps.keys()),
                    p=tuple(maybe_ps.values()),
                )
                txt.append(next_char)
                txt = txt[-n:]
                found = True
                yield next_char
                break
        if not found:
            succ[0] += 1
            next_char = choice(a=char_idx, p=ps)
            txt.append(next_char)
            txt = txt[-n:]
            yield next_char

    if show_metrics:
        # metrics
        log.info('-' * (2 + 6 + 15 + 2))
        log.info('%9s%s' % (' ', 'METRICS'))
        log.info('-' * (2 + 6 + 15 + 2))
        log.info('%-2s %-6s %-15s' % ('##', 'PROB', 'NO EXAMPLES'))
        log.info('%-2s %-6s %-15s' % ('-' * 2, '-' * 6, '-' * 15))
        no_gen_char: int = sum(succ)
        for i in range(n, -1, -1):
            log.info('%-2d %-6.4f %-15d' % (i, succ[i] / no_gen_char, succ[i]))

    log.debug(f'[finished] generating text (took {time() - start:4.2f}s)')

    return txt.decode('ascii', 'ignore')
示例#8
0
 def pwlist(self):
     self.pw = input(" [*]. password list : ").split(",")
     if len(self.pw) == 0:
         self.pwlist()
     else:
         for i in self.fl:
             i.update({"pw": self.pw})
         print("  crack started...")
         time.sleep(0.07)
         print("  account ok saved to: ok.txt")
         time.sleep(0.07)
         print("  account checkpoint saved to: checkpoint.txt")
         time.sleep(0.07)
         ThreadPool(30).map(self.main, self.fl)
示例#9
0
def main(argv: List[str] = sys.argv) -> int:
    level = os.environ.get(theLogName, 'WARN').upper()
    logging.basicConfig(
        level=level,
        format=theDebugLogFormat if level == 'DEBUG' else theLogFormat)
    logger.info('GoodMake version %s', theVersion)

    # interpreter = argv[1]  # interpreter will be taken from the file shebang
    scriptPath = argv[2]
    targetPaths = argv[3:] or ['default']
    depPath = cast(Optional[FullPath], os.environ.get(theDepName, None))
    currentDir = os.getcwd()

    logger.debug('PID %s:%s for %s', os.getpid(), os.getppid(), targetPaths)

    builder = Builder()

    def runBuild(target: str) -> None:
        if Builder.error:
            return
        try:
            command = BuildCommand(currentDir, scriptPath, target)
            event = builder.build(command)

            if depPath:
                logger.debug('Writing %s to parent %s', target, depPath)
                with open(depPath, 'a') as file:
                    file.write(event.toString(path.dirname(depPath)) + '\n')
        except Exception as e:
            logger.debug("Setting %s thread error %s", os.getpid(), e)
            Builder.error = e

    if theMaxThreads <= 1 or len(targetPaths) <= 1:
        for target in targetPaths:
            runBuild(target)
    else:
        with ThreadPool(max_workers=theMaxThreads) as threads:
            threads.map(runBuild, targetPaths)

    if Builder.error:
        logger.error(Builder.error)
        return int(getattr(Builder.error, 'returncode', 1))

    return 0
示例#10
0
def begin(philosopher_count, eat_count):
    forks = []
    for _ in range(philosopher_count):
        forks.append(threading.Lock())

    philosophers = []
    for num in range(philosopher_count):
        left_fork = forks[num]
        if num == philosopher_count - 1:
            right_fork = forks[0]
        else:
            right_fork = forks[num + 1]
        philosophers.append(DiningPhilosophers(num, left_fork, right_fork))

    pool = ThreadPool(max_workers=philosopher_count)
    for _ in range(eat_count):
        for philosopher in philosophers:
            pool.submit(philosopher.wantsToEat(), philosopher)
    pool.shutdown()
示例#11
0
    def create_frames(self, states):

        self.validate_states(states)

        states_to_be_created = self.get_nonexistent_states(states)

        if len(states_to_be_created) != 0 and self.psd is None:
            raise RuntimeError(
                "Need to generate states but no psd file supplied.")

        #ProcessPool for CPU bound image creation, ThreadPool for IO bound file saving
        with ProcessPool(initializer=ignore_signal
                         ) as process_pool, ThreadPool() as thread_pool:
            try:
                for image, state in process_pool.imap_unordered(
                        self.generate_image, states_to_be_created):
                    save_image = partial(image.save,
                                         self.args.directory / state.filename)
                    thread_pool.submit(save_image)
            except KeyboardInterrupt:
                process_pool.terminate()
                thread_pool.shutdown(wait=False)

                raise KeyboardInterrupt from None
示例#12
0
 def _make_process_pool(self):
     self.pool = ThreadPool(20)
示例#13
0
    def __init__(self):
        self.ada = []
        self.cp = []
        self.ko = 0
        print("\n  [+]Crack with pass deflaut or manual [D/m]")
        while True:
            f = input("  Input: ")
            if f == "": continue
            elif f == "m":
                try:
                    while True:
                        try:
                            self.apk = input("  [+]ID list file: ")
                            self.fs = open(self.apk).read().splitlines()
                            break
                        except Exception as e:
                            print(("  %s" % e))
                            continue
                    self.fl = []
                    for i in self.fs:
                        try:
                            self.fl.append({"id": i.split("<=>")[0]})
                        except:
                            continue
                except Exception as e:
                    print(("  %s" % e))
                    continue
                print("  [+]example pass123,pass12345")
                self.pwlist()
                break
            elif f == "d":
                try:
                    while True:
                        try:
                            self.apk = input("  [+]ID list file: ")
                            self.fs = open(self.apk).read().splitlines()
                            break
                        except Exception as e:
                            print(("  %s" % e))
                            continue
                    self.fl = []
                    for i in self.fs:
                        try:
                            self.fl.append({
                                "id": i.split("<=>")[0],
                                "pw": generate(i.split("<=>")[1])
                            })
                        except:
                            continue
                except Exception as e:
                    print(("  %s" % e))
                    continue
                print("  [+]Crack started...")
                time.sleep(0.07)
                print("  [+]Account ok saved to: ok.txt")
                time.sleep(0.07)
                print("  [+]Account chekpoint saved to: cp.txt")
                time.sleep(0.07)
                print(45 * ("_"))
                time.sleep(0.07)
                ThreadPool(35).map(self.main, self.fl)
                os.remove(self.apk)

                break
示例#14
0
 def run(self):
     with ThreadPool(self.limit) as pool:
         res = pool.map(self.call_crawl, self.urls)
     return res
示例#15
0
 def __init__(self):
     self.ada = []
     self.cp = []
     self.ko = 0
     print(" [?]. apakah ingin menggunakan katasandi manual [Y/t]")
     while True:
         f = input(" [*]. input : ")
         print
         if f == "": continue
         elif f == "t":
             try:
                 while True:
                     try:
                         self.apk = input(" [*]. masukan id list file: ")
                         self.fs = open(self.apk).read().splitlines()
                         break
                     except Exception as e:
                         print(("  %s" % e))
                         continue
                 self.fl = []
                 for i in self.fs:
                     try:
                         self.fl.append({"id": i.split("<=>")[0]})
                     except:
                         continue
             except Exception as e:
                 print(("  %s" % e))
                 continue
             print(" [*]. contoh pass123,pass12345")
             self.pwlist()
             break
         elif f == "Y":
             try:
                 while True:
                     try:
                         self.apk = input(" [*]. masukan id list file : ")
                         self.fs = open(self.apk).read().splitlines()
                         break
                     except Exception as e:
                         print(("  %s" % e))
                         continue
                 self.fl = []
                 for i in self.fs:
                     try:
                         self.fl.append({
                             "id": i.split("<=>")[0],
                             "pw": generate(i.split("<=>")[1])
                         })
                     except:
                         continue
             except Exception as e:
                 print(("  %s" % e))
                 continue
             print(" [!]. crack started...")
             time.sleep(0.07)
             print(" [+]. account ok saved to: \033[0;92mok.txt\033[0;97m")
             time.sleep(0.07)
             print(
                 " [*]. account checkpoint saved to: \033[0;93mcheckpoint.txt\033[0;97m\n"
             )
             time.sleep(0.07)
             ThreadPool(35).map(self.main, self.fl)
             break