Example #1
0
 def install_requirements(self, requirement_files):
     if requirement_files:
         utils.vagrant_pip_clear()
         old_packages = utils.vagrant_pip_freeze()
         for requirement_file in requirement_files:
             out = utils.vagrant_pip_install(requirement_file, True)
         new_packages = utils.vagrant_pip_freeze()
         diff_packages = list(set(new_packages) - set(old_packages))
         return diff_packages
     else:
         return []
Example #2
0
    def tryDeploy(self, attempt, manage_file, setting_file):
        self.rewrite_settings(setting_file)
        LOG.info('Settings appended')
        self.killServer()

        self.installed_requirements = []
        self.packages_from_database = []

        packages = self.install_requirements(self.requirement_files)
        for package in packages:
            name, version = package.split('==')
            pkg, created = Package.objects.get_or_create(name=name, version=version, project_type=self.repo.project_type)
            self.installed_requirements.append(pkg)
        ## FOR
        LOG.info('INSTALLED_REQUIREMENTS: ' + str(self.installed_requirements))

        threshold = 10
        last_missing_module_name = ''
        index = 0
        #candidate_packages = []
        for tmp in range(threshold):
            out = self.syncServer(manage_file)
            LOG.info('SYNCDB OUTPUT: ' + out) 
            out = out.strip()
            out = out.splitlines()
            if out and out[-1].strip().startswith('ImportError'):
                line = out[-1].strip()
                match = re.search('(?<=No module named )\S+', line)
                if match:
                    missing_module_name = match.group(0)
                    LOG.info('missing module: ' + missing_module_name) 
                    if missing_module_name == last_missing_module_name:
                        index = index + 1
                        if index == len(candidate_packages):
                            LOG.info('no more possible package')
                            return ATTEMPT_STATUS_MISSING_DEPENDENCIES
                        out = utils.vagrant_pip_install([candidate_packages[index]], False)
                        LOG.info('pip install output: ' + out)
                    else:
                        if last_missing_module_name != '':
                            self.packages_from_database.append(candidate_packages[index])
                        candidate_package_ids = Module.objects.filter(name=missing_module_name).values_list('package_id', flat=True)
                        if not candidate_package_ids:
                            LOG.info('no possible package')
                            return ATTEMPT_STATUS_MISSING_DEPENDENCIES
                        last_missing_module_name = missing_module_name
                        #packages_from_file = [pkg for pkg in packages_from_file if pkg.id not in pckage_ids]
                        candidate_packages = Package.objects.filter(id__in=candidate_package_ids).order_by('-count', 'name', '-version')
                        LOG.info('candidate packages: ' + str(candidate_packages))
                        index = 0
                        out = utils.vagrant_pip_install([candidate_packages[0]], False)
                        LOG.info('pip install output: ' + out)
                else:
                    return ATTEMPT_STATUS_MISSING_DEPENDENCIES
            else:
                if last_missing_module_name != '':
                    self.packages_from_database.append(candidate_packages[index])
                break
        
        # Fire away!
        out = self.runServer(manage_file)
        LOG.info(out)