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)
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)
def _get_site_name(self): """Return the name of the site to be imported. A valid site is any directory under sites/ that contains a settings.php """ root = os.path.join(self.working_dir, 'sites') sites =[s for s in os.listdir(root) \ if os.path.isdir(os.path.join(root,s)) and ( 'settings.php' in os.listdir(os.path.join(root,s)))] # Unless only one site is found, post error and exit. site_count = len(sites) if site_count > 1: err = 'Multiple settings.php files were found:\n' + \ '\n'.join(sites) jenkinstools.junit_fail(err, 'SiteCount') postback.build_error(err) elif site_count == 0: err = 'Error: No settings.php files were found.' jenkinstools.junit_fail(err, 'SiteCount') postback.build_error(err) else: jenkinstools.junit_pass('Site found.', 'SiteCount') return sites[0]
def _get_site_name(self): """Return the name of the site to be imported. A valid site is any directory under sites/ that contains a settings.php """ root = os.path.join(self.working_dir, 'sites') sites =[s for s in os.listdir(root) \ if os.path.isdir(os.path.join(root,s)) and ( 'settings.php' in os.listdir(os.path.join(root,s)))] # Unless only one site is found, post error and exit. site_count = len(sites) if site_count > 1: err = 'Multiple settings.php files were found:\n' + \ '\n'.join(sites) self.log.error(err) postback.build_error(err) elif site_count == 0: err = 'Error: No settings.php files were found.' self.log.error(err) postback.build_error(err) else: self.log.info('Site found.') return sites[0]
def get_drupal_root(base): """Return the location of drupal root within 'base' dir tree. """ for root, dirs, files in os.walk(base, topdown=True): if ('index.php' in files) and ('sites' in dirs): jenkinstools.junit_pass('Drupal root found.', 'DrupalRoot') return root err = 'Cannot locate drupal install in archive.' jenkinstools.junit_fail(err, 'DrupalRoot') postback.build_error(err)
def get_drupal_root(base): """Return the location of drupal root within 'base' dir tree. """ log = logger.logging.getLogger('pantheon.onramp.drupalroot') for root, dirs, files in os.walk(base, topdown=True): if ('index.php' in files) and ('sites' in dirs): log.info('Drupal root found.') return root log.error('Cannot locate drupal install in archive.') postback.build_error('Cannot locate drupal install in archive.')
def _get_archive_type(self): """Return the generic type of archive (tar/zip). """ if tarfile.is_tarfile(self.path): self.log.info("Tar archive found.") return "tar" elif zipfile.is_zipfile(self.path): self.log.info("Zip archive found.") return "zip" else: err = "Error: Not a valid tar/zip archive." self.log.error(err) postback.build_error(err)
def _get_archive_type(self): """Return the generic type of archive (tar/zip). """ if tarfile.is_tarfile(self.path): self.log.info('Tar archive found.') return 'tar' elif zipfile.is_zipfile(self.path): self.log.info('Zip archive found.') return 'zip' else: err = 'Error: Not a valid tar/zip archive.' self.log.error(err) postback.build_error(err)
def _get_archive_type(self): """Return the generic type of archive (tar/zip). """ if tarfile.is_tarfile(self.path): jenkinstools.junit_pass('Tar found.','ArchiveType') return 'tar' elif zipfile.is_zipfile(self.path): jenkinstools.junit_pass('Zip found.','ArchiveType') return 'zip' else: err = 'Error: Not a valid tar/zip archive.' jenkinstools.junit_fail(err,'ArchiveType') postback.build_error(err)
def _get_database_dump(self): """Return the filename of the database dump. This will look for *.mysql or *.sql files in the root drupal directory. If more than one dump is found, the build will exit with an error. """ sql_dump = [dump for dump in os.listdir(self.working_dir) \ if os.path.splitext(dump)[1] in ['.sql', '.mysql']] count = len(sql_dump) if count == 0: err = 'No database dump files were found (*.mysql or *.sql)' postback.build_error(err) elif count > 1: err = 'Multiple database dump files were found:\n' + \ '\n'.join(sql_dump) postback.build_error(err) else: return sql_dump[0]
def _get_database_dump(self): """Return the filename of the database dump. This will look for *.mysql or *.sql files in the root drupal directory. If more than one dump is found, the build will exit with an error. """ sql_dump = [dump for dump in os.listdir(self.working_dir) \ if os.path.splitext(dump)[1] in ['.sql', '.mysql']] count = len(sql_dump) if count == 0: err = 'No database dump files were found (*.mysql or *.sql)' self.log.error(err) postback.build_error(err) elif count > 1: err = 'Multiple database dump files were found:\n' + \ '\n'.join(sql_dump) self.log.error(err) postback.build_error(err) else: self.log.info('MYSQL Dump found at %s' % sql_dump[0]) return sql_dump[0]