def get_updated_versions(force_refresh=False): """ Get the full version numbers of versions avaliable at php.net. Args: force_refresh - (optional) When set to True, do not use cached values """ vers = [] cache_dir = settings.get('install_path') + 'var/cache/' cache_file = cache_dir + 'php-versions' use_cache = force_refresh == False if os.path.exists(cache_file): max_age = settings.get_num('build_cache_age') mod_time = os.stat(cache_file).st_mtime age = time.time() - mod_time if age > max_age: use_cache = False else: if not os.path.exists(cache_dir): os.makedirs(cache_dir) use_cache = False if use_cache: return file_filter.get_trimmed_file_as_array(cache_file) else: request = requests.get('https://www.php.net/downloads.php') regex = re.compile(r'.*/distributions/php-([0-9\.]*)\.tar\.bz2.*') for line in request.text.splitlines(): match = regex.match(line) if match == None: continue match = match.group(1) if len(match) > 0: vers.append(match) if settings.get_bool('enable_php_legacy_versions'): vers.append(php71version) vers.append(php70version) vers.append(php56version) if settings.get_bool('enable_php_super_legacy_versions'): vers.append(php55version) vers.append(php54version) vers.append(php53version) vers.append(php52version) vers.append(php51version) vers.append(php50version) vers.append(php44version) vers.append(php43version) vers.append(php42version) vers.append(php41version) vers.append(php40version) vers.append(php30version) if settings.get_bool('enable_php_prerelease_version'): vers.extend(get_prerelease_version(vers)) with open(cache_file, 'w+') as cache_write: for v in vers: cache_write.write(v + "\n") return vers
def source_dir(self): full_version = self.source_version if settings.get_bool('enable_php_prerelease_version'): if '.a.' in full_version: full_version = full_version.replace('.a.', 'alpha') if '.b.' in full_version: full_version = full_version.replace('.b.', 'beta') if '.r.' in full_version: full_version = full_version.replace('.r.', 'rc') if '.R.' in full_version: full_version = full_version.replace('.R.', 'RC') return self.build_dir + 'php-' + full_version + '/'
def get_connection(): """ Cet a connected MySQL connection. """ root_needs_pass = settings.get_bool('db_root_requires_password') socket = settings.get('mysql_socket') if (root_needs_pass): bitpass = getpass('Enter the MySQL root password: '******'root', passwd=bitpass) else: return connector.connect(unix_socket=socket, user='******')
def deploy_environment(log): """ Configure the system linker to use the new copy of openssl if the setting 'deploy_openssl' is set to True. Args: log - An open log to write to """ if settings.get_bool('deploy_openssl'): filename = '/etc/ld.so.conf.d/openssl.conf' log.log('Making sure ' + filename + ' exists') ld_filter = file_filter.AppendUnique(filename, libs_path()) ld_filter.run() subprocess.run(['ldconfig'])
def install(self, log): """ Install the software to the system. Args: log - An open log file or null """ old_pwd = os.getcwd() target_dir = self.source_dir() if os.path.exists(target_dir): os.chdir(target_dir) log.run(['make', 'install']) if not settings.get_bool('build_server'): self.clean(log) os.chdir(old_pwd)
def build(self): """ Download or update the source code, compile it and then install it. """ logfile = self.log_name() success = False old_pwd = os.getcwd() logdir = os.path.dirname(logfile) if not os.path.exists(logdir): os.makedirs(logdir) with open(logfile, 'w+') as open_log: log = logger.Log(open_log) log.log("Build started for " + self.slug + " at " + str(datetime.datetime.now())) source_url = self.get_source_url() if not is_frozen(self.slug): log.log('Fetching ' + source_url) self.fetch_source(source_url, log) os.chdir(self.source_dir()) log.log("Running pre-config") self.run_pre_config(log) log.log("Getting config arguments") command = self.populate_config_args(log) if len(command) > 0: log.log("Running configuration") if debug: log.log('CONFIG: ' + ' '.join(command)) log.run(command) log.log("Running make") make_ret_val = self.make(log) if make_ret_val != 0: # if not success log.log(self.slug + ' make command failed. Exiting.') else: log.log("Installing") self.install(log) log.log("Build completed for " + self.slug + " at " + str(datetime.datetime.now())) success = self.check_build() self.cleanup_old_versions(log) os.chdir(old_pwd) if not success: email.send_admin_logfile('Build failed for ' + self.slug, logfile) elif settings.get_bool('email_admin_on_build_success'): email.send_admin_log_clip('Build succeeded for ' + self.slug, logfile) return success, logfile
def get_source_url(self): full_version = self.versions['full'] source = 'https://www.php.net/distributions/php-' + full_version + '.tar.bz2' if settings.get_bool('enable_php_prerelease_version'): prerelease_username = get_prerelease_user() if '.a.' in full_version: source = 'https://downloads.php.net/~' + prerelease_username + '/php-' + full_version.replace( '.a.', 'alpha') + '.tar.bz2' if '.b.' in full_version: source = 'https://downloads.php.net/~' + prerelease_username + '/php-' + full_version.replace( '.b.', 'beta') + '.tar.bz2' if '.r.' in full_version: source = 'https://downloads.php.net/~' + prerelease_username + '/php-' + full_version.replace( '.r.', 'rc') + '.tar.bz2' if '.R.' in full_version: source = 'https://downloads.php.net/~' + prerelease_username + '/php-' + full_version.replace( '.R.', 'RC') + '.tar.bz2' return source