Ejemplo n.º 1
0
def _find_bin(binary, basedir):
    # If it doesn't exist it might be in the path
    logger.debug('Checking that {!r} is in the $PATH'.format(binary))
    try:
        shell_utils.which(binary, cwd=basedir)
    except subprocess.CalledProcessError:
        raise meta_errors.CommandError(binary)
Ejemplo n.º 2
0
def get_version(version: str, version_script: str = None) -> str:
    new_version = version
    if version_script:
        logger.info('Determining the version from the project '
                    'repo (version-script).')
        try:
            new_version = shell_utils.run_script(version_script).strip()
            if not new_version:
                raise _errors.CommandError(
                    'The version-script produced no output')
        except subprocess.CalledProcessError as e:
            raise _errors.CommandError(
                'The version-script failed to run (exit code {})'.format(
                    e.returncode))
    # we want to whitelist what we support here.
    elif version == 'git':
        logger.info('Determining the version from the project '
                    'repo (version: git).')
        vcs_handler = sources.get_source_handler_from_type('git')
        new_version = vcs_handler.generate_version()

    if new_version != version:
        logger.info('The version has been set to {!r}'.format(new_version))
    return new_version
Ejemplo n.º 3
0
    def generate_hook_wrappers(self) -> None:
        snap_hooks_dir = os.path.join(self._prime_dir, 'snap', 'hooks')
        hooks_dir = os.path.join(self._prime_dir, 'meta', 'hooks')
        if os.path.isdir(snap_hooks_dir):
            os.makedirs(hooks_dir, exist_ok=True)
            for hook_name in os.listdir(snap_hooks_dir):
                file_path = os.path.join(snap_hooks_dir, hook_name)
                # First, verify that the hook is actually executable
                if not os.stat(file_path).st_mode & stat.S_IEXEC:
                    raise meta_errors.CommandError(
                        'hook {!r} is not executable'.format(hook_name))

                hook_exec = os.path.join('$SNAP', 'snap', 'hooks', hook_name)
                hook_path = os.path.join(hooks_dir, hook_name)
                with contextlib.suppress(FileNotFoundError):
                    os.remove(hook_path)

                self._write_wrap_exe(hook_exec, hook_path)
Ejemplo n.º 4
0
def _validate_hook(hook_path):
    if not os.stat(hook_path).st_mode & stat.S_IEXEC:
        asset = os.path.basename(hook_path)
        raise meta_errors.CommandError(
            'hook {!r} is not executable'.format(asset))