How to use get_modules_dir method in avocado

Best Python code snippet using avocado_python

chewy

Source:chewy Github

copy

Full Screen

...104 , help='Module paths list'105 , nargs='+'106 )107 uninstall_parser.set_defaults(func=self.do_uninstall)108 def get_modules_dir(self):109 if not self.__modules_dir:110 if self.args.modules_dir:111 # TODO Check for symlinked directory112 if os.path.isdir(self.args.modules_dir):113 self.__modules_dir = self.args.modules_dir114 else:115 raise RuntimeError("Specified path is not a directory: `{}'".format(self.args.modules_dir))116 else:117 self.__modules_dir = chewy.modules_dir_lookup()118 log.einfo("Guessed CMake modules directory: `{}'".format(self.__modules_dir))119 return self.__modules_dir120 def uninstall(self, mod):121 '''122 Uninstall the chewy module and all related files123 Note uninstall doesn't clean empty directories possible after uninstall process124 '''125 for path in [ os.path.join(self.get_modules_dir(), f) for f in mod.addons + [mod.path] ]:126 abspath = chewy.sandbox_path(self.get_modules_dir(), path)127 # TODO: os.path.exists returns False for zero-sized files128 if os.path.exists(abspath):129 os.unlink(abspath)130 def rcv_module(self, obj, sf):131 # "Overloading" by the first argument132 local_module = None133 if isinstance(obj, chewy.Module):134 local_module = obj135 url = os.path.join(local_module.repobase, local_module.path)136 elif isinstance(obj, str):137 url = obj138 else:139 assert False140 # Doesn't catch any exception because any error means module receiving is fall141 ep = chewy.HttpEndpoint(url)142 cs = sf.get_session(ep)143 log.einfo('Receiving the module file {}'.format(url))144 data = cs.retrieve_remote_file(ep.geturl()) # Get a remote file into string145 mod = chewy.Module(data)146 def create_subtree(prefix, name):147 abs_path = chewy.sandbox_path(prefix, name)148 abs_dirname = os.path.dirname(abs_path)149 if not os.path.exists(abs_dirname):150 os.makedirs(151 abs_dirname152 , exist_ok=True153 )154 with tempfile.TemporaryDirectory() as tmpdirname:155 # Create necessary temporary directorie's sub tree156 create_subtree(tmpdirname, mod.path)157 # Write module to file158 with open(chewy.sandbox_path(tmpdirname, mod.path), 'w', encoding='utf-8') as f:159 f.write(data)160 # Receive all module-related files161 for relpath in mod.addons:162 url = os.path.join(mod.repobase, relpath)163 ep = chewy.HttpEndpoint(url)164 cs = sf.get_session(ep)165 log.einfo('Receiving the addon file {}'.format(url))166 data = cs.retrieve_remote_file(ep.geturl()) # Get a remote file into string167 # Create necessary temporary directorie's sub tree168 create_subtree(tmpdirname, relpath)169 # Going to write just received data to the temporary dir170 # TODO: Strip repobasename171 with open(chewy.sandbox_path(tmpdirname, relpath), 'w', encoding='utf-8') as f:172 f.write(data)173 # TODO: Version compare is required as well. Is it?174 if local_module:175 self.uninstall(local_module)176 # If success, install module to real modules path177 chewy.copytree(tmpdirname, self.get_modules_dir())178 def get_statuses(self):179 '''180 Return: Dictionary by unique repobase to module-related statuses' list181 '''182 # Get modules installed in a given dir183 status_map = chewy.collect_installed_modules(self.get_modules_dir())184 # Retrieve remote_modules_map for all used chewy repositories185 manifest_map = rcv_manifests(status_map.keys())186 # Iterate over installed modules (statuses actually) grouped by repository187 for repobase, modules in status_map.items():188 # Iterate over list of module statuses189 for status in modules:190 local_mod = status.module191 # Find local module in a remote repository192 remote_mod = chewy.find(manifest_map[repobase].modules, lambda x: x.path == local_mod.path)193 # If not found, mark current module as deleted194 if not remote_mod:195 status.set_remote_version(None)196 else:197 assert remote_mod.path == local_mod.path198 # Remember the remote version199 status.set_remote_version(remote_mod.version)200 return status_map201 def do_list(self):202 '''203 Execute `list' command204 If no repo given, the function try to find a modules base,205 scan it and collect used repo bases206 '''207 url_list = self.args.rep_url208 if not url_list:209 url_list = chewy.collect_installed_modules(self.get_modules_dir()).keys()210 # Make URLs unique211 urls = set(url_list)212 if not urls:213 raise RuntimeError('No chewy repository URLs was found and nothing provided in the command line')214 for repobase, manifest in rcv_manifests(urls).items():215 log.einfo("Modules from the `{}' repository".format(repobase))216 ordered_list = manifest.modules217 if self.args.s is True:218 ordered_list = sorted(manifest.modules, key=lambda mod: mod.path)219 if self.args.S is True:220 ordered_list = sorted(manifest.modules, key=lambda mod: mod.path, reverse=True)221 print(chewy.FancyGrid(222 [ [mod.path, str(mod.version), mod.description]223 for mod224 in ordered_list225 ]226 ))227 def do_install(self):228 '''Execute `install' command'''229 url_list = self.args.file_url230 if not url_list:231 raise RuntimeError('At least one url should be given')232 with chewy.session.Factory() as sf:233 for url in url_list:234 try:235 self.rcv_module(url, sf)236 # TODO pass 'can't create modules dir' exception through237 except RuntimeError as ex:238 log.eerror("Can't receive the file `{}': {}".format(url, ex))239 def do_status(self):240 '''Execute `status' command'''241 status_map = self.get_statuses().items()242 if not status_map:243 raise RuntimeError('No chewy repository URLs was found and nothing provided at the command line')244 for repobase, status_list in status_map:245 log.einfo('List of installed modules from the repository {}'.format(repobase))246 # TODO Colorise output (especially new versions)247 print(248 chewy.FancyGrid([249 [250 m.status_as_string()251 , m.module.path252 , str(m.module.version)253 , str(m.available_version())254 , m.module.description255 ]256 for m in status_list257 ])258 )259 def do_update(self):260 '''Execute `update' command'''261 # TODO: Use it262 # file_list = self.args.file_url263 with chewy.session.Factory() as sf:264 for repobase, status_list in self.get_statuses().items():265 for mod in [ st.module for st in status_list if st.needs_update() ]:266 try:267 self.rcv_module(mod, sf)268 # TODO pass 'can't create modules dir' exception through269 except RuntimeError as ex:270 log.eerror("Can't update the module `{}': {}".format(mod, ex))271 def do_uninstall(self):272 '''Execute `uninstall' command'''273 for f in self.args.file_url:274 try:275 abspath = os.path.abspath(f)276 if not abspath.startswith(self.get_modules_dir()):277 abspath = chewy.sandbox_path(self.get_modules_dir(), f)278 self.uninstall(chewy.open_module(abspath))279 except (RuntimeError, IOError) as ex:280 log.eerror("Can't uninstall `{}': {}".format(f, ex))281 continue282 def run(self):283 self.args = self.cmd_parser.parse_args()284 if self.args.cmd is not None:285 self.args.func()286 else:287 log.eerror('No command given')288if __name__ == "__main__":289 try:290 a = Application()291 a.run()...

Full Screen

Full Screen

modules.py

Source:modules.py Github

copy

Full Screen

...81 return None82def locate_modules_dir():83 logger.debug('Locating JAGS module directory.')84 return locate_modules_dir_using_shared_objects()85def get_modules_dir():86 """Return modules directory."""87 global modules_dir88 if modules_dir is None:89 modules_dir = locate_modules_dir()90 if modules_dir is None:91 raise RuntimeError(92 'Could not locate JAGS module directory. Use pyjags.set_modules_dir(path) to configure it manually.')93 return modules_dir94def set_modules_dir(directory):95 """Set modules directory."""96 global modules_dir97 modules_dir = directory98def list_modules():99 """Return a list of loaded modules."""100 return Console.listModules()101def load_module(name, modules_dir=None):102 """Load a module.103 Parameters104 ----------105 name : str106 A name of module to load.107 modules_dir : str, optional108 Directory where modules are located.109 """110 if name not in loaded_modules:111 dir = modules_dir or get_modules_dir()112 ext = '.so' if os.name == 'posix' else '.dll'113 path = os.path.join(dir, name + ext)114 logger.info('Loading module %s from %s', name, path)115 module = ctypes.cdll.LoadLibrary(path)116 loaded_modules[name] = module117 Console.loadModule(name)118loaded_modules = {}119def unload_module(name):120 """Unload a module."""...

Full Screen

Full Screen

install.py

Source:install.py Github

copy

Full Screen

...9 if is_installed():10 return11 12 powercli_zip = ZipFile(consts.POWERCLI_ZIP_PATH)13 modules_dir = Powershell.get_modules_dir(should_create=True)14 powercli_zip.extractall(path=modules_dir)15def uninstall_powercli():16 """ Uninstalls all PowerCLI modules from the current user. """17 powercli_modules_names = __get_powercli_modules_names(ZipFile(consts.POWERCLI_ZIP_PATH))18 modules_dir = Powershell.get_modules_dir()19 20 try: 21 for module in os.listdir(modules_dir):22 if module in powercli_modules_names:23 shutil.rmtree(os.path.join(modules_dir, module))24 except PermissionError as err:25 print("Access to the file {} is denied.".format(err.filename))26 print("Make sure you have closed all Powershell windows that use PowerCLI, and try again.")27def is_installed():28 """ Checks if all PowerCLI modules are installed correctly. """29 modules_dir = Powershell.get_modules_dir()30 if not os.path.exists(modules_dir):31 return False32 modules_in_powershell_dir = os.listdir(modules_dir)33 for module in __get_powercli_modules_names(ZipFile(consts.POWERCLI_ZIP_PATH)):34 if module not in modules_in_powershell_dir:35 return False36 37 return True38def __get_powercli_modules_names(powercli_zip):39 """ Extracts from the PowerCLI zip the PowerCLI modules names. """40 if not isinstance(powercli_zip, ZipFile):41 raise TypeError("The argument 'powercli_zip' isn't of type 'ZipFile'.")42 modules_names = []43 for single_file in powercli_zip.namelist():...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run avocado automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful