def _install_local_module(config): """Install a module from a local path.""" installed = False config["path"] = os.path.expanduser(config["path"]) installdir, _ = os.path.split(config["install_path"]) if not os.path.isdir(installdir): os.makedirs(installdir, exist_ok=True) if os.path.isdir(config["path"]): shutil.copytree(config["path"], config["install_path"]) installed = True if os.path.isfile(config["path"]): os.makedirs(config["install_path"], exist_ok=True) init_path = os.path.join(config["install_path"], "__init__.py") if file_is_ipython_notebook(config["path"]): convert_ipynb_to_script(config["path"], init_path) else: shutil.copyfile(config["path"], init_path) installed = True if not installed: _LOGGER.error("Failed to install from %s", str(config["path"]))
def _install_local_module(self, config): """Install a module from a local path. Args: config: dict of module config fields """ installed = False config["path"] = os.path.expanduser(config["path"]) installdir, _ = os.path.split(config["install_path"]) if not os.path.isdir(installdir): os.makedirs(installdir, exist_ok=True) if os.path.isdir(config["path"]): shutil.copytree(config["path"], config["install_path"]) installed = True if os.path.isfile(config["path"]): os.makedirs(config["install_path"], exist_ok=True) init_path = os.path.join(config["install_path"], "__init__.py") if file_is_ipython_notebook(config["path"]): convert_ipynb_to_script(config["path"], init_path) else: shutil.copyfile(config["path"], init_path) installed = True if not installed: _LOGGER.error("Failed to install from %s.", str(config["path"])) else: self.opsdroid.reload_paths.append(config["path"])
def test_convert_ipynb_to_script(self): notebook_path = os.path.abspath( "opsdroid/testing/mockmodules/skills/test_notebook.ipynb") with tempfile.NamedTemporaryFile(mode="w", delete=False) as output_file: convert_ipynb_to_script(notebook_path, output_file.name) assert os.path.getsize(output_file.name) > 0
def test_convert_ipynb_to_script(self): notebook_path = \ os.path.abspath("tests/mockmodules/skills/test_notebook.ipynb") with tempfile.NamedTemporaryFile(mode='w', delete=False) as output_file: convert_ipynb_to_script(notebook_path, output_file.name) self.assertTrue(os.path.getsize(output_file.name) > 0)
def test_convert_ipynb_to_script(self): notebook_path = \ os.path.abspath("tests/mockmodules/skills/test_notebook.ipynb") with tempfile.NamedTemporaryFile( mode='w', delete=False) as output_file: convert_ipynb_to_script(notebook_path, output_file.name) self.assertTrue(os.path.getsize(output_file.name) > 0)