Ejemplo n.º 1
0
    def _get_drupal_version_info(self):
        """Determine the platform, version, and revision of the imported site.
        Returns tuple of major_version (6 or 7) and the nearest git revision.

        """
        version = drupaltools.get_drupal_version(self.working_dir)
        if not version:
            err = 'Error: This does not appear to be a Drupal 6 site.'
            jenkinstools.junit_fail(err, 'DrupalVersion')
            postback.build_error(err)
        else:
            jenkinstools.junit_pass('Drupal version %s found.' % (version),
                                   'DrupalVersion')

        platform = drupaltools.get_drupal_platform(self.working_dir)

        major_version = int(version[0:1])
        if major_version == 6:
            if platform == 'DRUPAL':
                revision = 'DRUPAL-%s' % version
            elif platform == 'PRESSFLOW' or platform == 'PANTHEON':
                revision = self._get_pressflow_revision(6)
        elif major_version == 7:
            #TODO: Temporary until D7 git setup is finalized.
            if platform == 'DRUPAL':
                # TODO: replace - with . in tags once git repo is finalized.
                revision = version.replace('-','.') # temp hack
            elif platform == 'PRESSFLOW' or platform == 'PANTHEON':
                revision = self._get_pressflow_revision(7)
        return (major_version, revision)
Ejemplo n.º 2
0
    def parse_backup(self, location):
        """ Get project name from extracted backup.

        """
        self.working_dir = location
        self.backup_project = os.listdir(self.working_dir)[0]
        self.version = drupaltools.get_drupal_version(os.path.join(self.working_dir, self.backup_project, "dev"))[0]
Ejemplo n.º 3
0
    def _get_drupal_version_info(self):
        """Determine the platform, version, and revision of the imported site.
        Returns tuple of major_version (6 or 7) and the nearest git revision.

        """
        version = drupaltools.get_drupal_version(self.working_dir)
        if not version:
            err = 'Error: This does not appear to be a Drupal 6 site.'
            jenkinstools.junit_fail(err, 'DrupalVersion')
            postback.build_error(err)
        else:
            jenkinstools.junit_pass('Drupal version %s found.' % (version),
                                    'DrupalVersion')

        platform = drupaltools.get_drupal_platform(self.working_dir)

        major_version = int(version[0:1])
        if major_version == 6:
            if platform == 'DRUPAL':
                revision = 'DRUPAL-%s' % version
            elif platform == 'PRESSFLOW' or platform == 'PANTHEON':
                revision = self._get_pressflow_revision(6)
        elif major_version == 7:
            #TODO: Temporary until D7 git setup is finalized.
            if platform == 'DRUPAL':
                # TODO: replace - with . in tags once git repo is finalized.
                revision = version.replace('-', '.')  # temp hack
            elif platform == 'PRESSFLOW' or platform == 'PANTHEON':
                revision = self._get_pressflow_revision(7)
        return (major_version, revision)
Ejemplo n.º 4
0
    def parse_backup(self, location):
        """ Get project name from extracted backup.

        """
        self.working_dir = location
        self.backup_project = os.listdir(self.working_dir)[0]
        self.version = drupaltools.get_drupal_version(
            os.path.join(self.working_dir, self.backup_project, 'dev'))[0]
Ejemplo n.º 5
0
    def parse_archive(self, extract_location):
        """Get the site name and database dump file from archive to be imported.

        """
        # Find the Drupal installation and set it as the working_dir
        self.working_dir = get_drupal_root(extract_location)

        # Remove existing VCS files.
        with cd(self.working_dir):
            with settings(hide('warnings'), warn_only=True):
                local("find . -depth -name '._*' -exec rm -fr {} \;")
                local("find . -depth -name .git -exec rm -fr {} \;")
                local("find . -depth -name .bzr -exec rm -fr {} \;")
                local("find . -depth -name .svn -exec rm -fr {} \;")
                local("find . -depth -name CVS -exec rm -fr {} \;")
                # Comment any RewriteBase directives in .htaccess
                local("sed -i 's/^[^#]*RewriteBase/# RewriteBase/' .htaccess")

        self.site = self._get_site_name()
        self.db_dump = self._get_database_dump()
        self.version = int(drupaltools.get_drupal_version(self.working_dir)[0])
Ejemplo n.º 6
0
    def parse_archive(self, extract_location):
        """Get the site name and database dump file from archive to be imported.

        """
        # Find the Drupal installation and set it as the working_dir
        self.working_dir = get_drupal_root(extract_location)

        # Remove existing VCS files.
        with cd(self.working_dir):
            with settings(hide('warnings'), warn_only=True):
                local("find . -depth -name '._*' -exec rm -fr {} \;")
                local("find . -depth -name .git -exec rm -fr {} \;")
                local("find . -depth -name .bzr -exec rm -fr {} \;")
                local("find . -depth -name .svn -exec rm -fr {} \;")
                local("find . -depth -name CVS -exec rm -fr {} \;")
                # Comment any RewriteBase directives in .htaccess
                local("sed -i 's/^[^#]*RewriteBase/# RewriteBase/' .htaccess")

        self.site = self._get_site_name()
        self.db_dump = self._get_database_dump()
        self.version = int(drupaltools.get_drupal_version(self.working_dir)[0])
Ejemplo n.º 7
0
 def process_gitsource(self, url):
     self.setup_project_repo(url)
     self.setup_project_branch()
     self.setup_working_dir()
     self.version = int(drupaltools.get_drupal_version(self.working_dir)[:1])
Ejemplo n.º 8
0
 def process_gitsource(self, url):
     self.setup_project_repo(url)
     self.setup_project_branch()
     self.setup_working_dir()
     self.version = int(drupaltools.get_drupal_version(self.working_dir)[:1])
Ejemplo n.º 9
0
    def setup_permissions(self, handler, environment=None):
        """ Set permissions on project directory, settings.php, and files dir.

        handler: one of: 'import','restore','update','install'. How the
        permissions are set is determined by the handler.

        environment: In most cases this is left to None, as we will be
        processing all environments using self.environments. However,
        if handler='update' we need to know the specific environment for which
        the update is being run. We do this so we are not forcing permissions
        updates on files that have not changed.

        """
        # Get  owner
        #TODO: Allow non-getpantheon users to set a default user.
        if os.path.exists("/etc/pantheon/ldapgroup"):
            owner = self.server.get_ldap_group()
        else:
            owner = self.server.web_group

        # During code updates, we only make changes in one environment.
        # Otherwise, we are modifying all environments.
        environments = list()
        if handler == 'update':
            #Single environment during update.
            environments.append(environment)
        else:
            #All environments for install/import/restore.
            environments = self.environments


        """
        Project directory and sub files/directories

        """

        # installs / imports / restores.
        if handler in ['install', 'import', 'restore']:
            # setup shared repo config and set gid
            for env in environments:
                with cd(os.path.join(self.server.webroot, self.project, env)):
                    local('git config core.sharedRepository group')
            with cd(self.server.webroot):
                local('chown -R %s:%s %s' % (owner, owner, self.project))


        """
        Files directory and sub files/directories

        """

        # For installs, just set 770 on files dir.
        if handler == 'install':
            for env in environments:
                site_dir = os.path.join(self.project_path,
                                        env,
                                        'sites/default')
                with cd(site_dir):
                    local('chmod 770 files')
                    local('chown %s:%s files' % (self.server.web_group,
                                                 self.server.web_group))

        # For imports or restores: 770 on files dir (and subdirs). 660 on files
        elif handler in ['import', 'restore']:
            for env in environments:
                file_dir = os.path.join(self.project_path, env,
                                        'sites/default/files')
                with cd(file_dir):
                    local("chmod 770 .")
                    # All sub-files
                    local("find . -type d -exec find '{}' -type f \; | \
                           while read FILE; do chmod 660 \"$FILE\"; done")
                    # All sub-directories
                    local("find . -type d -exec find '{}' -type d \; | \
                          while read DIR; do chmod 770 \"$DIR\"; done")
                    # Apache should own files/*
                    local("chown -R %s:%s ." % (self.server.web_group,
                                                self.server.web_group))

        # For updates, set apache as owner of files dir.
        elif handler == 'update':
            site_dir = os.path.join(self.project_path,
                                    environments[0],
                                    'sites/default')
            with cd(site_dir):
                local('chown %s:%s files' % (self.server.web_group,
                                             self.server.web_group))


        """
        settings.php & pantheon.settings.php

        """

        #TODO: We could split this up based on handler, but changing perms on
        # two files is fast. Ignoring for now, and treating all the same.
        for env in environments:
            if pantheon.is_drupal_installed(self, env):
                # Drupal installed, Apache does not need to own settings.php
                settings_perms = '440'
                settings_owner = owner
                settings_group = self.server.web_group
            else:
                # Drupal is NOT installed. Apache must own settings.php
                settings_perms = '660'
                settings_owner = self.server.web_group
                settings_group = self.server.web_group

            site_dir = os.path.join(self.project_path, env, 'sites/default')
            with cd(site_dir):
                # settings.php
                local('chmod %s settings.php' % settings_perms)
                local('chown %s:%s settings.php' % (settings_owner,
                                                    settings_group))
                # TODO: New sites will not have a pantheon.settings.php in their
                # repos. However, existing backups will, and if the settings
                # file exists, we need it to have correct permissions.
                if os.path.exists(os.path.join(site_dir,
                                               'pantheon.settings.php')):
                    local('chmod 440 pantheon.settings.php')
                    local('chown %s:%s pantheon.settings.php' % (owner,
                                                       settings_group))
        if not self.version:
            self.version = drupaltools.get_drupal_version('%s/dev' %
                                                          self.project_path)[0]
        with cd(self.project_path):
            # pantheon.settings.php
            local('chmod 440 pantheon%s.settings.php' % self.version)
            local('chown %s:%s pantheon%s.settings.php' % (owner,
                                                           settings_group,
                                                           self.version))
Ejemplo n.º 10
0
    def setup_permissions(self, handler, environment=None):
        """ Set permissions on project directory, settings.php, and files dir.

        handler: one of: 'import','restore','update','install'. How the
        permissions are set is determined by the handler.

        environment: In most cases this is left to None, as we will be
        processing all environments using self.environments. However,
        if handler='update' we need to know the specific environment for which
        the update is being run. We do this so we are not forcing permissions
        updates on files that have not changed.

        """
        # Get  owner
        #TODO: Allow non-getpantheon users to set a default user.
        if os.path.exists("/etc/pantheon/ldapgroup"):
            owner = self.server.get_ldap_group()
        else:
            owner = self.server.web_group

        # During code updates, we only make changes in one environment.
        # Otherwise, we are modifying all environments.
        environments = list()
        if handler == 'update':
            #Single environment during update.
            environments.append(environment)
        else:
            #All environments for install/import/restore.
            environments = self.environments
        """
        Project directory and sub files/directories

        """

        # installs / imports / restores.
        if handler in ['install', 'import', 'restore']:
            # setup shared repo config and set gid
            for env in environments:
                with cd(os.path.join(self.server.webroot, self.project, env)):
                    local('git config core.sharedRepository group')
            with cd(self.server.webroot):
                local('chown -R %s:%s %s' % (owner, owner, self.project))
        """
        Files directory and sub files/directories

        """

        # For installs, just set 770 on files dir.
        if handler == 'install':
            for env in environments:
                site_dir = os.path.join(self.project_path, env,
                                        'sites/default')
                with cd(site_dir):
                    local('chmod 770 files')
                    local('chown %s:%s files' %
                          (self.server.web_group, self.server.web_group))

        # For imports or restores: 770 on files dir (and subdirs). 660 on files
        elif handler in ['import', 'restore']:
            for env in environments:
                file_dir = os.path.join(self.project_path, env,
                                        'sites/default/files')
                with cd(file_dir):
                    local("chmod 770 .")
                    # All sub-files
                    local("find . -type d -exec find '{}' -type f \; | \
                           while read FILE; do chmod 660 \"$FILE\"; done")
                    # All sub-directories
                    local("find . -type d -exec find '{}' -type d \; | \
                          while read DIR; do chmod 770 \"$DIR\"; done")
                    # Apache should own files/*
                    local("chown -R %s:%s ." %
                          (self.server.web_group, self.server.web_group))

        # For updates, set apache as owner of files dir.
        elif handler == 'update':
            site_dir = os.path.join(self.project_path, environments[0],
                                    'sites/default')
            with cd(site_dir):
                local('chown %s:%s files' %
                      (self.server.web_group, self.server.web_group))
        """
        settings.php & pantheon.settings.php

        """

        #TODO: We could split this up based on handler, but changing perms on
        # two files is fast. Ignoring for now, and treating all the same.
        for env in environments:
            if pantheon.is_drupal_installed(self, env):
                # Drupal installed, Apache does not need to own settings.php
                settings_perms = '440'
                settings_owner = owner
                settings_group = self.server.web_group
            else:
                # Drupal is NOT installed. Apache must own settings.php
                settings_perms = '660'
                settings_owner = self.server.web_group
                settings_group = self.server.web_group

            site_dir = os.path.join(self.project_path, env, 'sites/default')
            with cd(site_dir):
                # settings.php
                local('chmod %s settings.php' % settings_perms)
                local('chown %s:%s settings.php' %
                      (settings_owner, settings_group))
                # TODO: New sites will not have a pantheon.settings.php in their
                # repos. However, existing backups will, and if the settings
                # file exists, we need it to have correct permissions.
                if os.path.exists(
                        os.path.join(site_dir, 'pantheon.settings.php')):
                    local('chmod 440 pantheon.settings.php')
                    local('chown %s:%s pantheon.settings.php' %
                          (owner, settings_group))
        if not self.version:
            self.version = drupaltools.get_drupal_version('%s/dev' %
                                                          self.project_path)[0]
        with cd(self.project_path):
            # pantheon.settings.php
            local('chmod 440 pantheon%s.settings.php' % self.version)
            local('chown %s:%s pantheon%s.settings.php' %
                  (owner, settings_group, self.version))