diff options
| author | Richo Healey <richo@psych0tik.net> | 2015-01-27 00:22:24 -0800 |
|---|---|---|
| committer | Richo Healey <richo@psych0tik.net> | 2015-01-27 01:26:02 -0800 |
| commit | ab0081ae45f959fbf15cc532f8e2f4fa5192c4c5 (patch) | |
| tree | 4b6bc8a7c80fbd2851f831d1a9bb1750c57b2338 | |
| parent | 58d03ad95d2f02a693869faa1081091d6999cd93 (diff) | |
| download | rust-ab0081ae45f959fbf15cc532f8e2f4fa5192c4c5.tar.gz rust-ab0081ae45f959fbf15cc532f8e2f4fa5192c4c5.zip | |
Fix PEP8 in snapshot.py
| -rwxr-xr-x | src/etc/get-snapshot.py | 10 | ||||
| -rw-r--r-- | src/etc/mklldeps.py | 3 | ||||
| -rw-r--r-- | src/etc/snapshot.py | 285 |
3 files changed, 161 insertions, 137 deletions
diff --git a/src/etc/get-snapshot.py b/src/etc/get-snapshot.py index 432c6b24946..26246bd2c32 100755 --- a/src/etc/get-snapshot.py +++ b/src/etc/get-snapshot.py @@ -10,9 +10,13 @@ # option. This file may not be copied, modified, or distributed # except according to those terms. -import os, tarfile, re, shutil, sys +import os +import tarfile +import shutil +import sys from snapshot import * + def unpack_snapshot(triple, dl_path): print("opening snapshot " + dl_path) tar = tarfile.open(dl_path) @@ -29,14 +33,14 @@ def unpack_snapshot(triple, dl_path): os.unlink(os.path.join(root, f)) for p in tar.getnames(): - name = p.replace("rust-stage0/", "", 1); + name = p.replace("rust-stage0/", "", 1) fp = os.path.join(stagep, name) print("extracting " + p) tar.extract(p, download_unpack_base) tp = os.path.join(download_unpack_base, p) if os.path.isdir(tp) and os.path.exists(fp): - continue + continue shutil.move(tp, fp) tar.close() shutil.rmtree(download_unpack_base) diff --git a/src/etc/mklldeps.py b/src/etc/mklldeps.py index 834ba074c62..a4234159cb8 100644 --- a/src/etc/mklldeps.py +++ b/src/etc/mklldeps.py @@ -11,8 +11,6 @@ import os import sys import subprocess -import itertools -from os import path f = open(sys.argv[1], 'wb') @@ -35,6 +33,7 @@ f.write("""// Copyright 2013 The Rust Project Developers. See the COPYRIGHT // take a look at src/etc/mklldeps.py if you're interested """) + def run(args): proc = subprocess.Popen(args, stdout=subprocess.PIPE, stderr=subprocess.PIPE) out, err = proc.communicate() diff --git a/src/etc/snapshot.py b/src/etc/snapshot.py index 8f45f7f1af2..698c3a551e2 100644 --- a/src/etc/snapshot.py +++ b/src/etc/snapshot.py @@ -8,24 +8,32 @@ # option. This file may not be copied, modified, or distributed # except according to those terms. -import re, os, sys, glob, tarfile, shutil, subprocess, tempfile, distutils.spawn +import re +import os +import sys +import glob +import tarfile +import shutil +import subprocess +import distutils.spawn try: - import hashlib - sha_func = hashlib.sha1 + import hashlib + sha_func = hashlib.sha1 except ImportError: - import sha - sha_func = sha.new + import sha + sha_func = sha.new + def scrub(b): - if sys.version_info >= (3,) and type(b) == bytes: - return b.decode('ascii') - else: - return b + if sys.version_info >= (3,) and type(b) == bytes: + return b.decode('ascii') + else: + return b src_dir = scrub(os.getenv("CFG_SRC_DIR")) if not src_dir: - raise Exception("missing env var CFG_SRC_DIR") + raise Exception("missing env var CFG_SRC_DIR") snapshotfile = os.path.join(src_dir, "src", "snapshots.txt") download_url_base = "https://static.rust-lang.org/stage0-snapshots" @@ -33,54 +41,57 @@ download_dir_base = "dl" download_unpack_base = os.path.join(download_dir_base, "unpack") snapshot_files = { - "linux": ["bin/rustc"], - "macos": ["bin/rustc"], - "winnt": ["bin/rustc.exe"], - "freebsd": ["bin/rustc"], - "dragonfly": ["bin/rustc"], - } - -winnt_runtime_deps_32 = ["libgcc_s_dw2-1.dll", - "libstdc++-6.dll"] -winnt_runtime_deps_64 = ["libgcc_s_seh-1.dll", - "libstdc++-6.dll"] + "linux": ["bin/rustc"], + "macos": ["bin/rustc"], + "winnt": ["bin/rustc.exe"], + "freebsd": ["bin/rustc"], + "dragonfly": ["bin/rustc"], + } + +winnt_runtime_deps_32 = ["libgcc_s_dw2-1.dll", "libstdc++-6.dll"] +winnt_runtime_deps_64 = ["libgcc_s_seh-1.dll", "libstdc++-6.dll"] + def parse_line(n, line): - global snapshotfile + global snapshotfile - if re.match(r"\s*$", line): return None + if re.match(r"\s*$", line): + return None - if re.match(r"^T\s*$", line): return None + if re.match(r"^T\s*$", line): + return None - match = re.match(r"\s+([\w_-]+) ([a-fA-F\d]{40})\s*$", line) - if match: - return { "type": "file", - "platform": match.group(1), - "hash": match.group(2).lower() } + match = re.match(r"\s+([\w_-]+) ([a-fA-F\d]{40})\s*$", line) + if match: + return {"type": "file", + "platform": match.group(1), + "hash": match.group(2).lower()} - match = re.match(r"([ST]) (\d{4}-\d{2}-\d{2}) ([a-fA-F\d]+)\s*$", line); - if (not match): - raise Exception("%s:%d:E syntax error: " % (snapshotfile, n)) - return {"type": "snapshot", - "date": match.group(2), - "rev": match.group(3)} + match = re.match(r"([ST]) (\d{4}-\d{2}-\d{2}) ([a-fA-F\d]+)\s*$", line) + if not match: + raise Exception("%s:%d:E syntax error: " % (snapshotfile, n)) + return {"type": "snapshot", + "date": match.group(2), + "rev": match.group(3)} def partial_snapshot_name(date, rev, platform): - return ("rust-stage0-%s-%s-%s.tar.bz2" - % (date, rev, platform)) + return ("rust-stage0-%s-%s-%s.tar.bz2" % + (date, rev, platform)) + def full_snapshot_name(date, rev, platform, hsh): - return ("rust-stage0-%s-%s-%s-%s.tar.bz2" - % (date, rev, platform, hsh)) + return ("rust-stage0-%s-%s-%s-%s.tar.bz2" % + (date, rev, platform, hsh)) def get_kernel(triple): t = triple.split('-') if len(t) == 2: - os_name = t[1] + os_name = t[1] else: - os_name = t[2] + os_name = t[2] + if os_name == "windows": return "winnt" if os_name == "darwin": @@ -91,19 +102,20 @@ def get_kernel(triple): return "dragonfly" return "linux" + def get_cpu(triple): arch = triple.split('-')[0] if arch == "i686": - return "i386" + return "i386" return arch + def get_platform(triple): - return "%s-%s" % (get_kernel(triple), get_cpu(triple)) + return "%s-%s" % (get_kernel(triple), get_cpu(triple)) def cmd_out(cmdline): - p = subprocess.Popen(cmdline, - stdout=subprocess.PIPE) + p = subprocess.Popen(cmdline, stdout=subprocess.PIPE) return scrub(p.communicate()[0].strip()) @@ -124,7 +136,8 @@ def local_rev_short_sha(): def local_rev_committer_date(): return local_rev_info("ci") -def get_url_to_file(u,f): + +def get_url_to_file(u, f): # no security issue, just to stop partial download leaving a stale file tmpf = f + '.tmp' @@ -137,40 +150,44 @@ def get_url_to_file(u,f): if returncode != 0: try: os.unlink(tmpf) - except OSError as e: + except OSError: pass raise Exception("failed to fetch url") os.rename(tmpf, f) + def snap_filename_hash_part(snap): - match = re.match(r".*([a-fA-F\d]{40}).tar.bz2$", snap) - if not match: - raise Exception("unable to find hash in filename: " + snap) - return match.group(1) + match = re.match(r".*([a-fA-F\d]{40}).tar.bz2$", snap) + if not match: + raise Exception("unable to find hash in filename: " + snap) + return match.group(1) + def hash_file(x): h = sha_func() h.update(open(x, "rb").read()) return scrub(h.hexdigest()) -# Returns a list of paths of Rust's system runtime dependencies + def get_winnt_runtime_deps(platform): + """Returns a list of paths of Rust's system runtime dependencies""" if platform == "winnt-x86_64": - deps = winnt_runtime_deps_64 + deps = winnt_runtime_deps_64 else: - deps = winnt_runtime_deps_32 + deps = winnt_runtime_deps_32 runtime_deps = [] path_dirs = os.environ["PATH"].split(os.pathsep) for name in deps: - for dir in path_dirs: - filepath = os.path.join(dir, name) - if os.path.isfile(filepath): - runtime_deps.append(filepath) - break - else: - raise Exception("Could not find runtime dependency: %s" % name) + for dir in path_dirs: + filepath = os.path.join(dir, name) + if os.path.isfile(filepath): + runtime_deps.append(filepath) + break + else: + raise Exception("Could not find runtime dependency: %s" % name) return runtime_deps + def make_snapshot(stage, triple): kernel = get_kernel(triple) platform = get_platform(triple) @@ -180,31 +197,31 @@ def make_snapshot(stage, triple): file0 = partial_snapshot_name(date, rev, platform) def in_tar_name(fn): - cs = re.split(r"[\\/]", fn) - if len(cs) >= 2: - return os.sep.join(cs[-2:]) + cs = re.split(r"[\\/]", fn) + if len(cs) >= 2: + return os.sep.join(cs[-2:]) tar = tarfile.open(file0, "w:bz2") for name in snapshot_files[kernel]: - dir = stage - if stage == "stage1" and re.match(r"^lib/(lib)?std.*", name): - dir = "stage0" - fn_glob = os.path.join(triple, dir, name) - matches = glob.glob(fn_glob) - if not matches: - raise Exception("Not found file with name like " + fn_glob) - if len(matches) == 1: - tar.add(matches[0], "rust-stage0/" + in_tar_name(matches[0])) - else: - raise Exception("Found stale files: \n %s\n" - "Please make a clean build." % "\n ".join(matches)) - - if kernel=="winnt": - for path in get_winnt_runtime_deps(platform): - tar.add(path, "rust-stage0/bin/" + os.path.basename(path)) - tar.add(os.path.join(os.path.dirname(__file__), "third-party"), - "rust-stage0/bin/third-party") + dir = stage + if stage == "stage1" and re.match(r"^lib/(lib)?std.*", name): + dir = "stage0" + fn_glob = os.path.join(triple, dir, name) + matches = glob.glob(fn_glob) + if not matches: + raise Exception("Not found file with name like " + fn_glob) + if len(matches) == 1: + tar.add(matches[0], "rust-stage0/" + in_tar_name(matches[0])) + else: + raise Exception("Found stale files: \n %s\n" + "Please make a clean build." % "\n ".join(matches)) + + if kernel == "winnt": + for path in get_winnt_runtime_deps(platform): + tar.add(path, "rust-stage0/bin/" + os.path.basename(path)) + tar.add(os.path.join(os.path.dirname(__file__), "third-party"), + "rust-stage0/bin/third-party") tar.close() @@ -215,60 +232,64 @@ def make_snapshot(stage, triple): return file1 + def curr_snapshot_rev(): - i = 0 - found_snap = False - date = None - rev = None + i = 0 + found_snap = False + date = None + rev = None + + f = open(snapshotfile) + for line in f.readlines(): + i += 1 + parsed = parse_line(i, line) + if not parsed: + continue - f = open(snapshotfile) - for line in f.readlines(): - i += 1 - parsed = parse_line(i, line) - if (not parsed): continue + if parsed["type"] == "snapshot": + date = parsed["date"] + rev = parsed["rev"] + found_snap = True + break - if parsed["type"] == "snapshot": - date = parsed["date"] - rev = parsed["rev"] - found_snap = True - break + if not found_snap: + raise Exception("no snapshot entries in file") - if not found_snap: - raise Exception("no snapshot entries in file") + return (date, rev) - return (date, rev) def determine_curr_snapshot(triple): - i = 0 - platform = get_platform(triple) - - found_file = False - found_snap = False - hsh = None - date = None - rev = None - - f = open(snapshotfile) - for line in f.readlines(): - i += 1 - parsed = parse_line(i, line) - if (not parsed): continue - - if found_snap and parsed["type"] == "file": - if parsed["platform"] == platform: - hsh = parsed["hash"] - found_file = True - break; - elif parsed["type"] == "snapshot": - date = parsed["date"] - rev = parsed["rev"] - found_snap = True - - if not found_snap: - raise Exception("no snapshot entries in file") - - if not found_file: - raise Exception("no snapshot file found for platform %s, rev %s" % - (platform, rev)) - - return full_snapshot_name(date, rev, platform, hsh) + i = 0 + platform = get_platform(triple) + + found_file = False + found_snap = False + hsh = None + date = None + rev = None + + f = open(snapshotfile) + for line in f.readlines(): + i += 1 + parsed = parse_line(i, line) + if not parsed: + continue + + if found_snap and parsed["type"] == "file": + if parsed["platform"] == platform: + hsh = parsed["hash"] + found_file = True + break + elif parsed["type"] == "snapshot": + date = parsed["date"] + rev = parsed["rev"] + found_snap = True + + if not found_snap: + raise Exception("no snapshot entries in file") + + if not found_file: + raise Exception("no snapshot file found for platform %s, rev %s" % + (platform, rev)) + + return full_snapshot_name(date, rev, platform, hsh) |
