Beispiel #1
0
class HgVendor(BackendVendor):
    url = "http://github.com/couchapp/couchapp"
    author = "Benoit Chesneau"
    author_email = "*****@*****.**"
    description = "HG vendor handler"
    long_description = """couchapp vendor install|update from mercurial::
    
    hg://somerepo (repo available via http, use http+ssh:// for ssh repos)
    """

    scheme = ['hg', 'hg+ssh']

    def fetch(self, url, path, *args, **opts):
        """ return git cmd path """
        if url.startswith("hg+ssh://"):
            url = url[8:]
        else:
            url = url.replace("hg://", "http://")
        try:
            cmd = locate_program("hg", raise_error=True)
        except ValueError, e:
            raise VendorError(e)

        cmd += " clone %s %s" % (url, path)

        # exec cmd
        (child_stdin, child_stdout, child_stderr) = popen3(cmd)
        err = child_stderr.read()
        if err:
            raise VendorError(str(err))

        logger.debug(child_stdout.read())
Beispiel #2
0
    def fetch_vendor(self, uri, *args, **opts):
        """ fetch a vendor from uri """

        # get fetch cmd
        vendor_obj = self.find_handler(uri)

        # execute fetch command
        path = _tempdir()
        vendor_obj.fetch(uri, path, *args, **opts)

        vendors = []
        for name in os.listdir(path):
            vpath = os.path.join(path, name)
            metaf = os.path.join(vpath, "metadata.json")
            if not os.path.isfile(metaf):
                continue
            else:
                meta = util.read_json(metaf)
                meta["fetch_uri"] = uri
                name = meta.get('name', name)
                vendors.append((name, vpath, meta))
                os.unlink(metaf)

        if not vendors:
            util.deltree(path)
            raise VendorError("Invalid vendor, medata not found.")

        return vendors, path
Beispiel #3
0
class GitVendor(BackendVendor):
    url = "http://github.com/couchapp/couchapp"
    author = "Benoit Chesneau"
    author_email = "*****@*****.**"
    description = "Git vendor handler"
    long_description = """couchapp vendor install|update from git::

    git://somerepo.git (use git+ssh:// for ssh repos)
    """

    scheme = ['git', 'git+ssh']

    def fetch(self, url, path, *args, **opts):
        if url.startswith("git+ssh://"):
            url = url[9:]
        """ return git cmd path """
        try:
            cmd = locate_program("git", raise_error=True)
        except ValueError, e:
            raise VendorError(e)

        cmd += " clone %s %s" % (url, path)

        # exec cmd
        (child_stdin, child_stdout, child_stderr) = popen3(cmd)
        err = child_stderr.read()
        if err:
            raise VendorError(str(err))
        logger.debug(child_stdout.read())
Beispiel #4
0
 def fetch(self, url, path, *args, **opts):
     if url.startswith("git+ssh://"):
         url = url[9:]
     """ return git cmd path """
     try:
         cmd = locate_program("git", raise_error=True)
     except ValueError, e:
         raise VendorError(e)
Beispiel #5
0
 def fetch(self, url, path, *args, **opts):
     """ return git cmd path """
     if url.startswith("hg+ssh://"):
         url = url[8:]
     else:
         url = url.replace("hg://", "http://")
     try:
         cmd = locate_program("hg", raise_error=True)
     except ValueError, e:
         raise VendorError(e)
Beispiel #6
0
    def fetch(self, url, path, *args, **opts):
        if url.startswith("couchdb://"):
            url = url.replace("couchdb://", "http://")
        else:
            url = url.replace("couchdbs://", "https://")

        try:
            dburl, docid = url.split('_design/')
        except ValueError:
            raise VendorError("%s isn't a valid source" % url)
        dest = os.path.join(path, docid)
        clone(url, dest=dest)
        rcfile = os.path.join(dest, ".couchapprc")
        try:
            os.unlink(rcfile)
        except:
            pass
Beispiel #7
0
 def find_handler(self, uri):
     scheme = uri.split("://")[0]
     if scheme in self.scheme:
         return self.scheme[scheme]
     else:
         raise VendorError("unkonw vendor url scheme: %s" % uri)
Beispiel #8
0
    def update(self, appdir, name=None, *args, **opts):
        should_force = opts.get('force', False)
        vendordir = os.path.join(appdir, "vendor")
        if not os.path.isdir(vendordir):
            os.makedirs(vendordir)

        if name is not None:
            if name not in self.installed_vendors(vendordir):
                raise VendorError("vendor `%s` doesn't exist" % name)
            dest = os.path.join(vendordir, name)
            metaf = os.path.join(dest, "metadata.json")
            meta = util.read_json(metaf)
            uri = meta.get("fetch_uri", "")
            if not uri:
                raise VendorError(
                    "Can't update vendor `%s`: fetch_uri undefined." % name)
            new_vendors, temppath = self.fetch_vendor(uri, *args, **opts)
            for vname, vpath, vmeta in new_vendors:
                if name != vname:
                    continue
                else:
                    util.deltree(dest)
                    shutil.copytree(vpath, dest)
                    util.write_json(metaf, vmeta)
                    logger.info("%s updated in vendors" % vname)
                    break

            util.deltree(temppath)
        else:  # update all vendors
            updated = []
            for vendor in self.installed_vendors(vendordir):
                if vendor in updated:
                    continue
                else:
                    dest = os.path.join(vendordir, vendor)
                    metaf = os.path.join(dest, "metadata.json")
                    meta = util.read_json(metaf)
                    uri = meta.get("fetch_uri", "")
                    if not uri:
                        logger.warning(
                            "Can't update vendor `%s`: fetch_uri undefined." %
                            vendor)
                        continue
                    else:
                        new_vendors, temppath = self.fetch_vendor(
                            uri, *args, **opts)
                        for vname, vpath, vmeta in new_vendors:
                            dest1 = os.path.join(vendordir, vname)
                            metaf1 = os.path.join(dest1, "metadata.json")
                            if os.path.exists(dest1):
                                util.deltree(dest1)
                                shutil.copytree(vpath, dest1)
                                util.write_json(metaf1, vmeta)
                                logger.info("%s updated in vendors" % vname)
                                updated.append(vname)
                            elif should_force:
                                #install forced
                                shutil.copytree(vpath, dest1)
                                util.write_json(metaf1, vmeta)
                                logger.info("%s installed in vendors" % vname)
                                updated.append(vname)
                        util.deltree(temppath)
        return 0