Example #1
0
 def run_buildout(self):
     with OutputCapture() as output:
         buildout = Buildout('buildout.cfg', [], command='install')
         with LogCapture('zc.buildout', level=INFO) as log:
             buildout.install([])
     self.output = output
     self.log = log
 def testPyPath(self):
     """testPyPath."""
     p = tmp
     bd = Buildout(fp, [])
     bd.offline = False
     recipe = MinitageCommonRecipe(bd, '666', bd['part'])
     ppath = sys.path
     recipe._set_py_path()
     nppath = os.environ['PYTHONPATH']
     for elem in [recipe.buildout['buildout']['directory'],
                  recipe.options['location'],]\
                 + ['/eggs/egg1/parts/%s' % (
                         recipe.site_packages
                     ),
                     '/eggs/egg2/parts/%s' % (
                        recipe.site_packages
                     ),
                     '/eggs/legg1/parts/%s' % (
                         recipe.site_packages
                     ),
                     '/eggs/egg3/parts/%s'  % (
                        recipe.site_packages
                     ),
                 ]:
         print elem
         self.assertTrue(elem in nppath)
Example #3
0
 def __init__(self, config_file, options, args=(), **keys):
     # hijack the zc.buildout command line option API
     # in order to change the Buildout class defaults
     # without being too invasive
     options = [
         # disable bootstrap directories and installed parts tracking
         ('buildout', 'installed', ''),
         ('buildout', 'bin-directory', '.'),
         ('buildout', 'eggs-directory', '.'),
         ('buildout', 'develop-eggs-directory', '.'),
         ('buildout', 'parts-directory', '.'),
         ('buildout', 'offline', 'true'),
         # custom default config
         ('buildout', 'parts', '${smithery:parts}'),
         # override args usage
         ('smithery', 'args', ' '.join(args)),
     ] + options
     Buildout.__init__(self, config_file, options, **keys)
     smithery_options = [
         ('smithery', 'log-file', ''),
         ('smithery', 'log-format', '%(asctime)s %(levelname)s %(message)s'),
         ('smithery', 'log-level', 'INFO'),
         ('smithery', 'log-no-stdout', 'false'),
         ('smithery', 'log-email-server', 'localhost:25'),
         ('smithery', 'log-email-alerts-to', ''),
     ]
     for section, k, v in smithery_options:
         if not self[section].has_key(k):
             self[section][k] = v
     self.config_logging()
Example #4
0
 def __init__(self, config_file, clopts):
     #if not os.path.exists(buildout_conf):
     #    raise GrapeError("No buildout configuration file found!")
     #else:
     try:
         Bout.__init__(self,config_file, clopts)
     except UserError as e:
         raise GrapeError(str(e))
     self['buildout']['installed'] = ''
     self._type = 'tar'
Example #5
0
 def __init__(self, config_file, clopts):
     #if not os.path.exists(buildout_conf):
     #    raise GrapeError("No buildout configuration file found!")
     #else:
     try:
         Bout.__init__(self, config_file, clopts)
     except UserError as e:
         raise GrapeError(str(e))
     self['buildout']['installed'] = ''
     self._type = 'tar'
 def testPath(self):
     """testPath."""
     p = tmp
     bd = Buildout(fp, [])
     bd.offline = False
     recipe = MinitageCommonRecipe(bd, '666', bd['part'])
     recipe._set_path()
     path = os.environ['PATH']
     for elem in [recipe.buildout['buildout']['directory'],
                  recipe.options['location'],]\
                 + os.environ.get('PATH','').split(':') :
         self.assertTrue(elem in path)
Example #7
0
def get_buildout_config(buildout_filename):
    """Parse buildout config with zc.buildout ConfigParser
    """
    print("[localhost] get_buildout_config: {0:s}".format(buildout_filename))
    buildout = Buildout(buildout_filename, [('buildout', 'verbosity', '-100')])
    while True:
        try:
            len(buildout.items())
            break
        except OSError:
            pass
    return buildout
 def testPkgconfigpath(self):
     """testPkgconfigpath."""
     p = tmp
     bd = Buildout(fp, [])
     bd.offline = False
     recipe = MinitageCommonRecipe(bd, '666', bd['part'])
     recipe._set_pkgconfigpath()
     path = os.environ.get(
         'PKG_CONFIG_PATH', ''
     )
     for elem in ['1a']\
                 + os.environ.get('PKG_CONFIG_PATH','').split(':')\
                 + ['%s/lib/pkgconfig' % dep \
                    for dep in recipe.minitage_dependencies]:
         self.assertTrue(elem in path)
    def testGetCompilDir(self):
        """testGetCompilDir."""
        p = tmp
        os.system("""
cd %s
mkdir .download
mkdir tutu
mkdir tutu/.download
""" % (tmp))
        bd = Buildout(fp, [])
        bd.offline = False
        recipe = MinitageCommonRecipe(bd, '666', bd['part'])
        directory = recipe._get_compil_dir(tmp)

        self.assertEquals(directory, os.path.join(tmp, 'tutu'))
Example #10
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
Example #11
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)
Example #12
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
Example #13
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
Example #14
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)
Example #15
0
 def __init__(self, config_file, options, args=(), **keys):
     # hijack the zc.buildout command line option API
     # in order to change the Buildout class defaults
     # without being too invasive
     options = [
         # disable bootstrap directories and installed parts tracking
         ('buildout', 'installed', ''),
         ('buildout', 'bin-directory', '.'),
         ('buildout', 'eggs-directory', '.'),
         ('buildout', 'develop-eggs-directory', '.'),
         ('buildout', 'parts-directory', '.'),
         ('buildout', 'offline', 'true'),
         # custom default config
         ('buildout', 'parts', '${smithery:parts}'),
         # override args usage
         ('smithery', 'args', ' '.join(args)),
     ] + options
     Buildout.__init__(self, config_file, options, **keys)
Example #16
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
Example #17
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']
Example #18
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'))
Example #19
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'))
    def testCompilationFlags(self):
        """testCompilationFlags."""
        p = tmp
        bd = Buildout(fp, [])
        bd.offline = False
        os.environ['LD_RUN_PATH'] = ''
        os.environ['CFLAGS'] = ''
        os.environ['PKG_CONFIG_PATH'] = ''
        os.environ['LDFLAGS'] = ''
        recipe = MinitageCommonRecipe(bd, '666', bd['part'])
        recipe.uname = 'darwin'
        recipe._set_compilation_flags()

        a = os.environ.get('LD_RUN_PATH')
        b = 'a:b:c:d:e:f:%s/lib'% (
            '/lib:'.join(recipe.minitage_dependencies
                         + [recipe.prefix])
                          )
        self.assertEquals(a, b)

        a = os.environ.get('CFLAGS')
        b = '-Ia -Ib -Ic -Id -Ie -If %s' % (
            '-I%s/include' % (
                '/include -I'.join(
                    recipe.minitage_dependencies
                )
            )
        )
        self.assertEquals(a, b)

        self.assertTrue(os.path.join(d, 'dependencies', 'ldep2', 'parts', 'part') in recipe.minitage_dependencies)

        a = '%s%s' %(
                ''.join(['-L%s/lib -Wl,-rpath -Wl,%s/lib ' % (s,s) \
                         for s in ['a','b','c','d','e','f'] \
                         + recipe.minitage_dependencies + [recipe.prefix]]),
                ' -mmacosx-version-min=None   -lc',
            )
        b = os.environ.get('LDFLAGS')
        self.assertEquals(a.replace('   ', ' ').replace('  ', ' '), b)
Example #21
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"]
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)
    def testCallHook(self):
        """testCallHook."""
        p = tmp
        hook = os.path.join(tmp, 'toto.py')
        os.system("""
cd %s
cat << EOF  > %s
import os
def write(options, buildout):
    open(
        os.path.join('%s','foo'),
        'w').write('foo')
EOF""" % (tmp, hook, tmp))
        bd = Buildout(fp, [])
        bd.offline = False
        recipe = MinitageCommonRecipe(bd, '666', bd['part'])
        recipe.options['hook'] = '%s:write' % hook
        recipe._call_hook('hook')
        self.assertEquals(
            open(
                os.path.join(tmp, 'foo')
            ).read(),
            'foo'
        )
Example #24
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')
     )
Example #25
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)
Example #26
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'))
Example #27
0
 def install(self, install_args):
     Bout.install(self, install_args)
     if self._type == 'tar':
         self.cleanup()
Example #28
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
Example #29
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
Example #30
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"]))
Example #31
0
def test_noop():
    buildout = Buildout(_testfname('empty.cfg'), [])
Example #32
0
 def install(self, install_args):
     Bout.install(self,install_args)
     if self._type == 'tar':
         self.cleanup()
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)