Ejemplo n.º 1
0
    def test_external_public_function(self):
        test_url = "http://scripts.com/foobar.py"
        test_content = "test content of the remote script ññ"
        with patch('fades.helpers._ScriptDownloader') as mock_downloader_class:
            mock_downloader = mock_downloader_class()
            mock_downloader.get.return_value = test_content
            mock_downloader.name = 'mock downloader'
            filepath = helpers.download_remote_script(test_url)

        # plan to remove the downloaded content (so test remains clean)
        self.addCleanup(os.unlink, filepath)

        # checks
        mock_downloader_class.assert_called_with(test_url)
        self.assertLoggedInfo(
            "Downloading remote script", test_url, repr(filepath), 'mock downloader')
        with open(filepath, "rt", encoding='utf8') as fh:
            self.assertEqual(fh.read(), test_content)
Ejemplo n.º 2
0
    def test_external_public_function(self):
        test_url = "http://scripts.com/foobar.py"
        test_content = "test content of the remote script ññ"
        with patch('fades.helpers._ScriptDownloader') as mock_downloader_class:
            mock_downloader = mock_downloader_class()
            mock_downloader.get.return_value = test_content
            mock_downloader.name = 'mock downloader'
            filepath = helpers.download_remote_script(test_url)

        # plan to remove the downloaded content (so test remains clean)
        self.addCleanup(os.unlink, filepath)

        # checks
        mock_downloader_class.assert_called_with(test_url)
        self.assertLoggedInfo(
            "Downloading remote script from {!r}".format(test_url),
            repr(filepath), "(using 'mock downloader' downloader)")
        with open(filepath, "rt", encoding='utf8') as fh:
            self.assertEqual(fh.read(), test_content)
Ejemplo n.º 3
0
def decide_child_program(args_executable, args_module, args_child_program):
    """Decide which the child program really is (if any)."""
    if args_executable:
        # If --exec given, check that it's just the executable name or an absolute path;
        # relative paths are forbidden (as the location of the venv should not be known).
        if os.path.sep in args_child_program and args_child_program[
                0] != os.path.sep:
            logger.error(
                "The parameter to --exec must be a file name (to be found "
                "inside venv's bin directory), not a file path: %r",
                args_child_program)
            raise FadesError("File path given to --exec parameter")

        # indicated --execute, local and not analyzable for dependencies
        analyzable_child_program = None
        child_program = args_child_program
    elif args_module:
        # If --module given, the module may be installed (nothing can be really checked),
        # but surely it's not used as a source for dependencies.
        analyzable_child_program = None
        child_program = args_child_program
    elif args_child_program is not None:
        # normal case, the child program is to be analyzed (being it local or remote)
        if args_child_program.startswith(("http://", "https://")):
            args_child_program = helpers.download_remote_script(
                args_child_program)
        else:
            if not os.access(args_child_program, os.R_OK):
                logger.error(
                    "'%s' not found. If you want to run an executable "
                    "file from a library installed in the virtualenv "
                    "check the `--exec` option in the help.",
                    args_child_program)
                raise FadesError("child program  not found.")
        analyzable_child_program = args_child_program
        child_program = args_child_program
    else:
        # not indicated executable, not child program, "interpreter" mode
        analyzable_child_program = None
        child_program = None

    return analyzable_child_program, child_program
Ejemplo n.º 4
0
def decide_child_program(args_executable, args_module, args_child_program):
    """Decide which the child program really is (if any)."""
    if args_executable:
        # If --exec given, check that it's just the executable name or an absolute path;
        # relative paths are forbidden (as the location of the venv should not be known).
        if os.path.sep in args_child_program and args_child_program[0] != os.path.sep:
            logger.error(
                "The parameter to --exec must be a file name (to be found "
                "inside venv's bin directory), not a file path: %r",
                args_child_program)
            raise FadesError("File path given to --exec parameter")

        # indicated --execute, local and not analyzable for dependencies
        analyzable_child_program = None
        child_program = args_child_program
    elif args_module:
        # If --module given, the module may be installed (nothing can be really checked),
        # but surely it's not used as a source for dependencies.
        analyzable_child_program = None
        child_program = args_child_program
    elif args_child_program is not None:
        # normal case, the child program is to be analyzed (being it local or remote)
        if args_child_program.startswith(("http://", "https://")):
            args_child_program = helpers.download_remote_script(args_child_program)
        else:
            if not os.access(args_child_program, os.R_OK):
                logger.error("'%s' not found. If you want to run an executable "
                             "file from a library installed in the virtualenv "
                             "check the `--exec` option in the help.",
                             args_child_program)
                raise FadesError("child program  not found.")
        analyzable_child_program = args_child_program
        child_program = args_child_program
    else:
        # not indicated executable, not child program, "interpreter" mode
         help=("Indicate that the child_program should be looked up in the "
                              "virtualenv."))
    parser.add_argument('-i', '--ipython', action='store_true', help="use IPython shell.")
    parser.add_argument('-m', '--module', action='store', help="Run library module as a script")
    parser.add_argument('--system-site-packages', action='store_true', default=False,
                        help=("Give the virtual environment access to the "
                              "system site-packages dir."))
Ejemplo n.º 5
0
def decide_child_program(args_executable, args_child_program):
    """Decide which the child program really is (if any)."""
    # We get the logger here because it's not defined at module level
    logger = logging.getLogger('fades')

    if args_executable:
        # if --exec given, check that it's just the executable name,
        # not absolute or relative paths
        if os.path.sep in args_child_program:
            logger.error(
                "The parameter to --exec must be a file name (to be found "
                "inside venv's bin directory), not a file path: %r",
                args_child_program)
            raise FadesError("File path given to --exec parameter")

        # indicated --execute, local and not analyzable for dependencies
        analyzable_child_program = None
        child_program = args_child_program
    elif args_child_program is not None:
        # normal case, the child program is to be analyzed (being it local or remote)
        if args_child_program.startswith(("http://", "https://")):
            args_child_program = helpers.download_remote_script(
                args_child_program)
        else:
            if not os.access(args_child_program, os.R_OK):
                logger.error(
                    "'%s' not found. If you want to run an executable "
                    "file from a library installed in the virtualenv "
                    "check the `--exec` option in the help.",
                    args_child_program)
                raise FadesError("child program  not found.")
        analyzable_child_program = args_child_program
        child_program = args_child_program
    else:
        # not indicated executable, not child program, "interpreter" mode
        analyzable_child_program = None
        child_program = None

    return analyzable_child_program, child_program
Ejemplo n.º 6
0
Archivo: main.py Proyecto: PyAr/fades
def decide_child_program(args_executable, args_child_program):
    """Decide which the child program really is (if any)."""
    # We get the logger here because it's not defined at module level
    logger = logging.getLogger('fades')

    if args_executable:
        # if --exec given, check that it's just the executable name,
        # not absolute or relative paths
        if os.path.sep in args_child_program:
            logger.error(
                "The parameter to --exec must be a file name (to be found "
                "inside venv's bin directory), not a file path: %r",
                args_child_program)
            raise FadesError("File path given to --exec parameter")

        # indicated --execute, local and not analyzable for dependencies
        analyzable_child_program = None
        child_program = args_child_program
    elif args_child_program is not None:
        # normal case, the child program is to be analyzed (being it local or remote)
        if args_child_program.startswith(("http://", "https://")):
            args_child_program = helpers.download_remote_script(args_child_program)
        else:
            if not os.access(args_child_program, os.R_OK):
                logger.error("'%s' not found. If you want to run an executable "
                             "file from a library installed in the virtualenv "
                             "check the `--exec` option in the help.",
                             args_child_program)
                raise FadesError("child program  not found.")
        analyzable_child_program = args_child_program
        child_program = args_child_program
    else:
        # not indicated executable, not child program, "interpreter" mode
        analyzable_child_program = None
        child_program = None

    return analyzable_child_program, child_program