def __create_app(self):
     """
       Create a new app with name, shortname and description passed in constructor
       and with category_id = 1 and return app.id. Or return the app.id from the app registered
       in pybossa database.
       
       :returns: app.id
       :rtype: int
       
     """
     
     apps = pbclient.find_app(short_name=self.short_name)
     if not len(apps) == 0:
         app = apps[0]
         msg = '{app_name} app is already registered in the DB'.format(app_name=app.name.encode('utf-8', 'replace'))
         logger.info(unicode(msg, "utf-8"))
         return app.id
     else:
         logger.info("The application is not registered in PyBOSSA. Creating it...")
         ans = pbclient.create_app(name=self.name, short_name=self.short_name, description=self.description)
         try:
             if ans:
                 app = pbclient.find_app(short_name=self.short_name)[0]
                 app.info = dict(newtask="%s/app/%s/newtask" % (flask_app.config['PYBOSSA_URL'], self.short_name))
                 app.category_id = 1
                 pbclient.update_app(app)
                 return app.id
         except Exception as ex:
             logger.error(Meb_apps_exception(4, -1, self.short_name))
             raise ex
def create_home_app():
    try:
        
        meb_short_name = "meb_home"
        apps = pbclient.find_app(short_name=meb_short_name)
        pyb_app = None
        if len(apps) != 0:
            pyb_app = apps[0]
        else:
            ans = pbclient.create_app(name="Memória Estatística do Brasil", short_name=meb_short_name, description="Página inicial do MEB.")
            if ans:
                pyb_app = pbclient.find_app(short_name=meb_short_name)[0]
                pbclient.create_task(pyb_app.id, {})

        if pyb_app == None:
            return False

        new_long_desc_template = meb_util.set_url(urllib2.urlopen(
                                                 urllib2.Request(app.config['URL_TEMPLATES'] +
                                                                 "/templates/long_description-home.html")), meb_short_name)
        new_template = meb_util.set_url(urllib2.urlopen(
                                       urllib2.Request(app.config['URL_TEMPLATES'] +
                                                        "/templates/template-home.html")), meb_short_name)

        pyb_app.info['thumbnail'] = app.config['URL_TEMPLATES'] + "/images/meb_icon.png"

        pyb_app.category_id = 1
        pyb_app.long_description = new_long_desc_template
        pyb_app.info['task_presenter'] = new_template
        
        pbclient.update_app(pyb_app)

        return True

    except Exception as e:
        return False