Exemplo n.º 1
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, metadata not found.")

        return vendors, path
Exemplo n.º 2
0
 def tearDown(self):
     try:
         self.db.delete()
     except:
         pass
     deltree(self.tempdir)
     os.chdir(self.startdir)
Exemplo n.º 3
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
Exemplo n.º 4
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
Exemplo n.º 5
0
    def testClone(self):
        self._make_testapp()
        child_stdout, child_stderr = sh_open("{0} push -v my-app {1}couchapp-test".format(self.cmd, url))

        design_doc = self._retrieve_ddoc()

        app_dir = os.path.join(self.tempdir, "couchapp-test")

        child_stdout, child_stderr = sh_open(
            "{0} clone {1} {2}".format(self.cmd, url + "couchapp-test/_design/my-app", app_dir)
        )

        # should create .couchapprc
        self.assertTrue(os.path.isfile(os.path.join(app_dir, ".couchapprc")))

        # should clone the views
        self.assertTrue(os.path.isdir(os.path.join(app_dir, "views")))

        # should create foo/bar.txt file
        self.assertTrue(os.path.isfile(os.path.join(app_dir, "foo/bar.txt")))

        # should create lib/helpers/math.js file
        self.assertTrue(os.path.isfile(os.path.join(app_dir, "lib/helpers/math.js")))

        # should work when design doc is edited manually
        design_doc["test.txt"] = "essai"

        design_doc = self.db.save_doc(design_doc)

        deltree(app_dir)
        child_stdout, child_stderr = sh_open(
            "{0} clone {1} {2}".format(self.cmd, url + "couchapp-test/_design/my-app", app_dir)
        )
        self.assertTrue(os.path.isfile(os.path.join(app_dir, "test.txt")))

        # should work when a view is added manually
        design_doc["views"]["more"] = {"map": "function(doc) { emit(null, doc); }"}

        design_doc = self.db.save_doc(design_doc)

        deltree(app_dir)
        child_stdout, child_stderr = sh_open(
            "{0} clone {1} {2}".format(self.cmd, url + "couchapp-test/_design/my-app", app_dir)
        )
        self.assertTrue(os.path.isfile(os.path.join(app_dir, "views/example/map.js")))

        # should work without manifest
        del design_doc["couchapp"]["manifest"]
        design_doc = self.db.save_doc(design_doc)
        deltree(app_dir)
        child_stdout, child_stderr = sh_open(
            "{0} clone {1} {2}".format(self.cmd, url + "couchapp-test/_design/my-app", app_dir)
        )
        self.assertTrue(os.path.isfile(os.path.join(app_dir, "views/example/map.js")))

        # should create foo/bar without manifest
        self.assertTrue(os.path.isfile(os.path.join(app_dir, "foo/bar")))

        # should create lib/helpers.json without manifest
        self.assertTrue(os.path.isfile(os.path.join(app_dir, "lib/helpers.json")))
Exemplo n.º 6
0
    def install(self, appdir, uri, *args, **opts):
        """ install a vendor in the couchapp dir.
        """
        should_force = opts.get('force', False)
        vendordir = os.path.join(appdir, "vendor")
        if not os.path.isdir(vendordir):
            os.makedirs(vendordir)

        new_vendors, temppath = self.fetch_vendor(uri, *args, **opts)
        for name, path, meta in new_vendors:
            dest = os.path.join(vendordir, name)
            metaf = os.path.join(dest, "metadata.json")
            if os.path.isdir(dest):
                if should_force:
                    util.deltree(dest)
                else:
                    logger.warning("vendor: %s already installed" % name)
                    continue
            shutil.copytree(path, dest)
            util.write_json(metaf, meta)
            logger.info("%s installed in vendors" % name)
        util.deltree(temppath)
        return 0
Exemplo n.º 7
0
    def install(self, appdir,  uri, *args, **opts):
        """ install a vendor in the couchapp dir.
        """
        should_force = opts.get('force', False)
        vendordir = os.path.join(appdir, "vendor")
        if not os.path.isdir(vendordir):
            os.makedirs(vendordir)

        new_vendors, temppath = self.fetch_vendor(uri, *args, **opts)
        for name, path, meta in new_vendors:
            dest = os.path.join(vendordir, name)
            metaf = os.path.join(dest, "metadata.json")
            if os.path.isdir(dest):
                if should_force:
                    util.deltree(dest)
                else:
                    logger.warning("vendor: %s already installed" % name)
                    continue
            shutil.copytree(path, dest)
            util.write_json(metaf, meta)
            logger.info("%s installed in vendors" % name)
        util.deltree(temppath)
        return 0
Exemplo n.º 8
0
 def testClone(self):
     self._make_testapp()
     (child_stdin, child_stdout, child_stderr) = popen3("%s push -v my-app couchapp-test" % self.cmd)
             
     design_doc = self.db.open_doc('_design/my-app')
     
     app_dir =  os.path.join(self.tempdir, "couchapp-test")
     
     (child_stdin, child_stdout, child_stderr) = popen3("%s clone %s %s" % (
                 self.cmd, "http://127.0.0.1:5984/couchapp-test/_design/my-app",
                 app_dir))
                 
     # should create .couchapprc
     self.assert_(os.path.isfile(os.path.join(app_dir, ".couchapprc")))
      
      
     # should clone the views
     self.assert_(os.path.isdir(os.path.join(app_dir, "views")))
     
     # should create foo/bar.txt file
     self.assert_(os.path.isfile(os.path.join(app_dir, 'foo/bar.txt')))
     
     # should create lib/helpers/math.js file
     self.assert_(os.path.isfile(os.path.join(app_dir, 'lib/helpers/math.js')))
     
     # should work when design doc is edited manually
     design_doc['test.txt'] = "essai"
     
     design_doc = self.db.save_doc(design_doc)
             
     deltree(app_dir)
     (child_stdin, child_stdout, child_stderr) = popen3("%s clone %s %s" % (self.cmd, 
                 "http://127.0.0.1:5984/couchapp-test/_design/my-app",
                 app_dir))
     self.assert_(os.path.isfile(os.path.join(app_dir, 'test.txt')))
     
     # should work when a view is added manually
     design_doc["views"]["more"] = { "map": "function(doc) { emit(null, doc); }" }
     
     design_doc = self.db.save_doc(design_doc)        
     
     deltree(app_dir)
     (child_stdin, child_stdout, child_stderr) = popen3("%s clone %s %s" % (
                 self.cmd, "http://127.0.0.1:5984/couchapp-test/_design/my-app",
                 app_dir))
     self.assert_(os.path.isfile(os.path.join(app_dir, 'views/example/map.js')))
     
     # should work without manifest
     del design_doc['couchapp']['manifest']
     design_doc = self.db.save_doc(design_doc)   
     deltree(app_dir)
     (child_stdin, child_stdout, child_stderr) = popen3("%s clone %s %s" % (
                 self.cmd, "http://127.0.0.1:5984/couchapp-test/_design/my-app",
                 app_dir))
     self.assert_(os.path.isfile(os.path.join(app_dir, 'views/example/map.js')))
     
     # should create foo/bar without manifest
     self.assert_(os.path.isfile(os.path.join(app_dir, 'foo/bar')))
     
     # should create lib/helpers.json without manifest
     self.assert_(os.path.isfile(os.path.join(app_dir, 'lib/helpers.json')))
Exemplo n.º 9
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
Exemplo n.º 10
0
 def tearDown(self):
     self.db.delete()
     deltree(self.tempdir)
     os.chdir(self.startdir)
Exemplo n.º 11
0
    def testClone(self):
        self._make_testapp()
        (child_stdin, child_stdout,
         child_stderr) = popen3("%s push -v my-app couchapp-test" % self.cmd)

        design_doc = self.db.open_doc('_design/my-app')

        app_dir = os.path.join(self.tempdir, "couchapp-test")

        (child_stdin, child_stdout, child_stderr) = popen3(
            "%s clone %s %s" %
            (self.cmd, "http://127.0.0.1:5984/couchapp-test/_design/my-app",
             app_dir))

        # should create .couchapprc
        self.assert_(os.path.isfile(os.path.join(app_dir, ".couchapprc")))

        # should clone the views
        self.assert_(os.path.isdir(os.path.join(app_dir, "views")))

        # should create foo/bar.txt file
        self.assert_(os.path.isfile(os.path.join(app_dir, 'foo/bar.txt')))

        # should create lib/helpers/math.js file
        self.assert_(
            os.path.isfile(os.path.join(app_dir, 'lib/helpers/math.js')))

        # should work when design doc is edited manually
        design_doc['test.txt'] = "essai"

        design_doc = self.db.save_doc(design_doc)

        deltree(app_dir)
        (child_stdin, child_stdout, child_stderr) = popen3(
            "%s clone %s %s" %
            (self.cmd, "http://127.0.0.1:5984/couchapp-test/_design/my-app",
             app_dir))
        self.assert_(os.path.isfile(os.path.join(app_dir, 'test.txt')))

        # should work when a view is added manually
        design_doc["views"]["more"] = {
            "map": "function(doc) { emit(null, doc); }"
        }

        design_doc = self.db.save_doc(design_doc)

        deltree(app_dir)
        (child_stdin, child_stdout, child_stderr) = popen3(
            "%s clone %s %s" %
            (self.cmd, "http://127.0.0.1:5984/couchapp-test/_design/my-app",
             app_dir))
        self.assert_(
            os.path.isfile(os.path.join(app_dir, 'views/example/map.js')))

        # should work without manifest
        del design_doc['couchapp']['manifest']
        design_doc = self.db.save_doc(design_doc)
        deltree(app_dir)
        (child_stdin, child_stdout, child_stderr) = popen3(
            "%s clone %s %s" %
            (self.cmd, "http://127.0.0.1:5984/couchapp-test/_design/my-app",
             app_dir))
        self.assert_(
            os.path.isfile(os.path.join(app_dir, 'views/example/map.js')))

        # should create foo/bar without manifest
        self.assert_(os.path.isfile(os.path.join(app_dir, 'foo/bar')))

        # should create lib/helpers.json without manifest
        self.assert_(os.path.isfile(os.path.join(app_dir, 'lib/helpers.json')))
Exemplo n.º 12
0
 def tearDown(self):
     self.db.delete()
     deltree(self.tempdir)
     os.chdir(self.startdir)
Exemplo n.º 13
0
    def testClone(self):
        self._make_testapp()
        child_stdout, child_stderr = sh_open(
            '{0} push -v my-app {1}couchapp-test'.format(self.cmd, url))

        design_doc = self._retrieve_ddoc()

        app_dir = os.path.join(self.tempdir, "couchapp-test")

        child_stdout, child_stderr = sh_open('{0} clone {1} {2}'.format(
            self.cmd, url + 'couchapp-test/_design/my-app', app_dir))

        # should create .couchapprc
        self.assertTrue(os.path.isfile(os.path.join(app_dir, ".couchapprc")))

        # should clone the views
        self.assertTrue(os.path.isdir(os.path.join(app_dir, "views")))

        # should create foo/bar.txt file
        self.assertTrue(os.path.isfile(os.path.join(app_dir, 'foo/bar.txt')))

        # should create lib/helpers/math.js file
        self.assertTrue(
            os.path.isfile(os.path.join(app_dir, 'lib/helpers/math.js')))

        # should work when design doc is edited manually
        design_doc['test.txt'] = "essai"

        design_doc = self.db.save_doc(design_doc)

        deltree(app_dir)
        child_stdout, child_stderr = sh_open('{0} clone {1} {2}'.format(
            self.cmd, url + 'couchapp-test/_design/my-app', app_dir))
        self.assertTrue(os.path.isfile(os.path.join(app_dir, 'test.txt')))

        # should work when a view is added manually
        design_doc["views"]["more"] = {
            "map": "function(doc) { emit(null, doc); }"
        }

        design_doc = self.db.save_doc(design_doc)

        deltree(app_dir)
        child_stdout, child_stderr = sh_open('{0} clone {1} {2}'.format(
            self.cmd, url + 'couchapp-test/_design/my-app', app_dir))
        self.assertTrue(
            os.path.isfile(os.path.join(app_dir, 'views/example/map.js')))

        # should work without manifest
        del design_doc['couchapp']['manifest']
        design_doc = self.db.save_doc(design_doc)
        deltree(app_dir)
        child_stdout, child_stderr = sh_open('{0} clone {1} {2}'.format(
            self.cmd, url + 'couchapp-test/_design/my-app', app_dir))
        self.assertTrue(
            os.path.isfile(os.path.join(app_dir, 'views/example/map.js')))

        # should create foo/bar without manifest
        self.assertTrue(os.path.isfile(os.path.join(app_dir, 'foo/bar')))

        # should create lib/helpers.json without manifest
        self.assertTrue(
            os.path.isfile(os.path.join(app_dir, 'lib/helpers.json')))