コード例 #1
0
 def run_command(self,
                 cmd,
                 show_stdout=True,
                 cwd=None,
                 on_returncode='raise',
                 command_level=logging.DEBUG,
                 command_desc=None,
                 extra_environ=None,
                 spinner=None):
     """
     Run a VCS subcommand
     This is simply a wrapper around call_subprocess that adds the VCS
     command name, and checks that the VCS is available
     """
     cmd = [self.name] + cmd
     try:
         return call_subprocess(cmd, show_stdout, cwd, on_returncode,
                                command_level, command_desc, extra_environ,
                                spinner)
     except OSError as e:
         # errno.ENOENT = no such file or directory
         # In other words, the VCS executable isn't available
         if e.errno == errno.ENOENT:
             raise BadCommand('Cannot find command %r' % self.name)
         else:
             raise  # re-raise exception if a different error occurred
コード例 #2
0
ファイル: util.py プロジェクト: bennihepp/sandbox
def find_command(cmd, paths=None, pathext=None):
    """Searches the PATH for the given command and returns its path"""
    if paths is None:
        paths = os.environ.get('PATH', '').split(os.pathsep)
    if isinstance(paths, string_types):
        paths = [paths]
    # check if there are funny path extensions for executables, e.g. Windows
    if pathext is None:
        pathext = get_pathext()
    pathext = [ext for ext in pathext.lower().split(os.pathsep)]
    # don't use extensions if the command ends with one of them
    if os.path.splitext(cmd)[1].lower() in pathext:
        pathext = ['']
    # check if we find the command on PATH
    for path in paths:
        # try without extension first
        cmd_path = os.path.join(path, cmd)
        for ext in pathext:
            # then including the extension
            cmd_path_ext = cmd_path + ext
            if os.path.isfile(cmd_path_ext):
                return cmd_path_ext
        if os.path.isfile(cmd_path):
            return cmd_path
    raise BadCommand('Cannot find command %r' % cmd)
コード例 #3
0
 def cmd(self):
     if self._cmd is not None:
         return self._cmd
     command = find_command(self.name)
     if command is None:
         raise BadCommand('Cannot find command %r' % self.name)
     logger.info('Found command %r at %r' % (self.name, command))
     self._cmd = command
     return command
コード例 #4
0
def restart_in_venv(venv, base, site_packages, args):
    """
    Restart this script using the interpreter in the given virtual environment
    """
    if base and not os.path.isabs(venv) and not venv.startswith('~'):
        base = os.path.expanduser(base)
        # ensure we have an abs basepath at this point:
        #    a relative one makes no sense (or does it?)
        if os.path.isabs(base):
            venv = os.path.join(base, venv)

    if venv.startswith('~'):
        venv = os.path.expanduser(venv)

    if not os.path.exists(venv):
        try:
            import virtualenv
        except ImportError:
            print('The virtual environment does not exist: %s' % venv)
            print(
                'and virtualenv is not installed, so a new environment cannot be created'
            )
            sys.exit(3)
        print('Creating new virtualenv environment in %s' % venv)
        virtualenv.logger = logger
        logger.indent += 2
        virtualenv.create_environment(venv, site_packages=site_packages)
    if sys.platform == 'win32':
        python = os.path.join(venv, 'Scripts', 'python.exe')
        # check for bin directory which is used in buildouts
        if not os.path.exists(python):
            python = os.path.join(venv, 'bin', 'python.exe')
    else:
        python = os.path.join(venv, 'bin', 'python')
    if not os.path.exists(python):
        python = venv
    if not os.path.exists(python):
        raise BadCommand('Cannot find virtual environment interpreter at %s' %
                         python)
    base = os.path.dirname(os.path.dirname(python))
    file = os.path.join(os.path.dirname(__file__), 'runner.py')
    if file.endswith('.pyc'):
        file = file[:-1]
    proc = subprocess.Popen([python, file] + args +
                            [base, '___VENV_RESTART___'])
    proc.wait()
    sys.exit(proc.returncode)
コード例 #5
0
                    extra_environ=None):
        """
        Run a VCS subcommand
        This is simply a wrapper around call_subprocess that adds the VCS
        command name, and checks that the VCS is available
        """
        cmd = [self.name] + cmd
        try:
            return call_subprocess(cmd, show_stdout, filter_stdout, cwd,
                                   raise_on_returncode, command_level,
                                   command_desc, extra_environ)
        except OSError as e:
            # errno.ENOENT = no such file or directory
            # In other words, the VCS executable isn't available
            if e.errno == errno.ENOENT:
                raise BadCommand('Cannot find command %r' % self.name)
            else:
                raise  # re-raise exception if a different error occured

=======
>>>>>>> bde4533e29dfedadf6bcf9d451baa615bc828a59

def get_src_requirement(dist, location, find_tags):
    version_control = vcs.get_backend_from_location(location)
    if version_control:
        try:
            return version_control().get_src_requirement(dist,
                                                         location,
                                                         find_tags)
        except BadCommand:
            logger.warning(