Ejemplo n.º 1
0
def produce_consume():
    real_path, word_path, config_path = paths()
    check_paths(word_path, config_path)
    config = get_config(config_path)
    try:
        error = check_config(config)
    except Exception as e:
        print(type(e).__name__, e)
        exit(1)
    else:
        if error is not None:
            print(error)
            exit(1)
    q = Queue()
    consumer = Consumer(q)
    for i in range(16):
        t = Thread(target=consumer.consume_domains)
        t.daemon = True
        t.start()
    Producer(q, config, word_path).get_doms()
    q.join()
    if config['write_to_file']:
        print_red('writing to domains.json')
        p = Process(target=add_data, args=(real_path, consumer.get_domains()))
        p.start()
    print_red('sleeping zzzzz...')
    sleep(config['interval'])
Ejemplo n.º 2
0
    def __computeBestAssignments_(self, drones_map):
        drones = {int(k):drones_map[k] for k in drones_map.keys()}
        print("drones->>>>", drones)
        drone_positions = list(drones.values())
        rev = {tuple(v): k for k, v in drones.items()}
        print('reversed---->', rev)

        print(drone_positions)
        distance_matrix, checkpoints = self.__computeDistanceMatrix_(drone_positions)
        print("45", drone_positions)
        min_sum = (sys.maxsize, None)
        all_poss = list(permutations([i for i in range(len(distance_matrix[0]))]))
        print(46)
        for poss in all_poss:
            s = sum(distance_matrix[fp][poss[fp]] for fp in
                    range(len(self.__individual_flight_plans_)))
            if s < min_sum[0]:
                min_sum = (s, poss)
        print(47)
        for i in range(len(drone_positions)):
            drone_pos_index = min_sum[1][i]
            print("Drone pos index", drone_pos_index)
            self.__individual_flight_plans_[i].nodeid = int(rev[tuple(drone_positions[drone_pos_index])])
            self.__individual_flight_plans_[i].start_waypoint = checkpoints[i][drone_pos_index]
            print_red("# Assinging fp %d to nodeid=%d" % ( i, self.__individual_flight_plans_[i].nodeid))
Ejemplo n.º 3
0
def run_boot(build):
    cbl_arch = get_cbl_name()
    kernel_image = cwd() + "/" + get_image_name()
    boot_qemu = [
        "./boot-utils/boot-qemu.sh", "-a", cbl_arch, "-k", kernel_image
    ]
    # If we are running a sanitizer build, we should increase the number of
    # cores and timeout because booting is much slower
    if "CONFIG_KASAN=y" in build["kconfig"] or \
       "CONFIG_KCSAN=y" in build["kconfig"] or \
       "CONFIG_UBSAN=y" in build["kconfig"]:
        boot_qemu += ["-s", "4"]
        if "CONFIG_KASAN=y" in build["kconfig"]:
            boot_qemu += ["-t", "20m"]
        else:
            boot_qemu += ["-t", "10m"]
        if "CONFIG_KASAN_KUNIT_TEST=y" in build["kconfig"] or \
           "CONFIG_KCSAN_KUNIT_TEST=y" in build["kconfig"]:
            print_yellow(
                "Disabling Oops problem matcher under Sanitizer KUnit build")
            print("::remove-matcher owner=linux-kernel-oopses")

    # Before spawning a process with potentially different IO buffering,
    # flush the existing buffers so output is ordered correctly.
    sys.stdout.flush()
    sys.stderr.flush()

    try:
        subprocess.run(boot_qemu, check=True)
    except subprocess.CalledProcessError as e:
        if e.returncode == 124:
            print_red("Image failed to boot")
        raise e
Ejemplo n.º 4
0
def verify_build():
    build = get_build()

    # If the build was neither fail nor pass, we need to fetch the status.json
    # of the particular build to try and get an updated result. We attempt this
    # up to 7 times.
    retries = 0
    max_retries = 7
    while retries < max_retries:
        if build["result"] == "fail" or build["result"] == "pass":
            break

        if retries:
            time.sleep(2**retries)
        retries += 1

        status_json = "status.json"
        url = build["download_url"] + status_json
        _fetch("status.json", url, status_json)
        build = json.load(open(status_json))

    print(json.dumps(build, indent=4))

    if retries == max_retries:
        print_red("status.json did not give a pass/fail result!")
        sys.exit(1)

    if build["status_message"] == "Unable to apply kernel patch":
        print_red(
            "Patch failed to apply to current kernel tree, does it need to be removed or updated?"
        )
        fetch_logs(build)
        sys.exit(1)

    return build
Ejemplo n.º 5
0
 def set_position(self, newpos):
     self.__position = newpos
     self.__con = sqlite3.connect(gs.DB_PATH)
     db_update_currPos(self.__con,
                       self.__nodeID,
                       longitude=newpos[0],
                       latitude=newpos[1])
     self.__con.close()
     print_red("Position: %s" % str(newpos))
Ejemplo n.º 6
0
 def vectorize(self, text):
     """Transforms text to a vector of integers"""
     tokens = self._tokenize(text)
     indices = []
     for token in tokens:
         if token in self._token_indices:
             indices.append(self._token_indices[token])
         else:
             print_red('Ignoring unrecognized token:', token)
     return np.array(indices, dtype=np.int32)
Ejemplo n.º 7
0
def boot_test(build):
    if build["result"] == "fail":
        print_red("fatal build errors encountered during build, skipping boot")
        sys.exit(1)
    if "BOOT" in os.environ and os.environ["BOOT"] == "0":
        print_yellow("boot test disabled via config, skipping boot")
        return
    fetch_kernel_image(build)
    fetch_dtb(build)
    run_boot(build)
Ejemplo n.º 8
0
def copy_files(from_dir: Path, to_dir: Path) -> None:
    if path_exists(from_dir) and path_exists(to_dir):
        file_names = os.listdir(from_dir)
        for file_name in file_names:
            srcname = os.path.join(from_dir, file_name)
            dstname = os.path.join(to_dir, file_name)
            shutil.copy2(srcname, dstname)
    elif path_exists(from_dir):
        shutil.copytree(from_dir, to_dir)
    else:
        print_red(f"from_dir: {from_dir} does not exists. Skip copying files.")
Ejemplo n.º 9
0
 def __tr_update_position(self):
     print_red("starting thread")
     # todo: current version drone teleported to new pos -- to fix
     while not self.halt:
         self.__mutex_fp.acquire()
         try:
             if (self.__flightplan):
                 self.set_position(self.next_wp)
                 self.next_wp = next(self.it)
         finally:
             self.__mutex_fp.release()
         sleep(self.__speed)
Ejemplo n.º 10
0
def fetch_kernel_image(build):
    image_name = get_image_name()
    url = build["download_url"] + image_name
    print_yellow("fetching kernel image from: %s" % url)
    # TODO: use something more robust like python wget library.
    urllib.request.urlretrieve(url, image_name)
    # Suspect download is failing.
    if os.path.exists:
        print_yellow("Filesize: %d" % os.path.getsize(image_name))
    else:
        print_red("Unable to download kernel image")
        sys.exit(1)
Ejemplo n.º 11
0
 def _create_mysql_monitor(self):
     monitors = self._monitor.get_template_list()
     filtered = [monitor for monitor in monitors
                 if monitor.template_name == self.MONITOR_NAME]
     if filtered:
         msg = '  - mysql_monitor already exists'
         utils.print_yellow(msg)
     else:
         # TODO(retr0h): How to upload a custom monitor.  Once uploaded
         # can configure an external template.
         msg = '  - need to upload and configure mysql_monitor'
         utils.print_red(msg)
Ejemplo n.º 12
0
    def __computeSubPolygons_(self):
        """
        Create flight plans with loaded subpoly and add to list
        FlightPlan is able to autonomously deduct route and encodage from subpoly
        """
        print_red("--> COMPUTING SUBPOLYGONS WITH GLOBAL=%s"%str(self.__global_area_polygon_))
        assert self.__num_partitions_
        sub_polygons = getFairPartitioning(self.__global_area_polygon_,
                                           self.__num_partitions_)

        for sub_poly in sub_polygons:
            self.__individual_flight_plans_.append(
                FlightPlan(sub_poly, self.__scope_))
Ejemplo n.º 13
0
 def _set_time_zone(self):
     """
     TODO(retr0h): How to set the time zone.  Cannot find API docs on how
     to do this.  The current timezone can be obtained via:
       ``self._pc.System.SystemInfo.get_time_zone().time_zone``
     """
     system_info = self._pc.System.SystemInfo
     result = system_info.get_time_zone()
     if result.time_zone == 'UTC':
         msg = '  - already has UTC time'
         utils.print_yellow(msg)
     else:
         msg = '  - need to set device to UTC time'
         utils.print_red(msg)
Ejemplo n.º 14
0
 def _set_time_zone(self):
     """
     TODO(retr0h): How to set the time zone.  Cannot find API docs on how
     to do this.  The current timezone can be obtained via:
       ``self._pc.System.SystemInfo.get_time_zone().time_zone``
     """
     system_info = self._pc.System.SystemInfo
     result = system_info.get_time_zone()
     if result.time_zone == 'UTC':
         msg = '  - already has UTC time'
         utils.print_yellow(msg)
     else:
         msg = '  - need to set device to UTC time'
         utils.print_red(msg)
Ejemplo n.º 15
0
 def _create_mysql_monitor(self):
     monitors = self._monitor.get_template_list()
     filtered = [
         monitor for monitor in monitors
         if monitor.template_name == self.MONITOR_NAME
     ]
     if filtered:
         msg = '  - mysql_monitor already exists'
         utils.print_yellow(msg)
     else:
         # TODO(retr0h): How to upload a custom monitor.  Once uploaded
         # can configure an external template.
         msg = '  - need to upload and configure mysql_monitor'
         utils.print_red(msg)
Ejemplo n.º 16
0
def remove_dir(dir: Path) -> None:
    def onerror(func: Callable[..., Any], path: Path, exe_info: Any) -> None:
        import stat

        if not os.access(path, os.W_OK):
            # Is the error an access error ?
            os.chmod(path, stat.S_IWUSR)
            func(path)
        else:
            raise Exception(f"other errors happened when removing path: {dir}")

    if path_exists(dir):
        shutil.rmtree(dir, onerror=onerror)
    else:
        print_red(f"{dir} does not exists. Skip removing it")
Ejemplo n.º 17
0
    def do_exclude(self, arg):

        if not arg:
            print "Exclusion list:"
            print self.excludes
            return

        args = arg.split(" ")

        if args[0] == "clear":
            self.excludes = []
            utils.print_blue("Exclusion list cleared.")
        elif utils.is_valid_regex(args[0]):
            self.excludes.append(args[0])
        else:
            utils.print_red("No valid exclusion regex provided.")
    def __init__(self, file_name):

        if file_name.endswith('.ascii'):
            # Read in seismogram.
            temp = np.loadtxt(file_name)
            self.t, self.data = temp[:, 0], temp[:, 1]
            self.fname = file_name
            self.directory = os.path.dirname(file_name)

            # Initialize obspy
            self.tr = obspy.Trace(data=self.data)
            self.tr.stats.delta = (self.t[1] - self.t[0])
            self.tr.stats.sampling_rate = 1 / self.tr.stats.delta
            self.tr.stats.network, self.tr.stats.station, \
                self.tr.stats.channel = \
                os.path.basename(self.fname).split('.')[:3]
            self.tr.stats.channel = self.tr.stats.channel[2]

            # Reverse X component to agree with LASIF
            if self.tr.stats.channel == 'X':
                self.data = self.data * (-1)

        elif file_name.endswith('.mseed') or file_name.endswith('.sac'):
            self.tr = obspy.read(file_name)[0]
            self.fname = file_name
            self.t = np.array([
                x * self.tr.stats.delta for x in range(0, self.tr.stats.npts)
            ])
        else:
            raise SeismogramNotFoundError(
                utils.print_red("Seismogram not "
                                "found."))
Ejemplo n.º 19
0
def check_built_config(build):
    # Only check built configs if we have specific CONFIGs requested.
    custom = False
    for config in build["kconfig"]:
        if 'CONFIG' in config:
            custom = True
    if not custom:
        return

    fetch_built_config(build)
    # Build dictionary of CONFIG_NAME: y/m/n ("is not set" translates to 'n').
    configs = dict()
    for line in open(".config"):
        line = line.strip()
        if len(line) == 0:
            continue

        name = None
        state = None
        if '=' in line:
            name, state = line.split('=', 1)
        elif line.startswith("# CONFIG_"):
            name, state = line.split(" ", 2)[1:]
            if state != "is not set":
                print_yellow("Could not parse '%s' from .config line '%s'!?" %
                             (name, line))
            state = 'n'
        elif not line.startswith("#"):
            print_yellow("Could not parse .config line '%s'!?" % (line))
        configs[name] = state

    # Compare requested configs against the loaded dictionary.
    fail = False
    for config in build["kconfig"]:
        if not 'CONFIG' in config:
            continue
        name, state = config.split('=')
        # If a config is missing from the dictionary, it is considered 'n'.
        if state != configs.get(name, 'n'):
            print_red("FAIL: %s not found in .config!" % (config))
            fail = True
        else:
            print("ok: %s=%s" % (name, state))
    if fail:
        sys.exit(1)
Ejemplo n.º 20
0
def fetch_dtb(build):
    config = os.environ["CONFIG"]
    if config != "multi_v5_defconfig" and config != "aspeed_g5_defconfig":
        return
    dtb = {
        "multi_v5_defconfig": "aspeed-bmc-opp-palmetto.dtb",
        "aspeed_g5_defconfig": "aspeed-bmc-opp-romulus.dtb",
    }[config]
    dtb_path = "dtbs/" + dtb
    url = build["download_url"] + dtb_path
    # mkdir -p
    os.makedirs(dtb_path.split("/")[0], exist_ok=True)
    print_yellow("fetching DTB from: %s" % url)
    urllib.request.urlretrieve(url, dtb_path)
    if os.path.exists:
        print_yellow("Filesize: %d" % os.path.getsize(dtb_path))
    else:
        print_red("Unable to download dtb")
        sys.exit(1)
Ejemplo n.º 21
0
    def do_classes(self, arg):
        args = arg.split(" ")
        classes = self.code_parser.get_classes()

        if not arg:
            utils.print_blue("Found %s classes" % str(len(classes)))

        if args[0] == "find":
            if len(args) == 1:
                utils.print_red("Please specify a regex to match a class name.")
            else:
                regex = args[1]
                if utils.is_valid_regex(regex):
                    pattern = re.compile(regex)
                    for clazz in classes:
                        if pattern.match(clazz["name"]) and not self.is_excluded(clazz["name"]):
                            print clazz["name"]
                else:
                    utils.print_red("Invalid regex.")
Ejemplo n.º 22
0
def run_boot(build):
    cbl_arch = get_cbl_name()
    kernel_image = cwd() + "/" + get_image_name()
    boot_qemu = [
        "./boot-utils/boot-qemu.sh", "-a", cbl_arch, "-k", kernel_image
    ]
    if cbl_arch == "s390":
        boot_qemu += ["--use-cbl-qemu"]
    # If we are running a sanitizer build, we should increase the number of
    # cores and timeout because booting is much slower
    if "CONFIG_KASAN=y" in build["kconfig"] or \
       "CONFIG_KCSAN=y" in build["kconfig"] or \
       "CONFIG_UBSAN=y" in build["kconfig"]:
        boot_qemu += ["-s", "4", "-t", "10m"]
    try:
        subprocess.run(boot_qemu, check=True)
    except subprocess.CalledProcessError as e:
        if e.returncode == 124:
            print_red("Image failed to boot")
        raise e
Ejemplo n.º 23
0
def _print_help(fcts):
    """
    Prints the master help.
    """
    utils.print_ylw(
        "\n\nWelcome to the oval office. There's no clever acronym "
        "here, I was just reading the Hunt for the Red October while writing "
        "this.\n\n")
    fct_groups = {}
    for fct_name, fct in fcts.iteritems():
        group_name = fct.group_name if hasattr(fct, "group_name") else "Misc"
        fct_groups.setdefault(group_name, {})
        fct_groups[group_name][fct_name] = fct

    for group_name in sorted(fct_groups.iterkeys()):
        utils.print_red(("{0:=>25s} Functions".format(" " + group_name)))
        current_functions = fct_groups[group_name]
        for name in sorted(current_functions.keys()):
            utils.print_cyn(name)
            utils.print_gry(_get_cmd_description(fcts[name]))
Ejemplo n.º 24
0
def compile(filename):
    arguments = [
        "lualatex", "--jobname={0}".format(filename), "--output-dir=out",
        "\"\\def\\filename{{{0}}} \\input{{./latex_template/root_singleSong.tex}}\""
        .format(filename)
    ]
    FNULL = open(os.devnull, 'w')
    errFile = open('./out/compile.log', 'w+')
    print(' '.join(arguments))
    code = subprocess.call(' '.join(arguments), shell=True, stderr=errFile)
    if code is 0:
        # compilation successful
        copyfile("./out/{0}.pdf".format(filename),
                 path.join(pdfFolderPath, filename + ".pdf"))
        utils.print_green(filename, "success")
        return 1
    else:
        utils.print_red(filename, "compilation failed!")
        printErrorLog(filename)
        return 0
Ejemplo n.º 25
0
    def enter_queue(self):
        self.sem_queue.acquire()
        for i in range(0, self.num_people):
            if random.randint(0, 2) == MALE:
                self.start_male_time.append(time.time())

                self.queue.put([MALE, self.count_person])
                self.count_person += 1
                male_enqueue_message = (
                    '|ENQUEUE|> People #{0}: A man has arrived to the queue'.
                    format(self.count_person - 1))
                print_cyan(male_enqueue_message)
                sleep(random.randint(1, 7))

            elif random.randint(0, 2) == FEMALE:
                self.start_female_time.append(time.time())

                self.queue.put([FEMALE, self.count_person])
                self.count_person += 1
                female_enqueue_message = (
                    '|ENQUEUE|> People #{0}: A woman has arrived to the queue'.
                    format(self.count_person - 1))
                print_red(female_enqueue_message)
                sleep(random.randint(1, 7))
            else:
                self.start_third_gender_time.append(time.time())

                self.queue.put([THIRD_GENDER, self.count_person])
                self.count_person += 1
                third_gender_message = (
                    '|ENQUEUE|> People #{0}: A third gender people has arrived to the queue'
                    .format(self.count_person - 1))
                print(third_gender_message)
                sleep(random.randint(1, 7))
        start_timers = {
            'start_female_time': self.start_female_time,
            'start_male_time': self.start_male_time,
            'start_third_gender_time': self.start_third_gender_time
        }
        self.queue_time.put(start_timers)
        self.sem_queue.release()
Ejemplo n.º 26
0
def sum_kernels(params, first_job, last_job):
    """
    Goes through the output solver directory, and runs the summing
    commands on the kernels that were output. Kernels will end up in the
    optimization/processed kernels directory.
    """
    forward_run_dir = params['forward_run_dir']
    event_list = params['event_list']
    optimization_dir = os.path.join(forward_run_dir, 'OPTIMIZATION')
    gradient_info_dir = os.path.join(optimization_dir, 'GRADIENT_INFO')
    file_name = os.path.join(gradient_info_dir, 'kernels_list.txt')

    # First, make sure that kernels exist in the directories.
    event_kernels = []
    for event in os.listdir(forward_run_dir):
        if event not in event_list[first_job:last_job + 1]:
            continue
        databases_mpi = os.path.join(forward_run_dir, event, 'DATABASES_MPI')
        kerns = []
        for x in os.listdir(databases_mpi):
            if 'hess' in x:
                kerns.append(x)
        if len(kerns) == 24:
            event_kernels.append(event)
        else:
            utils.print_red("Kernel not found for event: " + event)

    # Write the existing kernels_list file.
    with open(file_name, 'w') as outfile:
        for event in event_kernels:
            full_path = os.path.join(forward_run_dir, event, 'DATABASES_MPI')
            outfile.write(full_path + '\n')

    # Get path of this script and .sbatch file.
    this_script = os.path.dirname(os.path.realpath(__file__))
    sbatch_file = os.path.join(this_script, 'sbatch_scripts',
                               'job_sum_kernels.sbatch')

    # Change to the directory above this script, and submit the job.
    os.chdir(this_script)
    subprocess.Popen(['sbatch', sbatch_file, optimization_dir]).wait()
Ejemplo n.º 27
0
Archivo: all.py Proyecto: zaxs002/fanyi
def submit_to_network(current_url):
    print(current_url)
    print(configs.user.id)
    print(configs.user.worker_name)
    found_ids = re.findall(r'=(\w+)&', current_url)
    if len(found_ids) <= 0:
        found_ids = re.findall(r'=(\w+)', current_url)
    if len(found_ids) <= 0:
        print_red('检查URL里是否有ID 不要乱搞啊兄弟')
        return
    work_id = found_ids[0]
    secondid, rework_num = get_secondid_and_rework_num(work_id)
    u = 'http://{}:{}/'.format(configs.server.address, configs.server.port)
    c = requests.post(u,
                      data={
                          'work_id': work_id,
                          'second_id': secondid,
                          'rework_num': rework_num,
                          'account_id': configs.user.id,
                          'worker': configs.user.worker_name
                      })
Ejemplo n.º 28
0
    def send_draft(self, message_id, bypass=False):
        utils.print_magenta('Send draft')
        draft = self.client.drafts.find(message_id)
        utils.print_pretty(draft)

        if bypass:
            message = draft.send()
            self.handle.set_message_status(message_id, 1)
            self.handle.set_message_thread(message_id, message['thread_id'])
            print(' ')
            utils.print_red('MESSAGE SENT')
            utils.print_magenta('thread id: ' + message['thread_id'])
            print(' ')
            return message['thread_id']

        send = input("Send draft? (y/n) ")

        if send == 'y' or send == 'Y':
            message = draft.send()
            self.handle.set_message_status(message_id, 1)
            self.handle.set_message_thread(message_id, message['thread_id'])
            print(' ')
            utils.print_red('MESSAGE SENT')
            utils.print_magenta('thread id: ' + message['thread_id'])
            print(' ')
        else:
            utils.print_red('Draft not sent.')
Ejemplo n.º 29
0
    def train(self, data_dir, word_tokens, pristine_input, pristine_output,
              batch_size, seq_length, seq_step, embedding_size, rnn_size,
              num_layers, num_epochs, live_sample):
        """Train the model"""
        print_green('Loading data...')
        load_start = time.time()
        x, y, x_val, y_val = self._load_data(data_dir, word_tokens,
                                             pristine_input, pristine_output,
                                             batch_size, seq_length, seq_step)
        load_end = time.time()
        print_red('Data load time', load_end - load_start)

        print_green('Building model...')
        model_start = time.time()
        self._build_models(batch_size, embedding_size, rnn_size, num_layers)
        model_end = time.time()
        print_red('Model build time', model_end - model_start)

        print_green('Training...')
        train_start = time.time()
        validation_data = (x_val, y_val) if (x_val is not None) else None
        callbacks = [LiveSamplerCallback(self)] if live_sample else None
        self.train_model.fit(x,
                             y,
                             validation_data=validation_data,
                             batch_size=batch_size,
                             shuffle=False,
                             epochs=num_epochs,
                             verbose=1,
                             callbacks=callbacks)
        self.update_sample_model_weights()
        train_end = time.time()
        print_red('Training time', train_end - train_start)
Ejemplo n.º 30
0
 def notifyNewPolygon(self):
     print("Reading new polygon file")
     self.__global_area_polygon_ = None
     
     self.__global_area_polygon_ = parsePolygonFile(self._global_area_path)
     self.__global_area_vertices_ = [tuple(e) for e in
                                     self.__global_area_polygon_.vertices]
     
     xmax, xmin, ymax, ymin = 0, float('inf'), 0, float('inf')
     for x,y in self.__global_area_vertices_:
         if x > xmax:
             xmax = x
         if x < xmin:
             xmin = x
         if y > ymax:
             ymax = y
         if y < ymin:
             ymin = y
     longueur = xmax-xmin
     largeur = ymax - ymin
     self.__scope_ = calcul_scope(longueur=longueur, largeur=largeur, alpha=gs.ALPHA)
     print_red("Setting scope to %d" % self.__scope_)
Ejemplo n.º 31
0
    def _load_data(self, data_dir, word_tokens, pristine_input,
                   pristine_output, batch_size, seq_length, seq_step):
        try:
            with open(os.path.join(data_dir, 'input.txt'),
                      encoding='utf-8') as input_file:
                text = input_file.read()
        except FileNotFoundError:
            print_red("No input.txt in data_dir")
            sys.exit(1)

        skip_validate = True
        try:
            with open(os.path.join(data_dir, 'validate.txt')) as validate_file:
                text_val = validate_file.read()
                skip_validate = False
        except FileNotFoundError:
            pass  # Validation text optional

        # Find some good default seed string in our source text.
        self.seeds = find_random_seeds(text)
        # Include our validation texts with our vectorizer
        all_text = text if skip_validate else '\n'.join([text, text_val])
        self.vectorizer = Vectorizer(all_text, word_tokens, pristine_input,
                                     pristine_output)

        data = self.vectorizer.vectorize(text)
        x, y = shape_for_stateful_rnn(data, batch_size, seq_length, seq_step)
        print('x.shape:', x.shape)
        print('y.shape:', y.shape)

        if skip_validate:
            return x, y, None, None

        data_val = self.vectorizer.vectorize(text_val)
        x_val, y_val = shape_for_stateful_rnn(data_val, batch_size, seq_length,
                                              seq_step)
        print('x_val.shape:', x_val.shape)
        print('y_val.shape:', y_val.shape)
        return x, y, x_val, y_val
Ejemplo n.º 32
0
def setup_cli(args: Namespace, command_args: dict) -> None:
    extension_path = Path("azure-cli-extensions")

    print_red("- Installing azure-cli")
    run_command(["pip", "install", "azure-cli"], **command_args)

    print_red("- Cloning azure-cli-extensions into repository")
    remove_dir(extension_path)
    run_command(["git", "clone", "https://github.com/Azure/azure-cli-extensions", "--depth", "1"], **command_args)
    cli_folder = Path("./src/cli")

    print_red("- Building cli extensions")

    extra = ["--debug"] if args.debug else []
    run_command(
        [
            "autorest",
            "--az",
            "--use=@autorest/az@latest",
            "--version=3.0.6271",
            "--clear-output-folder=true",
            f"--azure-cli-extension-folder={cli_folder.absolute()}",
            str(Path("./autorest/readme.md").absolute()),
            "--title=Azure Machine Learning Workspaces",
            "--modelerfour.lenient-model-deduplication",
        ]
        + extra,
        **command_args,
    )
    cli_src = cli_folder / "src"

    if not args.no_install:
        print_red("- Installing cli extension from source code")
        run_command(["pip", "install", "-e", f'{(cli_src / "machinelearningservices").absolute()}'], **command_args)
        print_red("---------------------------- TO DO For YOU!! -----------------------------------")
        print(f"Please set the environment variable AZURE_EXTENSION_DIR to {cli_src.absolute()}")
        print(f'In Powershell, you can set in this way: $Env:AZURE_EXTENSION_DIR="{cli_src.absolute()}"')
        print(f"In bash, you can set in this way: export AZURE_EXTENSION_DIR={cli_src.absolute()}")
    def work(self):
        lat = self.fort["latitude"]
        lng = self.fort["longitude"]
        unit = self.config.distance_unit  # Unit to use when printing formatted distance

        fortID = self.fort["id"]
        dist = distance(self.position[0], self.position[1], lat, lng)

        logger.log("[#] Found fort {} at distance {}".format(fortID, format_dist(dist, unit)))

        if dist > 0:
            logger.log("[#] Need to move closer to Pokestop")
            position = (lat, lng, 0.0)

            if self.config.walk > 0:
                self.stepper.walk_to(self.config.walk, *position)
            else:
                self.api.set_position(*position)
            self.api.player_update(latitude=lat, longitude=lng)
            logger.log("[#] Arrived at Pokestop")
            sleep(2)

        self.api.fort_details(fort_id=self.fort["id"],
                              latitude=lat,
                              longitude=lng)
        response_dict = self.api.call()
        fort_details = response_dict.get("responses", {}).get("FORT_DETAILS", {})
        fort_name = fort_details.get("name").encode("utf8", "replace")
        fort_name = fort_name if fort_name is not None else "Unknown"
        logger.log("[#] Now at Pokestop: " + fort_name + " - Spinning...",
                   "yellow")
        sleep(3)
        self.api.fort_search(fort_id=self.fort["id"],
                             fort_latitude=lat,
                             fort_longitude=lng,
                             player_latitude=f2i(self.position[0]),
                             player_longitude=f2i(self.position[1]))
        response_dict = self.api.call()
        spin_details = response_dict.get("responses", {}).get("FORT_SEARCH", {})
        spin_result = spin_details.get("result")
        if spin_result == 1:
            logger.log("[+] Loot: ", "green")
            experience_awarded = spin_details.get("experience_awarded",
                                                  False)
            if experience_awarded:
                logger.log("[+] " + str(experience_awarded) + " xp",
                           "green")

            items_awarded = spin_details.get("items_awarded", False)
            if items_awarded:
                tmp_count_items = {}
                for item in items_awarded:
                    item_id = item["item_id"]
                    if item_id not in tmp_count_items:
                        tmp_count_items[item_id] = item["item_count"]
                    else:
                        tmp_count_items[item_id] += item["item_count"]

                for item_id, item_count in tmp_count_items.iteritems():
                    item_id = str(item_id)
                    item_name = self.item_list[item_id]

                    logger.log("[+] " + str(item_count) + "x " + item_name,
                               "green")

            else:
                logger.log("[#] Nothing found.", "yellow")

            pokestop_cooldown = spin_details.get(
                "cooldown_complete_timestamp_ms")
            if pokestop_cooldown:
                seconds_since_epoch = time.time()
                logger.log("[#] PokeStop on cooldown. Time left: " + str(
                    format_time((pokestop_cooldown / 1000) -
                                seconds_since_epoch)))

            if not items_awarded and not experience_awarded and not pokestop_cooldown:
                message = (
                    "Stopped at Pokestop and did not find experience, items "
                    "or information about the stop cooldown. You are "
                    "probably softbanned. Try to play on your phone, "
                    "if pokemons always ran away and you find nothing in "
                    "PokeStops you are indeed softbanned. Please try again "
                    "in a few hours.")
                raise RuntimeError(message)
        elif spin_result == 2:
            logger.log("[#] Pokestop out of range")
        elif spin_result == 3:
            pokestop_cooldown = spin_details.get(
                "cooldown_complete_timestamp_ms")
            if pokestop_cooldown:
                seconds_since_epoch = time.time()
                logger.log("[#] PokeStop on cooldown. Time left: " + str(
                    format_time((pokestop_cooldown / 1000) -
                                seconds_since_epoch)))
        elif spin_result == 4:
            print_red("[#] Inventory is full, switching to catch mode...")
            self.config.mode = "poke"

        if "chain_hack_sequence_number" in fort_details:
            time.sleep(2)
            return fort_details[
                "chain_hack_sequence_number"]
        else:
            print_yellow("[#] may search too often, lets have a rest")
            return 11
        sleep(10)
        return 0
Ejemplo n.º 34
0
    def work(self):
        lat = self.fort['latitude']
        lng = self.fort['longitude']
        unit = self.config.distance_unit  # Unit to use when printing formatted distance

        fortID = self.fort['id']
        dist = distance(self.position[0], self.position[1], lat, lng)

        # print('[#] Found fort {} at distance {}m'.format(fortID, dist))
        logger.log('[#] Found fort {} at distance {}'.format(
            fortID, format_dist(dist, unit)))

        if dist > 10:
            logger.log('[#] Need to move closer to Pokestop')
            position = (lat, lng, 0.0)

            if self.config.walk > 0:
                self.stepper._walk_to(self.config.walk, *position)
            else:
                self.api.set_position(*position)
            self.api.player_update(latitude=lat, longitude=lng)
            response_dict = self.api.call()
            logger.log('[#] Arrived at Pokestop')
            sleep(2)

        self.api.fort_details(fort_id=self.fort['id'],
                              latitude=lat,
                              longitude=lng)
        response_dict = self.api.call()
        if 'responses' in response_dict \
                and'FORT_DETAILS' in response_dict['responses'] \
                and 'name' in response_dict['responses']['FORT_DETAILS']:
            fort_details = response_dict['responses']['FORT_DETAILS']
            fort_name = fort_details['name'].encode('utf8', 'replace')
        else:
            fort_name = 'Unknown'
        logger.log('[#] Now at Pokestop: ' + fort_name + ' - Spinning...',
                   'yellow')
        sleep(2)
        self.api.fort_search(fort_id=self.fort['id'],
                             fort_latitude=lat,
                             fort_longitude=lng,
                             player_latitude=f2i(self.position[0]),
                             player_longitude=f2i(self.position[1]))
        response_dict = self.api.call()
        if 'responses' in response_dict and \
                'FORT_SEARCH' in response_dict['responses']:

            spin_details = response_dict['responses']['FORT_SEARCH']
            if spin_details['result'] == 1:
                logger.log("[+] Loot: ", 'green')
                experience_awarded = spin_details.get('experience_awarded',
                                                      False)
                if experience_awarded:
                    logger.log("[+] " + str(experience_awarded) + " xp",
                               'green')

                items_awarded = spin_details.get('items_awarded', False)
                if items_awarded:
                    tmp_count_items = {}
                    for item in items_awarded:
                        item_id = item['item_id']
                        if not item_id in tmp_count_items:
                            tmp_count_items[item_id] = item['item_count']
                        else:
                            tmp_count_items[item_id] += item['item_count']

                    for item_id, item_count in tmp_count_items.iteritems():
                        item_id = str(item_id)
                        item_name = self.item_list[item_id]

                        logger.log("[+] " + str(item_count) + "x " + item_name,
                                   'green')

                else:
                    logger.log("[#] Nothing found.", 'yellow')

                pokestop_cooldown = spin_details.get(
                    'cooldown_complete_timestamp_ms')
                if pokestop_cooldown:
                    seconds_since_epoch = time.time()
                    logger.log('[#] PokeStop on cooldown. Time left: ' + str(
                        format_time((pokestop_cooldown / 1000) -
                                    seconds_since_epoch)))

                if not items_awarded and not experience_awarded and not pokestop_cooldown:
                    message = (
                        'Stopped at Pokestop and did not find experience, items '
                        'or information about the stop cooldown. You are '
                        'probably softbanned. Try to play on your phone, '
                        'if pokemons always ran away and you find nothing in '
                        'PokeStops you are indeed softbanned. Please try again '
                        'in a few hours.')
                    raise RuntimeError(message)
            elif spin_details['result'] == 2:
                logger.log("[#] Pokestop out of range")
            elif spin_details['result'] == 3:
                pokestop_cooldown = spin_details.get(
                    'cooldown_complete_timestamp_ms')
                if pokestop_cooldown:
                    seconds_since_epoch = time.time()
                    logger.log('[#] PokeStop on cooldown. Time left: ' + str(
                        format_time((pokestop_cooldown / 1000) -
                                    seconds_since_epoch)))
            elif spin_details['result'] == 4:
                print_red("[#] Inventory is full, switching to catch mode...")
                self.config.mode = 'poke'

            if 'chain_hack_sequence_number' in response_dict['responses'][
                    'FORT_SEARCH']:
                time.sleep(2)
                return response_dict['responses']['FORT_SEARCH'][
                    'chain_hack_sequence_number']
            else:
                print_yellow('[#] may search too often, lets have a rest')
                return 11
        sleep(8)
        return 0
Ejemplo n.º 35
0
    def work(self):
        lat = self.fort['latitude']
        lng = self.fort['longitude']

        self.api.fort_details(fort_id=self.fort['id'],
                              latitude=lat,
                              longitude=lng)
        response_dict = self.api.call()
        if 'responses' in response_dict \
                and'FORT_DETAILS' in response_dict['responses'] \
                and 'name' in response_dict['responses']['FORT_DETAILS']:
            fort_details = response_dict['responses']['FORT_DETAILS']
            fort_name = fort_details['name'].encode('utf8', 'replace')
        else:
            fort_name = 'Unknown'
        logger.log('[#] Now at Pokestop: ' + fort_name + ' - Spinning...',
                   'yellow')
        sleep(2)
        self.api.fort_search(fort_id=self.fort['id'],
                             fort_latitude=lat,
                             fort_longitude=lng,
                             player_latitude=f2i(self.position[0]),
                             player_longitude=f2i(self.position[1]))
        response_dict = self.api.call()
        if 'responses' in response_dict and \
                'FORT_SEARCH' in response_dict['responses']:

            spin_details = response_dict['responses']['FORT_SEARCH']
            if spin_details['result'] == 1:
                logger.log("[+] Loot: ", 'green')
                experience_awarded = spin_details.get('experience_awarded',
                                                      False)
                if experience_awarded:
                    logger.log("[+] " + str(experience_awarded) + " xp",
                               'green')

                items_awarded = spin_details.get('items_awarded', False)
                if items_awarded:
                    tmp_count_items = {}
                    for item in items_awarded:
                        item_id = item['item_id']
                        if not item_id in tmp_count_items:
                            tmp_count_items[item_id] = item['item_count']
                        else:
                            tmp_count_items[item_id] += item['item_count']

                    for item_id, item_count in tmp_count_items.iteritems():
                        item_name = self.item_list[str(item_id)]

                        logger.log("[+] " + str(item_count) +
                                    "x " + item_name +
                                    " (Total: " + str(self.bot.item_inventory_count(item_id)) + ")", 'green')

                        # RECYCLING UNWANTED ITEMS
                        if str(item_id) in self.config.item_filter:
                            logger.log("[+] Recycling " + str(item_count) + "x " + item_name + "...", 'green')
                            #RECYCLE_INVENTORY_ITEM
                            response_dict_recycle = self.bot.drop_item(item_id=item_id, count=item_count)

                            if response_dict_recycle and \
                                'responses' in response_dict_recycle and \
                                'RECYCLE_INVENTORY_ITEM' in response_dict_recycle['responses'] and \
                                    'result' in response_dict_recycle['responses']['RECYCLE_INVENTORY_ITEM']:
                                result = response_dict_recycle['responses']['RECYCLE_INVENTORY_ITEM']['result']
                            if result is 1: # Request success
                                logger.log("[+] Recycling success", 'green')
                            else:
                                logger.log("[+] Recycling failed!", 'red')
                else:
                    logger.log("[#] Nothing found.", 'yellow')

                pokestop_cooldown = spin_details.get(
                    'cooldown_complete_timestamp_ms')
                if pokestop_cooldown:
                    seconds_since_epoch = time.time()
                    logger.log('[#] PokeStop on cooldown. Time left: ' + str(
                        format_time((pokestop_cooldown / 1000) -
                                    seconds_since_epoch)))

                if not items_awarded and not experience_awarded and not pokestop_cooldown:
                    message = (
                        'Stopped at Pokestop and did not find experience, items '
                        'or information about the stop cooldown. You are '
                        'probably softbanned. Try to play on your phone, '
                        'if pokemons always ran away and you find nothing in '
                        'PokeStops you are indeed softbanned. Please try again '
                        'in a few hours.')
                    raise RuntimeError(message)
            elif spin_details['result'] == 2:
                logger.log("[#] Pokestop out of range")
            elif spin_details['result'] == 3:
                pokestop_cooldown = spin_details.get(
                    'cooldown_complete_timestamp_ms')
                if pokestop_cooldown:
                    seconds_since_epoch = time.time()
                    logger.log('[#] PokeStop on cooldown. Time left: ' + str(
                        format_time((pokestop_cooldown / 1000) -
                                    seconds_since_epoch)))
            elif spin_details['result'] == 4:
                print_red("[#] Inventory is full, switching to catch mode...")
                self.config.mode = 'poke'

            if 'chain_hack_sequence_number' in response_dict['responses'][
                    'FORT_SEARCH']:
                time.sleep(2)
                return response_dict['responses']['FORT_SEARCH'][
                    'chain_hack_sequence_number']
            else:
                print_yellow('[#] may search too often, lets have a rest')
                return 11
        sleep(8)
        return 0
Ejemplo n.º 36
0
    def work(self):
        lat = self.fort['latitude']
        lng = self.fort['longitude']

        self.api.fort_details(fort_id=self.fort['id'],
                              latitude=lat,
                              longitude=lng)
        response_dict = self.api.call()
        if 'responses' in response_dict \
                and'FORT_DETAILS' in response_dict['responses'] \
                and 'name' in response_dict['responses']['FORT_DETAILS']:
            fort_details = response_dict['responses']['FORT_DETAILS']
            fort_name = fort_details['name'].encode('utf8', 'replace')
        else:
            fort_name = 'Unknown'
        logger.log('[#]  Sekarang berada di  Pokestop: ' + fort_name + ' - Memutar...',
                   'yellow')
        sleep(2)
        self.api.fort_search(fort_id=self.fort['id'],
                             fort_latitude=lat,
                             fort_longitude=lng,
                             player_latitude=f2i(self.position[0]),
                             player_longitude=f2i(self.position[1]))
        response_dict = self.api.call()
        if 'responses' in response_dict and \
                'FORT_SEARCH' in response_dict['responses']:

            spin_details = response_dict['responses']['FORT_SEARCH']
            if spin_details['result'] == 1:
                logger.log("[+] Loot: ", 'green')
                experience_awarded = spin_details.get('experience_awarded',
                                                      False)
                if experience_awarded:
                    logger.log("[+] " + str(experience_awarded) + " xp",
                               'green')

                items_awarded = spin_details.get('items_awarded', False)
                if items_awarded:
                    self.config.mode = 'all'
                    tmp_count_items = {}
                    for item in items_awarded:
                        item_id = item['item_id']
                        if not item_id in tmp_count_items:
                            tmp_count_items[item_id] = item['item_count']
                        else:
                            tmp_count_items[item_id] += item['item_count']

                    for item_id, item_count in tmp_count_items.iteritems():
                        item_name = self.item_list[str(item_id)]

                        logger.log("[+] " + str(item_count) +
                                    "x " + item_name +
                                    " (Total: " + str(self.bot.item_inventory_count(item_id)) + ")", 'green')
                        
                        # RECYCLING UNWANTED ITEMS
                        if str(item_id) in self.config.item_filter:
                            logger.log("[+] Recycling " + str(item_count) + "x " + item_name + "...", 'green')
                            #RECYCLE_INVENTORY_ITEM
                            response_dict_recycle = self.bot.drop_item(item_id=item_id, count=item_count)

                            if response_dict_recycle and \
                                'responses' in response_dict_recycle and \
                                'RECYCLE_INVENTORY_ITEM' in response_dict_recycle['responses'] and \
                                    'result' in response_dict_recycle['responses']['RECYCLE_INVENTORY_ITEM']:
                                result = response_dict_recycle['responses']['RECYCLE_INVENTORY_ITEM']['result']
                            if result is 1: # Request success
                                logger.log("[+] Recycling success", 'green')
                            else:
                                logger.log("[+] Recycling gagal!", 'red')
                else:
                    logger.log("[#] Nothing found.", 'yellow')

                pokestop_cooldown = spin_details.get(
                    'cooldown_complete_timestamp_ms')
                if pokestop_cooldown:
                    seconds_since_epoch = time.time()
                    logger.log('[#] PokeStop on cooldown. Time left: ' + str(
                        format_time((pokestop_cooldown / 1000) -
                                    seconds_since_epoch)))

                if not items_awarded and not experience_awarded and not pokestop_cooldown:
                        print_red('Masih kena softbanned')
                        self.config.mode = 'farm'
            elif spin_details['result'] == 2:
                logger.log("[#] Pokestop out of range")
            elif spin_details['result'] == 3:
                pokestop_cooldown = spin_details.get(
                    'cooldown_complete_timestamp_ms')
                if pokestop_cooldown:
                    seconds_since_epoch = time.time()
                    logger.log('[#] PokeStop  cooldown. Time left: ' + str(
                        format_time((pokestop_cooldown / 1000) -
                                    seconds_since_epoch)))
            elif spin_details['result'] == 4:
                print_red("[#] Inventory penuh, ke mode berburu...")
                self.config.mode = 'poke'

            if 'chain_hack_sequence_number' in response_dict['responses'][
                    'FORT_SEARCH']:
                time.sleep(2)
                return response_dict['responses']['FORT_SEARCH'][
                    'chain_hack_sequence_number']
            else:
                print_yellow('[#] Leren seek...')
                return 11
        sleep(8)
        return 0