Esempio n. 1
0
def import_data(self, environment, source):
    """Create database then import from source.

    """
    (db_username, db_password, db_name) = pantheon.get_database_vars(self, environment)
    create_database(db_name)
    import_db_dump(source, db_name)
Esempio n. 2
0
 def _get_files_dir(self, environment='dev'):
     (db_username, db_password, db_name) = pantheon.get_database_vars(self, environment)
     # Get file_directory_path directly from database, as we don't have a working drush yet.
     return local("mysql -u %s -p'%s' %s --skip-column-names --batch -e \
                   \"SELECT value FROM variable WHERE name='file_directory_path';\" | \
                     sed 's/^.*\"\(.*\)\".*$/\\1/'" % (db_username,
                                                       db_password,
                                                       db_name)).rstrip('\n')
Esempio n. 3
0
 def _get_files_dir(self, environment='dev'):
     (db_username, db_password,
      db_name) = pantheon.get_database_vars(self, environment)
     # Get file_directory_path directly from database, as we don't have a working drush yet.
     return local("mysql -u %s -p'%s' %s --skip-column-names --batch -e \
                   \"SELECT value FROM variable WHERE name='file_directory_path';\" | \
                     sed 's/^.*\"\(.*\)\".*$/\\1/'" %
                  (db_username, db_password, db_name)).rstrip('\n')
Esempio n. 4
0
def import_data(self, environment, source):
    """Create database then import from source.

    """
    (db_username, db_password,
     db_name) = pantheon.get_database_vars(self, environment)
    create_database(db_name)
    import_db_dump(source, db_name)
Esempio n. 5
0
def export_data(self, environment, destination):
    """Export the database for a particular project/environment to destination.

    Exported database will have a name in the form of:
        /destination/project_environment.sql

    """
    project = self.project
    filepath = os.path.join(destination, '%s_%s.sql' % (project, environment))
    username, password, db_name = pantheon.get_database_vars(self, environment)
    local("mysqldump --single-transaction --user='******' \
                                          --password='******' \
                                            %s > %s" %
          (username, password, db_name, filepath))
    return filepath
Esempio n. 6
0
def export_data(self, environment, destination):
    """Export the database for a particular project/environment to destination.

    Exported database will have a name in the form of:
        /destination/project_environment.sql

    """
    project = self.project
    filepath = os.path.join(destination, '%s_%s.sql' % (project, environment))
    username, password, db_name = pantheon.get_database_vars(self, environment)
    local("mysqldump --single-transaction --user='******' \
                                          --password='******' \
                                            %s > %s" % (username,
                                                       password,
                                                       db_name,
                                                       filepath))
    return filepath
Esempio n. 7
0
    def setup_database(self):
        """ Create a new database and import from dumpfile.

        """
        for env in self.environments:
            (db_username, db_password,
             db_name) = pantheon.get_database_vars(self, env)
            # The database is only imported into the dev environment initially
            # so that we can do all import processing in one place, then deploy
            # to the other environments.
            if env == 'dev':
                db_dump = os.path.join(self.working_dir, self.db_dump)
            else:
                db_dump = None

            super(ImportTools, self).setup_database(env, db_password, db_dump,
                                                    True)
        # Remove the database dump from processing dir after import.
        local('rm -f %s' % (os.path.join(self.working_dir, self.db_dump)))
Esempio n. 8
0
    def setup_database(self):
        """ Create a new database and import from dumpfile.

        """
        for env in self.environments:
            (db_username, db_password, db_name) = pantheon.get_database_vars(self, env)
            # The database is only imported into the dev environment initially
            # so that we can do all import processing in one place, then deploy
            # to the other environments.
            if env == 'dev':
                db_dump = os.path.join(self.working_dir, self.db_dump)
            else:
                db_dump = None

            super(ImportTools, self).setup_database(env,
                                                    db_password,
                                                    db_dump,
                                                    True)
        # Remove the database dump from processing dir after import.
        local('rm -f %s' % (os.path.join(self.working_dir, self.db_dump)))
Esempio n. 9
0
    def enable_pantheon_settings(self):
        """Enable required modules, and set Pantheon defaults.

        """
        if self.version == 6:
            required_modules = ['apachesolr',
                                'apachesolr_search',
                                'locale',
                                'pantheon_api',
                                'pantheon_login',
                                'syslog',
                                'varnish']
        elif self.version == 7:
            required_modules = ['apachesolr',
                                'apachesolr_search',
                                'syslog',
                                'pantheon_api',
                                'pantheon_login',
                                'pantheon_apachesolr']

        # Enable modules.
        with settings(hide('warnings'), warn_only=True):
            for module in required_modules:
                result = local('drush -by @working_dir en %s' % module)
                pantheon.log_drush_backend(result, self.log)
                if result.failed:
                    # If importing vanilla drupal, this module wont exist.
                    if module != 'cookie_cache_bypass':
                        message = 'Could not enable %s module.' % module
                        self.log.warning('%s\n%s' % (message, result.stderr))
                        postback.build_warning(message)
                        print message
                        print '\n%s module could not be enabled. ' % module + \
                              'Error Message:'
                        print '\n%s' % result.stderr
                else:
                    self.log.info('%s enabled.' % module)

        if self.version == 6:
            drupal_vars = {
                'apachesolr_search_make_default': 1,
                'apachesolr_search_spellcheck': 1,
                'cache': '3',
                'block_cache': '1',
                'page_cache_max_age': '900',
                'page_compression': '0',
                'preprocess_js': '1',
                'preprocess_css': '1'}

        elif self.version == 7:
            drupal_vars = {
                'cache': 1,
                'block_cache': 1,
                'cache_lifetime': "0",
                'page_cache_maximum_age': "900",
                'page_compression': 0,
                'preprocess_css': 1,
                'preprocess_js': 1,
                'search_active_modules': {
                    'apachesolr_search':'apachesolr_search',
                    'user': '******',
                    'node': 0},
                'search_default_module': 'apachesolr_search'}

        # Set variables.
        (db_username, db_password, db_name) = pantheon.get_database_vars(self, 'dev')
        db = dbtools.MySQLConn(database = db_name,
                               username = db_username,
                               password = db_password)
        for key, value in drupal_vars.iteritems():
            db.vset(key, value)

        # apachesolr module for drupal 7 stores config in db.
        # TODO: use drush/drupal api to do this work.
        try:
            if self.version == 7:
                db.execute('TRUNCATE apachesolr_environment')
                for env in self.environments:
                    config = self.config['environments'][env]['solr']

                    env_id = '%s_%s' % (self.project, env)
                    name = '%s %s' % (self.project, env)
                    url = 'http://%s:%s%s' % (config['solr_host'],
                                              config['solr_port'],
                                              config['solr_path'])

                    # Populate the solr environments
                    db.execute('INSERT INTO apachesolr_environment ' + \
                        '(env_id, name, url) VALUES ' + \
                        '("%s", "%s", "%s")' % (env_id, name, url))

                    # Populate the solr environment variables
                    db.execute('INSERT INTO apachesolr_environment_variable '+\
                               '(env_id, name, value) VALUES ' + \
                               "('%s','apachesolr_read_only','s:1:\"0\"')" % (
                                                                      env_id))
        except Exception as mysql_error:
             self.log.error('Auto-configuration of ApacheSolr module failed: %s' % mysql_error)
             pass

        db.close()

        # D7: apachesolr config link will not display until cache cleared?
        with settings(warn_only=True):
            result = local('drush @working_dir -y cc all')
            pantheon.log_drush_backend(result, self.log)

        # Run updatedb
        drupaltools.updatedb(alias='@working_dir')

        # Remove temporary working_dir drush alias.
        alias_file = '/opt/drush/aliases/working_dir.alias.drushrc.php'
        if os.path.exists(alias_file):
            local('rm -f %s' % alias_file)
Esempio n. 10
0
    def setup_files_dir(self):
        """Move site files to sites/default/files if they are not already.

        This will move the files from their former location, change the file
        path in the database (for all files and the variable itself), then
        create a symlink in their former location.

        """
        file_location = self._get_files_dir()
        if file_location:
            file_path = os.path.join(self.working_dir, file_location)
        else:
            file_path = None
        file_dest = os.path.join(self.working_dir, 'sites/default/files')

        # After moving site to 'default', does 'files' not exist?
        if not os.path.exists(file_dest):
            # Broken symlink at sites/default/files
            if os.path.islink(file_dest):
                local('rm -f %s' % file_dest)
                msg = 'File path was broken symlink. Site files may be missing'
                self.log.info(msg)
                postback.build_warning(msg)
            local('mkdir -p %s' % file_dest)

        # if files are not located in default location, move them there.
        if (file_path) and (file_location != 'sites/%s/files' % self.site):
            with settings(warn_only=True):
                local('cp -R %s/* %s' % (file_path, file_dest))
            local('rm -rf %s' % file_path)
            path = os.path.split(file_path)
            # Symlink from former location to sites/default/files
            if not os.path.islink(path[0]):
                # If parent folder for files path doesn't exist, create it.
                if not os.path.exists(path[0]):
                    local('mkdir -p %s' % path[0])
                rel_path = os.path.relpath(file_dest, path[0])
                local('ln -s %s %s' % (rel_path, file_path))

        # Change paths in the files table
        (db_username, db_password, db_name) = pantheon.get_database_vars(self, 'dev')

        if self.version == 6:
            file_var = 'file_directory_path'
            file_var_temp = 'file_directory_temp'
            # Change the base path in files table for Drupal 6
            local('mysql -u root %s -e "UPDATE files SET filepath = \
                   REPLACE(filepath,\'%s\',\'%s\');"'% (db_name,
                                                        file_location,
                                                        'sites/default/files'))
        elif self.version == 7:
            file_var = 'file_public_path'
            file_var_temp = 'file_temporary_path'

        # Change file path drupal variables
        db = dbtools.MySQLConn(database = db_name,
                               username = db_username,
                               password = db_password)
        db.vset(file_var, 'sites/default/files')
        db.vset(file_var_temp, '/tmp')
        db.close()

        # Ignore files directory
        with open(os.path.join(file_dest,'.gitignore'), 'a') as f:
            f.write('*\n')
            f.write('!.gitignore\n')
Esempio n. 11
0
    def enable_pantheon_settings(self):
        """Enable required modules, and set Pantheon defaults.

        """
        if self.version == 6:
            required_modules = [
                'apachesolr', 'apachesolr_search', 'locale', 'pantheon_api',
                'pantheon_login', 'syslog', 'varnish'
            ]
        elif self.version == 7:
            required_modules = [
                'apachesolr', 'apachesolr_search', 'syslog', 'pantheon_api',
                'pantheon_login', 'pantheon_apachesolr'
            ]

        # Enable modules.
        with settings(hide('warnings'), warn_only=True):
            for module in required_modules:
                result = local('drush -by @working_dir en %s' % module)
                pantheon.log_drush_backend(result, self.log)
                if result.failed:
                    # If importing vanilla drupal, this module wont exist.
                    if module != 'cookie_cache_bypass':
                        message = 'Could not enable %s module.' % module
                        self.log.warning('%s\n%s' % (message, result.stderr))
                        postback.build_warning(message)
                        print message
                        print '\n%s module could not be enabled. ' % module + \
                              'Error Message:'
                        print '\n%s' % result.stderr
                else:
                    self.log.info('%s enabled.' % module)

        if self.version == 6:
            drupal_vars = {
                'apachesolr_search_make_default': 1,
                'apachesolr_search_spellcheck': 1,
                'cache': '3',
                'block_cache': '1',
                'page_cache_max_age': '900',
                'page_compression': '0',
                'preprocess_js': '1',
                'preprocess_css': '1'
            }

        elif self.version == 7:
            drupal_vars = {
                'cache': 1,
                'block_cache': 1,
                'cache_lifetime': "0",
                'page_cache_maximum_age': "900",
                'page_compression': 0,
                'preprocess_css': 1,
                'preprocess_js': 1,
                'search_active_modules': {
                    'apachesolr_search': 'apachesolr_search',
                    'user': '******',
                    'node': 0
                },
                'search_default_module': 'apachesolr_search'
            }

        # Set variables.
        (db_username, db_password,
         db_name) = pantheon.get_database_vars(self, 'dev')
        db = dbtools.MySQLConn(database=db_name,
                               username=db_username,
                               password=db_password)
        for key, value in drupal_vars.iteritems():
            db.vset(key, value)

        # apachesolr module for drupal 7 stores config in db.
        # TODO: use drush/drupal api to do this work.
        try:
            if self.version == 7:
                db.execute('TRUNCATE apachesolr_environment')
                for env in self.environments:
                    config = self.config['environments'][env]['solr']

                    env_id = '%s_%s' % (self.project, env)
                    name = '%s %s' % (self.project, env)
                    url = 'http://%s:%s%s' % (config['solr_host'],
                                              config['solr_port'],
                                              config['solr_path'])

                    # Populate the solr environments
                    db.execute('INSERT INTO apachesolr_environment ' + \
                        '(env_id, name, url) VALUES ' + \
                        '("%s", "%s", "%s")' % (env_id, name, url))

                    # Populate the solr environment variables
                    db.execute('INSERT INTO apachesolr_environment_variable '+\
                               '(env_id, name, value) VALUES ' + \
                               "('%s','apachesolr_read_only','s:1:\"0\"')" % (
                                                                      env_id))
        except Exception as mysql_error:
            self.log.error(
                'Auto-configuration of ApacheSolr module failed: %s' %
                mysql_error)
            pass

        db.close()

        # D7: apachesolr config link will not display until cache cleared?
        with settings(warn_only=True):
            result = local('drush @working_dir -y cc all')
            pantheon.log_drush_backend(result, self.log)

        # Run updatedb
        drupaltools.updatedb(alias='@working_dir')

        # Remove temporary working_dir drush alias.
        alias_file = '/opt/drush/aliases/working_dir.alias.drushrc.php'
        if os.path.exists(alias_file):
            local('rm -f %s' % alias_file)
Esempio n. 12
0
    def setup_files_dir(self):
        """Move site files to sites/default/files if they are not already.

        This will move the files from their former location, change the file
        path in the database (for all files and the variable itself), then
        create a symlink in their former location.

        """
        file_location = self._get_files_dir()
        if file_location:
            file_path = os.path.join(self.working_dir, file_location)
        else:
            file_path = None
        file_dest = os.path.join(self.working_dir, 'sites/default/files')

        # After moving site to 'default', does 'files' not exist?
        if not os.path.exists(file_dest):
            # Broken symlink at sites/default/files
            if os.path.islink(file_dest):
                local('rm -f %s' % file_dest)
                msg = 'File path was broken symlink. Site files may be missing'
                self.log.info(msg)
                postback.build_warning(msg)
            local('mkdir -p %s' % file_dest)

        # if files are not located in default location, move them there.
        if (file_path) and (file_location != 'sites/%s/files' % self.site):
            with settings(warn_only=True):
                local('cp -R %s/* %s' % (file_path, file_dest))
            local('rm -rf %s' % file_path)
            path = os.path.split(file_path)
            # Symlink from former location to sites/default/files
            if not os.path.islink(path[0]):
                # If parent folder for files path doesn't exist, create it.
                if not os.path.exists(path[0]):
                    local('mkdir -p %s' % path[0])
                rel_path = os.path.relpath(file_dest, path[0])
                local('ln -s %s %s' % (rel_path, file_path))

        # Change paths in the files table
        (db_username, db_password,
         db_name) = pantheon.get_database_vars(self, 'dev')

        if self.version == 6:
            file_var = 'file_directory_path'
            file_var_temp = 'file_directory_temp'
            # Change the base path in files table for Drupal 6
            local('mysql -u root %s -e "UPDATE files SET filepath = \
                   REPLACE(filepath,\'%s\',\'%s\');"' %
                  (db_name, file_location, 'sites/default/files'))
        elif self.version == 7:
            file_var = 'file_public_path'
            file_var_temp = 'file_temporary_path'

        # Change file path drupal variables
        db = dbtools.MySQLConn(database=db_name,
                               username=db_username,
                               password=db_password)
        db.vset(file_var, 'sites/default/files')
        db.vset(file_var_temp, '/tmp')
        db.close()

        # Ignore files directory
        with open(os.path.join(file_dest, '.gitignore'), 'a') as f:
            f.write('*\n')
            f.write('!.gitignore\n')