コード例 #1
0
ファイル: basebox.py プロジェクト: jwal/jwallib-retired
def main(argv):
    parser = optparse.OptionParser(__doc__)
    parser.add_option("--tear-down", dest="tear_down_dir")
    parser.add_option("--show-config", dest="do_show_config",
                      action="store_const", const=True, default=False)
    parser.add_option("--show-ssh-cmd", dest="do_show_ssh_cmd",
                      action="store_const", const=True, default=False)
    parser.allow_interspersed_args = False
    options, args = parser.parse_args(argv)
    if len(args) == 0:
        args = ["bash"]
    if options.tear_down_dir is not None:
        force_rm(options.tear_down_dir)
        return
    config_path = find_config_path(on_not_found=parser.error)
    config = json.loads(read_file(config_path))
    config.setdefault("project_path", os.path.dirname(config_path))
    config.setdefault("cwd", os.path.abspath("."))
    config.setdefault("home", os.path.abspath(os.path.expanduser("~")))
    expand_config(config)
    if options.do_show_config:
        print json.dumps(config, indent=2, sort_keys=True)
        return
    if options.do_show_ssh_cmd:
        ssh_argv = get_ssh_argv(config)
        print "~~~", " ".join(shell_escape(a) for a in ssh_argv)
        return
    basebox(config, args)
コード例 #2
0
 def test(self):
     golden = read_file(
         os.path.join(os.path.dirname(os.path.abspath(__file__)),
                      "aptconfig_golden.txt"))
     config = aptconfig.DEFAULT_CONFIG
     config.update({"distribution": "lucid"})
     actual = aptconfig.render_to_sources_list(config)
     self.assertEqual(actual, golden)
コード例 #3
0
ファイル: ubuntu_to_hg.py プロジェクト: jwal/jwallib-retired
def ubuntu_to_hg(hg_path, username, do_development=False):

    def hg(argv, **kwargs):
        kwargs.setdefault("cwd", hg_path)
        kwargs.setdefault("do_print", True)
        prefix = ["hg"]
        if username is not None and argv[0] in ("commit", "ci"):
            prefix.extend(["--config", "ui.username=%s" % (username,)])
        return call(prefix + argv, **kwargs)

    with with_ubuntu_keyring() as gpg:
        meta_release_data = get(
            join(BASE_URL, "meta-release-development")).content
        meta_release = parse_control_file(meta_release_data)
        group_by(meta_release, lambda r: r["dist"])
        if not os.path.exists(hg_path):
            os.makedirs(hg_path)
            hg(["init"])
        branches = set([a.split()[0] for a in read_lines(hg(["branches"]))])
        ok_branches = set()
        seen_supported_non_lts = False
        for release in meta_release:
            branch = "ubuntu_codename_%s" % (release["dist"],)
            is_lts = "LTS" in release["version"]
            is_supported = release["supported"] == "1"
            if is_supported and not is_lts:
                seen_supported_non_lts = True
            is_development = not is_supported and seen_supported_non_lts
            if not is_supported and not is_development:
                continue
            ok_branches.add(branch)
            if is_development and not do_development:
                continue
            done = set()
            if branch not in branches:
                hg(["update", "--clean", "--rev", "00"])
                hg(["branch", "--force", branch])
            else:
                hg(["update", "--clean", branch])
            hg(["--config", "extensions.purge=", "purge", "--all"])
            release_gpg_path = os.path.join(hg_path, "Release.gpg")
            release_path = os.path.join(hg_path, "Release")
            old_sha1sums = {}
            release_gpg_data = get(release["release-file"] + ".gpg").content
            if os.path.exists(release_gpg_path):
                if release_gpg_data == read_file(release_gpg_path):
                    continue
                release_data = read_file(release_path)
                old_sha1sums = get_release_sha1sums(release_data)
                old_sha1sums["Release"] = hashlib.sha1(
                    release_data).hexdigest()
                old_sha1sums["Release.gpg"] = hashlib.sha1(
                    release_gpg_data).hexdigest()
                # for relpath in sorted(old_sha1sums):
                #     if posixpath.dirname(relpath) == "Index":
                #         index_data = read_file(os.path.join(hg_path, relpath))
                #         child_sha1sums = get_release_sha1sums(index_data)
                #         for relpath2 in sorted(child_sha1sums):
                #             relpath3 = posixpath.join(
                #                 posixpath.dirname(relpath), relpath2)
                #             old_sha1sums[relpath3] = child_sha1sums[relpath2]
            release_data = get(release["release-file"]).content
            with open(release_gpg_path, "wb") as fh:
                fh.write(release_gpg_data)
            done.add("Release")
            with open(release_path, "wb") as fh:
                fh.write(release_data)
            done.add("Release.gpg")
            gpg(["--verify", release_gpg_path, release_path])
            new_sha1sums = get_release_sha1sums(release_data)
            new_sha1sums["Release.gpg"] = hashlib.sha1(
                release_gpg_data).hexdigest()
            new_sha1sums["Release"] = hashlib.sha1(
                release_data).hexdigest()
            # for relpath in sorted(new_sha1sums):
            #     if posixpath.basename(relpath) == "Index":
            #         if new_sha1sums[relpath] == old_sha1sums.get(relpath):
            #             index_data = read_file(os.path.join(hg_path, relpath))
            #         else:
            #             index_data = get(
            #                 posixpath.join(
            #                     posixpath.dirname(release["Release-File"]),
            #                     relpath)).content
            #             sha1sum = hashlib.sha1(index_data).hexdigest()
            #             if sha1sum != new_sha1sums[relpath]:
            #                 raise Exception("sha1sum mismatch for %r: "
            #                                 "got %s expecting %s"
            #                                 % (url, sha1sum, 
            #                                    new_sha1sums[relpath]))
            #             index_path = os.path.join(hg_path, relpath)
            #             if not os.path.exists(os.path.dirname(index_path)):
            #                 os.makedirs(os.path.dirname(index_path))
            #             with open(index_path, "wb") as fh:
            #                 fh.write(index_data)
            #         done.add(relpath)
            #         child_sha1sums = get_release_sha1sums(index_data)
            #         for relpath2 in sorted(child_sha1sums):
            #             relpath3 = posixpath.join(
            #                 posixpath.dirname(relpath), relpath2)
            #             new_sha1sums[relpath3] = child_sha1sums[relpath2]
            for relpath in old_sha1sums:
                if relpath in new_sha1sums:
                    continue
                file_path = os.path.join(hg_path, relpath)
                call(["rm", "-rf", "--one-file-system", file_path])
            for relpath in new_sha1sums:
                if relpath in old_sha1sums:
                    if new_sha1sums[relpath] == old_sha1sums[relpath]:
                        continue
                if (relpath.endswith(".gz") 
                        and trim(relpath, suffix=".gz") in new_sha1sums):
                    continue
                if (relpath.endswith(".bz2") 
                        and trim(relpath, suffix=".bz2") in new_sha1sums):
                    continue
                if relpath in done:
                    continue
                file_path = os.path.join(hg_path, relpath)
                file_data = get_release_file(
                    posixpath.join(
                        posixpath.dirname(release["release-file"]), relpath))
                sha1sum = hashlib.sha1(file_data).hexdigest()
                if sha1sum != new_sha1sums[relpath]:
                    raise Exception("sha1sum mismatch for %r: "
                                    "got %s expecting %s"
                                    % (url, sha1sum, new_sha1sums[relpath]))
                if not os.path.exists(os.path.dirname(file_path)):
                    os.makedirs(os.path.dirname(file_path))
                with open(file_path, "wb") as fh:
                    fh.write(file_data)
            hg(["addremove"])
            if len(read_lines(hg(["status"]))) > 0:
                hg(["commit", "-m", "Update from upstream"])
        for branch in branches:
            if branch == "default" or branch in ok_branches:
                continue
            hg(["update", "--clean", branch])
            hg(["commit", "--close-branch", 
                "-m", "Closing unsupported release"])