Пример #1
0
def read_sources(confpath, part):
    """Return the list of sources the buildout configuration file is about.

    in the zc.buildout version I'm writing this against, introspection
    of the resolved conf (with all extend etc applied is quite easy.
    This used to be a lot more complicated (leading to creation of
    ``anybox.hosting.buildout`` to read it from outside the process space),
    or I missed the point entirely. TODO determine what's the minimal
    version for which this works.
    """
    buildout = Buildout(confpath, {})
    # this will not resolve extra requirements, such as (currently the only
    # one) bzr. But we don't really need the latter. Actually we are better
    # off with our FakeLaunchpadDirectory
    recipe = arobase.BaseRecipe(buildout, part, buildout[part])
    for target, (loc_type, loc, options) in recipe.sources.iteritems():
        if target is arobase.main_software:
            target = recipe.openerp_dir
        # vcs package is imported into aro.base
        vcs_cls = arobase.vcs.SUPPORTED.get(loc_type)
        if vcs_cls is None:  # probably not a VCS location at all
            continue
        url, rev = loc
        target = fix_standalone_magic(vcs_cls, target)
        repo = vcs_cls(target, url, options)
        if repo.buildbot_to_watch(rev):
            yield loc_type, url, rev
Пример #2
0
    def __call__(self, *args, **kwargs):
        logger.setLevel(logging.INFO)
        ch = logging.StreamHandler()
        ch.setFormatter(logging.Formatter("%(levelname)s: %(message)s"))
        logger.addHandler(ch)
        self.parser = ArgumentParser()
        version = pkg_resources.get_distribution("mr.developer").version
        self.parser.add_argument('-v',
                                 '--version',
                                 action='version',
                                 version='mr.developer %s' % version)
        self.parsers = self.parser.add_subparsers(title="commands", metavar="")

        for command in get_commands():
            command(self)

        if not args:
            args = None
        args = self.parser.parse_args(args)

        try:
            self.buildout_dir = find_base()
        except IOError:
            if isinstance(args.func, CmdHelp):
                args.func(args)
                return
            self.parser.print_help()
            print()
            logger.error(
                "You are not in a path which has mr.developer installed (%s)."
                % sys.exc_info()[1])
            return
        if not hasattr(args, 'func'):
            self.parser.print_help()
            return

        self.config = Config(self.buildout_dir)
        self.original_dir = os.getcwd()
        atexit.register(self.restore_original_dir)
        os.chdir(self.buildout_dir)
        buildout = Buildout(self.config.buildout_settings['config_file'],
                            self.config.buildout_options,
                            self.config.buildout_settings['user_defaults'],
                            self.config.buildout_settings['windows_restart'])
        root_logger = logging.getLogger()
        root_logger.handlers = []
        root_logger.setLevel(logging.INFO)
        extension = Extension(buildout)
        self.sources = extension.get_sources()
        self.sources_dir = extension.get_sources_dir()
        self.auto_checkout = extension.get_all_auto_checkout()
        self.always_checkout = extension.get_always_checkout()
        self.update_git_submodules = extension.get_update_git_submodules()
        self.always_accept_server_certificate = extension.get_always_accept_server_certificate(
        )
        develop, self.develeggs, versions = extension.get_develop_info()
        self.threads = extension.get_threads()

        args.func(args)
Пример #3
0
def test_develop_packages_platform_versions():
    buildout = Buildout(_testfname('develop_packages.cfg'), [])
    bf.start (buildout)
    #print "platform-versions-config", buildout["platform-versions-config"]
    assert buildout["versions"]["alpha"] == "1.0"
    assert buildout["versions"]["beta"] == "2.0"
    nt.assert_true (not buildout["versions"].has_key("gamma"))
    assert len(buildout["versions"]) == 2
Пример #4
0
def test_develop_eggs_platform_versions():
    buildout = Buildout(_testfname('develop_eggs.cfg'), [])
    bf.start (buildout)
    #print "platform-versions-config", buildout["platform-versions-config"]
    assert buildout["versions"]["alpha"] == "1.0"
    assert buildout["versions"]["beta"] == "2.0"
    assert buildout["versions"]["gamma"] == "1.0.0.d"
    assert len(buildout["versions"]) == 3
Пример #5
0
class Develop(object):
    def __call__(self, **kwargs):
        logger.setLevel(logging.INFO)
        ch = logging.StreamHandler()
        ch.setFormatter(logging.Formatter("%(levelname)s: %(message)s"))
        logger.addHandler(ch)
        self.parser = ArgumentParser()
        version = pkg_resources.get_distribution("mr.developer").version
        self.parser.add_argument('-v',
                                 '--version',
                                 action='version',
                                 version='mr.developer %s' % version)
        self.parsers = self.parser.add_subparsers(title="commands", metavar="")
        CmdActivate(self)
        CmdCheckout(self)
        CmdDeactivate(self)
        CmdHelp(self)
        CmdInfo(self)
        CmdList(self)
        CmdPony(self)
        CmdPurge(self)
        CmdRebuild(self)
        CmdReset(self)
        CmdStatus(self)
        CmdUpdate(self)
        args = self.parser.parse_args()

        try:
            self.buildout_dir = find_base()
        except IOError, e:
            self.parser.print_help()
            print
            logger.error(
                "You are not in a path which has mr.developer installed (%s)."
                % e)
            return

        self.config = Config(self.buildout_dir)
        self.original_dir = os.getcwd()
        atexit.register(self.restore_original_dir)
        os.chdir(self.buildout_dir)
        buildout = Buildout(self.config.buildout_settings['config_file'],
                            self.config.buildout_options,
                            self.config.buildout_settings['user_defaults'],
                            self.config.buildout_settings['windows_restart'])
        root_logger = logging.getLogger()
        root_logger.handlers = []
        root_logger.setLevel(logging.INFO)
        extension = Extension(buildout)
        self.sources = extension.get_sources()
        self.sources_dir = extension.get_sources_dir()
        self.auto_checkout = extension.get_auto_checkout()
        self.always_checkout = extension.get_always_checkout()
        self.always_accept_server_certificate = extension.get_always_accept_server_certificate(
        )
        develop, self.develeggs, versions = extension.get_develop_info()

        args.func(args)
Пример #6
0
def get_buildout(version):
    versions_url = 'http://dist.plone.org/release/{version}/versions.cfg'
    url = versions_url.format(version=version)
    buildout = Buildout(
        config_file=url,
        cloptions=[('buildout', 'directory', '/tmp')],
        user_defaults=False,
    )
    return buildout
Пример #7
0
 def testdownload(self):
     """testDownload."""
     p = tmp
     bd = Buildout(fp, [])
     bd.offline = False
     recipe = MinitageCommonRecipe(bd, '666', bd['part'])
     ret = recipe._download()
     self.assertTrue(
         os.path.isfile(os.path.join(recipe.download_cache,
                                     'buildouttest')))
     p = tmp
     bd = Buildout(fp, [])
     bd.offline = True
     open(os.path.join(p, 'a'), 'w').write('test')
     recipe = MinitageCommonRecipe(bd, '666', bd['part'])
     recipe.url = 'http://foo/a'
     recipe.download_cache = p
     ret = recipe._download()
     self.assertEquals(ret, os.path.join(p, 'a'))
Пример #8
0
    def get_versions(self):
        buildout = Buildout(self.filename, '')

        # set the index URL from the buildout if not already provided
        buildout_index = buildout['buildout'].get('index')
        if not self.__custom_url:
            self._set_index_url(buildout_index)

        print("# Checking buildout file %s" % self.filename)
        return buildout['versions']
Пример #9
0
def test_platform_versions_env():
    old_env = os.environ.get ("ZILLOW_PYTHON_PLATFORM_VERSION", None)
    os.environ["ZILLOW_PYTHON_PLATFORM_VERSION"] = "next"
    buildout = Buildout(_testfname('extra.cfg'), [])
    bf.start (buildout)
    #print "platform-versions-config", buildout["platform-versions-config"]
    assert buildout["versions"]["alpha"] == "1.0"
    assert buildout["versions"]["beta"] == "2.0"
    assert buildout["versions"]["gamma"] == "10.0"
    assert len(buildout["versions"]) == 3
    if old_env:
        os.environ["ZILLOW_PYTHON_PLATFORM_VERSION"] = old_env
    else:
        del os.environ["ZILLOW_PYTHON_PLATFORM_VERSION"]
Пример #10
0
def load_buildout_from_url(url):
    """Load a buildout config from an URL.
    """
    tempdir = tempfile.mkdtemp('ftw.recipe.checkversions')
    with chdir(tempdir):
        try:
            path = os.path.join(tempdir, 'temp.cfg')
            with open(path, 'w+') as cfg:
                cfg.write('[buildout]\n')
                cfg.write('extends = %s' % url)
            return Buildout(path, cloptions='', user_defaults=False)

        finally:
            shutil.rmtree(tempdir)
Пример #11
0
    def testChooseConfigure(self):
        """testChooseConfigure."""
        p = tmp
        os.system("""
cd %s
touch configure
mkdir toto
touch toto/test
""" % (tmp))
        bd = Buildout(fp, [])
        bd.offline = False
        recipe = MinitageCommonRecipe(bd, '666', bd['part'])
        configure = recipe._choose_configure(tmp)
        self.assertEquals(configure, os.path.join(tmp, 'configure'))
        self.assertEquals(recipe.build_dir, tmp)

        recipe.build_dir = os.path.join(tmp, 'toto')
        recipe.configure = 'test'
        configure = recipe._choose_configure(recipe.build_dir)
        self.assertEquals(configure, os.path.join(tmp, 'toto', 'test'))
        self.assertEquals(recipe.build_dir, os.path.join(tmp, 'toto'))
Пример #12
0
    def _get_buildout_source_item(self):
        self.ensure_one()
        # the recipe switches working directory
        cwd = os.getcwd()
        buildout = Buildout(self._path('buildout.cfg'), [])
        section = buildout[self.buildout_section]
        recipe = BaseRecipe(buildout, 'buildout', section)
        recipe.parse_addons(section)
        os.chdir(cwd)

        for parts_dir, (loc_type, loc_spec, options) in recipe.sources.items():
            # we only support git urls
            if loc_type != 'git':
                continue
            # urls on github and gitlab aren't case sensitive
            normalized_name = self.repo_id.base.lower()
            normalized_location = self.env['runbot.repo'].new({
                'name': loc_spec[0],
            }).base.lower()
            if normalized_name == normalized_location:
                return parts_dir, (loc_type, loc_spec, options)
Пример #13
0
def load_buildout_from_file(buildout_directory, filename):
    """Load a buildout config from a local file.
    """
    with chdir(buildout_directory):
        return Buildout(filename, cloptions='', user_defaults=False)
Пример #14
0
def make_buildout(config):
    buildout = Buildout(config.buildout_settings['config_file'],
                        config.buildout_options,
                        config.buildout_settings['user_defaults'],
                        config.buildout_settings['windows_restart'])
    return buildout
Пример #15
0
def test_noop():
    buildout = Buildout(_testfname('empty.cfg'), [])
Пример #16
0
def test_regression():
    buildout = Buildout(_testfname('simple.cfg'), [])
    assert buildout["versions"]["alpha"] == "1.0"
    assert buildout["versions"]["beta"] == "2.0"
    assert_equal (2, len (buildout["versions"]))
Пример #17
0
def _extract_versions_section(  # NOQA: C901
    session,
    filename,
    base_dir=None,
    version_sections=None,
    annotations=None,
    relative=None,
    version_section_name=None,
    versionannotation_section_name="versionannotations",
):
    if base_dir is None:
        base_dir = os.path.dirname(os.path.abspath(filename))
    if version_sections is None:
        version_sections = OrderedDict()
    if annotations is None:
        annotations = OrderedDict()
    if "://" not in filename:
        if relative and "://" in relative:
            # relative to url!
            filename = "{0}/{1}".format(relative, filename)
        else:
            if relative:
                if filename.startswith(relative + "/"):
                    filename = filename[len(relative + "/"):]
                filename = os.path.join(base_dir, relative, filename)
            else:
                filename = os.path.join(base_dir, filename)

    sys.stderr.write("\n- {0}".format(filename))

    try:
        with nostdout():
            buildout = Buildout(filename, [])  # Use zc.buildout parser
    except UserError:
        buildout = {"buildout": {}}
    config = ConfigParser()
    if os.path.isfile(filename):
        config.read(filename)
    elif "://" in filename:
        resp = session.get(filename)
        config.readfp(StringIO(resp.text))
        if resp.from_cache:
            sys.stderr.write("\n  from cache")
        elif resp.status_code != 200:
            sys.stderr.write("\n  ERROR {0:d}".format(resp.status_code))
        else:
            sys.stderr.write("\n  fresh from server")
    else:
        raise ValueError("{0} does not exist!".format(filename))

    # first read own versions section
    current_version_section_name = buildout["buildout"].get(
        "versions", "versions")
    if version_section_name is None:
        # initial name
        version_section_name = current_version_section_name
    elif version_section_name != current_version_section_name:
        # name changed, not sure if this works as expected! - jensens
        sys.stderr.write(
            "\nName of [versions] (versions = versions) has changed."
            '\nGlobal versions section name: "{gname}"'
            '\nVersions pinned under that new Section namespace "{nname}"'
            " will be ignored.".format(
                gname=version_section_name,
                nname=buildout["buildout"].get("versions")))

    if filename.startswith(base_dir):
        key_name = filename[len(base_dir) + 1:]
    else:
        key_name = filename

    if config.has_section(version_section_name):
        version_sections[key_name] = OrderedDict(
            config.items(version_section_name))
        sys.stderr.write("\n  {0:d} entries in versions section.".format(
            len(version_sections[key_name])))

    # read versionannotations
    versionannotation_section_name = buildout["buildout"].get(
        "versionannotations", versionannotation_section_name)
    if config.has_section(versionannotation_section_name):
        annotations[key_name] = OrderedDict(
            config.items(versionannotation_section_name))
        sys.stderr.write("\n  {0:d} entries in annotations section.".format(
            len(annotations[key_name])))
    try:
        extends = config.get("buildout", "extends").strip()
    except (NoSectionError, NoOptionError):
        return version_sections, annotations
    for extend in reversed(extends.splitlines()):
        extend = extend.strip()
        if not extend:
            continue
        sub_relative, extend = find_relative(extend, relative)
        _extract_versions_section(
            session,
            extend,
            base_dir,
            version_sections,
            annotations,
            sub_relative,
            version_section_name,
            versionannotation_section_name,
        )
    return version_sections, annotations