Example #1
0
def handle_response(resp):
    if resp == "":
        reporter.report_failure("Unrecognized command")
    else:
        try:
            hypotheses = json.loads(resp)['hypotheses']
        except json.decoder.JSONDecodeError:
            no_response = _("No response received")
            behind_firewall = _("Are you behind a firewall?")
            reporter.report_error(no_response + "." + behind_firewall)
            return

        for index in range(len(hypotheses)):
            values = hypotheses[index].values()

            if len(values) == 1:
                text = values[0]
                logging.debug("Result \"" + text +
                              "\" with unknown confidence")
            else:
                confidence, text = values
                logging.debug("Result \"" + text + "\" with confidence " +
                              str(confidence))

            retp = text_processor.process_text(text,
                                               status_icon.get_language())

            if (retp == True):
                return
def handle_response(resp):
  if resp =="":
    reporter.report_failure("Unrecognized command")
  else:
    try:
      hypotheses = json.loads(resp)['hypotheses']
    except json.decoder.JSONDecodeError:
      no_response=_("No response received")
      behind_firewall=_("Are you behind a firewall?")
      reporter.report_error(no_response + "." + behind_firewall)
      return     
      
    for index in range(len(hypotheses)):
      values = hypotheses[index].values()
          
      if len(values)==1:
        text = values[0]
        logging.debug( "Result \"" + text + "\" with unknown confidence" )
      else:
        confidence, text = values
        logging.debug( "Result \"" + text + "\" with confidence " + str(confidence) )
      
      retp = text_processor.process_text(text, status_icon.get_language())
          
      if (retp==True):
        return;
 def create_initial_structure(self):
     if not os.path.exists(self.project_name):
         os.mkdir(self.project_name)
         report_info("[Create] ./{}/\n".format(self.project_name))
     else:
         error = "Ops! Directory already exists\n"
         error_description = "We cannot create {} structure.\n"
         report_error(error + error_description.format(self.project_name))
         sys.exit(1)
 def init(self):
     if self.check_templates():
         self.directory.create_initial_structure()
         self.directory.create_directory_structure()
         self.files.create_template_config()
     else:
         error = "Ops! Theme '{}' not configured properly.\n"
         error_description = "Missing template files.\n"
         report_error(error.format(self.theme) + error_description)
         sys.exit(1)
 def get_template(self, template):
     try:
         template = Template(codecs.open(template,
                                         encoding='utf-8').read())
         return template
     except IOError:
         error = "Ops! Theme '{}' not configured properly.\n"
         error_description = "Template '{}' does not exist\n."
         report_error(error.format(self.theme) +
                      error_description.format(template.split('/')[-1]))
         sys.exit(1)
    def get_theme_structure(self):
        themes_file = yaml.load(open(THEMES_FILE))

        try:
            theme = themes_file.get(self.theme)
            return theme.get('dirs')
        except AttributeError:
            error = "Ops! This theme does not exist!\n"
            error_description = "Available themes: {}\n"
            report_error(error + error_description.format(themes_file.keys()))
            sys.exit(1)
 def load_config(cls):
     working_dir = os.getcwd()
     file_dir = os.path.join(working_dir, 'config.yml')
     try:
         config_file = open(file_dir)
         return yaml.load(config_file.read())
     except IOError:
         error = "Ops! Out of project root directory.\n"
         error_description = "config.yml file not found.\n"
         report_error(error + error_description)
         sys.exit(1)