Пример #1
0
    def install(self):
        installed = [self.ensure_dir(self.options['location'])]
        self.configure_password()
        # Use the egg recipe to make sure we have the right eggs available
        # and activate the eggs in the `global` working set.
        egg = zc.recipe.egg.Egg(self.buildout, self.name, self.options)
        distributions, ws = egg.working_set()
        for dist in ws:
            pkg_resources.working_set.add(dist)

        # CAUTION: self.conn is everywhere expected to be a psycopg2 connection
        self.conn = psycopg2.connect(self.dsn)

        table_names = self.get_table_names()
        has_generation_table = GENERATION_TABLE in table_names
        if has_generation_table:
            table_names.remove(GENERATION_TABLE)
            current_generation = self.get_current_generation()
            assert table_names, "No application tables found."
            self.update_schema(current_generation)
        else:
            if table_names:
                self.install_generation_table()
                self.update_schema(0)
            else:
                assert pkg_resources.resource_exists(self.schema, 'init.sql'),\
                    'Initial generation script init.sql not found.'
                ret_code = self.call_psql(
                    pkg_resources.resource_filename(self.schema, 'init.sql'))

                assert ret_code == 0, 'Initial generation failed.'
                self.install_generation_table()
                self.update_generation(self.get_newest_generation())
        return installed
Пример #2
0
 def getVersions(self):
     versions = {}
     for part, recipe, options in self.getAllRecipes():
         egg = zc.recipe.egg.Egg(self.buildout, recipe, options)
         spec, entry = _recipe({'recipe':recipe})
         req = pkg_resources.Requirement.parse(spec)
         dist = pkg_resources.working_set.find(req)
         if "collective.hostout" in spec:
             continue #HACK
         requirements, ws = egg.working_set()
         for dist in [dist] + [d for d in ws]:
             old_version,dep = versions.get(dist.project_name,('',[]))
             if recipe not in dep:
                 dep.append(recipe)
             if dist.version != '0.0':
                 versions[dist.project_name] = (dist.version,dep)
     spec = ""
     return versions
Пример #3
0
 def getVersions(self):
     versions = {}
     for part, recipe, options in self.getAllRecipes():
         egg = zc.recipe.egg.Egg(self.buildout, recipe, options)
         spec, entry = _recipe({'recipe':recipe})
         req = pkg_resources.Requirement.parse(spec)
         recipeegg = pkg_resources.working_set.find(req)
         if "collective.hostout" in spec:
             continue #HACK
         requirements, ws = egg.working_set()
         if recipeegg is None:
             raise Exception ("Could not find version info for recipe %s (%s)" % (spec, part))
         for dist in [recipeegg] + [d for d in ws]:
             if dist is None:
                 raise Exception ("Could not find version info for a dependency of recipe %s" % spec)
             old_version,dep = versions.get(dist.project_name,('',[]))
             #if recipe not in dep:
             #    dep.append(recipe)
             if dist.version != '0.0':
                 versions[dist.project_name] = (dist.version,dep)
     spec = ""
     return versions
Пример #4
0
    def install(self):
        """Let's build vscode settings file:
        This is the method will be called by buildout it-self and this recipe
        will generate or/update vscode setting file (.vscode/settings.json) based
        on provided options.
        """

        if self.options.get("eggs"):
            # Need working set for all eggs and zc.recipe.egg also
            parts = [
                (self.name, self.options["recipe"], self.options),
                ("dummy", "zc.recipe.egg", {}),
            ]
        else:
            parts = []
            # get the parts including those not explicity in parts
            # TODO: is there a way without a private method?
            installed_part_options, _ = self.buildout._read_installed_part_options()
            for part, options in installed_part_options.items():
                if options is None or not options.get("recipe", None):
                    continue
                recipe = options["recipe"]
                if ":" in recipe:
                    recipe, _ = recipe.split(":")
                parts.append((part, recipe, options))

        eggs_locations = set()
        develop_eggs_locations = set()
        develop_eggs = os.listdir(self.buildout["buildout"]["develop-eggs-directory"])
        develop_eggs = [dev_egg[:-9] for dev_egg in develop_eggs]

        for part, recipe, options in parts:
            egg = zc.recipe.egg.Egg(self.buildout, recipe, options)
            try:
                _, ws = egg.working_set()
            except Exception as exc:  # noqa: B902
                raise UserError(str(exc))

            for dist in ws.by_key.values():

                project_name = dist.project_name
                if project_name not in self.ignored_eggs:
                    eggs_locations.add(dist.location)
                if project_name in develop_eggs:
                    develop_eggs_locations.add(dist.location)

            for package in self.packages:
                eggs_locations.add(package)

        try:
            with io.open(
                os.path.join(self.settings_dir, "settings.json"), "r", encoding="utf-8"
            ) as fp:
                json_text = fp.read()
                existing_settings = json.loads(json_text)

        except ValueError as e:
            raise UserError(str(e))
        except IOError:
            existing_settings = dict()

        vscode_settings = self._prepare_settings(
            list(eggs_locations), list(develop_eggs_locations), existing_settings
        )

        self._write_project_file(vscode_settings, existing_settings)

        # Write json file values only those are generated by this recipe.
        # Also dodges (by giving fake like file) buildout to
        # remove original settings.json file.
        vs_generated_file = os.path.join(
            self.settings_dir, "vs-recipe-generated-settings.json"
        )
        with io.open(vs_generated_file, "w", encoding="utf-8") as fp:
            json_text = json.dumps(vscode_settings, indent=2, sort_keys=True)
            fp.write(ensure_unicode(json_text))

        return vs_generated_file
Пример #5
0
 def rws(self):
     egg = zc.recipe.egg.Egg(
         self.buildout, self.options['recipe'], self.options
     )
     return egg.working_set(self.eggs)