| 1 |  |  | """Setup script. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  | Run "python3 setup.py --help-commands" to list all available commands and their | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  | descriptions. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  | """ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  | import os | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  | import shutil | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  | import sys | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  | from abc import abstractmethod | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  | from pathlib import Path | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  | from subprocess import CalledProcessError, call, check_call | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  | from setuptools import Command, setup | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  | from setuptools.command.develop import develop | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  | from setuptools.command.egg_info import egg_info | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  | from setuptools.command.install import install | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  | if 'bdist_wheel' in sys.argv: | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  |     raise RuntimeError("This setup.py does not support wheels") | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  | # Paths setup with virtualenv detection | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  | BASE_ENV = Path(os.environ.get('VIRTUAL_ENV', '/')) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  | NAPP_NAME = 'topology' | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  | NAPP_VERSION = '3.9.0' | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  | # Kytos var folder | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  | VAR_PATH = BASE_ENV / 'var' / 'lib' / 'kytos' | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  | # Path for enabled NApps | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  | ENABLED_PATH = VAR_PATH / 'napps' | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  | # Path to install NApps | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  | INSTALLED_PATH = VAR_PATH / 'napps' / '.installed' | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  | CURRENT_DIR = Path('.').resolve() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  | # NApps enabled by default | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  | CORE_NAPPS = ['of_core'] | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  | class SimpleCommand(Command): | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  |     """Make Command implementation simpler.""" | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  |     user_options = [] | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  |     @abstractmethod | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  |     def run(self): | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  |         """Run when command is invoked. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  |         Use *call* instead of *check_call* to ignore failures. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  |         """ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 |  |  |     def initialize_options(self): | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 |  |  |         """Set default values for options.""" | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 |  |  |     def finalize_options(self): | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 |  |  |         """Post-process options.""" | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 |  |  | # pylint: disable=attribute-defined-outside-init, abstract-method | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 |  |  | class TestCommand(Command): | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 |  |  |     """Test tags decorators.""" | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 |  |  |     user_options = [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 63 |  |  |         ('size=', None, 'Specify the size of tests to be executed.'), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 |  |  |         ('type=', None, 'Specify the type of tests to be executed.'), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 65 |  |  |     ] | 
            
                                                                                                            
                            
            
                                    
            
            
                | 66 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 67 |  |  |     sizes = ('small', 'medium', 'large', 'all') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 68 |  |  |     types = ('unit', 'integration', 'e2e', 'all') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 69 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 70 |  |  |     def get_args(self): | 
            
                                                                                                            
                            
            
                                    
            
            
                | 71 |  |  |         """Return args to be used in test command.""" | 
            
                                                                                                            
                            
            
                                    
            
            
                | 72 |  |  |         return f'--size {self.size} --type {self.type}' | 
            
                                                                                                            
                            
            
                                    
            
            
                | 73 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 74 |  |  |     def initialize_options(self): | 
            
                                                                                                            
                            
            
                                    
            
            
                | 75 |  |  |         """Set default size and type args.""" | 
            
                                                                                                            
                            
            
                                    
            
            
                | 76 |  |  |         self.size = 'all' | 
            
                                                                                                            
                            
            
                                    
            
            
                | 77 |  |  |         self.type = 'all' | 
            
                                                                                                            
                            
            
                                    
            
            
                | 78 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 79 |  |  |     def finalize_options(self): | 
            
                                                                                                            
                            
            
                                    
            
            
                | 80 |  |  |         """Post-process.""" | 
            
                                                                                                            
                            
            
                                    
            
            
                | 81 |  |  |         try: | 
            
                                                                                                            
                            
            
                                    
            
            
                | 82 |  |  |             assert self.size in self.sizes, ('ERROR: Invalid size:' | 
            
                                                                                                            
                            
            
                                    
            
            
                | 83 |  |  |                                              f':{self.size}') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 84 |  |  |             assert self.type in self.types, ('ERROR: Invalid type:' | 
            
                                                                                                            
                            
            
                                    
            
            
                | 85 |  |  |                                              f':{self.type}') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 86 |  |  |         except AssertionError as exc: | 
            
                                                                                                            
                            
            
                                    
            
            
                | 87 |  |  |             print(exc) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 88 |  |  |             sys.exit(-1) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 89 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 90 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 91 |  |  | class Cleaner(SimpleCommand): | 
            
                                                                                                            
                            
            
                                    
            
            
                | 92 |  |  |     """Custom clean command to tidy up the project root.""" | 
            
                                                                                                            
                            
            
                                    
            
            
                | 93 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 94 |  |  |     description = 'clean build, dist, pyc and egg from package and docs' | 
            
                                                                                                            
                            
            
                                    
            
            
                | 95 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 96 |  |  |     def run(self): | 
            
                                                                                                            
                            
            
                                    
            
            
                | 97 |  |  |         """Clean build, dist, pyc and egg from package and docs.""" | 
            
                                                                                                            
                            
            
                                    
            
            
                | 98 |  |  |         call('rm -vrf ./build ./dist ./*.egg-info', shell=True) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 99 |  |  |         call('find . -name __pycache__ -type d | xargs rm -rf', shell=True) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 100 |  |  |         call('make -C docs/ clean', shell=True) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 101 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 102 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 103 |  |  | class Test(TestCommand): | 
            
                                                                                                            
                            
            
                                    
            
            
                | 104 |  |  |     """Run all tests.""" | 
            
                                                                                                            
                            
            
                                    
            
            
                | 105 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 106 |  |  |     description = 'run tests and display results' | 
            
                                                                                                            
                            
            
                                    
            
            
                | 107 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 108 |  |  |     def get_args(self): | 
            
                                                                                                            
                            
            
                                    
            
            
                | 109 |  |  |         """Return args to be used in test command.""" | 
            
                                                                                                            
                            
            
                                    
            
            
                | 110 |  |  |         markers = self.size | 
            
                                                                                                            
                            
            
                                    
            
            
                | 111 |  |  |         if markers == "small": | 
            
                                                                                                            
                            
            
                                    
            
            
                | 112 |  |  |             markers = 'not medium and not large' | 
            
                                                                                                            
                            
            
                                    
            
            
                | 113 |  |  |         size_args = "" if self.size == "all" else f"-m f'{markers}'" | 
            
                                                                                                            
                            
            
                                    
            
            
                | 114 |  |  |         test_type = "" if self.type == "all" else self.type | 
            
                                                                                                            
                            
            
                                    
            
            
                | 115 |  |  |         return f'--addopts="tests/{test_type} {size_args}"' | 
            
                                                                                                            
                            
            
                                    
            
            
                | 116 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 117 |  |  |     def run(self): | 
            
                                                                                                            
                            
            
                                    
            
            
                | 118 |  |  |         """Run tests.""" | 
            
                                                                                                            
                            
            
                                    
            
            
                | 119 |  |  |         cmd = f'python setup.py pytest {self.get_args()}' | 
            
                                                                                                            
                            
            
                                    
            
            
                | 120 |  |  |         try: | 
            
                                                                                                            
                            
            
                                    
            
            
                | 121 |  |  |             check_call(cmd, shell=True) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 122 |  |  |         except CalledProcessError as exc: | 
            
                                                                                                            
                            
            
                                    
            
            
                | 123 |  |  |             print(exc) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 124 |  |  |             print('Unit tests failed. Fix the errors above and try again.') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 125 |  |  |             sys.exit(-1) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 126 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 127 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 128 |  |  | class TestCoverage(Test): | 
            
                                                                                                            
                            
            
                                    
            
            
                | 129 |  |  |     """Display test coverage.""" | 
            
                                                                                                            
                            
            
                                    
            
            
                | 130 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 131 |  |  |     description = 'run tests and display code coverage' | 
            
                                                                                                            
                            
            
                                    
            
            
                | 132 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 133 |  |  |     def run(self): | 
            
                                                                                                            
                            
            
                                    
            
            
                | 134 |  |  |         """Run tests quietly and display coverage report.""" | 
            
                                                                                                            
                            
            
                                    
            
            
                | 135 |  |  |         cmd = f'coverage3 run setup.py pytest {self.get_args()}' | 
            
                                                                                                            
                            
            
                                    
            
            
                | 136 |  |  |         cmd += '&& coverage3 report' | 
            
                                                                                                            
                            
            
                                    
            
            
                | 137 |  |  |         try: | 
            
                                                                                                            
                            
            
                                    
            
            
                | 138 |  |  |             check_call(cmd, shell=True) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 139 |  |  |         except CalledProcessError as exc: | 
            
                                                                                                            
                            
            
                                    
            
            
                | 140 |  |  |             print(exc) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 141 |  |  |             print('Coverage tests failed. Fix the errors above and try again.') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 142 |  |  |             sys.exit(-1) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 143 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 144 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 145 |  |  | class Linter(SimpleCommand): | 
            
                                                                                                            
                            
            
                                    
            
            
                | 146 |  |  |     """Code linters.""" | 
            
                                                                                                            
                            
            
                                    
            
            
                | 147 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 148 |  |  |     description = 'lint Python source code' | 
            
                                                                                                            
                            
            
                                    
            
            
                | 149 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 150 |  |  |     def run(self): | 
            
                                                                                                            
                            
            
                                    
            
            
                | 151 |  |  |         """Run yala.""" | 
            
                                                                                                            
                            
            
                                    
            
            
                | 152 |  |  |         print('Yala is running. It may take several seconds...') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 153 |  |  |         check_call('yala *.py tests', shell=True) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 154 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 155 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 156 |  |  | class CITest(TestCommand): | 
            
                                                                                                            
                            
            
                                    
            
            
                | 157 |  |  |     """Run all CI tests.""" | 
            
                                                                                                            
                            
            
                                    
            
            
                | 158 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 159 |  |  |     description = 'run all CI tests: unit and doc tests, linter' | 
            
                                                                                                            
                            
            
                                    
            
            
                | 160 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 161 |  |  |     def run(self): | 
            
                                                                                                            
                            
            
                                    
            
            
                | 162 |  |  |         """Run unit tests with coverage, doc tests and linter.""" | 
            
                                                                                                            
                            
            
                                    
            
            
                | 163 |  |  |         coverage_cmd = f'python3.6 setup.py coverage {self.get_args()}' | 
            
                                                                                                            
                            
            
                                    
            
            
                | 164 |  |  |         lint_cmd = 'python3.6 setup.py lint' | 
            
                                                                                                            
                            
            
                                    
            
            
                | 165 |  |  |         cmd = f'{coverage_cmd} && {lint_cmd}' | 
            
                                                                                                            
                            
            
                                    
            
            
                | 166 |  |  |         check_call(cmd, shell=True) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 167 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 168 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 169 |  |  | class KytosInstall: | 
            
                                                                                                            
                            
            
                                    
            
            
                | 170 |  |  |     """Common code for all install types.""" | 
            
                                                                                                            
                            
            
                                    
            
            
                | 171 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 172 |  |  |     @staticmethod | 
            
                                                                                                            
                            
            
                                    
            
            
                | 173 |  |  |     def enable_core_napps(): | 
            
                                                                                                            
                            
            
                                    
            
            
                | 174 |  |  |         """Enable a NAPP by creating a symlink.""" | 
            
                                                                                                            
                            
            
                                    
            
            
                | 175 |  |  |         (ENABLED_PATH / 'kytos').mkdir(parents=True, exist_ok=True) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 176 |  |  |         for napp in CORE_NAPPS: | 
            
                                                                                                            
                            
            
                                    
            
            
                | 177 |  |  |             napp_path = Path('kytos', napp) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 178 |  |  |             src = ENABLED_PATH / napp_path | 
            
                                                                                                            
                            
            
                                    
            
            
                | 179 |  |  |             dst = INSTALLED_PATH / napp_path | 
            
                                                                                                            
                            
            
                                    
            
            
                | 180 |  |  |             symlink_if_different(src, dst) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 181 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 182 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 183 |  |  | class InstallMode(install): | 
            
                                                                                                            
                            
            
                                    
            
            
                | 184 |  |  |     """Create files in var/lib/kytos.""" | 
            
                                                                                                            
                            
            
                                    
            
            
                | 185 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 186 |  |  |     description = 'To install NApps, use kytos-utils. Devs, see "develop".' | 
            
                                                                                                            
                            
            
                                    
            
            
                | 187 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 188 |  |  |     def run(self): | 
            
                                                                                                            
                            
            
                                    
            
            
                | 189 |  |  |         """Direct users to use kytos-utils to install NApps.""" | 
            
                                                                                                            
                            
            
                                    
            
            
                | 190 |  |  |         print(self.description) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 191 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 192 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 193 |  |  | class EggInfo(egg_info): | 
            
                                                                                                            
                            
            
                                    
            
            
                | 194 |  |  |     """Prepare files to be packed.""" | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 195 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 196 |  |  |     def run(self): | 
            
                                                                        
                            
            
                                    
            
            
                | 197 |  |  |         """Build css.""" | 
            
                                                                        
                            
            
                                    
            
            
                | 198 |  |  |         self._install_deps_wheels() | 
            
                                                                        
                            
            
                                    
            
            
                | 199 |  |  |         super().run() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 200 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 201 |  |  |     @staticmethod | 
            
                                                                                                            
                            
            
                                    
            
            
                | 202 |  |  |     def _install_deps_wheels(): | 
            
                                                                                                            
                            
            
                                    
            
            
                | 203 |  |  |         """Python wheels are much faster (no compiling).""" | 
            
                                                                                                            
                            
            
                                    
            
            
                | 204 |  |  |         print('Installing dependencies...') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 205 |  |  |         check_call([sys.executable, '-m', 'pip', 'install', '-r', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 206 |  |  |                     'requirements/run.txt']) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 207 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 208 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 209 |  |  | class DevelopMode(develop): | 
            
                                                                                                            
                            
            
                                    
            
            
                | 210 |  |  |     """Recommended setup for kytos-napps developers. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 211 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 212 |  |  |     Instead of copying the files to the expected directories, a symlink is | 
            
                                                                                                            
                            
            
                                    
            
            
                | 213 |  |  |     created on the system aiming the current source code. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 214 |  |  |     """ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 215 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 216 |  |  |     description = 'Install NApps in development mode' | 
            
                                                                                                            
                            
            
                                    
            
            
                | 217 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 218 |  |  |     def run(self): | 
            
                                                                                                            
                            
            
                                    
            
            
                | 219 |  |  |         """Install the package in a developer mode.""" | 
            
                                                                                                            
                            
            
                                    
            
            
                | 220 |  |  |         super().run() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 221 |  |  |         if self.uninstall: | 
            
                                                                                                            
                            
            
                                    
            
            
                | 222 |  |  |             shutil.rmtree(str(ENABLED_PATH), ignore_errors=True) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 223 |  |  |         else: | 
            
                                                                                                            
                            
            
                                    
            
            
                | 224 |  |  |             self._create_folder_symlinks() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 225 |  |  |             # self._create_file_symlinks() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 226 |  |  |             KytosInstall.enable_core_napps() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 227 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 228 |  |  |     @staticmethod | 
            
                                                                                                            
                            
            
                                    
            
            
                | 229 |  |  |     def _create_folder_symlinks(): | 
            
                                                                                                            
                            
            
                                    
            
            
                | 230 |  |  |         """Symlink to all Kytos NApps folders. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 231 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 232 |  |  |         ./napps/kytos/napp_name will generate a link in | 
            
                                                                                                            
                            
            
                                    
            
            
                | 233 |  |  |         var/lib/kytos/napps/.installed/kytos/napp_name. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 234 |  |  |         """ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 235 |  |  |         links = INSTALLED_PATH / 'kytos' | 
            
                                                                                                            
                            
            
                                    
            
            
                | 236 |  |  |         links.mkdir(parents=True, exist_ok=True) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 237 |  |  |         code = CURRENT_DIR | 
            
                                                                                                            
                            
            
                                    
            
            
                | 238 |  |  |         src = links / NAPP_NAME | 
            
                                                                                                            
                            
            
                                    
            
            
                | 239 |  |  |         symlink_if_different(src, code) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 240 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 241 |  |  |         (ENABLED_PATH / 'kytos').mkdir(parents=True, exist_ok=True) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 242 |  |  |         dst = ENABLED_PATH / Path('kytos', NAPP_NAME) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 243 |  |  |         symlink_if_different(dst, src) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 244 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 245 |  |  |     @staticmethod | 
            
                                                                                                            
                            
            
                                    
            
            
                | 246 |  |  |     def _create_file_symlinks(): | 
            
                                                                                                            
                            
            
                                    
            
            
                | 247 |  |  |         """Symlink to required files.""" | 
            
                                                                                                            
                            
            
                                    
            
            
                | 248 |  |  |         src = ENABLED_PATH / '__init__.py' | 
            
                                                                                                            
                            
            
                                    
            
            
                | 249 |  |  |         dst = CURRENT_DIR / 'napps' / '__init__.py' | 
            
                                                                                                            
                            
            
                                    
            
            
                | 250 |  |  |         symlink_if_different(src, dst) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 251 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 252 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 253 |  |  | def symlink_if_different(path, target): | 
            
                                                                                                            
                            
            
                                    
            
            
                | 254 |  |  |     """Force symlink creation if it points anywhere else.""" | 
            
                                                                                                            
                            
            
                                    
            
            
                | 255 |  |  |     # print(f"symlinking {path} to target: {target}...", end=" ") | 
            
                                                                                                            
                            
            
                                    
            
            
                | 256 |  |  |     if not path.exists(): | 
            
                                                                                                            
                            
            
                                    
            
            
                | 257 |  |  |         # print(f"path doesn't exist. linking...") | 
            
                                                                                                            
                            
            
                                    
            
            
                | 258 |  |  |         path.symlink_to(target) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 259 |  |  |     elif not path.samefile(target): | 
            
                                                                                                            
                            
            
                                    
            
            
                | 260 |  |  |         # print(f"path exists, but is different. removing and linking...") | 
            
                                                                                                            
                            
            
                                    
            
            
                | 261 |  |  |         # Exists but points to a different file, so let's replace it | 
            
                                                                                                            
                            
            
                                    
            
            
                | 262 |  |  |         path.unlink() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 263 |  |  |         path.symlink_to(target) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 264 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 265 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 266 |  |  | def read_requirements(path="requirements/run.txt"): | 
            
                                                                                                            
                            
            
                                    
            
            
                | 267 |  |  |     """Read requirements file and return a list.""" | 
            
                                                                                                            
                            
            
                                    
            
            
                | 268 |  |  |     with open(path, "r", encoding="utf8") as file: | 
            
                                                                                                            
                            
            
                                    
            
            
                | 269 |  |  |         return [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 270 |  |  |             line.strip() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 271 |  |  |             for line in file.readlines() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 272 |  |  |             if not line.startswith("#") | 
            
                                                                                                            
                            
            
                                    
            
            
                | 273 |  |  |         ] | 
            
                                                                                                            
                            
            
                                    
            
            
                | 274 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 275 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 276 |  |  | setup(name=f'kytos_{NAPP_NAME}', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 277 |  |  |       version=NAPP_VERSION, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 278 |  |  |       description='Core NApps developed by the Kytos Team', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 279 |  |  |       url=f'http://github.com/kytos/{NAPP_NAME}', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 280 |  |  |       author='Kytos Team', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 281 |  |  |       author_email='[email protected]', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 282 |  |  |       license='MIT', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 283 |  |  |       install_requires=read_requirements(), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 284 |  |  |       setup_requires=['pytest-runner'], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 285 |  |  |       tests_require=['pytest'], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 286 |  |  |       extras_require={ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 287 |  |  |           'dev': [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 288 |  |  |               'coverage', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 289 |  |  |               'pip-tools', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 290 |  |  |               'yala', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 291 |  |  |               'tox', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 292 |  |  |           ], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 293 |  |  |       }, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 294 |  |  |       cmdclass={ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 295 |  |  |           'clean': Cleaner, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 296 |  |  |           'ci': CITest, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 297 |  |  |           'coverage': TestCoverage, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 298 |  |  |           'develop': DevelopMode, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 299 |  |  |           'install': InstallMode, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 300 |  |  |           'lint': Linter, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 301 |  |  |           'egg_info': EggInfo, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 302 |  |  |           'test': Test, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 303 |  |  |       }, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 304 |  |  |       zip_safe=False, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 305 |  |  |       classifiers=[ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 306 |  |  |           'License :: OSI Approved :: MIT License', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 307 |  |  |           'Operating System :: POSIX :: Linux', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 308 |  |  |           'Programming Language :: Python :: 3.6', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 309 |  |  |           'Topic :: System :: Networking', | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 310 |  |  |       ]) | 
            
                                                        
            
                                    
            
            
                | 311 |  |  |  |