def show_config(): '''Load the config file and write it to STDOUT ''' import json click.echo(get_config_dir()) config = get_config() click.echo(json.dumps(config, sort_keys=True, indent=2))
def register_thermo_com_net(path): '''Register a bundle of Thermo's RawFileReader library's DLLs. The `--path` option can be used to specify additional search paths. ''' if path is None: path = [] try: import clr except ImportError: click.secho("pythonnet not installed", fg='yellow') raise click.ClickException( "This feature requires the pythonnet library. Please install it.") from ms_deisotope.data_source.thermo_raw_net import _register_dll, _RawFileReader from ms_deisotope.data_source.thermo_raw_net import determine_if_available if _RawFileReader: click.secho("DLL Already Registered and Loaded") return result = _register_dll(path) if result: click.secho("DLL Registration Successful") if determine_if_available(): click.secho("DLL Load Succesful", fg='cyan') if path is not None: config = get_config() rest = sorted(set(path) - set(config['vendor_readers']['thermo-net'])) config['vendor_readers']['thermo-net'].extend(rest) save_config(config) else: click.secho("DLL Load Unsuccessful", fg='red') else: click.secho("DLL Registration Unsuccessful")
def register_waters_masslynx(path): if path is None: path = [] from ms_deisotope.data_source._vendor.masslynx import libload path = list(map(os.path.abspath, path)) result = libload._register_dll(path) if result: click.secho("DLL Registration Successful") out = libload.determine_if_available() if out: click.secho("DLL Load Succesful", fg='cyan') if path is not None: config = get_config() config.setdefault('vendor_readers', {}) config['vendor_readers'].setdefault("waters-masslynx", []) rest = sorted( set(path) - set( config.get('vendor_readers', {}).get( 'waters-masslynx', []))) config['vendor_readers']['waters-masslynx'].extend(rest) save_config(config) else: click.secho("DLL Load Unsuccessful", fg='red') else: click.secho("DLL Registration Unsuccessful")
def _register_dll(search_paths=None): '''Start the Common Language Runtime interop service by importing the :mod:`clr` module from Pythonnet, and then populate the global names referring to .NET entities, and finally attempt to locate the ThermoRawFileReader DLLs by searching alogn ``search_paths``. Parameters ---------- search_paths: list The paths to check along for the ThermoRawFileReader DLL bundle. Returns ------- :class:`bool`: Whether or not the .NET library successfully loaded ''' from ms_deisotope.config import get_config if search_paths is None: search_paths = [] search_paths = list(search_paths) search_paths.append(_DEFAULT_DLL_PATH) # Take user-specified search paths first. search_paths = get_config().get('vendor_readers', {}).get( 'thermo-net', []) + search_paths global _RawFileReader, Business, clr, NullReferenceException # pylint: disable=global-statement global Marshal, IntPtr, Int64 # pylint: disable=global-statement if _test_dll_loaded(): return True try: import clr # pylint: disable=redefined-outer-name from System import NullReferenceException # pylint: disable=redefined-outer-name clr.AddReference("System.Runtime") clr.AddReference("System.Runtime.InteropServices") from System import IntPtr, Int64 # pylint: disable=redefined-outer-name from System.Runtime.InteropServices import Marshal # pylint: disable=redefined-outer-name except ImportError: return False for path in search_paths: sys.path.append(path) try: clr.AddReference('ThermoFisher.CommonCore.RawFileReader') clr.AddReference('ThermoFisher.CommonCore.Data') except OSError: continue try: import ThermoFisher.CommonCore.Data.Business as Business # pylint: disable=redefined-outer-name import ThermoFisher.CommonCore.RawFileReader as _RawFileReader # pylint: disable=redefined-outer-name except ImportError: continue return _test_dll_loaded()
def _register_dll(search_paths=None, override=True): if search_paths is None: search_paths = [] elif isinstance(search_paths, str): search_paths = [search_paths] from ms_deisotope.config import get_config search_paths.extend(get_config().get('vendor_readers', {}).get('waters-masslynx', [])) search_paths.append(find_library("MassLynx.dll")) global dll if dll is None or override: for lib_path in search_paths: try: dll = _load_library(lib_path) except (Exception) as err: continue if dll is not None: break return dll
def _register_dll_dir(search_paths=None): from ms_deisotope.config import get_config if search_paths is None: search_paths = [] global DLL_IS_LOADED if DLL_IS_LOADED: return True search_paths = list(search_paths) search_paths.extend(_default_paths) search_paths.extend(get_config().get('vendor_readers', {}).get('agilent-com', [])) for dll_dir in search_paths: try: GetModule(os.path.join(dll_dir, 'MassSpecDataReader.tlb')) GetModule(os.path.join(dll_dir, 'BaseCommon.tlb')) GetModule(os.path.join(dll_dir, 'BaseDataAccess.tlb')) DLL_IS_LOADED = True return True except Exception: continue else: return False
def _register_dll(search_paths=None, override=True): if search_paths is None: search_paths = [] elif isinstance(search_paths, str): search_paths = [search_paths] elif not isinstance(search_paths, list): raise TypeError("Expected a list of paths or a single path string") from ms_deisotope.config import get_config search_paths = list(search_paths) search_paths.extend(get_config().get('vendor_readers', {}).get('waters-masslynx', [])) found = find_library("MassLynx.dll") if found: search_paths.append(found) global dll if dll is None or override: for lib_path in search_paths: try: dll = _load_library(lib_path) except (Exception) as err: continue if dll is not None: break return dll
def register_thermo_com(path=None): '''Register an installed MSFileReader or XRawFile DLL. Searches the standard installation paths, but the `--path` option can be used to specify additional search paths. ''' if path is None: path = [] try: import comtypes except ImportError: click.secho("comtypes not installed", fg='yellow') raise click.ClickException( "This feature requires the comtypes library. Please install it.") import logging from ms_deisotope.data_source._vendor.MSFileReader import _register_dll, log, DLL_IS_LOADED from ms_deisotope.data_source.thermo_raw import determine_if_available if DLL_IS_LOADED: click.secho("DLL Already Registered and Loaded") return if log is not None: log.addHandler(logging.StreamHandler()) log.setLevel('DEBUG') result = _register_dll(path) if result: click.secho("DLL Registration Successful") if determine_if_available(): click.secho("DLL Load Succesful", fg='cyan') if path is not None: config = get_config() config['vendor_readers']['thermo-com'].extend(path) save_config(config) else: click.secho("DLL Load Unsuccessful", fg='red') else: click.secho("DLL Registration Unsuccessful") if log is not None: log.handlers = log.handlers[:-1]