def download_and_compile(self):
def _progress_hook(count, block_size, total_size):<EOL><INDENT>if total_size < <NUM_LIT:0>:<EOL><INDENT>sys.stdout.write("<STR_LIT>" % local_file)<EOL><DEDENT>else:<EOL><INDENT>percentage = count * block_size * <NUM_LIT> / total_size<EOL>percentage = min(percentage, <NUM_LIT>)<EOL>sys.stdout.write("<STR_LIT>" % (local_file, percentage))<EOL><DEDENT>sys.stdout.flush()<EOL><DEDENT>if self.remote_url is None:<EOL><INDENT>self.version, remote_url = self.find_first_version()<EOL>if not self.version:<EOL><INDENT>print("<STR_LIT>"<EOL>"<STR_LIT>" % self.versions_to_try[<NUM_LIT:0>])<EOL>print("<STR_LIT>")<EOL>print("<STR_LIT>")<EOL>return False<EOL><DEDENT>local_file = "<STR_LIT>" % self.version<EOL><DEDENT>else:<EOL><INDENT>remote_url = self.remote_url<EOL>local_file = remote_url.rsplit("<STR_LIT:/>", <NUM_LIT:1>)[<NUM_LIT:1>]<EOL><DEDENT>local_file_full_path = os.path.join(self.tmpdir, local_file)<EOL>if self.show_progress_bar:<EOL><INDENT>urlretrieve(remote_url, local_file_full_path, reporthook=_progress_hook)<EOL>print("<STR_LIT>")<EOL><DEDENT>else:<EOL><INDENT>print("<STR_LIT>" % local_file)<EOL>urlretrieve(remote_url, local_file_full_path)<EOL><DEDENT>print("<STR_LIT>" % local_file)<EOL>archive = tarfile.open(local_file_full_path, "<STR_LIT>")<EOL>archive.extractall(self.tmpdir)<EOL>self.builddir = None<EOL>for name in os.listdir(self.tmpdir):<EOL><INDENT>full_path = os.path.join(self.tmpdir, name)<EOL>if name.startswith("<STR_LIT>") and os.path.isdir(full_path):<EOL><INDENT>self.builddir = full_path<EOL>break<EOL><DEDENT><DEDENT>if not self.builddir:<EOL><INDENT>print("<STR_LIT>"<EOL>"<STR_LIT>")<EOL>return False<EOL><DEDENT>cwd = os.getcwd()<EOL>try:<EOL><INDENT>print("<STR_LIT>")<EOL>os.chdir(self.builddir)<EOL>retcode = subprocess.call("<STR_LIT>",<EOL>shell=True)<EOL>if retcode:<EOL><INDENT>return False<EOL><DEDENT>retcode = subprocess.call("<STR_LIT>", shell=True)<EOL>if retcode:<EOL><INDENT>return False<EOL><DEDENT>libraries = []<EOL>for line in open(os.path.join(self.builddir, "<STR_LIT>")):<EOL><INDENT>if line.startswith("<STR_LIT>") or line.startswith("<STR_LIT>"):<EOL><INDENT>words = line.strip().split()<EOL>libraries.extend(word[<NUM_LIT:2>:] for word in words if word.startswith("<STR_LIT>"))<EOL><DEDENT><DEDENT>if not libraries:<EOL><INDENT>libraries = ["<STR_LIT>"]<EOL><DEDENT><DEDENT>finally:<EOL><INDENT>os.chdir(cwd)<EOL><DEDENT>create_dir_unless_exists("<STR_LIT>")<EOL>ensure_dir_does_not_exist("<STR_LIT>", "<STR_LIT>")<EOL>ensure_dir_does_not_exist("<STR_LIT>", "<STR_LIT>")<EOL>shutil.copytree(os.path.join(self.builddir, "<STR_LIT>"),<EOL>os.path.join("<STR_LIT>", "<STR_LIT>"))<EOL>shutil.copytree(os.path.join(self.builddir, "<STR_LIT:src>", "<STR_LIT>"),<EOL>os.path.join("<STR_LIT>", "<STR_LIT>"))<EOL>f = open(os.path.join("<STR_LIT>", "<STR_LIT>"), "<STR_LIT:w>")<EOL>f.write(repr(libraries))<EOL>f.close()<EOL>return True<EOL>
Downloads and compiles the C core of igraph.