Python MySQLdb.Warning() Examples

The following are code examples for showing how to use MySQLdb.Warning(). They are from open source Python projects. You can vote up the examples you like or vote down the ones you don't like.

Example 1
Project: wikilinks   Author: trovdimi   File: redirectscandidatespostioninserter.py    MIT License 6 votes vote down vote up
def insert_pagelength(self, source_article_id, screen_positions_1920_1080, zip_file_path):

               data={}
               data['source_article_id'] = source_article_id
               if screen_positions_1920_1080 is not None:
                   data['page_length_1920_1080'] = screen_positions_1920_1080
               else:
                   data['page_length_1920_1080'] = None
               #print data
               sql = "INSERT INTO redirects_candidates_page_length (id, page_length_1920_1080) VALUES" \
                      "(%(source_article_id)s, %(page_length_1920_1080)s);"
               try:
                   self.cursor.execute(sql, data)
               except (MySQLdb.Error, MySQLdb.Warning), e:
                   print ('FAIL: Data caused warning or error "%s" for source_article_id: "%s"', data,  source_article_id)
                   print 'FAIL: EXCEPTION:', e
                   print zip_file_path 
Example 2
Project: wikilinks   Author: trovdimi   File: linkpostioninserter.py    MIT License 6 votes vote down vote up
def insert_pagelength(self, source_article_id, screen_positions_1920_1080, zip_file_path):

               data={}
               data['source_article_id'] = source_article_id
               if screen_positions_1920_1080 is not None:
                   data['page_length_1920_1080'] = screen_positions_1920_1080
               else:
                   data['page_length_1920_1080'] = None
               #print data
               sql = "INSERT INTO page_length (id, page_length_1920_1080) VALUES" \
                      "(%(source_article_id)s, %(page_length_1920_1080)s);"
               try:
                   self.cursor.execute(sql, data)
               except (MySQLdb.Error, MySQLdb.Warning), e:
                   print ('FAIL: Data caused warning or error "%s" for source_article_id: "%s"', data,  source_article_id)
                   print 'FAIL: EXCEPTION:', e
                   print zip_file_path 
Example 3
Project: mysql_utils   Author: pinterest   File: mysql_lib.py    GNU General Public License v2.0 6 votes vote down vote up
def create_db(instance, db):
    """ Create a database if it does not already exist

    Args:
    instance - a hostAddr object
    db - the name of the db to be created
    """
    conn = connect_mysql(instance)
    cursor = conn.cursor()

    sql = ('CREATE DATABASE IF NOT EXISTS `{}`'.format(db))
    log.info(sql)

    # We don't care if the db already exists and this was a no-op
    warnings.filterwarnings('ignore', category=MySQLdb.Warning)
    cursor.execute(sql)
    warnings.resetwarnings() 
Example 4
Project: mysql_utils   Author: pinterest   File: mysql_lib.py    GNU General Public License v2.0 6 votes vote down vote up
def drop_db(instance, db):
    """ Drop a database, if it exists.

    Args:
    instance - a hostAddr object
    db - the name of the db to be dropped
    """
    conn = connect_mysql(instance)
    cursor = conn.cursor()

    sql = ('DROP DATABASE IF EXISTS `{}`'.format(db))
    log.info(sql)

    # If the DB isn't there, we'd throw a warning, but we don't
    # actually care; this will be a no-op.
    warnings.filterwarnings('ignore', category=MySQLdb.Warning)
    cursor.execute(sql)
    warnings.resetwarnings() 
Example 5
Project: mysql_utils   Author: pinterest   File: mysql_lib.py    GNU General Public License v2.0 6 votes vote down vote up
def start_event_scheduler(instance):
    """ Enable the event scheduler on a given MySQL server.

    Args:
        instance: The hostAddr object to act upon.
    """
    cmd = 'SET GLOBAL event_scheduler=ON'

    # We don't use the event scheduler in many places, but if we're
    # not able to start it when we want to, that could be a big deal.
    try:
        conn = connect_mysql(instance)
        cursor = conn.cursor()
        warnings.filterwarnings('ignore', category=MySQLdb.Warning)
        log.info(cmd)
        cursor.execute(cmd)
    except Exception as e:
        log.error('Unable to start event scheduler: {}'.format(e))
        raise
    finally:
        warnings.resetwarnings() 
Example 6
Project: mysql_utils   Author: pinterest   File: mysql_lib.py    GNU General Public License v2.0 6 votes vote down vote up
def stop_event_scheduler(instance):
    """ Disable the event scheduler on a given MySQL server.

    Args:
        instance: The hostAddr object to act upon.
    """
    cmd = 'SET GLOBAL event_scheduler=OFF'

    # If for some reason we're unable to disable the event scheduler,
    # that isn't likely to be a big deal, so we'll just pass after
    # logging the exception.
    try:
        conn = connect_mysql(instance)
        cursor = conn.cursor()
        warnings.filterwarnings('ignore', category=MySQLdb.Warning)
        log.info(cmd)
        cursor.execute(cmd)
    except Exception as e:
        log.error('Unable to stop event scheduler: {}'.format(e))
        pass
    finally:
        warnings.resetwarnings() 
Example 7
Project: index-digest   Author: macbre   File: database.py    MIT License 6 votes vote down vote up
def __init__(self, host, user, passwd, db):
        """
        Connects to a given database

        :type host str
        :type user str
        :type passwd str
        :type db str
        """
        self.logger = logging.getLogger(__name__)
        self.query_logger = logging.getLogger(__name__ + '.query')

        # lazy connect
        self._connection_params = dict(host=host, user=user, passwd=passwd, db=db)
        self._connection = None
        self.db_name = db

        # Suppress MySQL warnings when EXPLAIN is run (#63)
        filterwarnings('ignore', category=MySQLdb.Warning)

        # register queries
        self._queries = [] 
Example 8
Project: ops   Author: xiaomatech   File: mysqlops.py    MIT License 6 votes vote down vote up
def create_db(instance, db):
    """ Create a database if it does not already exist

    Args:
    instance - a hostAddr object
    db - the name of the to be created
    """
    conn = connect_mysql(instance)
    cursor = conn.cursor()

    sql = ('CREATE DATABASE IF NOT EXISTS ' '`{db}`;'.format(db=db))
    log.info(sql)

    # We don't care if the db already exists and this was a no-op
    warnings.filterwarnings('ignore', category=MySQLdb.Warning)
    cursor.execute(sql)
    warnings.resetwarnings() 
Example 9
Project: lightbulb-framework   Author: lightbulb-framework   File: sqlhandler.py    MIT License 6 votes vote down vote up
def query_database(self, query):
        """
        Perform a database query
        Args:
            query (str): The SQL query
        Returns:
            list: Mysql Rows
        """
        try:
            self.cursor.execute(query)
            return self.cursor.fetchall()
        except MySQLdb.Error as err:
            # print("Failed executing query: {}".format(err))
            return 0
        except MySQLdb.Warning as wrn:
            return 0 
Example 10
Project: wikilinks   Author: trovdimi   File: redirectscandidatespostioninserter.py    MIT License 5 votes vote down vote up
def insert_link(self, source_article_id, target_article_name, data, position,  zip_file_path):

        target_article_id = self.db_build_view._resolve_title(target_article_name.split('-----##$$$##-----')[0].replace('_', ' '))
        data['target_article_name'] = target_article_name.split('-----##$$$##-----')[0].replace('_', ' ')
        data['source_article_id'] = source_article_id
        data['target_article_id'] = target_article_id
        if position is not None:
            data['target_x_coord_1920_1080'] = position[0]
            data['target_y_coord_1920_1080'] = position[1]
            if data['target_y_coord_1920_1080'] < 0:
                data['target_y_coord_1920_1080'] = 0
        else:
            data['target_x_coord_1920_1080'] = None
            data['target_y_coord_1920_1080'] = None
        #print data
        sql = "INSERT INTO redirects_candidates (source_article_id, target_article_id, target_article_name," \
               "target_position_in_text, target_position_in_text_only, target_position_in_section, " \
               "target_position_in_section_in_text_only, section_name," \
               " section_number, target_position_in_table, table_number, table_css_class, table_css_style," \
               " target_x_coord_1920_1080, target_y_coord_1920_1080) VALUES" \
               "(%(source_article_id)s, %(target_article_id)s, %(target_article_name)s, %(target_position_in_text)s," \
               "%(target_position_in_text_only)s, %(target_position_in_section)s,  %(target_position_in_section_in_text_only)s, " \
               "%(section_name)s, %(section_number)s, %(target_position_in_table)s, %(table_number)s, " \
               "%(table_css_class)s, %(table_css_style)s," \
               "%(target_x_coord_1920_1080)s, %(target_y_coord_1920_1080)s);"
        try:
            self.cursor.execute(sql, data)
            #logging.info('DB Insert Success for  target article id: "%s" ' % target_article_id)
        except (MySQLdb.Error, MySQLdb.Warning), e:
            #print sql
            print ('FAIL: Data caused warning or error "%s" for target_article_id: "%s" in for source_article_id: "%s"', data, target_article_id, source_article_id)
            print 'FAIL: EXCEPTION:', e
            print zip_file_path
            #print('DB Insert Error  target article id: "%s" ' % target_article_id) 
Example 11
Project: wikilinks   Author: trovdimi   File: linkpostioninserter.py    MIT License 5 votes vote down vote up
def insert_link(self, source_article_id, target_article_name, data, position,  zip_file_path):

        target_article_id = self.db_build_view._resolve_title(target_article_name.split('-----##$$$##-----')[0].replace('_', ' '))
        if target_article_id is not None:

            data['source_article_id'] = source_article_id
            data['target_article_id'] = target_article_id
            if position is not None:
                data['target_x_coord_1920_1080'] = position[0]
                data['target_y_coord_1920_1080'] = position[1]
                if data['target_y_coord_1920_1080'] < 0:
                    data['target_y_coord_1920_1080'] = 0
            else:
                data['target_x_coord_1920_1080'] = None
                data['target_y_coord_1920_1080'] = None
            #print data
            sql = "INSERT INTO links (source_article_id, target_article_id," \
                   "target_position_in_text, target_position_in_text_only, target_position_in_section, " \
                   "target_position_in_section_in_text_only, section_name," \
                   " section_number, target_position_in_table, table_number, table_css_class, table_css_style," \
                   " target_x_coord_1920_1080, target_y_coord_1920_1080) VALUES" \
                   "(%(source_article_id)s, %(target_article_id)s, %(target_position_in_text)s," \
                   "%(target_position_in_text_only)s, %(target_position_in_section)s,  %(target_position_in_section_in_text_only)s, " \
                   "%(section_name)s, %(section_number)s, %(target_position_in_table)s, %(table_number)s, " \
                   "%(table_css_class)s, %(table_css_style)s," \
                   "%(target_x_coord_1920_1080)s, %(target_y_coord_1920_1080)s);"
            try:
                self.cursor.execute(sql, data)
                #logging.info('DB Insert Success for  target article id: "%s" ' % target_article_id)
            except (MySQLdb.Error, MySQLdb.Warning), e:
                #print sql
                print ('FAIL: Data caused warning or error "%s" for target_article_id: "%s" in for source_article_id: "%s"', data, target_article_id, source_article_id)
                print 'FAIL: EXCEPTION:', e
                print zip_file_path
                #print('DB Insert Error  target article id: "%s" ' % target_article_id) 
Example 12
Project: mysql_utils   Author: pinterest   File: mysql_lib.py    GNU General Public License v2.0 5 votes vote down vote up
def stop_replication(instance, thread_type=REPLICATION_THREAD_ALL):
    """ Stop replication, if running

    Args:
    instance - A hostAddr object
    thread - Which thread to stop. Options are in REPLICATION_THREAD_TYPES.
    """
    if thread_type not in REPLICATION_THREAD_TYPES:
        raise Exception('Invalid input for arg thread: {thread}'
                        ''.format(thread=thread_type))

    conn = connect_mysql(instance)
    cursor = conn.cursor()

    ss = get_slave_status(instance)
    if (ss['Slave_IO_Running'] != 'No' and ss['Slave_SQL_Running'] != 'No' and
            thread_type == REPLICATION_THREAD_ALL):
        cmd = 'STOP SLAVE'
    elif ss['Slave_IO_Running'] != 'No' and thread_type != REPLICATION_THREAD_SQL:
        cmd = 'STOP SLAVE IO_THREAD'
    elif ss['Slave_SQL_Running'] != 'No' and thread_type != REPLICATION_THREAD_IO:
        cmd = 'STOP SLAVE SQL_THREAD'
    else:
        log.info('Replication already stopped')
        return

    warnings.filterwarnings('ignore', category=MySQLdb.Warning)
    log.info(cmd)
    cursor.execute(cmd)
    warnings.resetwarnings() 
Example 13
Project: ops   Author: xiaomatech   File: mysqlops.py    MIT License 5 votes vote down vote up
def stop_replication(instance, thread_type=REPLICATION_THREAD_ALL):
    """ Stop replication, if running

    Args:
    instance - A hostAddr object
    thread - Which thread to stop. Options are in REPLICATION_THREAD_TYPES.
    """
    if thread_type not in REPLICATION_THREAD_TYPES:
        raise Exception('Invalid input for arg thread: {thread}'
                        ''.format(thread=thread_type))

    conn = connect_mysql(instance)
    cursor = conn.cursor()

    ss = get_slave_status(instance)
    if (ss['Slave_IO_Running'] != 'No' and ss['Slave_SQL_Running'] != 'No' and
            thread_type == REPLICATION_THREAD_ALL):
        cmd = 'STOP SLAVE'
    elif ss['Slave_IO_Running'] != 'No' and thread_type != REPLICATION_THREAD_SQL:
        cmd = 'STOP SLAVE IO_THREAD'
    elif ss['Slave_SQL_Running'] != 'No' and thread_type != REPLICATION_THREAD_IO:
        cmd = 'STOP SLAVE SQL_THREAD'
    else:
        log.info('Replication already stopped')
        return

    warnings.filterwarnings('ignore', category=MySQLdb.Warning)
    log.info(cmd)
    cursor.execute(cmd)
    warnings.resetwarnings() 
Example 14
Project: ops   Author: xiaomatech   File: mysqlops.py    MIT License 5 votes vote down vote up
def start_replication(instance, thread_type=REPLICATION_THREAD_ALL):
    """ Start replication, if not running

    Args:
    instance - A hostAddr object
    thread - Which thread to start. Options are in REPLICATION_THREAD_TYPES.
    """
    if thread_type not in REPLICATION_THREAD_TYPES:
        raise Exception('Invalid input for arg thread: {thread}'
                        ''.format(thread=thread_type))

    conn = connect_mysql(instance)
    cursor = conn.cursor()

    ss = get_slave_status(instance)
    if (ss['Slave_IO_Running'] != 'Yes' and
            ss['Slave_SQL_Running'] != 'Yes' and
            thread_type == REPLICATION_THREAD_ALL):
        cmd = 'START SLAVE'
    elif ss['Slave_IO_Running'] != 'Yes' and thread_type != REPLICATION_THREAD_SQL:
        cmd = 'START SLAVE IO_THREAD'
    elif ss['Slave_SQL_Running'] != 'Yes' and thread_type != REPLICATION_THREAD_IO:
        cmd = 'START SLAVE SQL_THREAD'
    else:
        log.info('Replication already running')
        return

    warnings.filterwarnings('ignore', category=MySQLdb.Warning)
    log.info(cmd)
    cursor.execute(cmd)
    warnings.resetwarnings()
    time.sleep(1) 
Example 15
Project: lightbulb-framework   Author: lightbulb-framework   File: sqlhandler.py    MIT License 5 votes vote down vote up
def initialize(self):
        """Initialize SQL database in the correct state"""
        for name, ddl in self.DROP.iteritems():
            try:
                print "Drop table {}:".format(name),
                self.cursor.execute(ddl)
            except MySQLdb.Error as err:
                print err
            except MySQLdb.Warning as wrn:
                pass
            finally:
                print 'OK'
        for name, ddl in self.TABLES.iteritems():
            try:
                print "Creating table {}:".format(name),
                self.cursor.execute(ddl)
            except MySQLdb.Error as err:
                print err
            except MySQLdb.Warning as wrn:
                pass
            finally:
                print 'OK'
        for name, ddl in self.INSERT.iteritems():
            try:
                print "Inserting into table {}:".format(name),
                self.cursor.execute(ddl)
            except MySQLdb.Error as err:
                print err
            except MySQLdb.Warning as wrn:
                pass
            finally:
                print 'OK' 
Example 16
Project: deep_data_bench   Author: DeepFound   File: metadata.py    GNU General Public License v3.0 5 votes vote down vote up
def __execute_query(self, sql):
		with warnings.catch_warnings():
			warnings.simplefilter('error', MySQLdb.Warning)
			try:
				self.__cur.execute(sql)
				return True
			except MySQLdb.Error, e:
				print "An Error occured running query. %s" %e
				#print sql;
				return False
			except MySQLdb.Warning, e:
				print "An Warning occured running query. %s" %e
				return True 
Example 17
Project: galera-ansible-operator   Author: water-hole   File: mysql_status.py    GNU General Public License v3.0 4 votes vote down vote up
def run(self, terms, variables, **kwargs):
        if not mysqldb_found:
            raise AnsibleError("The MySQL-python module is required.")
        else:
            warnings.filterwarnings('error', category=MySQLdb.Warning)

        options = {}
        for field in MYSQL_FIELDS:
            if field in kwargs:
                if field.startswith('ssl_'):
                    if 'ssl' not in options:
                        options['ssl'] = {}
                    ssl_entry = field.replace('ssl_', '')
                    options['ssl'][ssl_entry] = kwargs[field]
                elif field == 'config_file':
                    options['read_default_file'] = kwargs[field]
                else:
                    options[field] = kwargs[field]

        host_statuses = []
        for term in terms:
            host_status = {}
            try:
                options['host'] = term
                db_connection = MySQLdb.connect(**options)
                cursor = db_connection.cursor()
                try:
                    mysqlstatus_res = self.getstatus(cursor, r'%')
                    if mysqlstatus_res:
                        mysqlstatus_res = [(x[0].lower(), typedvalue(x[1])) for x in mysqlstatus_res]
                        for res in mysqlstatus_res:
                            host_status[res[0]] = res[1]
                        host_status["functional"] = True
                    else:
                        raise Exception("No wsrep status variables were found.")
                except Exception as e:
                    host_status["functional"] = False
                    host_status["reason"] = to_native(e)
            except Exception as e:
                host_status["functional"] = False
                if 'read_default_file' in options:
                    if os.path.exists(options['read_default_file']):
                        host_status["reason"] = "Unable to connect to database, check login_user and " \
                                                "login_password are correct or %s has the credentials. " \
                                                "Exception message: %s" % (options['read_default_file'], to_native(e))
                    else:
                        host_status["reason"] = "Unable to find %s. Exception message: %s" % (options['read_default_file'], to_native(e))
                else:
                    host_status["reason"] = "Unable to connect to database on %s: %s" % (term, to_native(e))

            host_statuses.append(host_status)

        return host_statuses 
Example 18
Project: ops   Author: xiaomatech   File: mysqlops.py    MIT License 4 votes vote down vote up
def swap_master_and_slave(instance, dry_run):
    """ Swap a master and slave in zk. Warning: this does not sanity checks
        and does nothing more than update zk. YOU HAVE BEEN WARNED!

    Args:
    instance - An instance in the replica set. This function will figure
               everything else out.
    dry_run - If set, do not modify configuration.
    """
    zk_local = MysqlZookeeper()
    kazoo_client = get_kazoo_client()
    if not kazoo_client:
        raise Exception('Could not get a zk connection')

    log.info('Instance is {inst}'.format(inst=instance))
    (replica_set, version) = zk_local.get_replica_set_from_instance(instance)
    log.info('Detected replica_set as '
             '{replica_set}'.format(replica_set=replica_set))
    (zk_node, parsed_data,
     version) = get_zk_node_for_replica_set(kazoo_client, replica_set)
    log.info('Replica set {replica_set} is held in zk_node '
             '{zk_node}'.format(
                 zk_node=zk_node, replica_set=replica_set))

    log.info('Existing config:')
    log.info(pprint.pformat(remove_auth(parsed_data[replica_set])))
    new_data = copy.deepcopy(parsed_data)
    new_data[replica_set][REPLICA_ROLE_MASTER] = \
        parsed_data[replica_set][REPLICA_ROLE_SLAVE]
    new_data[replica_set][REPLICA_ROLE_SLAVE] = \
        parsed_data[replica_set][REPLICA_ROLE_MASTER]

    log.info('New config:')
    log.info(pprint.pformat(remove_auth(new_data[replica_set])))

    if new_data == parsed_data:
        raise Exception('No change would be made to zk, '
                        'will not write new config')
    elif dry_run:
        log.info('dry_run is set, therefore not modifying zk')
    else:
        log.info('Pushing new configuration for '
                 '{replica_set}:'.format(replica_set=replica_set))
        kazoo_client.set(zk_node, simplejson.dumps(new_data), version) 
Example 19
Project: ops   Author: xiaomatech   File: mysqlops.py    MIT License 4 votes vote down vote up
def change_master(slave_hostaddr,
                  master_hostaddr,
                  master_log_file,
                  master_log_pos,
                  no_start=False):
    """ Setup MySQL replication on new replica

    Args:
    slave_hostaddr -  hostaddr object for the new replica
    hostaddr - A hostaddr object for the master db
    master_log_file - Replication log file to begin streaming
    master_log_pos - Position in master_log_file
    no_start - Don't run START SLAVE after CHANGE MASTER
    """
    conn = connect_mysql(slave_hostaddr)
    cursor = conn.cursor()

    set_global_variable(slave_hostaddr, 'read_only', True)
    reset_slave(slave_hostaddr)
    master_user, master_password = get_mysql_user_for_role('replication')
    parameters = {
        'master_user': master_user,
        'master_password': master_password,
        'master_host': master_hostaddr.hostname,
        'master_port': master_hostaddr.port,
        'master_log_file': master_log_file,
        'master_log_pos': master_log_pos
    }
    sql = ''.join(("CHANGE MASTER TO "
                   "MASTER_USER=%(master_user)s, "
                   "MASTER_PASSWORD=%(master_password)s, "
                   "MASTER_HOST=%(master_host)s, "
                   "MASTER_PORT=%(master_port)s, "
                   "MASTER_LOG_FILE=%(master_log_file)s, "
                   "MASTER_LOG_POS=%(master_log_pos)s "))
    warnings.filterwarnings('ignore', category=MySQLdb.Warning)
    cursor.execute(sql, parameters)
    warnings.resetwarnings()
    log.info(cursor._executed)

    if not no_start:
        start_replication(slave_hostaddr)
        # Replication reporting is wonky for the first second
        time.sleep(1)
        # Avoid race conditions for zk update monitor
        assert_replication_sanity(slave_hostaddr,
                                  set([CHECK_SQL_THREAD, CHECK_IO_THREAD])) 
Example 20
Project: seafile   Author: raghon1   File: setup-seafile-mysql.py    GNU General Public License v3.0 4 votes vote down vote up
def main():
    global db_config

    #Utils.welcome()
    warnings.filterwarnings('ignore', category=MySQLdb.Warning)

    env_mgr.check_pre_condiction()

    # Part 1: collect configuration

    #ccnet_config.ask_questions()
    #seafile_config.ask_questions()
    #seahub_config.ask_questions()
    
    ccnet_config.port = int(os.environ.get('CCNET_PORT'))
    ccnet_config.server_name = os.environ.get('CCNET_NAME')
    ccnet_config.ip_or_domain = os.environ.get('CCNET_IP')
    seafile_config.seafile_dir = os.environ.get('SEAFILE_DATA')
    #seafile_config.seafile_dir = os.path.join(env_mgr.top_dir, 'seafile-data')
    seafile_config.port = int(os.environ.get('SEAFILE_PORT'))
    seafile_config.fileserver_port = int(os.environ.get('FILESERVER_PORT'))
    
    if os.environ.get('EXISTING_DB') == 'true':
        db_config = ExistingDBConfigurator()
        db_config.mysql_host = os.environ.get('MYSQL_CONTAINER_PORT_3306_TCP_ADDR')
        db_config.mysql_port = int(os.environ.get('MYSQL_CONTAINER_PORT_3306_TCP_PORT'))
        db_config.seafile_mysql_password = os.getenv('MYSQL_PASSWORD')

    else:
        db_config = NewDBConfigurator()
        db_config.mysql_host = os.environ.get('MYSQL_CONTAINER_PORT_3306_TCP_ADDR')
        db_config.mysql_port = int(os.environ.get('MYSQL_CONTAINER_PORT_3306_TCP_PORT'))
        db_config.root_user = os.getenv('MYSQL_ROOT_USER', 'root')
        db_config.root_password = os.environ.get('MYSQL_ROOT_PASSWORD')
        db_config.root_conn = db_config.check_mysql_user(db_config.root_user, db_config.root_password)
        db_config.seafile_mysql_password = os.getenv('MYSQL_PASSWORD', subprocess.check_output(['pwgen','-s','-1','16']).rstrip())

    db_config.seafile_mysql_user = os.environ.get('MYSQL_USER')
    db_config.ccnet_db_name = os.environ.get('CCNET_DB_NAME')
    db_config.seafile_db_name = os.environ.get('SEAFILE_DB_NAME')
    db_config.seahub_db_name = os.environ.get('SEAHUB_DB_NAME')
    
    #db_config.ask_questions()

    report_config()

    # Part 2: generate configuration
    db_config.generate()
    ccnet_config.generate()
    seafile_config.generate()
    seafdav_config.generate()
    seahub_config.generate()

    seahub_config.do_syncdb()
    seahub_config.prepare_avatar_dir()
    # db_config.create_seahub_admin()
    user_manuals_handler.copy_user_manuals()
    create_seafile_server_symlink()

    report_success() 
Example 21
Project: seafile   Author: raghon1   File: setup-seafile-mysql.py    GNU General Public License v3.0 4 votes vote down vote up
def main():
    global db_config

    #Utils.welcome()
    warnings.filterwarnings('ignore', category=MySQLdb.Warning)

    env_mgr.check_pre_condiction()

    # Part 1: collect configuration

    #ccnet_config.ask_questions()
    #seafile_config.ask_questions()
    #seahub_config.ask_questions()
    
    ccnet_config.port = int(os.environ.get('CCNET_PORT'))
    ccnet_config.server_name = os.environ.get('CCNET_NAME')
    ccnet_config.ip_or_domain = os.environ.get('CCNET_IP')
    seafile_config.seafile_dir = os.environ.get('SEAFILE_DATA')
    #seafile_config.seafile_dir = os.path.join(env_mgr.top_dir, 'seafile-data')
    seafile_config.port = int(os.environ.get('SEAFILE_PORT'))
    seafile_config.fileserver_port = int(os.environ.get('FILESERVER_PORT'))
    
    if os.environ.get('EXISTING_DB') == 'true':
        db_config = ExistingDBConfigurator()
        db_config.mysql_host = os.environ.get('MYSQL_CONTAINER_PORT_3306_TCP_ADDR')
        db_config.mysql_port = int(os.environ.get('MYSQL_CONTAINER_PORT_3306_TCP_PORT'))
        db_config.seafile_mysql_password = os.getenv('MYSQL_PASSWORD')

    else:
        db_config = NewDBConfigurator()
        db_config.mysql_host = os.environ.get('MYSQL_CONTAINER_PORT_3306_TCP_ADDR')
        db_config.mysql_port = int(os.environ.get('MYSQL_CONTAINER_PORT_3306_TCP_PORT'))
        db_config.root_user = os.getenv('MYSQL_ROOT_USER', 'root')
        db_config.root_password = os.environ.get('MYSQL_ROOT_PASSWORD')
        db_config.root_conn = db_config.check_mysql_user(db_config.root_user, db_config.root_password)
        db_config.seafile_mysql_password = os.getenv('MYSQL_PASSWORD', subprocess.check_output(['pwgen','-s','-1','16']).rstrip())

    db_config.seafile_mysql_user = os.environ.get('MYSQL_USER')
    db_config.ccnet_db_name = os.environ.get('CCNET_DB_NAME')
    db_config.seafile_db_name = os.environ.get('SEAFILE_DB_NAME')
    db_config.seahub_db_name = os.environ.get('SEAHUB_DB_NAME')
    
    #db_config.ask_questions()

    report_config()

    # Part 2: generate configuration
    db_config.generate()
    ccnet_config.generate()
    seafile_config.generate()
    seafdav_config.generate()
    seahub_config.generate()

    seahub_config.do_syncdb()
    seahub_config.prepare_avatar_dir()
    # db_config.create_seahub_admin()
    user_manuals_handler.copy_user_manuals()
    create_seafile_server_symlink()

    report_success() 
Example 22
Project: seafile   Author: raghon1   File: setup-seafile-mysql.py    GNU General Public License v3.0 4 votes vote down vote up
def main():
    global db_config

    #Utils.welcome()
    warnings.filterwarnings('ignore', category=MySQLdb.Warning)

    env_mgr.check_pre_condiction()

    # Part 1: collect configuration

    #ccnet_config.ask_questions()
    #seafile_config.ask_questions()
    #seahub_config.ask_questions()
    
    ccnet_config.port = int(os.environ.get('CCNET_PORT'))
    ccnet_config.server_name = os.environ.get('CCNET_NAME')
    ccnet_config.ip_or_domain = os.environ.get('CCNET_IP')
    seafile_config.seafile_dir = os.environ.get('SEAFILE_DATA')
    #seafile_config.seafile_dir = os.path.join(env_mgr.top_dir, 'seafile-data')
    seafile_config.port = int(os.environ.get('SEAFILE_PORT'))
    seafile_config.fileserver_port = int(os.environ.get('FILESERVER_PORT'))
    
    if os.environ.get('EXISTING_DB') == 'true':
        db_config = ExistingDBConfigurator()
        db_config.mysql_host = os.environ.get('MYSQL_CONTAINER_PORT_3306_TCP_ADDR')
        db_config.mysql_port = int(os.environ.get('MYSQL_CONTAINER_PORT_3306_TCP_PORT'))
        db_config.seafile_mysql_password = os.getenv('MYSQL_PASSWORD')

    else:
        db_config = NewDBConfigurator()
        db_config.mysql_host = os.environ.get('MYSQL_CONTAINER_PORT_3306_TCP_ADDR')
        db_config.mysql_port = int(os.environ.get('MYSQL_CONTAINER_PORT_3306_TCP_PORT'))
        db_config.root_user = os.getenv('MYSQL_ROOT_USER', 'root')
        db_config.root_password = os.environ.get('MYSQL_ROOT_PASSWORD')
        db_config.root_conn = db_config.check_mysql_user(db_config.root_user, db_config.root_password)
        db_config.seafile_mysql_password = os.getenv('MYSQL_PASSWORD', subprocess.check_output(['pwgen','-s','-1','16']).rstrip())

    db_config.seafile_mysql_user = os.environ.get('MYSQL_USER')
    db_config.ccnet_db_name = os.environ.get('CCNET_DB_NAME')
    db_config.seafile_db_name = os.environ.get('SEAFILE_DB_NAME')
    db_config.seahub_db_name = os.environ.get('SEAHUB_DB_NAME')
    
    #db_config.ask_questions()

    report_config()

    # Part 2: generate configuration
    db_config.generate()
    ccnet_config.generate()
    seafile_config.generate()
    seafdav_config.generate()
    seahub_config.generate()

    seahub_config.do_syncdb()
    seahub_config.prepare_avatar_dir()
    # db_config.create_seahub_admin()
    user_manuals_handler.copy_user_manuals()
    create_seafile_server_symlink()

    report_success() 
Example 23
Project: seafile   Author: raghon1   File: setup-seafile-mysql.py    GNU General Public License v3.0 4 votes vote down vote up
def main():
    global db_config

    #Utils.welcome()
    warnings.filterwarnings('ignore', category=MySQLdb.Warning)

    env_mgr.check_pre_condiction()

    # Part 1: collect configuration

    #ccnet_config.ask_questions()
    #seafile_config.ask_questions()
    #seahub_config.ask_questions()
    
    ccnet_config.port = int(os.environ.get('CCNET_PORT'))
    ccnet_config.server_name = os.environ.get('CCNET_NAME')
    ccnet_config.ip_or_domain = os.environ.get('CCNET_IP')
    seafile_config.seafile_dir = os.environ.get('SEAFILE_DATA')
    #seafile_config.seafile_dir = os.path.join(env_mgr.top_dir, 'seafile-data')
    seafile_config.port = int(os.environ.get('SEAFILE_PORT'))
    seafile_config.fileserver_port = int(os.environ.get('FILESERVER_PORT'))
    
    if os.environ.get('EXISTING_DB') == 'true':
        db_config = ExistingDBConfigurator()
        db_config.mysql_host = os.environ.get('MYSQL_CONTAINER_PORT_3306_TCP_ADDR')
        db_config.mysql_port = int(os.environ.get('MYSQL_CONTAINER_PORT_3306_TCP_PORT'))
        db_config.seafile_mysql_password = os.getenv('MYSQL_PASSWORD')

    else:
        db_config = NewDBConfigurator()
        db_config.mysql_host = os.environ.get('MYSQL_CONTAINER_PORT_3306_TCP_ADDR')
        db_config.mysql_port = int(os.environ.get('MYSQL_CONTAINER_PORT_3306_TCP_PORT'))
        db_config.root_user = os.getenv('MYSQL_ROOT_USER', 'root')
        db_config.root_password = os.environ.get('MYSQL_ROOT_PASSWORD')
        db_config.root_conn = db_config.check_mysql_user(db_config.root_user, db_config.root_password)
        db_config.seafile_mysql_password = os.getenv('MYSQL_PASSWORD', subprocess.check_output(['pwgen','-s','-1','16']).rstrip())

    db_config.seafile_mysql_user = os.environ.get('MYSQL_USER')
    db_config.ccnet_db_name = os.environ.get('CCNET_DB_NAME')
    db_config.seafile_db_name = os.environ.get('SEAFILE_DB_NAME')
    db_config.seahub_db_name = os.environ.get('SEAHUB_DB_NAME')
    
    #db_config.ask_questions()

    report_config()

    # Part 2: generate configuration
    db_config.generate()
    ccnet_config.generate()
    seafile_config.generate()
    seafdav_config.generate()
    seahub_config.generate()

    seahub_config.do_syncdb()
    seahub_config.prepare_avatar_dir()
    # db_config.create_seahub_admin()
    user_manuals_handler.copy_user_manuals()
    create_seafile_server_symlink()

    report_success()