Example #1
0
File: main.py Project: dejw/vip
def main():
    parser, args = create_argument_parser()

    commands = ["init", "locate", "command"]

    # Configure logger using --verbose option
    core.logger.verbose = bool(args.verbose)

    with protect_from_VipError():

        if args.version:
            sys.stdout.write("%s\n" % vip.VERSION)
            sys.exit(0)

        # Check for only one command
        used_commands = [int(bool(getattr(args, cmd))) for cmd in commands]
        if sum(used_commands) > 1:
            parser.print_help()

        elif args.init:
            directory = core.create_virtualenv(args.init)
            core.logger.info("Initialized virtualenv in %s" % directory)

        elif args.locate:
            sys.stdout.write(core.find_vip_directory(args.locate) + "\n")

        elif args.command:
            directory = core.find_vip_directory()
            return_code = core.execute_virtualenv_command(
                directory, args.command, args.arguments)

            sys.exit(return_code)
        else:
            parser.print_help()
Example #2
0
    def test_should_skip_vip_which_is_no_directory(self):
        root = path.join(self.root, "fixtures", "test2")

        directory = core.find_vip_directory(start=path.join(root,
                                                            "with_plain_file"))
        expected = path.abspath(path.join(root, ".vip"))
        self.assertEqual(expected, directory)
Example #3
0
    def test_should_return_absolute_path_to_vip_directory(self):
        start = path.join(self.root, "fixtures", "test1", "..",
                          "test1")

        directory = core.find_vip_directory(start=start)

        self.assertEqual(path.abspath(path.join(start, ".vip")), directory)
Example #4
0
 def test_should_raise_VipError_when_no_vip_is_found(self):
     not_a_virtualenv = os.path.splitdrive(sys.executable)[0] + os.path.sep
     with self.assertRaisesRegexp(core.VipError, "not a virtualenv"):
         core.find_vip_directory(start=not_a_virtualenv)