Beispiel #1
0
def command_uninstall(name):
    """Delete files writen in meta-info."""
    info = get_record(name)
    if not info:
        print >>sys.stderr, "%s is not installed" % name
        return
    home = get_vimhome()
    for f in info["files"]:
        f = os.path.join(home, f)
        if os.path.exists(f):
            os.remove(f)
            remove_empty_dir(os.path.dirname(f))
    delete_record(name)
Beispiel #2
0
def command_install(name):
    """Install from remote."""
    if isinstance(name, dict):
        info = name
        name = info["name"]

    if name.startswith("git!"):
        url = name[4:]
        name = urlparse(url).path.split("/").pop()
        info = {
            "name": name,
            "url": url,
            "author": "unknown",
            "description": "%s via %s" % (name, url),
            "version": "unknown",
            "packer": "unknown",
            "requires": "unknown",
            "extractor": "git",
            "installer": "",
        }
    elif name.startswith("svn!"):
        url = name[4:]
        name = urlparse(url).path.split("/").pop()
        info = {
            "name": name,
            "url": url,
            "author": "unknown",
            "description": "%s via %s" % (name, url),
            "version": "unknown",
            "packer": "unknown",
            "requires": "unknown",
            "extractor": "svn",
            "installer": "",
        }
    elif name.startswith("http://"):
        name = urlparse(url).path.split("/").pop()
        info = {
            "name": name,
            "url": url,
            "author": "unknown",
            "description": "%s via %s" % (name, url),
            "version": "unknown",
            "packer": "unknown",
            "requires": "unknown",
            "extractor": "",
            "installer": "",
        }
    else:
        info = get_joltinfo(name)
    if not info:
        print >>sys.stderr, name + ": Jolt not found"
        return

    tmpdir = tempfile.mkdtemp()
    olddir = os.getcwd()
    try:
        os.chdir(tmpdir)

        if info["extractor"] == "git":
            os.system("git clone --depth=1 %s %s" % (info["url"], tmpdir))

            def handle_remove_readonly(func, path, exc):
                """Remove error handler. change file permission and retry delete."""
                excvalue = exc[1]
                if func in (os.rmdir, os.remove):
                    os.chmod(path, stat.S_IRWXU| stat.S_IRWXG| stat.S_IRWXO)
                    func(path)
                else:
                    raise
            shutil.rmtree(os.path.join(tmpdir, ".git"), ignore_errors=False, onerror=handle_remove_readonly)
            # TODO: fix behavior when it's not general vim's runtime path structure.
        elif info["extractor"] == "svn":
            os.system("svn export %s %s" % (info["url"], tmpdir))
        else:
            f = urllib2.urlopen(info["url"])
            filename = f.info()["Content-Disposition"].split("filename=")[1]
            with open(filename, "wb") as f:
                f.write(r.read())

            if filename.endswith(".vba"):
                extract_vba(tmpdir, filename)
                os.remove(filename)
            elif filename.endswith(".vba.gz"):
                with open(filename[:-3], "wb") as f:
                    with gzip.open(filename) as gz:
                        f.write(gz.read())
                os.remove(filename)
                filename = filename[:-3]
                extract_vba(tmpdir, filename)
                os.remove(filename)
            elif filename.endswith(".tar.gz") or filename.endswith(".tar.bz2"):
                extract_tar_gz(tmpdir, filename)
                os.remove(filename)
            elif filename.endswith(".zip"):
                extract_zip(tmpdir, filename)
                os.remove(filename)
            elif info["installer"] in ["plugin", "ftplugin", "syntax", "colors", "doc", "indent", "dict"]:
                os.makedirs(os.path.join(tmpdir, info["installer"]))
                shutil.move(filename, os.path.join(tmpdir, info["installer"], filename))
            elif info["installer"] == "custom":
                invoke_custom_installer(tmpdir, info)

        copy_tree(tmpdir, get_vimhome(), tmpdir)
        filelist = []
        for root, subdirs, files in os.walk(tmpdir):
            for f in files:
                filelist.append(re.sub("\\\\", "/", os.path.relpath(os.path.join(root, f), tmpdir)))
        info["files"] = filelist

        add_record(name, info)

    except RuntimeError, e:
        print >>sys.stderr, "Exception occured in %s" % tmpdir
        traceback.print_exc()