def __eq__(self, other: Union[str, 'ElementAttribute']): if isinstance(other, str): return case_and_space_insensitive_equals(self.name, other) elif isinstance(other, ElementAttribute): return case_and_space_insensitive_equals(self.name, other.name) else: raise ValueError( "Argument: 'other' must be of type str or ElementAttribute")
def test_get_active_users(self): current_user = self.tm1.security.get_current_user() active_users = self.tm1.monitoring.get_active_users() self.assertTrue( any( case_and_space_insensitive_equals(user.name, current_user.name) for user in active_users))
def substitute_title(self, dimension: str, hierarchy: str, element: str): """ dimension and hierarchy name are space sensitive! :param dimension: :param hierarchy: :param element: :return: """ pattern = re.compile( r"\[" + dimension + r"\].\[" + hierarchy + r"\].\[(.*?)\]", re.IGNORECASE) findings = re.findall(pattern, self._mdx) if findings: self._mdx = re.sub(pattern=pattern, repl=f"[{dimension}].[{hierarchy}].[{element}]", string=self._mdx) return if hierarchy is None or case_and_space_insensitive_equals( dimension, hierarchy): pattern = re.compile(r"\[" + dimension + r"\].\[(.*?)\]", re.IGNORECASE) findings = re.findall(pattern, self._mdx) if findings: self._mdx = re.sub(pattern=pattern, repl=f"[{dimension}].[{element}]", string=self._mdx) return raise ValueError( f"No selection in title with dimension: '{dimension}' and hierarchy: '{hierarchy}'" )
def test_get_sessions(self): current_user = self.tm1.security.get_current_user() sessions = self.tm1.monitoring.get_sessions() self.assertTrue( any( case_and_space_insensitive_equals(session["User"]["Name"], current_user.name) for session in sessions if session["User"]))
def remove_title(self, dimension_name: str): """ Remove dimension from the titles-axis :param dimension_name: name of the dimension. :return: """ for title in self._titles[:]: if case_and_space_insensitive_equals(title.dimension_name, dimension_name): self._titles.remove(title)
def remove_row(self, dimension_name: str): """ remove dimension from the row axis :param dimension_name: :return: """ for row in self._rows[:]: if case_and_space_insensitive_equals(row.dimension_name, dimension_name): self._rows.remove(row)
def remove_column(self, dimension_name: str): """ remove dimension from the column axis :param dimension_name: :return: """ for column in self._columns[:]: if case_and_space_insensitive_equals(column.dimension_name, dimension_name): self._columns.remove(column)
def disconnect_all_users(self, **kwargs) -> list: current_user = self.get_current_user(**kwargs) active_users = self.get_active_users(**kwargs) disconnected_users = list() for active_user in active_users: if not case_and_space_insensitive_equals(current_user.name, active_user.name): self.disconnect_user(active_user.name, **kwargs) disconnected_users += [active_user.name] return disconnected_users
def substitute_title(self, dimension: str, element: str): for title in self._titles: if case_and_space_insensitive_equals(title.dimension_name, dimension): title._subset = AnonymousSubset(dimension, dimension, elements=[element]) title._selected = element return raise ValueError(f"Dimension '{dimension}' not found in titles")
def get(self, cube_name: str, **kwargs) -> Cube: """ get cube from TM1 Server :param cube_name: :return: instance of TM1py.Cube """ url = format_url("/api/v1/Cubes('{}')?$expand=Dimensions($select=Name)", cube_name) response = self._rest.GET(url=url, **kwargs) cube = Cube.from_json(response.text) # cater for potential EnableSandboxDimension=T setup if case_and_space_insensitive_equals(cube.dimensions[0], "Sandboxes"): cube.dimensions = cube.dimensions[1:] return cube
def close_all_sessions(self, **kwargs) -> list: current_user = self.get_current_user(**kwargs) sessions = self.get_sessions(**kwargs) closed_sessions = list() for session in sessions: if "User" not in session: continue if session["User"] is None: continue if "Name" not in session["User"]: continue if case_and_space_insensitive_equals(current_user.name, session["User"]["Name"]): continue self.close_session(session['ID'], **kwargs) closed_sessions.append(session) return closed_sessions
def __init__(self, **kwargs): """ Create an instance of RESTService :param address: String - address of the TM1 instance :param port: Int - HTTPPortNumber as specified in the tm1s.cfg :param base_url - base url e.g. https://localhost:12354/api/v1 :param user: String - name of the user :param password String - password of the user :param decode_b64 - whether password argument is b64 encoded :param namespace String - optional CAM namespace :param ssl: boolean - as specified in the tm1s.cfg :param session_id: String - TM1SessionId e.g. q7O6e1w49AixeuLVxJ1GZg :param session_context: String - Name of the Application. Controls "Context" column in Arc / TM1top. If None, use default: TM1py :param verify: path to .cer file or 'True' / True / 'False' / False (if no ssl verification is required) :param logging: boolean - switch on/off verbose http logging into sys.stdout :param timeout: Float - Number of seconds that the client will wait to receive the first byte. :param async_requests_mode: changes internal REST execution mode to avoid 60s timeout on IBM cloud :param connection_pool_size - In a multithreaded environment, you should set this value to a higher number, such as the number of threads :param integrated_login: True for IntegratedSecurityMode3 :param integrated_login_domain: NT Domain name. Default: '.' for local account. :param integrated_login_service: Kerberos Service type for remote Service Principal Name. Default: 'HTTP' :param integrated_login_host: Host name for Service Principal Name. Default: Extracted from request URI :param integrated_login_delegate: Indicates that the user's credentials are to be delegated to the server. Default: False :param impersonate: Name of user to impersonate """ self._ssl = self.translate_to_boolean(kwargs['ssl']) self._address = kwargs.get('address', None) self._port = kwargs.get('port', None) self._verify = False self._timeout = None if kwargs.get('timeout', None) is None else float( kwargs.get('timeout')) self._async_requests_mode = self.translate_to_boolean( kwargs.get('async_requests_mode', False)) # populated on the fly if kwargs.get('user'): self._is_admin = True if case_and_space_insensitive_equals( kwargs.get('user'), 'ADMIN') else None else: self._is_admin = None if 'verify' in kwargs: if isinstance(kwargs['verify'], str): if kwargs['verify'].upper() == 'FALSE': self._verify = False elif kwargs['verify'].upper() == 'TRUE': self._verify = True # path to .cer file else: self._verify = kwargs.get('verify') elif isinstance(kwargs['verify'], bool): self._verify = kwargs['verify'] else: raise ValueError("verify argument must be of type str or bool") if 'base_url' in kwargs: self._base_url = kwargs['base_url'] else: self._base_url = "http{}://{}:{}".format( 's' if self._ssl else '', 'localhost' if len(self._address) == 0 else self._address, self._port) self._version = None self._headers = self.HEADERS.copy() if "session_context" in kwargs: self._headers["TM1-SessionContext"] = kwargs["session_context"] self.disable_http_warnings() # re-use or create tm1 http session self._s = requests.session() if "session_id" in kwargs: self._s.cookies.set("TM1SessionId", kwargs["session_id"]) else: self._start_session( user=kwargs.get("user", None), password=kwargs.get("password", None), namespace=kwargs.get("namespace", None), gateway=kwargs.get("gateway", None), decode_b64=self.translate_to_boolean( kwargs.get("decode_b64", False)), integrated_login=self.translate_to_boolean( kwargs.get("integrated_login", False)), integrated_login_domain=kwargs.get("integrated_login_domain"), integrated_login_service=kwargs.get( "integrated_login_service"), integrated_login_host=kwargs.get("integrated_login_host"), integrated_login_delegate=kwargs.get( "integrated_login_delegate"), impersonate=kwargs.get("impersonate", None)) if not self._version: self.set_version() self._sandboxing_disabled = None # manage connection pool if "connection_pool_size" in kwargs: self._manage_http_connection_pool( kwargs.get("connection_pool_size")) # Logging if 'logging' in kwargs: if self.translate_to_boolean(value=kwargs['logging']): http_client.HTTPConnection.debuglevel = 1
def __eq__(self, other: 'Element'): return all([ isinstance(other, Element), case_and_space_insensitive_equals(self.name, other.name), self.element_type == other.element_type])