Exemple #1
0
def run(args: List) -> int:
    """Run a script."""
    scripts = []
    path = os.path.dirname(__file__)
    for fil in os.listdir(path):
        if fil == '__pycache__':
            continue
        elif os.path.isdir(os.path.join(path, fil)):
            scripts.append(fil)
        elif fil != '__init__.py' and fil.endswith('.py'):
            scripts.append(fil[:-3])

    if not args:
        print('Please specify a script to run.')
        print('Available scripts:', ', '.join(scripts))
        return 1

    if args[0] not in scripts:
        print('Invalid script specified.')
        print('Available scripts:', ', '.join(scripts))
        return 1

    script = importlib.import_module('homeassistant.scripts.' + args[0])

    config_dir = extract_config_dir()
    deps_dir = mount_local_lib_path(config_dir)

    logging.basicConfig(stream=sys.stdout, level=logging.INFO)
    for req in getattr(script, 'REQUIREMENTS', []):
        if not install_package(req, target=deps_dir):
            print('Aborting scipt, could not install dependency', req)
            return 1

    return script.run(args[1:])  # type: ignore
Exemple #2
0
def run(args: List) -> int:
    """Run a script."""
    scripts = []
    path = os.path.dirname(__file__)
    for fil in os.listdir(path):
        if fil == '__pycache__':
            continue
        elif os.path.isdir(os.path.join(path, fil)):
            scripts.append(fil)
        elif fil != '__init__.py' and fil.endswith('.py'):
            scripts.append(fil[:-3])

    if not args:
        print('Please specify a script to run.')
        print('Available scripts:', ', '.join(scripts))
        return 1

    if args[0] not in scripts:
        print('Invalid script specified.')
        print('Available scripts:', ', '.join(scripts))
        return 1

    script = importlib.import_module('homeassistant.scripts.' + args[0])

    config_dir = extract_config_dir()
    deps_dir = mount_local_lib_path(config_dir)

    logging.basicConfig(stream=sys.stdout, level=logging.INFO)
    for req in getattr(script, 'REQUIREMENTS', []):
        if not install_package(req, target=deps_dir):
            print('Aborting scipt, could not install dependency', req)
            return 1

    return script.run(args[1:])  # type: ignore
Exemple #3
0
    def test_install_package_zip(self):
        """ Test an install attempt from a zip path """
        self.assertFalse(
            package.check_package_exists(TEST_ZIP_REQ, self.lib_dir))
        self.assertFalse(
            package.check_package_exists(TEST_NEW_REQ, self.lib_dir))

        self.assertTrue(
            package.install_package(TEST_ZIP_REQ, True, self.lib_dir))

        self.assertTrue(
            package.check_package_exists(TEST_ZIP_REQ, self.lib_dir))
        self.assertTrue(
            package.check_package_exists(TEST_NEW_REQ, self.lib_dir))

        bootstrap.mount_local_lib_path(self.tmp_dir.name)

        try:
            import pyhelloworld3
        except ImportError:
            self.fail('Unable to import pyhelloworld3 after installing it.')

        self.assertEqual(pyhelloworld3.__version__, '1.0.0')
Exemple #4
0
    def test_install_package_zip(self):
        """Test an install attempt from a zip path."""
        self.assertFalse(package.check_package_exists(
            TEST_ZIP_REQ, self.lib_dir))
        self.assertFalse(package.check_package_exists(
            TEST_NEW_REQ, self.lib_dir))

        self.assertTrue(package.install_package(
            TEST_ZIP_REQ, True, self.lib_dir))

        self.assertTrue(package.check_package_exists(
            TEST_ZIP_REQ, self.lib_dir))
        self.assertTrue(package.check_package_exists(
            TEST_NEW_REQ, self.lib_dir))

        bootstrap.mount_local_lib_path(self.tmp_dir.name)

        try:
            import pyhelloworld3
        except ImportError:
            self.fail('Unable to import pyhelloworld3 after installing it.')

        self.assertEqual(pyhelloworld3.__version__, '1.0.0')
 def setUp(self):
     """Create local library for testing."""
     self.tmp_dir = tempfile.TemporaryDirectory()
     self.lib_dir = mount_local_lib_path(self.tmp_dir.name)
 def setUp(self):
     """Create local library for testing."""
     self.tmp_dir = tempfile.TemporaryDirectory()
     self.lib_dir = mount_local_lib_path(self.tmp_dir.name)