<commit_before>##############################################################################
# Copyright (c) 2013-2017, Lawrence Livermore National Security, LLC.
# Produced at the Lawrence Livermore National Laboratory.
#
# This file is part of Spack.
# Created by Todd Gamblin, tgamblin@llnl.gov, All rights reserved.
# LLNL-CODE-647188
#
# For details, see https://github.com/spack/spack
# Please also see the NOTICE and LICENSE files for our notice and the LGPL.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License (as
# published by the Free Software Foundation) version 2.1, February 1999.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the IMPLIED WARRANTY OF
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the terms and
# conditions of the GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
##############################################################################
from spack import *

class Callpath(CMakePackage):
    """Library for representing callpaths consistently in
       distributed-memory performance tools."""

    homepage = "https://github.com/llnl/callpath"
    url      = "https://github.com/llnl/callpath/archive/v1.0.1.tar.gz"

    version('1.0.2', 'b1994d5ee7c7db9d27586fc2dcf8f373')
    version('1.0.1', '0047983d2a52c5c335f8ba7f5bab2325')

    depends_on('elf', type='link')
    depends_on('libdwarf')
    depends_on('dyninst')
    depends_on('adept-utils')
    depends_on('mpi')
    depends_on('cmake@2.8:', type='build')

    def cmake_args(self):
        # TODO: offer options for the walker used.
        args = ["-DCALLPATH_WALKER=dyninst"]

        if self.spec.satisfies("^dyninst@9.3.0:"):
            std_flag = self.compiler.cxx11_flag
            args.append("-DCMAKE_CXX_FLAGS='{0} -fpermissive'".format(
                std_flag))

        return args
<commit_msg>Add version 1.04 (#6259)<commit_after>##############################################################################
# Copyright (c) 2013-2017, Lawrence Livermore National Security, LLC.
# Produced at the Lawrence Livermore National Laboratory.
#
# This file is part of Spack.
# Created by Todd Gamblin, tgamblin@llnl.gov, All rights reserved.
# LLNL-CODE-647188
#
# For details, see https://github.com/spack/spack
# Please also see the NOTICE and LICENSE files for our notice and the LGPL.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License (as
# published by the Free Software Foundation) version 2.1, February 1999.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the IMPLIED WARRANTY OF
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the terms and
# conditions of the GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
##############################################################################
from spack import *

class Callpath(CMakePackage):
    """Library for representing callpaths consistently in
       distributed-memory performance tools."""

    homepage = "https://github.com/llnl/callpath"
    url      = "https://github.com/llnl/callpath/archive/v1.0.1.tar.gz"

    version('1.0.4', '39d2e06bfa316dec1085b874092e4b08')
    version('1.0.2', 'b1994d5ee7c7db9d27586fc2dcf8f373')
    version('1.0.1', '0047983d2a52c5c335f8ba7f5bab2325')

    depends_on('elf', type='link')
    depends_on('libdwarf')
    depends_on('dyninst')
    depends_on('adept-utils')
    depends_on('mpi')
    depends_on('cmake@2.8:', type='build')

    def cmake_args(self):
        # TODO: offer options for the walker used.
        args = ["-DCALLPATH_WALKER=dyninst"]

        if self.spec.satisfies("^dyninst@9.3.0:"):
            std_flag = self.compiler.cxx11_flag
            args.append("-DCMAKE_CXX_FLAGS='{0} -fpermissive'".format(
                std_flag))

        return args
<|endoftext|>


<commit_before>import re

from streamlink.compat import urljoin
from streamlink.plugin import Plugin
from streamlink.plugin.api import http, validate
from streamlink.stream import HLSStream

COOKIE_PARAMS = (
    "devicetype=desktop&"
    "preferred-player-odm=hlslink&"
    "preferred-player-live=hlslink"
)

_id_re = re.compile(r"/(?:program|direkte|serie/[^/]+)/([^/]+)")
_url_re = re.compile(r"https?://(tv|radio).nrk.no/")
_api_baseurl_re = re.compile(r'apiBaseUrl:\s*"(?P<baseurl>[^"]+)"')

_schema = validate.Schema(
    validate.transform(_api_baseurl_re.search),
    validate.any(
        None,
        validate.all(
            validate.get("baseurl"),
            validate.url(
                scheme="http"
            )
        )
    )
)

_mediaelement_schema = validate.Schema({
    "mediaUrl": validate.url(
        scheme="http",
        path=validate.endswith(".m3u8")
    )
})

class NRK(Plugin):
    @classmethod
    def can_handle_url(self, url):
        return _url_re.match(url)

    def _get_streams(self):
        # Get the stream type from the url (tv/radio).
        stream_type = _url_re.match(self.url).group(1).upper()
        cookie = {
            "NRK_PLAYER_SETTINGS_{0}".format(stream_type): COOKIE_PARAMS
        }

        # Construct API URL for this program.
        baseurl = http.get(self.url, cookies=cookie, schema=_schema)
        program_id = _id_re.search(self.url).group(1)

        # Extract media URL.
        json_url = urljoin(baseurl, "mediaelement/{0}".format(program_id))
        res = http.get(json_url, cookies=cookie)
        media_element = http.json(res, schema=_mediaelement_schema)
        media_url = media_element["mediaUrl"]

        return HLSStream.parse_variant_playlist(self.session, media_url)

__plugin__ = NRK
<commit_msg>[NRK.NO] fixed regex for _api_baseurl_re<commit_after>import re

from streamlink.compat import urljoin
from streamlink.plugin import Plugin
from streamlink.plugin.api import http, validate
from streamlink.stream import HLSStream

COOKIE_PARAMS = (
    "devicetype=desktop&"
    "preferred-player-odm=hlslink&"
    "preferred-player-live=hlslink"
)

_id_re = re.compile(r"/(?:program|direkte|serie/[^/]+)/([^/]+)")
_url_re = re.compile(r"https?://(tv|radio).nrk.no/")
_api_baseurl_re = re.compile(r'''apiBaseUrl:\s*["'](?P<baseurl>[^"']+)["']''')

_schema = validate.Schema(
    validate.transform(_api_baseurl_re.search),
    validate.any(
        None,
        validate.all(
            validate.get("baseurl"),
            validate.url(
                scheme="http"
            )
        )
    )
)

_mediaelement_schema = validate.Schema({
    "mediaUrl": validate.url(
        scheme="http",
        path=validate.endswith(".m3u8")
    )
})

class NRK(Plugin):
    @classmethod
    def can_handle_url(self, url):
        return _url_re.match(url)

    def _get_streams(self):
        # Get the stream type from the url (tv/radio).
        stream_type = _url_re.match(self.url).group(1).upper()
        cookie = {
            "NRK_PLAYER_SETTINGS_{0}".format(stream_type): COOKIE_PARAMS
        }

        # Construct API URL for this program.
        baseurl = http.get(self.url, cookies=cookie, schema=_schema)
        program_id = _id_re.search(self.url).group(1)

        # Extract media URL.
        json_url = urljoin(baseurl, "mediaelement/{0}".format(program_id))
        res = http.get(json_url, cookies=cookie)
        media_element = http.json(res, schema=_mediaelement_schema)
        media_url = media_element["mediaUrl"]

        return HLSStream.parse_variant_playlist(self.session, media_url)

__plugin__ = NRK
<|endoftext|>


<commit_before>from __future__ import division, absolute_import, print_function

__all__ = ['punic_cli', 'main']

import logging
import logging.handlers
import sys
import click
from click_didyoumean import DYMGroup
import networkx as nx
from pathlib2 import Path

import punic
from .copy_frameworks import *
from .errors import *
from .logger import *
from .semantic_version import *
from .utilities import *
from .version_check import *
from .config_init import *
from .carthage_cache import *
from punic.graph import make_graph
import punic.shshutil as shutil
from punic import *
from .runner import *
from .checkout import *
from .search import *

@click.group(cls=DYMGroup)
@click.option('--echo', default=False, is_flag=True, help="""Echo all commands to terminal.""")
@click.option('--verbose', default=False, is_flag=True, help="""Verbose logging.""")
@click.option('--color/--no-color', default=True, is_flag=True, help="""TECHNICOLOR.""")
@click.option('--timing/--no-timing', default=False, is_flag=True, help="""Log timing info""")
@click.pass_context
def punic_cli(context, echo, verbose, timing, color):
    ### TODO: Clean this up!

    # Configure click
    context.token_normalize_func = lambda x: x if not x else x.lower()

    # Configure logging
    level = logging.DEBUG if verbose else logging.INFO

    logger = logging.getLogger()
    logger.setLevel(logging.DEBUG)

    formatter = HTMLFormatter()

    # create console handler and set level to debug
    stream_handler = logging.StreamHandler()
    stream_handler.setLevel(level)
    stream_handler.setFormatter(formatter)
    # add ch to logger
    logger.addHandler(stream_handler)

    logs_path = Path('~/Library/Application Support/io.schwa.Punic/Logs').expanduser()
    if not logs_path.exists():
        logs_path.mkdir(parents=True)

    log_path = logs_path / "punic.log"
    needs_rollover = log_path.exists()

    file_handler = logging.handlers.RotatingFileHandler(str(log_path), backupCount=4)
    if needs_rollover:
        file_handler.doRollover()
    file_handler.setLevel(logging.DEBUG)
    file_handler.setFormatter(HTMLStripperFormatter(logging.Formatter("%(asctime)s - %(name)s - %(levelname)s - %(message)s")))
    logger.addHandler(file_handler)

    for name in ['boto', 'requests.packages.urllib3']:
        named_logger = logging.getLogger(name)
        named_logger.setLevel(logging.WARNING)
        named_logger.propagate = True

    formatter.color = color
    logger.color = color
    runner.echo = echo

    # Set up punic
    punic = Punic()
    punic.config.log_timings = timing
    context.obj = punic
    punic.config.verbose = verbose
    punic.config.echo = verbose

@punic_cli.command()
@click.pass_context
@click.option('--use-submodules', default=None, help="""Add dependencies as Git submodules""")
@click.option('--use-ssh', default=None, help="""Use SSH for downloading GitHub repositories""")
def fetch(context, **kwargs):
    """Fetch the project's dependencies.."""
    logging.info("<cmd>fetch</cmd>")
    punic = context.obj
    punic.config.fetch = True  # obviously
    punic.config.update(**kwargs)

    with timeit('fetch', log=punic.config.log_timings):
        with error_handling():
            punic.fetch()

@punic_cli.command()
@click.pass_context
@click.option('--fetch/--no-fetch', default=True, is_flag=True, help="""Controls whether to fetch dependencies.""")
@click.option('--use-submodules', default=None, help="""Add dependencies as Git submodules""")
@click.option('--use-ssh', default=None, is_flag=True, help="""Use SSH for downloading GitHub repositories""")
def resolve(context, **kwargs):
    """Resolve dependencies and output `Carthage.resolved` file.

    This sub-command does not build dependencies. Use this sub-command when a dependency has changed and you just want to update `Cartfile.resolved`.
    """
    punic = context.obj
    logging.info("<cmd>Resolve</cmd>")
    punic.config.update(**kwargs)

    with timeit('resolve', log=punic.config.log_timings):
        with error_handling():
            punic.resolve()

@punic_cli.command()
@click.pass_context
@click.option('--configuration', default=None, help="""Dependency configurations to build. Usually 'Release' or 'Debug'.""")
@click.option('--platform', default=None, help="""Platform to build. Comma separated list.""")
@click.option('--fetch/--no-fetch', default=True, is_flag=True, help="""Controls whether to fetch dependencies.""")
@click.option('--xcode-version', default=None, help="""Xcode version to use""")
@click.option('--toolchain', default=None, help="""Xcode toolchain to use""")
@click.option('--dry-run', default=None, is_flag=True, help="""Do not actually perform final build""")
@click.option('--use-submodules', default=None, help="""Add dependencies as Git submodules""")
@click.option('--use-ssh', default=None, is_flag=True, help="""Use SSH for downloading GitHub repositories""")
@click.argument('deps', nargs=-1)
def build(context, **kwargs):
    """Fetch and build the project's dependencies."""
    logging.info("<cmd>Build</cmd>")
    punic = context.obj
    punic.config.update(**kwargs)

    deps = kwargs['deps']

    logging.debug('Platforms: {}'.format(punic.config.platforms))
    logging.debug('Configuration: {}'.format(punic.config.configuration))

    with timeit('build', log=punic.config.log_timings):
        with error_handling():
            punic.build(dependencies=deps)

@punic_cli.command()
@click.pass_context
@click.option('--configuration', default=None, help="""Dependency configurations to build. Usually 'Release' or 'Debug'.""")
@click.option('--platform', default=None, help="""Platform to build. Comma separated list.""")
@click.option('--fetch/--no-fetch', default=True, is_flag=True, help="""Controls whether to fetch dependencies.""")
@click.option('--xcode-version', default=None, help="""Xcode version to use""")
@click.option('--toolchain', default=None, help="""Xcode toolchain to use""")
@click.option('--use-submodules', default=None, help="""Add dependencies as Git submodules""")
@click.option('--use-ssh', default=None, is_flag=True, help="""Use SSH for downloading GitHub repositories""")
@click.argument('deps', nargs=-1)
def update(context, **kwargs):
    """Update and rebuild the project's dependencies."""
    logging.info("<cmd>Update</cmd>")
    punic = context.obj
    punic.config.update(**kwargs)

    deps = kwargs['deps']

    with timeit('update', log=punic.config.log_timings):
        with error_handling():
            punic.resolve()
            punic.build(dependencies=deps)

@punic_cli.command()
@click.pass_context
@click.option('--derived-data', default=False, is_flag=True, help="""Clean the punic derived data directory.""")
@click.option('--caches', default=False, is_flag=True, help="""Clean the global punic files.""")
@click.option('--build', default=False, is_flag=True, help="""Clean the locate Carthage/Build directorys.""")
@click.option('--all', default=False, is_flag=True, help="""Clean all.""")
def clean(context, derived_data, caches, build, all):
    """Clean project & punic environment."""
    logging.info("<cmd>Clean</cmd>")
    punic = context.obj

    if build or all:
        logging.info('Erasing Carthage/Build directory')
        if punic.config.build_path.exists():
            shutil.rmtree(punic.config.build_path)

    if derived_data or all:
        logging.info('Erasing derived data directory')
        if punic.config.derived_data_path.exists():
            shutil.rmtree(punic.config.derived_data_path)

    if caches or all:
        if punic.config.repo_cache_directory.exists():
            logging.info('Erasing {}'.format(punic.config.repo_cache_directory))
            shutil.rmtree(punic.config.repo_cache_directory)
        logging.info('Erasing run cache')
        runner.reset()

@punic_cli.command()
@click.pass_context
@click.option('--fetch/--no-fetch', default=True, is_flag=True, help="""Controls whether to fetch dependencies.""")
@click.option('--use-submodules', default=None, help="""Add dependencies as Git submodules""")
@click.option('--use-ssh', default=None, is_flag=True, help="""Use SSH for downloading GitHub repositories""")
@click.option('--open', default=False, is_flag=True, help="""Open the graph image file.""")
def graph(context, fetch, use_submodules, use_ssh, open):
    """Output resolved dependency graph."""
    logging.info("<cmd>Graph</cmd>")
    punic = context.obj
    punic.config.fetch = fetch
    if use_submodules:
        punic.config.use_submodules = use_submodules
    if use_ssh:
        punic.config.use_ssh = use_ssh

    make_graph(punic, open)

@punic_cli.command(name='copy-frameworks')
@click.pass_context
def copy_frameworks(context):
    """In a Run Script build phase, copies each framework specified by a SCRIPT_INPUT_FILE environment variable into the built app bundle."""
    copy_frameworks_main()

# noinspection PyUnusedLocal
@punic_cli.command()
@click.pass_context
@click.option('--check/--no-check', default=True, help="""Check for latest version.""")
@click.option('--simple', is_flag=True, default=False, help="""Only display simple version info. Implies --no-check.""")
def version(context, check, simple):
    """Display the current version of Punic."""

    if simple:
        print("{}".format(punic.__version__))
    else:
        logging.info('Punic version: {}'.format(punic.__version__))

        sys_version = sys.version_info
        sys_version = SemanticVersion.from_dict(dict(major=sys_version.major, minor=sys_version.minor, micro=sys_version.micro, releaselevel=sys_version.releaselevel, serial=sys_version.serial, ))
        logging.info('Python version: {}'.format(sys_version))

        if check:
            version_check(verbose=True, timeout=None, failure_is_an_option=False)

@punic_cli.command()
@click.pass_context
def readme(context):
    """Opens punic readme in your browser (https://github.com/schwa/punic/blob/HEAD/README.markdown)"""
    click.launch('https://github.com/schwa/punic/blob/HEAD/README.markdown')

@punic_cli.command()
@click.option('--configuration', default=None, help="""Dependency configurations to build. Usually 'Release' or 'Debug'.""")
@click.option('--platform', default=None, help="""Platform to build. Comma separated list.""")
@click.option('--fetch/--no-fetch', default=True, is_flag=True, help="""Controls whether to fetch dependencies.""")
@click.option('--xcode-version', default=None, help="""Xcode version to use""")
@click.option('--toolchain', default=None, help="""Xcode toolchain to use""")
@click.option('--use-submodules', default=None, help="""Add dependencies as Git submodules""")
@click.option('--use-ssh', default=None, is_flag=True, help="""Use SSH for downloading GitHub repositories""")
@click.argument('deps', nargs=-1)
@click.pass_context
def list(context, **kwargs):
    """Lists all platforms, projects, xcode projects, schemes for all dependencies."""
    punic = context.obj
    punic.config.update(**kwargs)
    deps = kwargs['deps']

    config = punic.config

    configuration, platforms = config.configuration, config.platforms

    if not config.build_path.exists():
        config.build_path.mkdir(parents=True)

    filtered_dependencies = punic._ordered_dependencies(name_filter=deps)

    checkouts = [Checkout(punic=punic, identifier=identifier, revision=revision) for identifier, revision in filtered_dependencies]

    tree = {}

    for platform in platforms:
        tree[platform.name] = {}
        for checkout in checkouts:
            tree[platform.name][str(checkout.identifier)] = {'projects':{}}
            checkout.prepare()
            for project in checkout.projects:
                tree[platform.name][str(checkout.identifier)]['projects'][project.path.name] = {'schemes':{}}
                schemes = project.schemes
                schemes = [scheme for scheme in schemes if scheme.framework_target]
                schemes = [scheme for scheme in schemes if platform.device_sdk in scheme.framework_target.supported_platform_names]
                tree[platform.name][str(checkout.identifier)]['projects'][project.path.name]['schemes'] = [scheme.name for scheme in schemes]

    # from pprint import pprint
    #
    # pprint(tree)

    import yaml

    yaml.safe_dump(tree, stream = sys.stdout)

@punic_cli.command()
@click.pass_context
@click.option('--configuration', default=None, help="""Dependency configurations to build. Usually 'Release' or 'Debug'.""")
@click.option('--platform', default=None, help="""Platform to build. Comma separated list.""")
@click.option('--xcode', default=None)
def init(context, **kwargs):
    """Generate punic configuration file."""
    config_init(**kwargs)

@punic_cli.group(cls=DYMGroup)
@click.pass_context
def cache(context):
    """Cache punic build artifacts to Amazon S3"""
    pass

@cache.command()
@click.pass_context
@click.option('--xcode-version', default=None, help="""Xcode version to use""")
@click.option('--force', default=False, is_flag=True, help="""Force publishing""")
def publish(context, xcode_version, force):
    """Generates and uploads the cache archive for the current Cartfile.resolved"""
    with error_handling():
        logging.info("<cmd>Cache Publish</cmd>")
        punic = context.obj
        if xcode_version:
            punic.config.xcode_version = xcode_version
        carthage_cache = CarthageCache(config=punic.config)
        logging.info("Cache filename: <ref>'{}'</ref>".format(carthage_cache.archive_name_for_project()))
        carthage_cache.publish(force = force)

@cache.command()
@click.pass_context
@click.option('--xcode-version', default=None, help="""Xcode version to use""")
def install(context, xcode_version):
    """Installs the cache archive for the current Cartfile.resolved"""
    with error_handling():
        logging.info("<cmd>Cache Install</cmd>")
        punic = context.obj
        if xcode_version:
            punic.config.xcode_version = xcode_version
        carthage_cache = CarthageCache(config=punic.config)
        logging.info("Cache filename: <ref>'{}'</ref>".format(carthage_cache.archive_name_for_project()))
        carthage_cache.install()

@punic_cli.command()
@click.pass_context
@click.argument('name')
@click.option('--append', is_flag=True, default=False, help="""Add a selected project to a Cartfile""")
@click.option('--language', default='swift', help="""Search for projects of specified language""")
def search(context, name, append, language):
    """Search github for repositories and optionally add them to a Cartfile."""
    punic = context.obj

    github_search(punic, name, cartfile_append=append, language=language)

def main():
    punic_cli()
<commit_msg>Log path to project in `punic --list`<commit_after>from __future__ import division, absolute_import, print_function

__all__ = ['punic_cli', 'main']

import logging
import logging.handlers
import sys
import click
from click_didyoumean import DYMGroup
import networkx as nx
from pathlib2 import Path

import punic
from .copy_frameworks import *
from .errors import *
from .logger import *
from .semantic_version import *
from .utilities import *
from .version_check import *
from .config_init import *
from .carthage_cache import *
from punic.graph import make_graph
import punic.shshutil as shutil
from punic import *
from .runner import *
from .checkout import *
from .search import *

@click.group(cls=DYMGroup)
@click.option('--echo', default=False, is_flag=True, help="""Echo all commands to terminal.""")
@click.option('--verbose', default=False, is_flag=True, help="""Verbose logging.""")
@click.option('--color/--no-color', default=True, is_flag=True, help="""TECHNICOLOR.""")
@click.option('--timing/--no-timing', default=False, is_flag=True, help="""Log timing info""")
@click.pass_context
def punic_cli(context, echo, verbose, timing, color):
    ### TODO: Clean this up!

    # Configure click
    context.token_normalize_func = lambda x: x if not x else x.lower()

    # Configure logging
    level = logging.DEBUG if verbose else logging.INFO

    logger = logging.getLogger()
    logger.setLevel(logging.DEBUG)

    formatter = HTMLFormatter()

    # create console handler and set level to debug
    stream_handler = logging.StreamHandler()
    stream_handler.setLevel(level)
    stream_handler.setFormatter(formatter)
    # add ch to logger
    logger.addHandler(stream_handler)

    logs_path = Path('~/Library/Application Support/io.schwa.Punic/Logs').expanduser()
    if not logs_path.exists():
        logs_path.mkdir(parents=True)

    log_path = logs_path / "punic.log"
    needs_rollover = log_path.exists()

    file_handler = logging.handlers.RotatingFileHandler(str(log_path), backupCount=4)
    if needs_rollover:
        file_handler.doRollover()
    file_handler.setLevel(logging.DEBUG)
    file_handler.setFormatter(HTMLStripperFormatter(logging.Formatter("%(asctime)s - %(name)s - %(levelname)s - %(message)s")))
    logger.addHandler(file_handler)

    for name in ['boto', 'requests.packages.urllib3']:
        named_logger = logging.getLogger(name)
        named_logger.setLevel(logging.WARNING)
        named_logger.propagate = True

    formatter.color = color
    logger.color = color
    runner.echo = echo

    # Set up punic
    punic = Punic()
    punic.config.log_timings = timing
    context.obj = punic
    punic.config.verbose = verbose
    punic.config.echo = verbose

@punic_cli.command()
@click.pass_context
@click.option('--use-submodules', default=None, help="""Add dependencies as Git submodules""")
@click.option('--use-ssh', default=None, help="""Use SSH for downloading GitHub repositories""")
def fetch(context, **kwargs):
    """Fetch the project's dependencies.."""
    logging.info("<cmd>fetch</cmd>")
    punic = context.obj
    punic.config.fetch = True  # obviously
    punic.config.update(**kwargs)

    with timeit('fetch', log=punic.config.log_timings):
        with error_handling():
            punic.fetch()

@punic_cli.command()
@click.pass_context
@click.option('--fetch/--no-fetch', default=True, is_flag=True, help="""Controls whether to fetch dependencies.""")
@click.option('--use-submodules', default=None, help="""Add dependencies as Git submodules""")
@click.option('--use-ssh', default=None, is_flag=True, help="""Use SSH for downloading GitHub repositories""")
def resolve(context, **kwargs):
    """Resolve dependencies and output `Carthage.resolved` file.

    This sub-command does not build dependencies. Use this sub-command when a dependency has changed and you just want to update `Cartfile.resolved`.
    """
    punic = context.obj
    logging.info("<cmd>Resolve</cmd>")
    punic.config.update(**kwargs)

    with timeit('resolve', log=punic.config.log_timings):
        with error_handling():
            punic.resolve()

@punic_cli.command()
@click.pass_context
@click.option('--configuration', default=None, help="""Dependency configurations to build. Usually 'Release' or 'Debug'.""")
@click.option('--platform', default=None, help="""Platform to build. Comma separated list.""")
@click.option('--fetch/--no-fetch', default=True, is_flag=True, help="""Controls whether to fetch dependencies.""")
@click.option('--xcode-version', default=None, help="""Xcode version to use""")
@click.option('--toolchain', default=None, help="""Xcode toolchain to use""")
@click.option('--dry-run', default=None, is_flag=True, help="""Do not actually perform final build""")
@click.option('--use-submodules', default=None, help="""Add dependencies as Git submodules""")
@click.option('--use-ssh', default=None, is_flag=True, help="""Use SSH for downloading GitHub repositories""")
@click.argument('deps', nargs=-1)
def build(context, **kwargs):
    """Fetch and build the project's dependencies."""
    logging.info("<cmd>Build</cmd>")
    punic = context.obj
    punic.config.update(**kwargs)

    deps = kwargs['deps']

    logging.debug('Platforms: {}'.format(punic.config.platforms))
    logging.debug('Configuration: {}'.format(punic.config.configuration))

    with timeit('build', log=punic.config.log_timings):
        with error_handling():
            punic.build(dependencies=deps)

@punic_cli.command()
@click.pass_context
@click.option('--configuration', default=None, help="""Dependency configurations to build. Usually 'Release' or 'Debug'.""")
@click.option('--platform', default=None, help="""Platform to build. Comma separated list.""")
@click.option('--fetch/--no-fetch', default=True, is_flag=True, help="""Controls whether to fetch dependencies.""")
@click.option('--xcode-version', default=None, help="""Xcode version to use""")
@click.option('--toolchain', default=None, help="""Xcode toolchain to use""")
@click.option('--use-submodules', default=None, help="""Add dependencies as Git submodules""")
@click.option('--use-ssh', default=None, is_flag=True, help="""Use SSH for downloading GitHub repositories""")
@click.argument('deps', nargs=-1)
def update(context, **kwargs):
    """Update and rebuild the project's dependencies."""
    logging.info("<cmd>Update</cmd>")
    punic = context.obj
    punic.config.update(**kwargs)

    deps = kwargs['deps']

    with timeit('update', log=punic.config.log_timings):
        with error_handling():
            punic.resolve()
            punic.build(dependencies=deps)

@punic_cli.command()
@click.pass_context
@click.option('--derived-data', default=False, is_flag=True, help="""Clean the punic derived data directory.""")
@click.option('--caches', default=False, is_flag=True, help="""Clean the global punic files.""")
@click.option('--build', default=False, is_flag=True, help="""Clean the locate Carthage/Build directorys.""")
@click.option('--all', default=False, is_flag=True, help="""Clean all.""")
def clean(context, derived_data, caches, build, all):
    """Clean project & punic environment."""
    logging.info("<cmd>Clean</cmd>")
    punic = context.obj

    if build or all:
        logging.info('Erasing Carthage/Build directory')
        if punic.config.build_path.exists():
            shutil.rmtree(punic.config.build_path)

    if derived_data or all:
        logging.info('Erasing derived data directory')
        if punic.config.derived_data_path.exists():
            shutil.rmtree(punic.config.derived_data_path)

    if caches or all:
        if punic.config.repo_cache_directory.exists():
            logging.info('Erasing {}'.format(punic.config.repo_cache_directory))
            shutil.rmtree(punic.config.repo_cache_directory)
        logging.info('Erasing run cache')
        runner.reset()

@punic_cli.command()
@click.pass_context
@click.option('--fetch/--no-fetch', default=True, is_flag=True, help="""Controls whether to fetch dependencies.""")
@click.option('--use-submodules', default=None, help="""Add dependencies as Git submodules""")
@click.option('--use-ssh', default=None, is_flag=True, help="""Use SSH for downloading GitHub repositories""")
@click.option('--open', default=False, is_flag=True, help="""Open the graph image file.""")
def graph(context, fetch, use_submodules, use_ssh, open):
    """Output resolved dependency graph."""
    logging.info("<cmd>Graph</cmd>")
    punic = context.obj
    punic.config.fetch = fetch
    if use_submodules:
        punic.config.use_submodules = use_submodules
    if use_ssh:
        punic.config.use_ssh = use_ssh

    make_graph(punic, open)

@punic_cli.command(name='copy-frameworks')
@click.pass_context
def copy_frameworks(context):
    """In a Run Script build phase, copies each framework specified by a SCRIPT_INPUT_FILE environment variable into the built app bundle."""
    copy_frameworks_main()

# noinspection PyUnusedLocal
@punic_cli.command()
@click.pass_context
@click.option('--check/--no-check', default=True, help="""Check for latest version.""")
@click.option('--simple', is_flag=True, default=False, help="""Only display simple version info. Implies --no-check.""")
def version(context, check, simple):
    """Display the current version of Punic."""

    if simple:
        print("{}".format(punic.__version__))
    else:
        logging.info('Punic version: {}'.format(punic.__version__))

        sys_version = sys.version_info
        sys_version = SemanticVersion.from_dict(dict(major=sys_version.major, minor=sys_version.minor, micro=sys_version.micro, releaselevel=sys_version.releaselevel, serial=sys_version.serial, ))
        logging.info('Python version: {}'.format(sys_version))

        if check:
            version_check(verbose=True, timeout=None, failure_is_an_option=False)

@punic_cli.command()
@click.pass_context
def readme(context):
    """Opens punic readme in your browser (https://github.com/schwa/punic/blob/HEAD/README.markdown)"""
    click.launch('https://github.com/schwa/punic/blob/HEAD/README.markdown')

@punic_cli.command()
@click.option('--configuration', default=None, help="""Dependency configurations to build. Usually 'Release' or 'Debug'.""")
@click.option('--platform', default=None, help="""Platform to build. Comma separated list.""")
@click.option('--fetch/--no-fetch', default=True, is_flag=True, help="""Controls whether to fetch dependencies.""")
@click.option('--xcode-version', default=None, help="""Xcode version to use""")
@click.option('--toolchain', default=None, help="""Xcode toolchain to use""")
@click.option('--use-submodules', default=None, help="""Add dependencies as Git submodules""")
@click.option('--use-ssh', default=None, is_flag=True, help="""Use SSH for downloading GitHub repositories""")
@click.argument('deps', nargs=-1)
@click.pass_context
def list(context, **kwargs):
    """Lists all platforms, projects, xcode projects, schemes for all dependencies."""
    punic = context.obj
    punic.config.update(**kwargs)
    deps = kwargs['deps']

    config = punic.config

    configuration, platforms = config.configuration, config.platforms

    if not config.build_path.exists():
        config.build_path.mkdir(parents=True)

    filtered_dependencies = punic._ordered_dependencies(name_filter=deps)

    checkouts = [Checkout(punic=punic, identifier=identifier, revision=revision) for identifier, revision in filtered_dependencies]

    tree = {}

    for platform in platforms:
        tree[platform.name] = {}
        for checkout in checkouts:
            tree[platform.name][str(checkout.identifier)] = {'projects':{}}
            checkout.prepare()
            for project in checkout.projects:
                tree[platform.name][str(checkout.identifier)]['projects'][project.path.name] = {'schemes':{}}
                tree[platform.name][str(checkout.identifier)]['projects'][project.path.name]['path'] = str(project.path.relative_to(config.checkouts_path))
                schemes = project.schemes
                schemes = [scheme for scheme in schemes if scheme.framework_target]
                schemes = [scheme for scheme in schemes if platform.device_sdk in scheme.framework_target.supported_platform_names]
                tree[platform.name][str(checkout.identifier)]['projects'][project.path.name]['schemes'] = [scheme.name for scheme in schemes]

    import yaml

    yaml.safe_dump(tree, stream = sys.stdout)

@punic_cli.command()
@click.pass_context
@click.option('--configuration', default=None, help="""Dependency configurations to build. Usually 'Release' or 'Debug'.""")
@click.option('--platform', default=None, help="""Platform to build. Comma separated list.""")
@click.option('--xcode', default=None)
def init(context, **kwargs):
    """Generate punic configuration file."""
    config_init(**kwargs)

@punic_cli.group(cls=DYMGroup)
@click.pass_context
def cache(context):
    """Cache punic build artifacts to Amazon S3"""
    pass

@cache.command()
@click.pass_context
@click.option('--xcode-version', default=None, help="""Xcode version to use""")
@click.option('--force', default=False, is_flag=True, help="""Force publishing""")
def publish(context, xcode_version, force):
    """Generates and uploads the cache archive for the current Cartfile.resolved"""
    with error_handling():
        logging.info("<cmd>Cache Publish</cmd>")
        punic = context.obj
        if xcode_version:
            punic.config.xcode_version = xcode_version
        carthage_cache = CarthageCache(config=punic.config)
        logging.info("Cache filename: <ref>'{}'</ref>".format(carthage_cache.archive_name_for_project()))
        carthage_cache.publish(force = force)

@cache.command()
@click.pass_context
@click.option('--xcode-version', default=None, help="""Xcode version to use""")
def install(context, xcode_version):
    """Installs the cache archive for the current Cartfile.resolved"""
    with error_handling():
        logging.info("<cmd>Cache Install</cmd>")
        punic = context.obj
        if xcode_version:
            punic.config.xcode_version = xcode_version
        carthage_cache = CarthageCache(config=punic.config)
        logging.info("Cache filename: <ref>'{}'</ref>".format(carthage_cache.archive_name_for_project()))
        carthage_cache.install()

@punic_cli.command()
@click.pass_context
@click.argument('name')
@click.option('--append', is_flag=True, default=False, help="""Add a selected project to a Cartfile""")
@click.option('--language', default='swift', help="""Search for projects of specified language""")
def search(context, name, append, language):
    """Search github for repositories and optionally add them to a Cartfile."""
    punic = context.obj

    github_search(punic, name, cartfile_append=append, language=language)

def main():
    punic_cli()
<|endoftext|>


<commit_before># Copyright 2013-2021 Lawrence Livermore National Security, LLC and other
# Spack Project Developers. See the top-level COPYRIGHT file for details.
#
# SPDX-License-Identifier: (Apache-2.0 OR MIT)

from spack import *

class Hohqmesh(CMakePackage):
    """High Order mesh generator for Hexahedral and Quadrilateral meshes."""

    homepage = "https://github.com/trixi-framework/HOHQMesh"
    url      = "https://github.com/trixi-framework/HOHQMesh"
    git      = "https://github.com/trixi-framework/HOHQMesh.git"

    maintainers = ['schoonovernumerics']

    version('main', branch='main')
    version('v1.0.1', tag='v1.0.1')

    depends_on('ftobjectlibrary')

    parallel = False
<commit_msg>Add new versions for HOHQMesh and switch to tar-ball releases (#27194)<commit_after># Copyright 2013-2021 Lawrence Livermore National Security, LLC and other
# Spack Project Developers. See the top-level COPYRIGHT file for details.
#
# SPDX-License-Identifier: (Apache-2.0 OR MIT)

from spack import *

class Hohqmesh(CMakePackage):
    """High Order mesh generator for Hexahedral and Quadrilateral meshes."""

    homepage = "https://github.com/trixi-framework/HOHQMesh"
    git      = "https://github.com/trixi-framework/HOHQMesh.git"
    url      = "https://github.com/trixi-framework/HOHQMesh/archive/v1.0.0.tar.gz"

    maintainers = ['fluidnumerics-joe']

    version('1.1.0', sha256='5fdb75157d9dc29bba55e6ae9dc2be71294754204f4f0912795532ae66aada10')
    version('1.0.1', sha256='8435f13c96d714a287f3c24392330047e2131d53fafe251a77eba365bd2b3141')
    version('1.0.0', sha256='3800e63975d0a61945508f13fb76d5e2145c0260440484252b6b81aa0bfe076d')

    depends_on('ftobjectlibrary')

    parallel = False
<|endoftext|>


<commit_before><commit_msg>Use unix path separators in checkdeps. Otherwise it doesn't work on Unix systems. Review URL: http://codereview.chromium.org/27253<commit_after><|endoftext|>


<commit_before>#!/usr/bin/env python
# -*- coding: utf-8 -*-
import gdb
import pwndbg.arch
import pwndbg.arguments
import pwndbg.disasm
import pwndbg.disasm.arm
import pwndbg.disasm.jump
import pwndbg.disasm.mips
import pwndbg.disasm.ppc
import pwndbg.disasm.sparc
import pwndbg.disasm.x86

import pwndbg.vmmap
import pwndbg.dt
import pwndbg.memory
import pwndbg.inthook
import pwndbg.elf
import pwndbg.proc
import pwndbg.regs
import pwndbg.stack
import pwndbg.stdio
import pwndbg.color
import pwndbg.typeinfo
import pwndbg.constants
import pwndbg.argv
import pwndbg.commands
import pwndbg.commands.hexdump
import pwndbg.commands.context
import pwndbg.commands.telescope
import pwndbg.commands.vmmap
import pwndbg.commands.dt
import pwndbg.commands.search
import pwndbg.commands.start
import pwndbg.commands.procinfo
import pwndbg.commands.auxv
import pwndbg.commands.windbg
import pwndbg.commands.ida
import pwndbg.commands.reload
import pwndbg.commands.rop
import pwndbg.commands.shell
import pwndbg.commands.aslr
import pwndbg.commands.misc
import pwndbg.commands.next
import pwndbg.commands.dumpargs
import pwndbg.commands.cpsr
import pwndbg.commands.argv
import pwndbg.commands.heap

__all__ = [
'arch',
'auxv',
'chain',
'color',
'compat',
'disasm',
'dt',
'elf',
'enhance',
'events',
'file',
'function',
'hexdump',
'ida',
'info',
'linkmap',
'malloc',
'memoize',
'memory',
'proc',
'regs',
'remote',
'search',
'stack',
'strings',
'symbol',
'typeinfo',
'ui',
'vmmap'
]

# If the prompt is colorized, then the home and end keys
# don't work properly when on the prompt line.
#
# Instead, we set the prompt to be very plain.
#
# prompt = pwndbg.color.red('pwn> ')
# prompt = pwndbg.color.bold(prompt)
prompt = "pwn> "
prompt = "\x01" + prompt + "\x02" # SOH + prompt + STX
prompt = pwndbg.color.red(prompt)
prompt = pwndbg.color.bold(prompt)

pre_commands = """
set confirm off
set verbose off
set output-radix 0x10
set prompt %s
set height 0
set history expansion on
set history save on
set disassembly-flavor intel
set follow-fork-mode child
set backtrace past-main on
set step-mode on
set print pretty on
set width 0
set print elements 15
set input-radix 16
handle SIGALRM nostop print nopass
handle SIGSEGV stop   print nopass
""".strip() % prompt

for line in pre_commands.strip().splitlines():
	gdb.execute(line)

msg = "Loaded %i commands.  Type pwndbg for a list." % len(pwndbg.commands._Command.commands)
print(pwndbg.color.red(msg))

@pwndbg.memoize.reset_on_stop
def prompt_hook(*a):
    with pwndbg.stdio.stdio:
        pwndbg.commands.context.context()

gdb.prompt_hook = prompt_hook
<commit_msg>Remove unnecessary comment<commit_after>#!/usr/bin/env python
# -*- coding: utf-8 -*-
import gdb
import pwndbg.arch
import pwndbg.arguments
import pwndbg.disasm
import pwndbg.disasm.arm
import pwndbg.disasm.jump
import pwndbg.disasm.mips
import pwndbg.disasm.ppc
import pwndbg.disasm.sparc
import pwndbg.disasm.x86

import pwndbg.vmmap
import pwndbg.dt
import pwndbg.memory
import pwndbg.inthook
import pwndbg.elf
import pwndbg.proc
import pwndbg.regs
import pwndbg.stack
import pwndbg.stdio
import pwndbg.color
import pwndbg.typeinfo
import pwndbg.constants
import pwndbg.argv
import pwndbg.commands
import pwndbg.commands.hexdump
import pwndbg.commands.context
import pwndbg.commands.telescope
import pwndbg.commands.vmmap
import pwndbg.commands.dt
import pwndbg.commands.search
import pwndbg.commands.start
import pwndbg.commands.procinfo
import pwndbg.commands.auxv
import pwndbg.commands.windbg
import pwndbg.commands.ida
import pwndbg.commands.reload
import pwndbg.commands.rop
import pwndbg.commands.shell
import pwndbg.commands.aslr
import pwndbg.commands.misc
import pwndbg.commands.next
import pwndbg.commands.dumpargs
import pwndbg.commands.cpsr
import pwndbg.commands.argv
import pwndbg.commands.heap

__all__ = [
'arch',
'auxv',
'chain',
'color',
'compat',
'disasm',
'dt',
'elf',
'enhance',
'events',
'file',
'function',
'hexdump',
'ida',
'info',
'linkmap',
'malloc',
'memoize',
'memory',
'proc',
'regs',
'remote',
'search',
'stack',
'strings',
'symbol',
'typeinfo',
'ui',
'vmmap'
]

prompt = "pwn> "
prompt = "\x01" + prompt + "\x02" # SOH + prompt + STX
prompt = pwndbg.color.red(prompt)
prompt = pwndbg.color.bold(prompt)

pre_commands = """
set confirm off
set verbose off
set output-radix 0x10
set prompt %s
set height 0
set history expansion on
set history save on
set disassembly-flavor intel
set follow-fork-mode child
set backtrace past-main on
set step-mode on
set print pretty on
set width 0
set print elements 15
set input-radix 16
handle SIGALRM nostop print nopass
handle SIGSEGV stop   print nopass
""".strip() % prompt

for line in pre_commands.strip().splitlines():
	gdb.execute(line)

msg = "Loaded %i commands.  Type pwndbg for a list." % len(pwndbg.commands._Command.commands)
print(pwndbg.color.red(msg))

@pwndbg.memoize.reset_on_stop
def prompt_hook(*a):
    with pwndbg.stdio.stdio:
        pwndbg.commands.context.context()

gdb.prompt_hook = prompt_hook
<|endoftext|>


<commit_before>##############################################################################
# Copyright (c) 2013-2017, Lawrence Livermore National Security, LLC.
# Produced at the Lawrence Livermore National Laboratory.
#
# This file is part of Spack.
# Created by Todd Gamblin, tgamblin@llnl.gov, All rights reserved.
# LLNL-CODE-647188
#
# For details, see https://github.com/spack/spack
# Please also see the NOTICE and LICENSE files for our notice and the LGPL.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License (as
# published by the Free Software Foundation) version 2.1, February 1999.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the IMPLIED WARRANTY OF
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the terms and
# conditions of the GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
##############################################################################
from spack import *
import shutil

class Libiconv(AutotoolsPackage):
    """GNU libiconv provides an implementation of the iconv() function
    and the iconv program for character set conversion."""

    homepage = "https://www.gnu.org/software/libiconv/"
    url      = "http://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.15.tar.gz"

    version('1.15', 'ace8b5f2db42f7b3b3057585e80d9808')
    version('1.14', 'e34509b1623cec449dfeb73d7ce9c6c6')

    # We cannot set up a warning for gets(), since gets() is not part
    # of C11 any more and thus might not exist.
    patch('gets.patch', when='@1.14')

    def configure_args(self):
        args = ['--enable-extra-encodings']

        # A hack to patch config.guess in the libcharset sub directory
        shutil.copyfile('./build-aux/config.guess',
                        'libcharset/build-aux/config.guess')
        return args
<commit_msg>Older versions of libiconv don't work with newer versions of GCC (#6829)<commit_after>##############################################################################
# Copyright (c) 2013-2017, Lawrence Livermore National Security, LLC.
# Produced at the Lawrence Livermore National Laboratory.
#
# This file is part of Spack.
# Created by Todd Gamblin, tgamblin@llnl.gov, All rights reserved.
# LLNL-CODE-647188
#
# For details, see https://github.com/spack/spack
# Please also see the NOTICE and LICENSE files for our notice and the LGPL.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License (as
# published by the Free Software Foundation) version 2.1, February 1999.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the IMPLIED WARRANTY OF
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the terms and
# conditions of the GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
##############################################################################
from spack import *
import shutil

class Libiconv(AutotoolsPackage):
    """GNU libiconv provides an implementation of the iconv() function
    and the iconv program for character set conversion."""

    homepage = "https://www.gnu.org/software/libiconv/"
    url      = "http://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.15.tar.gz"

    version('1.15', 'ace8b5f2db42f7b3b3057585e80d9808')
    version('1.14', 'e34509b1623cec449dfeb73d7ce9c6c6')

    # We cannot set up a warning for gets(), since gets() is not part
    # of C11 any more and thus might not exist.
    patch('gets.patch', when='@1.14')

    conflicts('@1.14', when='%gcc@5:')

    def configure_args(self):
        args = ['--enable-extra-encodings']

        # A hack to patch config.guess in the libcharset sub directory
        shutil.copyfile('./build-aux/config.guess',
                        'libcharset/build-aux/config.guess')
        return args
<|endoftext|>


<commit_before>"""
Process raw qstr file and output qstr data with length, hash and data bytes.

This script works with Python 2.6, 2.7, 3.3 and 3.4.
"""

from __future__ import print_function

import re
import sys

# codepoint2name is different in Python 2 to Python 3
import platform
if platform.python_version_tuple()[0] == '2':
    from htmlentitydefs import codepoint2name
elif platform.python_version_tuple()[0] == '3':
    from html.entities import codepoint2name
codepoint2name[ord('-')] = 'hyphen';

# add some custom names to map characters that aren't in HTML
codepoint2name[ord(' ')] = 'space'
codepoint2name[ord('\'')] = 'squot'
codepoint2name[ord(',')] = 'comma'
codepoint2name[ord('.')] = 'dot'
codepoint2name[ord(':')] = 'colon'
codepoint2name[ord('/')] = 'slash'
codepoint2name[ord('%')] = 'percent'
codepoint2name[ord('#')] = 'hash'
codepoint2name[ord('(')] = 'paren_open'
codepoint2name[ord(')')] = 'paren_close'
codepoint2name[ord('[')] = 'bracket_open'
codepoint2name[ord(']')] = 'bracket_close'
codepoint2name[ord('{')] = 'brace_open'
codepoint2name[ord('}')] = 'brace_close'
codepoint2name[ord('*')] = 'star'
codepoint2name[ord('!')] = 'bang'
codepoint2name[ord('\\')] = 'backslash'
codepoint2name[ord('+')] = 'plus'

# this must match the equivalent function in qstr.c
def compute_hash(qstr, bytes_hash):
    hash = 5381
    for char in qstr:
        hash = (hash * 33) ^ ord(char)
    # Make sure that valid hash is never zero, zero means "hash not computed"
    return (hash & ((1 << (8 * bytes_hash)) - 1)) or 1

def qstr_escape(qst):
    return re.sub(r'[^A-Za-z0-9_]', lambda s: "_" + codepoint2name[ord(s.group(0))] + '_', qst)

def parse_input_headers(infiles):
    # read the qstrs in from the input files
    qcfgs = {}
    qstrs = {}
    for infile in infiles:
        with open(infile, 'rt') as f:
            for line in f:
                line = line.strip()

                # is this a config line?
                match = re.match(r'^QCFG\((.+), (.+)\)', line)
                if match:
                    value = match.group(2)
                    if value[0] == '(' and value[-1] == ')':
                        # strip parenthesis from config value
                        value = value[1:-1]
                    qcfgs[match.group(1)] = value
                    continue

                # is this a QSTR line?
                match = re.match(r'^Q\((.*)\)$', line)
                if not match:
                    continue

                # get the qstr value
                qstr = match.group(1)
                ident = qstr_escape(qstr)

                # don't add duplicates
                if ident in qstrs:
                    continue

                # add the qstr to the list, with order number to retain original order in file
                qstrs[ident] = (len(qstrs), ident, qstr)

    if not qcfgs:
        sys.stderr.write("ERROR: Empty preprocessor output - check for errors above\n")
        sys.exit(1)

    return qcfgs, qstrs

def make_bytes(cfg_bytes_len, cfg_bytes_hash, qstr):
    qhash = compute_hash(qstr, cfg_bytes_hash)
    # Calculate len of str, taking escapes into account
    qlen = len(qstr.replace("\\\\", "-").replace("\\", ""))
    qdata = qstr.replace('"', '\\"')
    if qlen >= (1 << (8 * cfg_bytes_len)):
        print('qstr is too long:', qstr)
        assert False
    qlen_str = ('\\x%02x' * cfg_bytes_len) % tuple(((qlen >> (8 * i)) & 0xff) for i in range(cfg_bytes_len))
    qhash_str = ('\\x%02x' * cfg_bytes_hash) % tuple(((qhash >> (8 * i)) & 0xff) for i in range(cfg_bytes_hash))
    return '(const byte*)"%s%s" "%s"' % (qhash_str, qlen_str, qdata)

def print_qstr_data(qcfgs, qstrs):
    # get config variables
    cfg_bytes_len = int(qcfgs['BYTES_IN_LEN'])
    cfg_bytes_hash = int(qcfgs['BYTES_IN_HASH'])

    # print out the starter of the generated C header file
    print('// This file was automatically generated by makeqstrdata.py')
    print('')

    # add NULL qstr with no hash or data
    print('QDEF(MP_QSTR_NULL, (const byte*)"%s%s" "")' % ('\\x00' * cfg_bytes_hash, '\\x00' * cfg_bytes_len))

    # go through each qstr and print it out
    for order, ident, qstr in sorted(qstrs.values(), key=lambda x: x[0]):
        qbytes = make_bytes(cfg_bytes_len, cfg_bytes_hash, qstr)
        print('QDEF(MP_QSTR_%s, %s)' % (ident, qbytes))

def do_work(infiles):
    qcfgs, qstrs = parse_input_headers(infiles)
    print_qstr_data(qcfgs, qstrs)

if __name__ == "__main__":
    do_work(sys.argv[1:])
<commit_msg>py/makeqstrdata: Add more names for escaped chars and esc non-printable.<commit_after>"""
Process raw qstr file and output qstr data with length, hash and data bytes.

This script works with Python 2.6, 2.7, 3.3 and 3.4.
"""

from __future__ import print_function

import re
import sys

# codepoint2name is different in Python 2 to Python 3
import platform
if platform.python_version_tuple()[0] == '2':
    from htmlentitydefs import codepoint2name
elif platform.python_version_tuple()[0] == '3':
    from html.entities import codepoint2name
codepoint2name[ord('-')] = 'hyphen';

# add some custom names to map characters that aren't in HTML
codepoint2name[ord(' ')] = 'space'
codepoint2name[ord('\'')] = 'squot'
codepoint2name[ord(',')] = 'comma'
codepoint2name[ord('.')] = 'dot'
codepoint2name[ord(':')] = 'colon'
codepoint2name[ord(';')] = 'semicolon'
codepoint2name[ord('/')] = 'slash'
codepoint2name[ord('%')] = 'percent'
codepoint2name[ord('#')] = 'hash'
codepoint2name[ord('(')] = 'paren_open'
codepoint2name[ord(')')] = 'paren_close'
codepoint2name[ord('[')] = 'bracket_open'
codepoint2name[ord(']')] = 'bracket_close'
codepoint2name[ord('{')] = 'brace_open'
codepoint2name[ord('}')] = 'brace_close'
codepoint2name[ord('*')] = 'star'
codepoint2name[ord('!')] = 'bang'
codepoint2name[ord('\\')] = 'backslash'
codepoint2name[ord('+')] = 'plus'
codepoint2name[ord('$')] = 'dollar'
codepoint2name[ord('=')] = 'equals'
codepoint2name[ord('?')] = 'question'
codepoint2name[ord('@')] = 'at_sign'
codepoint2name[ord('^')] = 'caret'
codepoint2name[ord('|')] = 'pipe'
codepoint2name[ord('~')] = 'tilde'

# this must match the equivalent function in qstr.c
def compute_hash(qstr, bytes_hash):
    hash = 5381
    for char in qstr:
        hash = (hash * 33) ^ ord(char)
    # Make sure that valid hash is never zero, zero means "hash not computed"
    return (hash & ((1 << (8 * bytes_hash)) - 1)) or 1

def qstr_escape(qst):
    def esc_char(m):
        c = ord(m.group(0))
        try:
            name = codepoint2name[c]
        except KeyError:
            name = '0x%02x' % c
        return "_" + name + '_'
    return re.sub(r'[^A-Za-z0-9_]', esc_char, qst)

def parse_input_headers(infiles):
    # read the qstrs in from the input files
    qcfgs = {}
    qstrs = {}
    for infile in infiles:
        with open(infile, 'rt') as f:
            for line in f:
                line = line.strip()

                # is this a config line?
                match = re.match(r'^QCFG\((.+), (.+)\)', line)
                if match:
                    value = match.group(2)
                    if value[0] == '(' and value[-1] == ')':
                        # strip parenthesis from config value
                        value = value[1:-1]
                    qcfgs[match.group(1)] = value
                    continue

                # is this a QSTR line?
                match = re.match(r'^Q\((.*)\)$', line)
                if not match:
                    continue

                # get the qstr value
                qstr = match.group(1)
                ident = qstr_escape(qstr)

                # don't add duplicates
                if ident in qstrs:
                    continue

                # add the qstr to the list, with order number to retain original order in file
                qstrs[ident] = (len(qstrs), ident, qstr)

    if not qcfgs:
        sys.stderr.write("ERROR: Empty preprocessor output - check for errors above\n")
        sys.exit(1)

    return qcfgs, qstrs

def make_bytes(cfg_bytes_len, cfg_bytes_hash, qstr):
    qhash = compute_hash(qstr, cfg_bytes_hash)
    # Calculate len of str, taking escapes into account
    qlen = len(qstr.replace("\\\\", "-").replace("\\", ""))
    qdata = qstr.replace('"', '\\"')
    if qlen >= (1 << (8 * cfg_bytes_len)):
        print('qstr is too long:', qstr)
        assert False
    qlen_str = ('\\x%02x' * cfg_bytes_len) % tuple(((qlen >> (8 * i)) & 0xff) for i in range(cfg_bytes_len))
    qhash_str = ('\\x%02x' * cfg_bytes_hash) % tuple(((qhash >> (8 * i)) & 0xff) for i in range(cfg_bytes_hash))
    return '(const byte*)"%s%s" "%s"' % (qhash_str, qlen_str, qdata)

def print_qstr_data(qcfgs, qstrs):
    # get config variables
    cfg_bytes_len = int(qcfgs['BYTES_IN_LEN'])
    cfg_bytes_hash = int(qcfgs['BYTES_IN_HASH'])

    # print out the starter of the generated C header file
    print('// This file was automatically generated by makeqstrdata.py')
    print('')

    # add NULL qstr with no hash or data
    print('QDEF(MP_QSTR_NULL, (const byte*)"%s%s" "")' % ('\\x00' * cfg_bytes_hash, '\\x00' * cfg_bytes_len))

    # go through each qstr and print it out
    for order, ident, qstr in sorted(qstrs.values(), key=lambda x: x[0]):
        qbytes = make_bytes(cfg_bytes_len, cfg_bytes_hash, qstr)
        print('QDEF(MP_QSTR_%s, %s)' % (ident, qbytes))

def do_work(infiles):
    qcfgs, qstrs = parse_input_headers(infiles)
    print_qstr_data(qcfgs, qstrs)

if __name__ == "__main__":
    do_work(sys.argv[1:])
<|endoftext|>


<commit_before>#! /usr/bin/python3

import sys
import argparse
import xml_utils as u
import datetime
import os
from argparse import RawTextHelpFormatter
from collections import defaultdict

##------------------------------------------------------------
##  generate csv of distances between all permutations of two
##  embedding files.
##
##	usage:
##    csv_embed_distances.py -out e_dist.csv e_test.xml e_train.xml
##------------------------------------------------------------
def main (argv) :
	parser = argparse.ArgumentParser(description='\nGenerate CSV of distances for all permutations of two input embedding files.\n\n \tExample: ' + os.path.basename (argv[0]) + ' -out e_dist.csv  embed1.xml embed2.xml',
		formatter_class=RawTextHelpFormatter)
	parser.add_argument ('embed1')
	parser.add_argument ('embed2')
	parser.add_argument ('-db', '--db',
		help='db of images info.')
	parser.add_argument ('-out', '--output', default="e_dist.csv",
		help='specify csv output file.')
	parser.add_argument ('-v', '--verbosity', type=int, default=1,
		choices=[0, 1, 2, 3], help='')
		# help="increase output verbosity"
	u.set_argv (argv)
	args = parser.parse_args()
	u.set_verbosity (args.verbosity)
	u.set_argv (argv)
	u.set_filetype ('embeds')
	verbose = 0
	if verbose > 0:
		print("files: ", args.files)
	if os.path.exists (args.output) :
		u.current_datetime ()
		csv_filename = 'e_dist_' + u.current_datetime () + '.csv'
		print ('CSV file exists, writing to ' +  csv_filename)
		args.output = csv_filename
	u.gen_embed_dist_csv ([args.embed1], [args.embed2], args.output, args.db)

if __name__ == "__main__":
	main (sys.argv)

<commit_msg>Added options for - average : returns nearest label average (instead of individual), - top : returns top n closest - stats : write out collective matching stats for each label<commit_after>#! /usr/bin/python3

import sys
import argparse
import xml_utils as u
import datetime
import os
from argparse import RawTextHelpFormatter
from collections import defaultdict

##------------------------------------------------------------
##  generate csv of distances between all permutations of two
##  embedding files.
##
##	usage:
##    csv_embed_distances.py -out e_dist.csv e_test.xml e_train.xml
##------------------------------------------------------------
def main (argv) :
	parser = argparse.ArgumentParser(description='\nGenerate CSV of distances for all permutations of two input embedding files.\n\n \tExample: ' + os.path.basename (argv[0]) + ' -out e_dist.csv  embed1.xml embed2.xml',
		formatter_class=RawTextHelpFormatter)
	parser.add_argument ('embed1')
	parser.add_argument ('embed2')
	parser.add_argument ('-av', '--average', action='store_true',
		help='for embed2, use average for each label instead of each embedding. Mutually exclusive with --top_match')
	parser.add_argument ('-top', '--top_match',
		help='find closest n matches and use simple majority for matching. Defaults to 1.  Used mutually exclusively with --average.')
	parser.add_argument ('-db', '--db',
		help='db of images info.')
	parser.add_argument ('-out', '--output', default="e_dist.csv",
		help='specify csv output file.')
	parser.add_argument ('-stats', '--stats', action='store_true',
		help='Write matching stats for each label.')
	parser.add_argument ('-v', '--verbosity', type=int, default=1,
		choices=[0, 1, 2, 3], help='')
		# help="increase output verbosity"
	u.set_argv (argv)
	args = parser.parse_args()
	u.set_verbosity (args.verbosity)
	u.set_argv (argv)
	u.set_filetype ('embeds')
	if args.verbosity > 0:
		print("input files: ", args.embed1, args.embed2)
	if args.average and args.top_match :
		print ('options --average and --top_match are mutually exclusive.\n')
		return
	if os.path.exists (args.output) :
		u.current_datetime ()
		csv_filename = 'e_dist_' + u.current_datetime () + '.csv'
		print ('CSV file exists, writing to ' +  csv_filename)
		args.output = csv_filename
	if args.average :
		top_match = 0
	elif args.top_match :
		top_match = args.top_match
	else :
		top_match = 1  # default value

	u.gen_embed_dist_csv ([args.embed1], [args.embed2], args.output, args.db, int (top_match), args.stats)

if __name__ == "__main__":
	main (sys.argv)

<|endoftext|>


<commit_before>"""List the moles in a mole catalog."""

import os

def setup_parser(parser):
    parser.add_argument(
        '--only-no-micro',
        action='store_true',
        help="Only list moles that have no microscope images.")

    assistance = parser.add_mutually_exclusive_group()
    assistance.add_argument(
        '--without-assistance',
        action='store_true',
        help="Only list moles that don't require assistance to capture.")
    assistance.add_argument(
        '--with-assistance',
        action='store_true',
        help="Only list moles that require assistance to capture.")

    parser.add_argument(
        '--sort',
        choices=['lastmicro'])

def process_args(args):
    if not args.sort:
        for mole in _yield_mole_dirs('.', args):
            print(mole.catalog_relative_path)
    else:
        keyfunc = None

        if args.sort == 'lastmicro':
            def keyfunc(x):
                if not x.micro_filenames:
                    return str()
                return sorted(x.micro_filenames)[-1]

        for mole in sorted(_yield_mole_dirs('.', args), key=keyfunc):
            print(mole.catalog_relative_path)

class _Mole(object):

    def __init__(self, catalog_relative_path, micro_filenames):
        super(_Mole, self).__init__()
        self.catalog_relative_path = catalog_relative_path
        self.micro_filenames = micro_filenames

def _yield_mole_dirs(rootpath, args):
    for path, dirs, files in os.walk(rootpath):

        this_dirname = os.path.basename(path)

        if this_dirname == '__micro__':
            continue

        catalog_relpath = os.path.relpath(path, rootpath)

        # ignore directories with no files
        if not files:
            continue

        # ignore dot-directories in the root, like '.git'
        if catalog_relpath.startswith('.'):
            continue

        unknown_dirs = set(dirs)

        if args.only_no_micro and '__micro__' in unknown_dirs:
            if os.listdir(os.path.join(path, '__micro__')):
                continue

        if args.without_assistance and '__need_assistance__' in files:
            continue

        if args.with_assistance and '__need_assistance__' not in files:
            continue

        micro_filenames = []
        if '__micro__' in unknown_dirs:
            unknown_dirs.discard('__micro__')
            micro_filenames = os.listdir(os.path.join(path, '__micro__'))

        # mole clusters have a picture and all the moles as child dirs, ignore
        if unknown_dirs:
            continue

        yield _Mole(
            catalog_relpath,
            micro_filenames)
<commit_msg>mel list: support --format for flexible printing<commit_after>"""List the moles in a mole catalog."""

import os

def setup_parser(parser):
    parser.add_argument(
        '--only-no-micro',
        action='store_true',
        help="Only list moles that have no microscope images.")

    assistance = parser.add_mutually_exclusive_group()
    assistance.add_argument(
        '--without-assistance',
        action='store_true',
        help="Only list moles that don't require assistance to capture.")
    assistance.add_argument(
        '--with-assistance',
        action='store_true',
        help="Only list moles that require assistance to capture.")

    assistance.add_argument(
        '--format',
        default="{relpath}",
        help="Print the results with the specified format. Defaults to "
             "'{relpath}'. Available keys: relpath, lastmicro.")

    parser.add_argument(
        '--sort',
        choices=['lastmicro'])

def process_args(args):
    keyfunc = None

    if args.sort == 'lastmicro':
        def keyfunc(x):
            if not x.micro_filenames:
                return str()
            return sorted(x.micro_filenames)[-1]
    else:
        def keyfunc(x):
            return 0

    for mole in sorted(_yield_mole_dirs('.', args), key=keyfunc):
        mole_data = {
            'relpath': mole.catalog_relative_path,
            'lastmicro': '',
        }
        if mole.micro_filenames:
            mole_data['lastmicro'] = sorted(mole.micro_filenames)[-1]
        print(args.format.format(**mole_data))

class _Mole(object):

    def __init__(self, catalog_relative_path, micro_filenames):
        super(_Mole, self).__init__()
        self.catalog_relative_path = catalog_relative_path
        self.micro_filenames = micro_filenames

def _yield_mole_dirs(rootpath, args):
    for path, dirs, files in os.walk(rootpath):

        this_dirname = os.path.basename(path)

        if this_dirname == '__micro__':
            continue

        catalog_relpath = os.path.relpath(path, rootpath)

        # ignore directories with no files
        if not files:
            continue

        # ignore dot-directories in the root, like '.git'
        if catalog_relpath.startswith('.'):
            continue

        unknown_dirs = set(dirs)

        if args.only_no_micro and '__micro__' in unknown_dirs:
            if os.listdir(os.path.join(path, '__micro__')):
                continue

        if args.without_assistance and '__need_assistance__' in files:
            continue

        if args.with_assistance and '__need_assistance__' not in files:
            continue

        micro_filenames = []
        if '__micro__' in unknown_dirs:
            unknown_dirs.discard('__micro__')
            micro_filenames = os.listdir(os.path.join(path, '__micro__'))

        # mole clusters have a picture and all the moles as child dirs, ignore
        if unknown_dirs:
            continue

        yield _Mole(
            catalog_relpath,
            micro_filenames)
<|endoftext|>


<commit_before>##############################################################################
# Copyright (c) 2013-2016, Lawrence Livermore National Security, LLC.
# Produced at the Lawrence Livermore National Laboratory.
#
# This file is part of Spack.
# Created by Todd Gamblin, tgamblin@llnl.gov, All rights reserved.
# LLNL-CODE-647188
#
# For details, see https://github.com/llnl/spack
# Please also see the LICENSE file for our notice and the LGPL.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License (as
# published by the Free Software Foundation) version 2.1, February 1999.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the IMPLIED WARRANTY OF
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the terms and
# conditions of the GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
##############################################################################
import sys

from spack import *
from spack.error import SpackError

def _process_manager_validator(values):
    if len(values) > 1 and 'slurm' in values:
        raise SpackError(
            'slurm cannot be activated along with other process managers'
        )

class Mvapich2(AutotoolsPackage):
    """MVAPICH2 is an MPI implementation for Infiniband networks."""
    homepage = "http://mvapich.cse.ohio-state.edu/"
    url = "http://mvapich.cse.ohio-state.edu/download/mvapich/mv2/mvapich2-2.2.tar.gz"
    list_url = "http://mvapich.cse.ohio-state.edu/downloads/"

    # Newer alpha release
    version('2.3a', '87c3fbf8a755b53806fa9ecb21453445')

    # Prefer the latest stable release
    version('2.2', '939b65ebe5b89a5bc822cdab0f31f96e', preferred=True)
    version('2.1', '0095ceecb19bbb7fb262131cb9c2cdd6')
    version('2.0', '9fbb68a4111a8b6338e476dc657388b4')
    version('1.9', '5dc58ed08fd3142c260b70fe297e127c')

    patch('ad_lustre_rwcontig_open_source.patch', when='@1.9')

    provides('mpi@:2.2', when='@1.9')  # MVAPICH2-1.9 supports MPI 2.2
    provides('mpi@:3.0', when='@2.0:')  # MVAPICH2-2.0 supports MPI 3.0

    variant('debug', default=False,
            description='Enable debug info and error messages at run-time')

    # Accepted values are:
    #   single      - No threads (MPI_THREAD_SINGLE)
    #   funneled    - Only the main thread calls MPI (MPI_THREAD_FUNNELED)
    #   serialized  - User serializes calls to MPI (MPI_THREAD_SERIALIZED)
    #   multiple    - Fully multi-threaded (MPI_THREAD_MULTIPLE)
    #   runtime     - Alias to "multiple"
    variant(
        'threads',
        default='multiple',
        values=('single', 'funneled', 'serialized', 'multiple'),
        multi=False,
        description='Control the level of thread support'
    )

    # 32 is needed when job size exceeds 32768 cores
    variant(
        'ch3_rank_bits',
        default='32',
        values=('16', '32'),
        multi=False,
        description='Number of bits allocated to the rank field (16 or 32)'
    )

    variant(
        'process_managers',
        description='List of the process managers to activate',
        values=('slurm', 'hydra', 'gforker', 'remshell'),
        multi=True,
        validator=_process_manager_validator
    )

    variant(
        'fabrics',
        description='The fabric enabled for this build',
        default='psm',
        values=(
            'psm', 'sock', 'nemesisib', 'nemesis', 'mrail', 'nemesisibtcp'
        )
    )

    # FIXME : CUDA support is missing
    depends_on('bison')
    depends_on('libpciaccess', when=(sys.platform != 'darwin'))

    def url_for_version(self, version):
        base_url = "http://mvapich.cse.ohio-state.edu/download"
        if version < Version('2.0'):
            return "%s/mvapich2/mv2/mvapich2-%s.tar.gz" % (base_url, version)
        else:
            return "%s/mvapich/mv2/mvapich2-%s.tar.gz"  % (base_url, version)

    @property
    def process_manager_options(self):
        spec = self.spec

        other_pms = []
        for x in ('hydra', 'gforker', 'remshell'):
            if 'process_managers={0}'.format(x) in spec:
                other_pms.append(x)
        opts = ['--with-pm=%s' % ':'.join(other_pms)]

        # See: http://slurm.schedmd.com/mpi_guide.html#mvapich2
        if 'process_managers=slurm' in spec:
            if self.version > Version('2.0'):
                opts = [
                    '--with-pmi=pmi2',
                    '--with-pm=slurm'
                ]
            else:
                opts = [
                    '--with-pmi=slurm',
                    '--with-pm=no'
                ]

        return opts

    @property
    def network_options(self):
        opts = []
        # From here on I can suppose that only one variant has been selected
        if 'fabrics=psm' in self.spec:
            opts = ["--with-device=ch3:psm"]
        elif 'fabrics=sock' in self.spec:
            opts = ["--with-device=ch3:sock"]
        elif 'fabrics=nemesisibtcp' in self.spec:
            opts = ["--with-device=ch3:nemesis:ib,tcp"]
        elif 'fabrics=nemesisib' in self.spec:
            opts = ["--with-device=ch3:nemesis:ib"]
        elif 'fabrics=nemesis' in self.spec:
            opts = ["--with-device=ch3:nemesis"]
        elif 'fabrics=mrail' in self.spec:
            opts = ["--with-device=ch3:mrail", "--with-rdma=gen2"]
        return opts

    def setup_environment(self, spack_env, run_env):
        spec = self.spec
        if 'process_managers=slurm' in spec and spec.satisfies('@2.0:'):
            run_env.set('SLURM_MPI_TYPE', 'pmi2')

    def setup_dependent_environment(self, spack_env, run_env, dependent_spec):
        spack_env.set('MPICC',  join_path(self.prefix.bin, 'mpicc'))
        spack_env.set('MPICXX', join_path(self.prefix.bin, 'mpicxx'))
        spack_env.set('MPIF77', join_path(self.prefix.bin, 'mpif77'))
        spack_env.set('MPIF90', join_path(self.prefix.bin, 'mpif90'))

        spack_env.set('MPICH_CC', spack_cc)
        spack_env.set('MPICH_CXX', spack_cxx)
        spack_env.set('MPICH_F77', spack_f77)
        spack_env.set('MPICH_F90', spack_fc)
        spack_env.set('MPICH_FC', spack_fc)

    def setup_dependent_package(self, module, dependent_spec):
        self.spec.mpicc  = join_path(self.prefix.bin, 'mpicc')
        self.spec.mpicxx = join_path(self.prefix.bin, 'mpicxx')
        self.spec.mpifc  = join_path(self.prefix.bin, 'mpif90')
        self.spec.mpif77 = join_path(self.prefix.bin, 'mpif77')
        self.spec.mpicxx_shared_libs = [
            join_path(self.prefix.lib, 'libmpicxx.{0}'.format(dso_suffix)),
            join_path(self.prefix.lib, 'libmpi.{0}'.format(dso_suffix))
        ]

    @run_before('configure')
    def die_without_fortran(self):
        # Until we can pass variants such as +fortran through virtual
        # dependencies depends_on('mpi'), require Fortran compiler to
        # avoid delayed build errors in dependents.
        if (self.compiler.f77 is None) or (self.compiler.fc is None):
            raise InstallError(
                'Mvapich2 requires both C and Fortran compilers!'
            )

    def configure_args(self):
        spec = self.spec
        args = [
            '--enable-shared',
            '--enable-romio',
            '-disable-silent-rules',
            '--enable-fortran=all',
            "--enable-threads={0}".format(spec.variants['threads'].value),
            "--with-ch3-rank-bits={0}".format(
                spec.variants['ch3_rank_bits'].value),
        ]

        if '+debug' in self.spec:
            args.extend([
                '--disable-fast',
                '--enable-error-checking=runtime',
                '--enable-error-messages=all',
                # Permits debugging with TotalView
                '--enable-g=dbg',
                '--enable-debuginfo'
            ])
        else:
            args.append('--enable-fast=all')

        args.extend(self.process_manager_options)
        args.extend(self.network_options)
        return args

    @run_after('install')
    def filter_compilers(self):
        """Run after install to make the MPI compilers use the
           compilers that Spack built the package with.

           If this isn't done, they'll have CC, CXX, F77, and FC set
           to Spack's generic cc, c++, f77, and f90.  We want them to
           be bound to whatever compiler they were built with.
        """
        bin = self.prefix.bin
        mpicc = join_path(bin, 'mpicc')
        mpicxx = join_path(bin, 'mpicxx')
        mpif77 = join_path(bin, 'mpif77')
        mpif90 = join_path(bin, 'mpif90')

        # Substitute Spack compile wrappers for the real
        # underlying compiler
        kwargs = {'ignore_absent': True, 'backup': False, 'string': True}
        filter_file(env['CC'], self.compiler.cc, mpicc, **kwargs)
        filter_file(env['CXX'], self.compiler.cxx, mpicxx, **kwargs)
        filter_file(env['F77'], self.compiler.f77, mpif77, **kwargs)
        filter_file(env['FC'], self.compiler.fc, mpif90, **kwargs)

        # Remove this linking flag if present
        # (it turns RPATH into RUNPATH)
        for wrapper in (mpicc, mpicxx, mpif77, mpif90):
            filter_file('-Wl,--enable-new-dtags', '', wrapper, **kwargs)
<commit_msg>Add nemesistcpib fabrics variant (#4197)<commit_after>##############################################################################
# Copyright (c) 2013-2016, Lawrence Livermore National Security, LLC.
# Produced at the Lawrence Livermore National Laboratory.
#
# This file is part of Spack.
# Created by Todd Gamblin, tgamblin@llnl.gov, All rights reserved.
# LLNL-CODE-647188
#
# For details, see https://github.com/llnl/spack
# Please also see the LICENSE file for our notice and the LGPL.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License (as
# published by the Free Software Foundation) version 2.1, February 1999.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the IMPLIED WARRANTY OF
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the terms and
# conditions of the GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
##############################################################################
import sys

from spack import *
from spack.error import SpackError

def _process_manager_validator(values):
    if len(values) > 1 and 'slurm' in values:
        raise SpackError(
            'slurm cannot be activated along with other process managers'
        )

class Mvapich2(AutotoolsPackage):
    """MVAPICH2 is an MPI implementation for Infiniband networks."""
    homepage = "http://mvapich.cse.ohio-state.edu/"
    url = "http://mvapich.cse.ohio-state.edu/download/mvapich/mv2/mvapich2-2.2.tar.gz"
    list_url = "http://mvapich.cse.ohio-state.edu/downloads/"

    # Newer alpha release
    version('2.3a', '87c3fbf8a755b53806fa9ecb21453445')

    # Prefer the latest stable release
    version('2.2', '939b65ebe5b89a5bc822cdab0f31f96e', preferred=True)
    version('2.1', '0095ceecb19bbb7fb262131cb9c2cdd6')
    version('2.0', '9fbb68a4111a8b6338e476dc657388b4')
    version('1.9', '5dc58ed08fd3142c260b70fe297e127c')

    patch('ad_lustre_rwcontig_open_source.patch', when='@1.9')

    provides('mpi@:2.2', when='@1.9')  # MVAPICH2-1.9 supports MPI 2.2
    provides('mpi@:3.0', when='@2.0:')  # MVAPICH2-2.0 supports MPI 3.0

    variant('debug', default=False,
            description='Enable debug info and error messages at run-time')

    # Accepted values are:
    #   single      - No threads (MPI_THREAD_SINGLE)
    #   funneled    - Only the main thread calls MPI (MPI_THREAD_FUNNELED)
    #   serialized  - User serializes calls to MPI (MPI_THREAD_SERIALIZED)
    #   multiple    - Fully multi-threaded (MPI_THREAD_MULTIPLE)
    #   runtime     - Alias to "multiple"
    variant(
        'threads',
        default='multiple',
        values=('single', 'funneled', 'serialized', 'multiple'),
        multi=False,
        description='Control the level of thread support'
    )

    # 32 is needed when job size exceeds 32768 cores
    variant(
        'ch3_rank_bits',
        default='32',
        values=('16', '32'),
        multi=False,
        description='Number of bits allocated to the rank field (16 or 32)'
    )

    variant(
        'process_managers',
        description='List of the process managers to activate',
        values=('slurm', 'hydra', 'gforker', 'remshell'),
        multi=True,
        validator=_process_manager_validator
    )

    variant(
        'fabrics',
        description='The fabric enabled for this build',
        default='psm',
        values=(
            'psm', 'sock', 'nemesisib', 'nemesis', 'mrail', 'nemesisibtcp',
            'nemesistcpib'
        )
    )

    # FIXME : CUDA support is missing
    depends_on('bison')
    depends_on('libpciaccess', when=(sys.platform != 'darwin'))

    def url_for_version(self, version):
        base_url = "http://mvapich.cse.ohio-state.edu/download"
        if version < Version('2.0'):
            return "%s/mvapich2/mv2/mvapich2-%s.tar.gz" % (base_url, version)
        else:
            return "%s/mvapich/mv2/mvapich2-%s.tar.gz"  % (base_url, version)

    @property
    def process_manager_options(self):
        spec = self.spec

        other_pms = []
        for x in ('hydra', 'gforker', 'remshell'):
            if 'process_managers={0}'.format(x) in spec:
                other_pms.append(x)
        opts = ['--with-pm=%s' % ':'.join(other_pms)]

        # See: http://slurm.schedmd.com/mpi_guide.html#mvapich2
        if 'process_managers=slurm' in spec:
            if self.version > Version('2.0'):
                opts = [
                    '--with-pmi=pmi2',
                    '--with-pm=slurm'
                ]
            else:
                opts = [
                    '--with-pmi=slurm',
                    '--with-pm=no'
                ]

        return opts

    @property
    def network_options(self):
        opts = []
        # From here on I can suppose that only one variant has been selected
        if 'fabrics=psm' in self.spec:
            opts = ["--with-device=ch3:psm"]
        elif 'fabrics=sock' in self.spec:
            opts = ["--with-device=ch3:sock"]
        elif 'fabrics=nemesistcpib' in self.spec:
            opts = ["--with-device=ch3:nemesis:tcp,ib"]
        elif 'fabrics=nemesisibtcp' in self.spec:
            opts = ["--with-device=ch3:nemesis:ib,tcp"]
        elif 'fabrics=nemesisib' in self.spec:
            opts = ["--with-device=ch3:nemesis:ib"]
        elif 'fabrics=nemesis' in self.spec:
            opts = ["--with-device=ch3:nemesis"]
        elif 'fabrics=mrail' in self.spec:
            opts = ["--with-device=ch3:mrail", "--with-rdma=gen2"]
        return opts

    def setup_environment(self, spack_env, run_env):
        spec = self.spec
        if 'process_managers=slurm' in spec and spec.satisfies('@2.0:'):
            run_env.set('SLURM_MPI_TYPE', 'pmi2')

    def setup_dependent_environment(self, spack_env, run_env, dependent_spec):
        spack_env.set('MPICC',  join_path(self.prefix.bin, 'mpicc'))
        spack_env.set('MPICXX', join_path(self.prefix.bin, 'mpicxx'))
        spack_env.set('MPIF77', join_path(self.prefix.bin, 'mpif77'))
        spack_env.set('MPIF90', join_path(self.prefix.bin, 'mpif90'))

        spack_env.set('MPICH_CC', spack_cc)
        spack_env.set('MPICH_CXX', spack_cxx)
        spack_env.set('MPICH_F77', spack_f77)
        spack_env.set('MPICH_F90', spack_fc)
        spack_env.set('MPICH_FC', spack_fc)

    def setup_dependent_package(self, module, dependent_spec):
        self.spec.mpicc  = join_path(self.prefix.bin, 'mpicc')
        self.spec.mpicxx = join_path(self.prefix.bin, 'mpicxx')
        self.spec.mpifc  = join_path(self.prefix.bin, 'mpif90')
        self.spec.mpif77 = join_path(self.prefix.bin, 'mpif77')
        self.spec.mpicxx_shared_libs = [
            join_path(self.prefix.lib, 'libmpicxx.{0}'.format(dso_suffix)),
            join_path(self.prefix.lib, 'libmpi.{0}'.format(dso_suffix))
        ]

    @run_before('configure')
    def die_without_fortran(self):
        # Until we can pass variants such as +fortran through virtual
        # dependencies depends_on('mpi'), require Fortran compiler to
        # avoid delayed build errors in dependents.
        if (self.compiler.f77 is None) or (self.compiler.fc is None):
            raise InstallError(
                'Mvapich2 requires both C and Fortran compilers!'
            )

    def configure_args(self):
        spec = self.spec
        args = [
            '--enable-shared',
            '--enable-romio',
            '-disable-silent-rules',
            '--enable-fortran=all',
            "--enable-threads={0}".format(spec.variants['threads'].value),
            "--with-ch3-rank-bits={0}".format(
                spec.variants['ch3_rank_bits'].value),
        ]

        if '+debug' in self.spec:
            args.extend([
                '--disable-fast',
                '--enable-error-checking=runtime',
                '--enable-error-messages=all',
                # Permits debugging with TotalView
                '--enable-g=dbg',
                '--enable-debuginfo'
            ])
        else:
            args.append('--enable-fast=all')

        args.extend(self.process_manager_options)
        args.extend(self.network_options)
        return args

    @run_after('install')
    def filter_compilers(self):
        """Run after install to make the MPI compilers use the
           compilers that Spack built the package with.

           If this isn't done, they'll have CC, CXX, F77, and FC set
           to Spack's generic cc, c++, f77, and f90.  We want them to
           be bound to whatever compiler they were built with.
        """
        bin = self.prefix.bin
        mpicc = join_path(bin, 'mpicc')
        mpicxx = join_path(bin, 'mpicxx')
        mpif77 = join_path(bin, 'mpif77')
        mpif90 = join_path(bin, 'mpif90')

        # Substitute Spack compile wrappers for the real
        # underlying compiler
        kwargs = {'ignore_absent': True, 'backup': False, 'string': True}
        filter_file(env['CC'], self.compiler.cc, mpicc, **kwargs)
        filter_file(env['CXX'], self.compiler.cxx, mpicxx, **kwargs)
        filter_file(env['F77'], self.compiler.f77, mpif77, **kwargs)
        filter_file(env['FC'], self.compiler.fc, mpif90, **kwargs)

        # Remove this linking flag if present
        # (it turns RPATH into RUNPATH)
        for wrapper in (mpicc, mpicxx, mpif77, mpif90):
            filter_file('-Wl,--enable-new-dtags', '', wrapper, **kwargs)
<|endoftext|>


<commit_before>#!/usr/bin/env python
# Displays all signals, their values, and their handlers.
from __future__ import print_function
import signal
FMT = '{name:<10} {value:<5} {description}'

# header
print(FMT.format(name='name', value='value', description='description'))
print('-' * (33))

for name, value in [(signal_name, getattr(signal, signal_name))
                    for signal_name in dir(signal)
                    if signal_name.startswith('SIG')
                    and not signal_name.startswith('SIG_')]:
    handler = signal.getsignal(value)
    description = {
        signal.SIG_IGN: "ignored(SIG_IGN)",
        signal.SIG_DFL: "default(SIG_DFL)"
    }.get(handler, handler)
    print(FMT.format(name=name, value=value, description=description))
<commit_msg>FreeBSD: catch 'ValueError: signal number out of range'<commit_after>#!/usr/bin/env python
# Displays all signals, their values, and their handlers.
from __future__ import print_function
import signal
FMT = '{name:<10} {value:<5} {description}'

# header
print(FMT.format(name='name', value='value', description='description'))
print('-' * (33))

for name, value in [(signal_name, getattr(signal, signal_name))
                    for signal_name in dir(signal)
                    if signal_name.startswith('SIG')
                    and not signal_name.startswith('SIG_')]:
    try:
        handler = signal.getsignal(value)
    except ValueError:
        # FreeBSD: signal number out of range
        handler = 'out of range'
    description = {
        signal.SIG_IGN: "ignored(SIG_IGN)",
        signal.SIG_DFL: "default(SIG_DFL)"
    }.get(handler, handler)
    print(FMT.format(name=name, value=value, description=description))
<|endoftext|>


<commit_before>"""List the moles in a mole catalog."""

from __future__ import absolute_import
from __future__ import division
from __future__ import print_function

import os

def setup_parser(parser):
    pass

def process_args(args):
    for mole_dir in _yield_mole_dirs('.'):
        print(mole_dir)

def _yield_mole_dirs(rootpath):
    for path, dirs, files in os.walk(rootpath):

        # ignore directories with no files
        if not files:
            continue

        # ignore dot-directories in the root, like '.git'
        if os.path.relpath(path, rootpath).startswith('.'):
            continue

        # mole clusters have a picture and all the moles as child dirs, ignore
        if dirs:
            continue

        yield path
<commit_msg>mel.cmd.list: store full path and rel path<commit_after>"""List the moles in a mole catalog."""

from __future__ import absolute_import
from __future__ import division
from __future__ import print_function

import os

def setup_parser(parser):
    pass

def process_args(args):
    for mole in _yield_mole_dirs('.'):
        print(mole.catalog_relative_path)

class _Mole(object):

    def __init__(self, full_path, catalog_relative_path):
        super(_Mole, self).__init__()
        self.full_path = full_path
        self.catalog_relative_path = catalog_relative_path

def _yield_mole_dirs(rootpath):
    for path, dirs, files in os.walk(rootpath):

        catalog_relpath = os.path.relpath(path, rootpath)

        # ignore directories with no files
        if not files:
            continue

        # ignore dot-directories in the root, like '.git'
        if catalog_relpath.startswith('.'):
            continue

        # mole clusters have a picture and all the moles as child dirs, ignore
        if dirs:
            continue

        yield _Mole(
            os.path.abspath(path),
            catalog_relpath)
<|endoftext|>