Ejemplo n.º 1
0
def main():

    DB_URL = 'mysql://{user}:{passwd}@{host}/{db}'.format(host=args.host, user=args.username,\
        passwd=args.password,db=args.db_name)
    logger.debug('DB_URL: {url}'.format(url=DB_URL))

    # Error handling for possible sql path location errors.
    try:
        os.path.exists(args.path_to_sql) or os.path.isdir(args.path_to_sql)
    except IOError as e:
        logger.error(e)
        sys.exit(1)

    if args.updateVersion:
        utils.update_db_version(DB_URL, args.updateVersion)
        sys.exit(0)

    # get scripts
    scripts = utils.get_scripts(args.path_to_sql)
    highest_value = utils.get_max_script(scripts)

    try:
        session = utils.create_connection(DB_URL)
    except CreateConnectionException as e:
        logger.error('There was an Error when creating the DB sesion')
        sys.exit(1)
    try:
        version = utils.get_db_version(session)
    except LoginDbException as e:
        logger.error(e)
        sys.exit(4)

    if utils.do_upgrade(version, highest_value):
        # each script which number is higher that version must be executed:
        # lower to higher => version must be updated for each script

        logger.info(
            "Highest value on sql scripts: {max}".format(max=highest_value))
        logger.info("Doing DB upgrade")

        ordered_scripts, scripts_dict = utils.get_ordered_scripts(scripts)

        for root, dirs, files in os.walk(args.path_to_sql):
            for f in files:
                if scripts_dict[f] > version:
                    # execute script
                    utils.run_sql_script(DB_URL,
                                         os.path.join(args.path_to_sql, f))
                    # update version
                    version = utils.update_db_version(DB_URL, scripts_dict[f])

        logger.info('Ugrade completed')
        logger.info('New version: {v}'.format(v=version))

    else:
        logger.info('Higher value on sql scripts: {max} is equal or lower than version: {version}'\
                .format(version=version, max=highest_value))
        logger.info('Nothing to do')
Ejemplo n.º 2
0
    def install_apps(self):
        # s'inspirer de mintinstall
        # https://github.com/linuxmint/mintinstall/blob/master/usr/bin/mint-synaptic-install

        #  systèmes sans synaptic : on tente de récupérer la commande
        #  d'installation du gestionnaire de paquets qu'on exécute
        #  normalement.

        #  à voir pour les autres plateformes ce qu'on peut faire avec
        #  leur installateur graphique.

        if self.TO_INSTALL:
            if os.path.isfile(_SYNAPTIC_PATH):
                ret = utils.synaptic_install(self.TO_INSTALL)

                if ret == 0:

                    self.display_dialog("Tous les paquets ont été installés avec succès.")


            else:
                pacman = utils.get_package_manager(packman=postinstaller._PACKMAN)
                if not pacman:
                    print "ERROR: what is your platform and your package manager ? Please e-mail the developper. No packages will be installed."

                else:

                    cmd = [pacman, ' '.join(['%s' % pac for pac in self.TO_INSTALL]) ]
                    comnd = Popen( ['gksudo', ' '.join(cmd)], stdout=PIPE, stderr=PIPE ) # todo: remplacer gksudo par sudocmnd
                    ret = comnd.wait()

                    # utils.exec_command("gksudo " + pacman +
                                       # " ".join( ['%s' % app for app in postinstaller.TO_INSTALL] ))

        # utils.packages_install(self.TO_INSTALL)

    # def execute_commands(self):
        ERROR = False
        for cmd in self.TO_EXEC:
            self.expander.set_label("Exécution de " + cmd)
            returnCode, stdout, stderr = utils.exec_command(cmd)
            if returnCode == 1:
                ERROR = True
                print 'erreur lors de l execution de ', cmd

        if ERROR:
            #TODO: le mieux est de récupérer la liste et d'afficher un dialogue avec expander qui montre les stderr.
            self.expander.set_label("Des commandes ont échoué")

        else:

            if len(self.TO_EXEC):
                # boite de dialogue très rapide :
                self.display_dialog("Toutes les commandes ont été exécutées avec succès.")

                # self.dialog = self.builder.get_object('messagedialog1')
                # self.dialog.format_secondary_text('Toutes les commandes ont été executées avec succès.')
                # self.dialog.run()
                # self.dialog.hide()


                # self.expander.set_label("Toutes les commandes ont été executées avec succès")


        if self.DO_UPGRADE:
            ret = utils.do_upgrade()

            if ret != 0:
                self.display_dialog("La mise à jour n'a pas pu se produire.")
Ejemplo n.º 3
0
    def OnInit(self):
        global client_id

        utils.assert_folders()
        utils.migrate_from_tmp()
        try:
            setup_log()
        except:
            wx.MessageBox('Another instance of Assembly is running', 'Unable to start',wx.OK | wx.ICON_ERROR)
            sys.exit(0)

        platform = utils.get_platform()
        auto_upgrade = utils.string2bool(platform['autoupgrade'])

        if len(sys.argv) > 1:
            utils.add_user_attribute('show_info_popup','True')
            utils.delete_folder_async('%s/upgrade' %os.getcwd())
            wx.MessageBox('Congratulations! Assembly64 was upgraded from version %s to %s.' %(sys.argv[1], version), 'Assembly64 upgraded!',wx.OK | wx.ICON_INFORMATION)

        try:
            utils.update_server_db()
            newer_available,force,available_version = utils.check_version(version)
            if newer_available and force:
                update_dia = UpdateDialog(None,"New version available", "New version available. Upgrade is vital!",auto_upgrade, True)
                update_dia.ShowModal()
                if update_dia.is_app_upgrade():
                    upgrade = UpgradeSplash()
                    upgrade.Show()
                    utils.do_upgrade(upgrade,version,platform)
                    os._exit(1)
            elif newer_available and not force:
                update_dia = UpdateDialog(None,"New version available", "New version available, but you can stay with this one.. For now!", auto_upgrade, False)
                update_dia.ShowModal()
                if update_dia.is_app_upgrade():
                    upgrade = UpgradeSplash()
                    upgrade.Show()
                    utils.do_upgrade(upgrade,version,platform)
                    os._exit(1)
        except FtpOverloadedException:
            wx.MessageBox('Too many users right now, please try later', 'Assembly Error',wx.OK | wx.ICON_WARNING)
            sys.exit(0)
        except ftplib.all_errors as a:
            wx.MessageBox('Unable to communicate with Assembly64 server.', 'Assembly Error',wx.OK | wx.ICON_WARNING)
            sys.exit(0)
        except:
            wx.MessageBox('Unable to communicate with assembly64 server.', 'Assembly Error',wx.OK | wx.ICON_WARNING)
            sys.exit(0)

        if not utils.has_attribute('uid'):
            client_id = str(uuid.uuid1())
            utils.add_user_attribute('uid',client_id)
            post_ga_event('application','startup_new_user')

        else:
            client_id = utils.get_user_attribute('uid')
            post_ga_event('application','startup_existing_user')

        if not utils.has_attribute('show_info_popup'):
            utils.add_user_attribute('show_info_popup','true')

        if utils.has_attribute(delete_files_after_install) is False:
            utils.add_user_attribute(delete_files_after_install,'true')

        thread = Thread(target = update_db,args = (10, ))
        thread.start()

        AssemblySplash().Show()
        return 1