def check_git_revision(state: State) -> R: sh_result = _check_sh([ (f"git clone https://github.com/apache/{state.git_repo_name} " f"{state.git_dir}"), (f"git --work-tree {state.git_dir} " f"--git-dir {state.git_dir}/.git " f"checkout --quiet {state.git_hash}"), ]) if sh_result is not None: return sh_result logging.info("NOTE: The following diff output is only informational.") logging.info("NOTE: The actual verification is done in Python.") sh(f"diff --recursive {state.git_dir} {state.source_dir}") diff = filecmp.dircmp(state.git_dir, state.source_dir, ignore=[]) errors: List[str] = [] # First, check that any files appearing in only one tree are allowed errors += _check_dircmp_only_either_allowed(diff) # Then make sure that all files that exist in both places have no diff errors += _check_dircmp_no_diff_files(diff) # And finally that there we could compare all the files errors += _check_dircmp_no_funny_files(diff) if errors: errors.append("See above for a full output of diff.") return "\n".join(errors), ResultKind.WARN return None
def _database_exists(): try: sh('mysql', '-u', db.user, '--password=%s' % db.password, '-e', 'use %s' % db.name) except subprocess.CalledProcessError: return False return True
def _database_exists(hostname = None): try: args = ['mysql', '-u', db.user, '--password=%s' % db.password, '-e', 'use %s' % db.name] if hostname != None: args.extend(["--host", hostname]) sh(*args) except subprocess.CalledProcessError: return False return True
def setup_db(): if _database_exists(): print 'Database already exists, no need for me to create it.' else: username = raw_input("Enter your mysql user name (default: root): ") or "root" sql = "CREATE DATABASE IF NOT EXISTS %(name)s " \ "DEFAULT CHARACTER SET utf8 DEFAULT COLLATE utf8_bin; " \ "GRANT ALL ON %(name)s.* TO '%(user)s' IDENTIFIED BY '%(password)s';" % db.__dict__ print "Now you will be prompted for the password that goes with that mysql account" sh('mysql', '-u', username, '-p', '-f', '-e', sql) print "Created database %s" % db.name _sync()
def check_gitignore_in_release(state: State) -> R: result = _check_sh( f"find . -name .gitignore | xargs cp --parents -t {state.source_dir}", workdir=state.git_dir, ) if not result: result = _check_sh( [ "git init --quiet && git add .", "shopt -s globstar; ! git check-ignore **", ], workdir=state.source_dir, ) sh(f"rm -rf {state.source_dir}/.git") sh(f"find {state.source_dir} -name .gitignore -delete") return result
def fetch_project(base_url: str, module: Optional[str], version: str, incubating: bool) -> None: step("Downloading release") version_root = f"{base_url}/" if module: version_root += f"{module}/" version_root += version cut_dirs = 3 if module: cut_dirs += 1 if incubating: cut_dirs += 1 sh("wget --recursive --no-parent --reject index.html " f"--no-verbose --user-agent='{USER_AGENT}' " f"--no-host-directories --cut-dirs={cut_dirs} {version_root}")
def _backup(path): print "Backing up database to %s" % path sql = sh('mysqldump', db.name, '--user=%s' % db.user, '--password=%s' % db.password, '--add-drop-table', '--add-drop-database') with open(path, 'w') as f: f.write(sql)
def setup_db(username = None, password = None, hostname = None): if _database_exists(hostname): print 'Database already exists, no need for me to create it.' else: if username == None: username = raw_input("Enter your mysql user name (default: root): ") or "root" sql = "CREATE DATABASE IF NOT EXISTS %(name)s " \ "DEFAULT CHARACTER SET utf8 DEFAULT COLLATE utf8_bin; " \ "GRANT ALL ON %(name)s.* TO '%(user)s' IDENTIFIED BY '%(password)s';" % db.__dict__ args = ['mysql', '-u', username, '-f', '-e', sql] if password == None: print "Now you will be prompted for the password that goes with that mysql account" args += "-p" else: args.append("--password=%s"%password) if hostname != None: args.extend(["--host", hostname]) sh(*args) print "Created database %s" % db.name _sync()
def _check_sh( cmds: Union[str, List[str]], workdir: Optional[str] = None, failure_level=ResultKind.FAIL, ) -> R: if isinstance(cmds, str): cmds = [cmds] for cmd in cmds: status = sh(cmd, workdir) if status != 0: msg = f"Executing `{cmd}`" if workdir is not None: msg += f" in {workdir}" msg += f" exited with non-zero status code {status}. " msg += "See above for output. (Note that the command was run under " msg += "`set -euo pipefail`)" return msg, failure_level return None
def fetch_keys(base_url: str) -> None: step("Downloading KEYS file") sh(f"wget --no-verbose --user-agent='{USER_AGENT}' {base_url}/KEYS")
def apache(action): print "Apache: %s" % action sh('/etc/init.d/apache2', action)
def setup_apache(): print "Ensuring apache is installed wth mod_wsgi and mod_headers" sh('apt-get', 'install', '-y', 'apache2', 'libapache2-mod-wsgi') sh('a2enmod', 'headers')
def _sync(): print "Running syncdb and migrate" sh('python', 'src/manage.py', 'syncdb', '--noinput') sh('python', 'src/manage.py', 'migrate')