Пример #1
0
def extract_countries():
  input_path = get_shape_path("ne_50m_admin_0_countries")
  output_path = path.join(OUT_DIR, "countries.json")

  props_to_keep = frozenset(["name"])

  features = []
  with fiona.open(input_path) as source:
    for feat in source:
      geometry = feat["geometry"]

      # convert country polygon to point
      geometry.update(mapping(shape(geometry).representative_point()))

      props = lower_dict_keys(feat["properties"])
      for k in frozenset(props) - props_to_keep:
        del props[k]

      feat["properties"] = props
      features.append(feat)

  my_layer = {
    "type": "FeatureCollection",
    "features": features
  }

  with open(output_path, "w") as f:
    f.write(json.dumps(my_layer))

  print c.green("Extracted data to {}".format(output_path))
Пример #2
0
def extract_cities():
  input_path = get_shape_path("ne_50m_populated_places")
  output_path = path.join(OUT_DIR, "cities.json")

  props_to_keep = frozenset(["scalerank", "name", "latitude", "longitude"])

  features = []
  with fiona.collection(input_path, "r") as source:
    for feat in source:
      props = lower_dict_keys(feat["properties"])

      if props["pop_max"] >= POPULATION_MAX_FILTER:
        for k in frozenset(props) - props_to_keep:
          del props[k]

        feat["properties"] = props
        features.append(feat)

  my_layer = {
    "type": "FeatureCollection",
    "features": features
  }

  with open(output_path, "w") as f:
    f.write(json.dumps(my_layer))

  print c.green("Extracted data to {}".format(output_path))
Пример #3
0
def first_run_tui():
    '''
    first setups and creating key's and personal passwords
    '''
    import os
    if (platform.system() == "Darwin"):
        pass
    if (platform.system() == "Windows"):
        os.system("pip install -r requirements.txt")
        # pass
    if (platform.system() == "Linux"):
        pass
    from cryptography.fernet import Fernet

    cryptocut_art = text2art("cRYPTOcUT", "confused3")
    setup_art = text2art("setup")
    print('\n', cf.green(cryptocut_art))
    print(cf.cyan(setup_art))
    user_pass = input(
        cf.yellow("enter your password for symmetric encryption : "))
    user_key = (create_user_key(user_pass))
    # generate a random secret for user using crypto lib
    fernet = Fernet(user_key)
    random_key = Fernet.generate_key()
    symmetric_key = fernet.encrypt(random_key)
    # write the random secret as symmetric_key in symmetric.key
    # TODO : we can use a diffrent path for this
    with open("symmetric.key", "wb") as key_file:
        key_file.write(symmetric_key)
    print(cf.green("done! \nsuccessfully initialized the symmetric key"))
Пример #4
0
def extract_countries_po():
    input_path = get_shape_path("ne_50m_admin_0_countries")

    for locale in os.listdir(LOCALE_DIR):
        locale_dir = path.join(LOCALE_DIR, locale)
        locale_out_dir = path.join(LOCALE_OUT_DIR, locale)

        if os.path.isdir(locale_dir):
            with fiona.open(input_path) as source:
                po = POFile(encoding='UTF-8')
                po.metadata = {"Content-Type": "text/plain; charset=utf-8"}
                output_path = path.join(locale_out_dir, "countries.po")

                if not path.exists(locale_out_dir):
                    os.makedirs(locale_out_dir)

                print "Generating {}/countries.po".format(locale)

                for feat in source:
                    props = lower_dict_keys(feat["properties"])

                    name_key = "name_" + map_locale(locale)
                    name_fallback = "name"

                    country_name = props.get("name")
                    formal_country_name = props.get("formal_en", country_name)

                    if props.get(name_key) is not None:
                        translated_name = props.get(name_key)
                    elif props.get(name_fallback) is not None:
                        translated_name = props.get(name_fallback)
                        print c.orange(u" Missing translation for {}".format(
                            translated_name))
                    else:
                        raise ValueError(
                            "Cannot find the translation for {}. Probe keys: {}"
                            .format(locale, (name_key, name_fallback)))

                    entry = POEntry(msgid=country_name, msgstr=translated_name)
                    po.append(entry)

                    # add additional record for the formal country name.
                    if country_name != formal_country_name and formal_country_name is not None:
                        entry = POEntry(msgid=formal_country_name,
                                        msgstr=translated_name)
                        po.append(entry)

                    # exception for the US
                    if props.get("iso_a3") == "USA":
                        entry = POEntry(msgid="USA", msgstr=translated_name)
                        po.append(entry)

                    # exception for the UK
                    if props.get("iso_a3") == "GBR":
                        entry = POEntry(msgid="UK", msgstr=translated_name)
                        po.append(entry)

                po.save(output_path)
                print c.green("Extracted {} countries for {} to {}".format(
                    len(po), locale, output_path))
Пример #5
0
def app_delete(drucker):
    """Deletes an arbitrary docroot"""
    param_check(drucker)

    if os.path.isdir("%s/%s" % (drucker.vars.CONTAINER_HTML_PATH, drucker.app)):
        if click.confirm(
            "Should we delete the existing codebase, files and database?", default=True
        ):
            print(colorful.white_on_blue("Deleting %s docroot..." % (drucker.app)))
            subprocess.run(
                """ansible-playbook -i %s/orchestration/hosts\
                              --user=%s %s/orchestration/commands/app-delete.yml\
                              --extra-vars "ansible_sudo_pass=%s app=delete sitename=%s"
                           """
                % (
                    drucker.vars.APP_DIR,
                    drucker.vars.APP,
                    drucker.vars.APP_DIR,
                    drucker.vars.APP,
                    drucker.app,
                ),
                shell=True,
            )
            print(
                colorful.green(
                    "Remember to remove the %s.local entry from your local /etc/hosts file!"
                    % (drucker.app)
                )
            )
        else:
            print(colorful.green("Back to the comfort zone. Aborting..."))
Пример #6
0
def extract_geometry():
  input_path = get_shape_path("ne_50m_admin_0_countries")
  output_path = path.join(OUT_DIR, "geometry.json")

  features = []
  with fiona.open(input_path) as source:
    for feat in source:
      del feat["properties"]
      geometry = feat["geometry"]
      feat["bbox"] = shape(geometry).bounds
      features.append(feat)

  my_layer = {
    "type": "FeatureCollection",
    "features": features
  }

  p = Popen(
    ['geo2topo', '-q', '1e5', 'geometry=-', '-o', output_path],
    stdin=PIPE, stdout=PIPE, stderr=PIPE
  )
  errors = p.communicate(input=json.dumps(my_layer))[1]
  if p.returncode == 0:
    print c.green("Extracted data to {}".format(output_path))
  else:
    print c.red("geo2topo exited with {}. {}".format(p.returncode, errors.decode('utf-8').strip()))
Пример #7
0
def provision_db_container(drucker):
    """Provision database container"""
    if subprocess.getoutput("docker ps -a | grep -o %s" % (drucker.vars.DB_CONTAINER)):
        print(
            colorful.green("%s container already exists." % (drucker.vars.DB_CONTAINER))
        )

        if subprocess.getoutput("docker ps | grep -o %s" % (drucker.vars.DB_CONTAINER)):
            o.run_db_orchestration(drucker)
        else:
            print(
                colorful.white_on_blue(
                    "Starting %s container..." % (drucker.vars.DB_CONTAINER)
                )
            )
            start_db_container(drucker)
            o.run_db_orchestration(drucker)
    else:
        if subprocess.getoutput(
            "docker images | awk '{print $1\":\"$2}' | grep %s"
            % (drucker.vars.DB_IMAGE)
        ):
            print(
                colorful.green(
                    "%s custom image already exists." % (drucker.vars.DB_IMAGE)
                )
            )
            create_db_container(drucker)
        else:
            create_base2db_container(drucker)
            create_db_image(drucker)
Пример #8
0
 def fetch_products(self):
     """Request the products in respect for the categories loaded"""
     print("API connexion and data transfer  - Please wait... \n"
           "It should takes less than a minute \n \n")
     all_products = {}
     for category in tqdm(self.list_cat, total=len(self.list_cat)):
         config = {
             "action": "process",
             # Get the result by category
             "tagtype_0": "categories",
             # the tag represents the article search
             'tag_0': category,
             "tag_contains_0": "contains",
             # Number of articles per page
             # Min content 20, Max content 1000
             "page_size": constant.PRODUCT_NUMBER,
             # The API response in JSON
             "json": 1
         }
         response = self.req(self.search_url, param=config)
         data = response.json()
         all_products[category] = data
     print(cf.green("\n Raw data is now downloaded successfully"))
     print("Now saving...")
     self.prod_to_json(all_products)
     print(cf.green("Success !"))
Пример #9
0
def extract_cities_po():
    input_path = get_shape_path("ne_50m_populated_places")
    stats = []

    for locale in os.listdir(LOCALE_DIR):
        locale_dir = path.join(LOCALE_DIR, locale)
        locale_out_dir = path.join(LOCALE_OUT_DIR, locale)

        if os.path.isdir(locale_dir):
            po = POFile(encoding='UTF-8')
            po.metadata = {"Content-Type": "text/plain; charset=utf-8"}
            output_path = path.join(locale_out_dir, "cities.po")
            hits = 0
            misses = 0

            if not path.exists(locale_out_dir):
                os.makedirs(locale_out_dir)

            print "Generating {}/cities.po".format(locale)

            with fiona.open(input_path) as source:
                for feat in source:
                    props = lower_dict_keys(feat["properties"])

                    if props["pop_max"] >= POPULATION_MAX_FILTER:
                        name_key = "_".join(
                            ("name", get_locale_language(locale)))
                        name_alt_key = "_".join(
                            ("name", convert_locale_ident(locale)))
                        name_fallback = "name"

                        if props.get(name_key) is not None:
                            translated_name = props.get(name_key)
                            hits += 1
                        elif props.get(name_alt_key) is not None:
                            translated_name = props.get(name_alt_key)
                            hits += 1
                        elif props.get(name_fallback) is not None:
                            translated_name = props.get(name_fallback)
                            print c.orange(
                                u"  Missing translation for {}".format(
                                    translated_name))
                            misses += 1
                        else:
                            raise ValueError(
                                "Cannot find the translation for {}. Probe keys: {}"
                                .format(locale, (name_key, name_alt_key)))

                        entry = POEntry(msgid=props["name"],
                                        msgstr=translated_name)
                        po.append(entry)

            po.save(output_path)
            print c.green("Extracted {} cities to {}".format(
                len(po), output_path))

            stats.append((locale, hits, misses))

    print_stats_table("Cities translations", stats)
Пример #10
0
class MyInteractive(cmd.Cmd):
    intro = colorful.green('Welcome come to my world!') + colorful.red(
        "Now,Let's start") + '\n' + '''
       fa              fafafa              fafafa
     fa  fa          fa                  fa
    fafafafa        fa                  fa    fafa
   fa      fa        fa                  fa     fa
  fa        fa         fafafa              fafafaf
''' + '\n' + colorful.green('''you could use
-help (get help)
-quit  (exit program)
-search  (migu video search)
-mgvideo (migu video channel)
''')
    prompt = colorful.red('bf>')
    file = None

    @docopt_cmd
    def do_mgvideo(self, arg):
        """Usage: mgvideo"""
        video_channel = mgvideo.Miguvideo()
        video_channel.run()

    @docopt_cmd
    def do_search(self, arg):
        """Usage: search

Options:
    --search=<n>
        """
        new = search.migu_go()
        new.run()

    @docopt_cmd
    def do_serial(self, arg):
        """Usage: serial <port> [--baud=<n>] [--timeout=<seconds>]

Options:
    --baud=<n>  Baudrate [default: 9600]
        """

        print(arg)

    @docopt_cmd
    def do_wait(self, arg):
        """Usage: wait <port> [--baud=<n>] [--timeout=<seconds>]

Options:
    --baud=<n>  Baudrate [default: 9600]
        """
        print(arg)

    def do_quit(self, arg):
        """Quits out of Interactive Mode."""

        print('Good Bye!')
        exit()
Пример #11
0
def prepare_stats_table_column(item):
  (locale, hits, misses) = item
  total = hits + misses
  hits_ratio = round(float(hits) / total * 100, 2) if total > 0 else 0

  misses_column = c.orange(str(misses)) if misses > 0 else c.green(str(misses))
  hits_column = c.green(str(hits))
  ratio_column = c.green(str(hits_ratio) + "%") if hits_ratio >= 80 else c.orange(str(hits_ratio))
  total_column = str(total)

  return (locale, hits_column, misses_column, ratio_column, total_column)
Пример #12
0
def show():
    """
    Show the modifiers and colors
    """
    # modifiers
    sys.stdout.write(colorful.bold('bold') + ' ')
    sys.stdout.write(colorful.dimmed('dimmed') + ' ')
    sys.stdout.write(colorful.italic('italic') + ' ')
    sys.stdout.write(colorful.underlined('underlined') + ' ')
    sys.stdout.write(colorful.inversed('inversed') + ' ')
    sys.stdout.write(colorful.concealed('concealed') + ' ')
    sys.stdout.write(colorful.struckthrough('struckthrough') + '\n')

    # foreground colors
    sys.stdout.write(colorful.red('red') + ' ')
    sys.stdout.write(colorful.green('green') + ' ')
    sys.stdout.write(colorful.yellow('yellow') + ' ')
    sys.stdout.write(colorful.blue('blue') + ' ')
    sys.stdout.write(colorful.magenta('magenta') + ' ')
    sys.stdout.write(colorful.cyan('cyan') + ' ')
    sys.stdout.write(colorful.white('white') + '\n')

    # background colors
    sys.stdout.write(colorful.on_red('red') + ' ')
    sys.stdout.write(colorful.on_green('green') + ' ')
    sys.stdout.write(colorful.on_yellow('yellow') + ' ')
    sys.stdout.write(colorful.on_blue('blue') + ' ')
    sys.stdout.write(colorful.on_magenta('magenta') + ' ')
    sys.stdout.write(colorful.on_cyan('cyan') + ' ')
    sys.stdout.write(colorful.on_white('white') + '\n')
Пример #13
0
def extract_provinces_and_states_lines():
    input_path = get_shape_path("ne_50m_admin_1_states_provinces_lines")
    output_path = path.join(OUT_DIR, "states-provinces-lines.json")

    features = []
    with fiona.open(input_path) as source:
        for feat in source:
            del feat["properties"]
            geometry = feat["geometry"]
            feat["bbox"] = shape(geometry).bounds
            features.append(feat)

    my_layer = {"type": "FeatureCollection", "features": features}

    with Popen(['geo2topo', '-q', '5e3', 'geometry=-', '-o', output_path],
               stdin=PIPE,
               stdout=PIPE,
               stderr=PIPE) as subproc:
        errors = subproc.communicate(input=json.dumps(my_layer).encode())[1]
        if subproc.returncode == 0:
            print(c.green("Extracted data to {}".format(output_path)))
        else:
            print(
                c.red("geo2topo exited with {}. {}".format(
                    subproc.returncode,
                    errors.decode().strip())))
Пример #14
0
 def run(cls, cmd):
     cls.show_cmd(cmd)
     try:
         output = subprocess.run(cmd.split(),
                                 stdout=PIPE,
                                 stderr=PIPE,
                                 universal_newlines=True)
         if output.returncode:
             cls.stdout(str(colorful.red(output.stdout)))
             cls.stdout(str(colorful.red(output.stderr)))
             return output
         cls.stdout(str(colorful.green(output.stderr)))
         cls.stdout(str(colorful.green(output.stdout)))
         return output
     except Exception as exc:
         cls.show_err(exc)
Пример #15
0
def merge_gettext_catalogues(existing_catalogue_file,
                             generated_catalogue_file):
    if path.exists(existing_catalogue_file):
        args = (
            existing_catalogue_file,
            generated_catalogue_file,
            "--output-file",
            existing_catalogue_file,

            # ensure that the first occurence takes precedence in merge conflict
            "--use-first",

            # sort by msgid
            "--sort-output",

            # disable wrapping long strings because crowdin does not do that
            "--no-wrap")

        (exit_code, errors) = run_program("msgcat", *args)

        if exit_code == 0:
            print(
                c.green("Merged {} into {}.".format(generated_catalogue_file,
                                                    existing_catalogue_file)))
        else:
            print(
                c.red("msgcat exited with {}: {}".format(
                    exit_code,
                    errors.decode().strip())))
    else:
        print(
            c.orange("The existing catalogue does not exist. Copying {} to {}"
                     ).format(generated_catalogue_file,
                              existing_catalogue_file))
        shutil.copyfile(generated_catalogue_file, existing_catalogue_file)
Пример #16
0
def run_tests(locals):
    outcomes = dict()

    def add_outcome(name, successful):
        if name in outcomes:
            raise RuntimeError("Duplicate test name: " + name)
        outcomes[name] = successful

    loc = list(locals.keys())
    for l in loc:
        if l.startswith("test_"):
            print(l, end=": ")
            f = locals[l]
            try:
                o = f()
            except Exception as e:
                print("EXCEPTION: " + str(e))
                o = False
            passed = (
                o is None
            ) or o  # "void" methods are successful if they don't raise an Exception
            print(cf.green("PASS") if passed else cf.red("FAIL"))
            add_outcome(l, passed)

    plot.set_property("Plot.Title", "See console for test results.")

    failed_names = [n for n, s in outcomes.items() if not s]
    faileds = ", ".join(failed_names)

    if faileds:
        print("FAILED TESTS: " + faileds, file=sys.stderr)

    if faileds:
        raise Exception(str(len(failed_names)) + " tests failed")
Пример #17
0
def hosts_file(app):
    """Prompts the user with modifying their /etc/hosts file"""
    print(
        colorful.green(
            "Remember to add the %s.local entry to your local /etc/hosts file!" % (app)
        )
    )
Пример #18
0
def colored_grade(grade):
    if grade < 4:
        return colorful.red(grade)
    elif grade < 4.5:
        return colorful.yellow(grade)
    else:
        return colorful.green(grade)
Пример #19
0
    def adjusted_dataframe_and_classification(self, title, override, export):
        '''
        Adjusts training data so that the coverage values are clustered, 
        using anvio clustering algorithm, and the dataframe is sorted 
        Overall, this eases the process of manually inputting the data.
        This is, however, only useful for inputting training data into the model.
        '''
        self.run_anvi_newick_matrix()
        self.is_tree_file_OK()

        self.F = AdjustClassification(
            tree_file=self.tree_file,
            directory=self.directory,
            coverage_values_file=self.coverage_values_file,
            classified_values_file=self.classified_values_file)

        self.dataframe = self.F.dataframe.reindex(self.F.genes)
        self.dataframe['Classification'] = 0
        self.dataframe.to_csv(self.coverage_values_file, sep='\t')

        print(
            cf.green(
                """Now we will open up the excel file so you can input the 
            classified values \n\n\n"""))

        print(
            cf.green("Opening up '%s' on an Excel spreadsheet\n" %
                     (self.coverage_values_file)))
        path_to_excel = '/Applications/Microsoft Excel.app'
        path_to_file = os.path.join(self.directory, self.coverage_values_file)
        string = "open -a '%s' '%s'" % (path_to_excel, path_to_file)
        os.system(string)

        print(
            cf.blue("""Now launching anvi-interactive. When you are done
        manually classifying the data, make sure to press CTRL + C to exit
        out. If the data is already classified, simply press CTRL + C\n"""))

        self.launch_anvi_interactive(title, override)

        print(
            cf.green("""Finished! By now, you must have a column
        in your Excel spreadsheet labeled 'Classification' and manually
        inputted the classifying data for each gene. """))

        if export:
            self.export_classifier()
Пример #20
0
def extract_countries_po():
  input_path = get_shape_path("ne_50m_admin_0_countries")

  for locale in os.listdir(LOCALE_DIR):
    locale_dir = path.join(LOCALE_DIR, locale)
    locale_out_dir = path.join(LOCALE_OUT_DIR, locale)

    if os.path.isdir(locale_dir):
      with fiona.open(input_path) as source:
        po = POFile(encoding='UTF-8')
        po.metadata = {"Content-Type": "text/plain; charset=utf-8"}
        output_path = path.join(locale_out_dir, "countries.po")

        if not path.exists(locale_out_dir):
          os.makedirs(locale_out_dir)

        print "Generating {}/countries.po".format(locale)

        for feat in source:
          props = lower_dict_keys(feat["properties"])
          name_key = "_".join(("name", get_locale_language(locale)))
          name_alt_key = "_".join(("name", convert_locale_ident(locale)))
          name_fallback = "name"

          if props.get(name_key) is not None:
            translated_name = props.get(name_key)
          elif props.get(name_alt_key) is not None:
            translated_name = props.get(name_alt_key)
          elif props.get(name_fallback) is not None:
            translated_name = props.get(name_fallback)
            print c.orange(u" Missing translation for {}".format(translated_name))
          else:
            raise ValueError(
              "Cannot find the translation for {}. Probe keys: {}"
              .format(locale, (name_key, name_alt_key))
              )

          entry = POEntry(
            msgid=props["name"],
            msgstr=translated_name
          )
          po.append(entry)

        po.save(output_path)
        print c.green("Extracted {} countries for {} to {}".format(len(po), locale, output_path))
Пример #21
0
 def wipe_out(self):
     """Simple query erasing every tables"""
     print("Ditching old database...")
     db.query(""" DROP TABLE IF EXISTS
                       Product, Category, Store,
                       Favorite, Product_category,
                       Product_Store;
                     """)
     print(cf.green("Database is now clean !"))
Пример #22
0
 def __str__(self):
     out_str = ""
     title = self.document.get("title")
     version = self.document.get("version")
     out_str += colorful.bold_red("{} {}\n".format(title, version))
     out_str += self.document.get("description") + "\n\n"
     out_str += header("Resources: ")
     for resource in self.get_resources():
         out_str += colorful.green(resource) + "\n"
     return out_str
Пример #23
0
 def __str__(self):
     out_str = ""
     out_str += header("Resource {}".format(".".join(self.resource_names)))
     out_str += "\n"
     if self.get_resources():
         out_str += header("Resources: ")
         out_str += colorful.green("\n".join(self.get_resources()))
         out_str += "\n\n"
     out_str += self.get_methods_string()
     return out_str
Пример #24
0
def input_yes_no(sentence):
    """Generic yes-no question and input catcher"""
    print(sentence)
    print(cf.white("Please " + cf.red('press "y" ', nested=True) + "if yes"))
    print(
        cf.white("Otherwise, " + cf.green('press any key ', nested=True) +
                 'to continue'))

    answer = input(": ")
    return answer
Пример #25
0
    def __log_room(platform, category, game, name, room, live, desc):
        print(platform, end="  ")

        print("%s >" % category, colorful.bold(game))
        print(" ", colorful.bold(name), "(%s)" % room, end=" ")
        if live:
            print(colorful.green("● 正在直播"))
        else:
            print(colorful.dimGray("● 未直播"))
        print(desc)
        print()
Пример #26
0
 def format(self, record):
     levelname = record.levelname
     if levelname in ('NOTSET', 'DEBUG'):
         record.levelname = colorful.cyan(levelname)
     elif levelname in ('INFO', ):
         record.levelname = colorful.green(levelname)
     elif levelname in ('WARNING', ):
         record.levelname = colorful.bold_yellow(levelname)
     elif levelname in ('ERROR', 'CRITICAL'):
         record.levelname = colorful.bold_red(levelname)
     return logging.Formatter.format(self, record)
Пример #27
0
 def get_methods_string(self, indent=0):
     resource = self.document  # rename
     methods = resource.get("methods")
     methods_string = ""
     if methods:
         methods_string += colorful.blue("Methods:")
         for k, v in methods.items():
             method = ("\n" + colorful.green(k) + ": " +
                       wrapped_text(v.get("description"), indent))
             methods_string += method
     return methods_string
Пример #28
0
def merge_single_locale_folder(src, dst):
    for f in os.listdir(src):
        src_po = path.join(src, f)
        dst_po = path.join(dst, f)

        if f in TRANSLATIONS_TO_COPY:
            print "Copying {} to {}".format(
                *remove_common_prefix(src_po, dst_po))
            shutil.copyfile(src_po, dst_po)
        elif f in TRANSLATIONS_TO_MERGE:
            if path.exists(dst_po):
                pot_basename = path.basename(path.splitext(dst_po)[0])
                pot_path = path.join(TRANSLATIONS_DEST_DIR,
                                     pot_basename + ".pot")

                (msgmerge_code, msgmerge_errors) = run_program([
                    "msgmerge", "--update", "--no-fuzzy-matching", dst_po,
                    pot_path
                ])

                if msgmerge_code == 0:
                    (msgcat_code, msgcat_errors) = run_program(
                        ["msgcat", src_po, dst_po, "--output-file", dst_po])

                    if msgcat_code == 0:
                        print c.green(
                            "Merged and concatenated the catalogues.")
                    else:
                        print c.red("msgcat exited with {}: {}".format(
                            msgcat_code,
                            msgcat_errors.decode('utf-8').strip()))
                else:
                    print c.red("msgmerge exited with {}: {}".format(
                        msgmerge_code,
                        msgmerge_errors.decode('utf-8').strip()))
            else:
                shutil.copy(src_po, dst_po)
        else:
            print c.orange("Unexpected file: {}".format(src_po))
Пример #29
0
 def log_message(self, message, color='blue'):
     # Outputs a colorful message to the terminal
     # and only if is_debug prop is set to True.
     if self.is_debug:
         if color == 'blue':
             message = cf.bold | cf.blue(message)
         elif color == 'orange':
             message = cf.bold | cf.orange(message)
         elif color == 'green':
             message = cf.bold | cf.green(message)
         elif color == 'red':
             message = cf.bold | cf.red(message)
         print(message)
Пример #30
0
def build_init_image(drucker):
    """Builds the init image from Dockerfile"""
    if subprocess.getoutput(drucker.vars.CHECK_INIT_IMAGE):
        print(colorful.green("%s image already exists." % (drucker.vars.INIT_IMAGE)))
    elif not subprocess.getoutput(drucker.vars.CHECK_BASE_IMAGE):
        print(
            colorful.white_on_blue(
                "Building %s image from Dockerfile..." % (drucker.vars.INIT_IMAGE)
            )
        )
        subprocess.run(
            'docker build -t "%s" %s' % (drucker.vars.INIT_IMAGE, drucker.vars.APP_DIR),
            shell=True,
        )
Пример #31
0
def create_bridge_network(drucker):
    """Creates a custom bridge network"""
    if subprocess.getoutput(drucker.vars.CHECK_BRIDGE):
        print(
            colorful.green(
                "Custom %s bridge network already exists." % (drucker.vars.APP)
            )
        )
    else:
        print(
            colorful.white_on_blue(
                "Creating custom %s bridge network..." % (drucker.vars.APP)
            )
        )
        subprocess.getoutput(drucker.vars.CREATE_BRIDGE)
Пример #32
0
    def create_person(self, first_name, last_name, person_type):
        """create_person
        """

        person_id = len(self.all_people) + 1  # Generate person_id
        if not first_name.isalpha() or not last_name.isalpha():
            print(
                colorful.orange(
                    "Name should only contain alphabetic characters. \
                Please rectify and try again"))
            return False
        person = Staff(first_name, last_name, person_id) \
            if person_type.lower() == "staff" else Fellow(
                first_name, last_name, wants_accommodation, person_id)
        print(
            colorful.green("{0} {1} {2} has been successfully added".format(
                person_type, first_name, last_name)))
        self.all_people.append(person)
        return person
Пример #33
0
def pull_base_image(drucker):
    """Pulls and updates the preferred distribution image from the Docker Hub"""
    distro_image_exists = subprocess.getoutput(drucker.vars.CHECK_DISTRO_IMAGE)
    base_image_exists = subprocess.getoutput(drucker.vars.CHECK_BASE_IMAGE)

    if distro_image_exists and not base_image_exists:
        print(colorful.green("%s image already exists" % (drucker.vars.DISTRO_IMAGE)))
        print(
            colorful.white_on_blue(
                "Check if %s can be updated..." % (drucker.vars.DISTRO_IMAGE)
            )
        )
        subprocess.run(drucker.vars.UPDATE_DISTRO_IMAGE, shell=True)
    elif not distro_image_exists:
        print(
            colorful.white_on_blue(
                "Pulling %s image from Docker Hub..." % (drucker.vars.DISTRO_IMAGE)
            )
        )
        subprocess.run(drucker.vars.PULL_DISTRO_IMAGE, shell=True)
Пример #34
0
def write_db(project_code, db_dir, dict_data):
    if db_dir:
        db_path = db_dir
    else:
        db_path = op.join(op.dirname(__file__), "db")
    db_full_path = op.join(db_path, project_code + "_db_.json")

    db = TinyDB(db_full_path)
    query = Query()

    for user in dict_data:
        for session in dict_data[user]:
            if not db.table(user).search(
                    query.session_id == session["session_id"]):
                db.table(user).insert(session)
                print(
                    colorful.green(" {} with session {} stored in db".format(
                        user, session["session_id"])))
            else:
                print(
                    colorful.orange(" {} with session {} already in db".format(
                        user, session["session_id"])))
    return db
Пример #35
0
def draw(coords: List, speed=0.0) -> None:
    # pyautogui.moveTo(0, 0, duration=0.5)
    # pyautogui.moveRel(0, 100, duration=0.5)
    # pyautogui.dragTo(button='left')
    # print(pyautogui.position())
    # pyautogui.write('Hello world')

    # selenium or pyautogui hmm
    # core-letter-cell contains each letters values
    print(
        cf.orange(
            'Warning: getting ready to draw, do not touch cursor, Move to a corner to exit'
        ))
    time.sleep(1)
    for w, cd in coords:
        off = grid_to_pix[cd[0]]
        print(cf.green(f'drawing {w}  \r'), end='')
        pyautogui.moveTo(off[0], off[1], duration=speed)
        pyautogui.mouseDown()
        for c in cd[1:]:
            off = grid_to_pix[c]
            pyautogui.moveTo(off[0], off[1], duration=speed)
        pyautogui.mouseUp()
Пример #36
0
    def create_room(self, room_type, *room_names):
        """ Used to create new rooms.

        Args:
            room_type (str): Type of room.
            room_names : List of room_names. It takes in one or more names

        Returns:
            Room || Room[]: One Room if one name is provided
            and a list of Rooms if more than one is provided.

        """

        created_rooms = []

        for room_name in room_names:
            # Check if room_name exists in the already created rooms
            if room_name not in [room.name for room in self.rooms]:
                # Check that room_name contains only alphabetic characters
                if not room_name.isalpha():
                    print("room name input must be string alphabet type")
                    return
                room = Office(room_name) if room_type.lower(
                ) == "office" else LivingSpace(room_name)
                self.rooms.append(room)
                created_rooms.append(room)
                print(
                    colorful.green(
                        "{0} called {1} has been successfully created!".format(
                            room_type.capitalize(), room_name)))
            else:
                print(
                    colorful.red(
                        "Room with name: {0} already exists. "
                        "Please try using another name".format(room_name)))
                break
        return created_rooms[0] if len(created_rooms) == 1 else created_rooms
Пример #37
0
    def console_write(self, features, marker):
        """
            Writes the endreport for all features

            :param list features: all features
        """
        stats = {
            "features": {
                "amount": 0,
                "passed": 0,
                "failed": 0,
                "skipped": 0,
                "untested": 0,
                "pending": 0,
            },
            "scenarios": {
                "amount": 0,
                "passed": 0,
                "failed": 0,
                "skipped": 0,
                "untested": 0,
                "pending": 0,
            },
            "steps": {
                "amount": 0,
                "passed": 0,
                "failed": 0,
                "skipped": 0,
                "untested": 0,
                "pending": 0,
            },
        }
        pending_steps = []
        duration = timedelta()
        for feature in features:
            if not feature.has_to_run(world.config.scenarios):
                continue
            stats["features"]["amount"] += 1
            stats["features"][feature.state] += 1

            if feature.state in [Step.State.PASSED, Step.State.FAILED]:
                duration += feature.duration

            for scenario in feature.all_scenarios:
                if not scenario.has_to_run(world.config.scenarios):
                    continue

                if isinstance(scenario, ScenarioOutline):  # skip ScenarioOutlines
                    continue
                if isinstance(scenario, ScenarioLoop):  # skip ScenarioLoop
                    continue

                stats["scenarios"]["amount"] += 1
                stats["scenarios"][scenario.state] += 1
                for step in scenario.steps:
                    stats["steps"]["amount"] += 1
                    stats["steps"][step.state] += 1

                    if step.state == Step.State.PENDING:
                        pending_steps.append(step)

        colored_closing_paren = colorful.bold_white(")")
        colored_comma = colorful.bold_white(", ")
        passed_word = colorful.bold_green("{0} passed")
        failed_word = colorful.bold_red("{0} failed")
        skipped_word = colorful.cyan("{0} skipped")
        pending_word = colorful.bold_yellow("{0} pending")

        output = colorful.bold_white(
            "{0} features (".format(stats["features"]["amount"])
        )
        output += passed_word.format(stats["features"]["passed"])
        if stats["features"]["failed"]:
            output += colored_comma + failed_word.format(stats["features"]["failed"])
        if stats["features"]["skipped"]:
            output += colored_comma + skipped_word.format(stats["features"]["skipped"])
        if stats["features"]["pending"]:
            output += colored_comma + pending_word.format(stats["features"]["pending"])
        output += colored_closing_paren

        output += "\n"
        output += colorful.bold_white(
            "{} scenarios (".format(stats["scenarios"]["amount"])
        )
        output += passed_word.format(stats["scenarios"]["passed"])
        if stats["scenarios"]["failed"]:
            output += colored_comma + failed_word.format(stats["scenarios"]["failed"])
        if stats["scenarios"]["skipped"]:
            output += colored_comma + skipped_word.format(stats["scenarios"]["skipped"])
        if stats["scenarios"]["pending"]:
            output += colored_comma + pending_word.format(stats["scenarios"]["pending"])
        output += colored_closing_paren

        output += "\n"
        output += colorful.bold_white("{} steps (".format(stats["steps"]["amount"]))
        output += passed_word.format(stats["steps"]["passed"])
        if stats["steps"]["failed"]:
            output += colored_comma + failed_word.format(stats["steps"]["failed"])
        if stats["steps"]["skipped"]:
            output += colored_comma + skipped_word.format(stats["steps"]["skipped"])
        if stats["steps"]["pending"]:
            output += colored_comma + pending_word.format(stats["steps"]["pending"])
        output += colored_closing_paren

        if pending_steps:
            sr = StepRegistry()
            pending_step_implementations = make_unique_obj_list(
                pending_steps, lambda x: x.definition_func
            )
            output += colorful.white(
                "\nYou have {0} pending step implementation{1} affecting {2} step{3}:\n  {4}\n\nNote: this could be the reason for some failing subsequent steps".format(
                    len(pending_step_implementations),
                    "s" if len(pending_step_implementations) is not 1 else "",
                    len(pending_steps),
                    "s" if len(pending_steps) is not 1 else "",
                    "\n  ".join(
                        [
                            "-  '{0}' @ {1}".format(
                                sr.get_pattern(s.definition_func),
                                get_func_code(s.definition_func).co_filename,
                            )
                            for s in pending_step_implementations
                        ]
                    ),
                )
            )

        output += "\n"

        if world.config.wip:
            if stats["scenarios"]["passed"] > 0:
                output += colorful.red(
                    "\nThe --wip switch was used, so I didn't expect anything to pass. These scenarios passed:\n"
                )

                has_passed_scenarios = False
                for feature in features:
                    passed_scenarios = list(
                        filter(
                            lambda s: s.state == Step.State.PASSED,
                            feature.all_scenarios,
                        )
                    )
                    for scenario in passed_scenarios:
                        output += colorful.red(
                            "\n - {}: {}".format(feature.path, scenario.sentence)
                        )
                        has_passed_scenarios = True

                if has_passed_scenarios:
                    output += "\n"
            else:
                output += colorful.green(
                    "\nThe --wip switch was used, so the failures were expected. All is good.\n"
                )

        output += colorful.cyan(
            "Run {0} finished within {1}".format(
                marker, humanize.naturaldelta(duration)
            )
        )

        write(output)