ITK-dev-shared-components 0.0.1__tar.gz → 0.0.2__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2023 ITK Development
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -1,16 +1,17 @@
1
- Metadata-Version: 2.1
2
- Name: ITK_dev_shared_components
3
- Version: 0.0.1
4
- Summary: Shared components to use in RPA projects
5
- Author-email: ITK Development <itk-rpa@mkb.aarhus.dk>
6
- Project-URL: Homepage, https://github.com/itk-dev-rpa/itk-dev-shared-components
7
- Project-URL: Bug Tracker, https://github.com/itk-dev-rpa/itk-dev-shared-components/issues
8
- Classifier: Programming Language :: Python :: 3
9
- Classifier: License :: OSI Approved :: MIT License
10
- Classifier: Operating System :: Microsoft :: Windows
11
- Requires-Python: >=3.7
12
- Description-Content-Type: text/markdown
13
-
14
- # itk-dev-shared-components
15
-
16
- Hej itk du er min ven
1
+ Metadata-Version: 2.1
2
+ Name: ITK_dev_shared_components
3
+ Version: 0.0.2
4
+ Summary: Shared components to use in RPA projects
5
+ Author-email: ITK Development <itk-rpa@mkb.aarhus.dk>
6
+ Project-URL: Homepage, https://github.com/itk-dev-rpa/itk-dev-shared-components
7
+ Project-URL: Bug Tracker, https://github.com/itk-dev-rpa/itk-dev-shared-components/issues
8
+ Classifier: Programming Language :: Python :: 3
9
+ Classifier: License :: OSI Approved :: MIT License
10
+ Classifier: Operating System :: Microsoft :: Windows
11
+ Requires-Python: >=3.7
12
+ Description-Content-Type: text/markdown
13
+ License-File: LICENSE
14
+
15
+ # itk-dev-shared-components
16
+
17
+ Version 0.0.2
@@ -1,3 +1,3 @@
1
- # itk-dev-shared-components
2
-
3
- Hej itk du er min ven
1
+ # itk-dev-shared-components
2
+
3
+ Version 0.0.2
@@ -1,22 +1,23 @@
1
- [build-system]
2
- requires = ["setuptools>=65.0"]
3
- build-backend = "setuptools.build_meta"
4
-
5
- [project]
6
- name = "ITK_dev_shared_components"
7
- version = "0.0.1"
8
- authors = [
9
- { name="ITK Development", email="itk-rpa@mkb.aarhus.dk" },
10
- ]
11
- description = "Shared components to use in RPA projects"
12
- readme = "README.md"
13
- requires-python = ">=3.7"
14
- classifiers = [
15
- "Programming Language :: Python :: 3",
16
- "License :: OSI Approved :: MIT License",
17
- "Operating System :: Microsoft :: Windows",
18
- ]
19
-
20
- [project.urls]
21
- "Homepage" = "https://github.com/itk-dev-rpa/itk-dev-shared-components"
22
- "Bug Tracker" = "https://github.com/itk-dev-rpa/itk-dev-shared-components/issues"
1
+ [build-system]
2
+ requires = ["setuptools>=65.0"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "ITK_dev_shared_components"
7
+ version = "0.0.2"
8
+ authors = [
9
+ { name="ITK Development", email="itk-rpa@mkb.aarhus.dk" },
10
+ ]
11
+ description = "Shared components to use in RPA projects"
12
+ readme = "README.md"
13
+ requires-python = ">=3.7"
14
+ classifiers = [
15
+ "Programming Language :: Python :: 3",
16
+ "License :: OSI Approved :: MIT License",
17
+ "Operating System :: Microsoft :: Windows",
18
+ ]
19
+
20
+ [project.urls]
21
+ "Homepage" = "https://github.com/itk-dev-rpa/itk-dev-shared-components"
22
+ "Bug Tracker" = "https://github.com/itk-dev-rpa/itk-dev-shared-components/issues"
23
+
@@ -1,4 +1,4 @@
1
- [egg_info]
2
- tag_build =
3
- tag_date = 0
4
-
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,120 @@
1
+ import pythoncom
2
+ import win32com.client
3
+ import win32gui
4
+ import threading
5
+
6
+ def run_with_session(session_index:int, func:function, args:tuple) -> None:
7
+ """Run a function in a sepcific session based on the sessions index.
8
+
9
+ This function is meant to be run inside a seperate thread.
10
+ Note that this function will not spawn the sessions before running,
11
+ use spawn_sessions to do that.
12
+ """
13
+
14
+ pythoncom.CoInitialize()
15
+
16
+ SAP = win32com.client.GetObject("SAPGUI")
17
+ app = SAP.GetScriptingEngine
18
+ connection = app.Connections(0)
19
+ session = connection.Sessions(session_index)
20
+
21
+ func(session, *args)
22
+
23
+ pythoncom.CoUninitialize()
24
+
25
+ def run_batch(func:function, args:tuple[tuple], num_sessions=6) -> None:
26
+ """Run a function in parallel sessions.
27
+
28
+ The function will be run {num_sessions} times with args[i] as input.
29
+ Note that this function will not spawn the sessions before running,
30
+ use spawn_sessions to do that.
31
+ """
32
+
33
+ threads = []
34
+ for i in range(num_sessions):
35
+ t = ExThread(target=run_with_session, args=(i, func, args[i]))
36
+ threads.append(t)
37
+
38
+ for t in threads:
39
+ t.start()
40
+ for t in threads:
41
+ t.join()
42
+ for t in threads:
43
+ if t.error:
44
+ raise t.error
45
+
46
+ def run_batches(func:function, args:tuple[tuple], num_sessions=6):
47
+ """Run a function in parallel batches.
48
+
49
+ This function runs the input function for each set of arguments in args.
50
+ The function will be run in parallel batches of size {num_sessions}.
51
+ Note that this function will not spawn the sessions before running,
52
+ use spawn_sessions to do that.
53
+ """
54
+
55
+ for b in range(0, len(args), num_sessions):
56
+ batch = args[b:b+num_sessions]
57
+ run_batch(func, args, len(batch))
58
+
59
+ def spawn_sessions(num_sessions=6) -> list:
60
+ """A function to spawn multiple sessions of SAP.
61
+
62
+ This function will attempt to spawn the desired number of sessions.
63
+ If the current number of open sessions exceeds the desired number of sessions
64
+ the already open sessions will not be closed to match the desired number.
65
+ The number of sessions must be between 1 and 6.
66
+ Returns a list of all open sessions.
67
+ """
68
+ SAP = win32com.client.GetObject("SAPGUI")
69
+ app = SAP.GetScriptingEngine
70
+ connection = app.Connections(0)
71
+ session = connection.Sessions(0)
72
+
73
+ if num_sessions < 1:
74
+ raise ValueError("Number of sessions cannot be less than 1")
75
+ if num_sessions > 6:
76
+ raise ValueError("Number of sessions cannot be more than 6")
77
+
78
+ for _ in range(num_sessions - connection.Sessions.count):
79
+ session.CreateSession()
80
+
81
+ sessions = list(connection.Sessions)
82
+ num_sessions = len(sessions)
83
+
84
+ if num_sessions == 1:
85
+ c = 1
86
+ elif num_sessions <= 4:
87
+ c = 2
88
+ elif num_sessions <= 6:
89
+ c = 3
90
+
91
+ if num_sessions < 3:
92
+ r = 1
93
+ else:
94
+ r = 2
95
+
96
+ w, h = 1920//c, 1040//r
97
+
98
+ for i, session in enumerate(sessions):
99
+ window = session.findById("wnd[0]")
100
+ window.Restore()
101
+ hwnd = window.Handle
102
+ x = i % c * w
103
+ y = i // c * h
104
+ win32gui.MoveWindow(hwnd, x, y, w, h, True)
105
+
106
+ return sessions
107
+
108
+ class ExThread(threading.Thread):
109
+ """A thread with a handle to get an exception raised inside the thread: ExThread.error"""
110
+ def __init__(self, *args, **kwargs):
111
+ super(ExThread, self).__init__(*args, **kwargs)
112
+ self.error = None
113
+
114
+ def run(self):
115
+ try:
116
+ self._target(*self._args, **self._kwargs)
117
+ except Exception as e:
118
+ self.error = e
119
+
120
+
@@ -1,50 +1,53 @@
1
- from selenium import webdriver
2
- from selenium.webdriver.common.by import By
3
- import os
4
- import pathlib
5
- import time
6
-
7
- def login(user, password):
8
- driver = webdriver.Chrome()
9
- driver.implicitly_wait(10)
10
- driver.get('https://portal.kmd.dk/irj/portal')
11
- driver.maximize_window()
12
-
13
- #Login
14
- user_field = driver.find_element(By.ID, 'logonuidfield')
15
- pass_field = driver.find_element(By.ID, 'logonpassfield')
16
- login_button = driver.find_element(By.ID, 'buttonLogon')
17
-
18
- user_field.clear()
19
- user_field.send_keys(user)
20
-
21
- pass_field.clear()
22
- pass_field.send_keys(password)
23
-
24
- login_button.click()
25
-
26
- #Opus
27
- mine_genveje = driver.find_element(By.CSS_SELECTOR, "div[title='Mine Genveje']")
28
- mine_genveje.click()
29
-
30
- #Wait for download and launch file
31
- wait_for_download()
32
-
33
- driver.quit()
34
-
35
- def wait_for_download():
36
- downloads_folder = str(pathlib.Path.home() / "Downloads")
37
- for _ in range(10):
38
- for file in os.listdir(downloads_folder):
39
- if file.endswith(".sap"):
40
- path = os.path.join(downloads_folder, file)
41
- os.startfile(path)
42
- return
43
-
44
- time.sleep(0.5)
45
-
46
- if __name__=="__main__":
47
- user, password = os.environ['Opus Login'].split(';')
48
- login(user, password)
49
-
50
-
1
+ from selenium import webdriver
2
+ from selenium.webdriver.common.by import By
3
+ import os
4
+ import pathlib
5
+ import time
6
+
7
+ def login(user, password):
8
+ driver = webdriver.Chrome()
9
+ driver.implicitly_wait(10)
10
+ driver.get('https://portal.kmd.dk/irj/portal')
11
+ driver.maximize_window()
12
+
13
+ #Login
14
+ user_field = driver.find_element(By.ID, 'logonuidfield')
15
+ pass_field = driver.find_element(By.ID, 'logonpassfield')
16
+ login_button = driver.find_element(By.ID, 'buttonLogon')
17
+
18
+ user_field.clear()
19
+ user_field.send_keys(user)
20
+
21
+ pass_field.clear()
22
+ pass_field.send_keys(password)
23
+
24
+ login_button.click()
25
+
26
+ #Opus
27
+ mine_genveje = driver.find_element(By.CSS_SELECTOR, "div[title='Mine Genveje']")
28
+ mine_genveje.click()
29
+
30
+ #Wait for download and launch file
31
+ wait_for_download()
32
+
33
+ driver.quit()
34
+
35
+ #TODO: Wait for if SAP has opened
36
+
37
+ def wait_for_download():
38
+ downloads_folder = str(pathlib.Path.home() / "Downloads")
39
+ for _ in range(10):
40
+ for file in os.listdir(downloads_folder):
41
+ if file.endswith(".sap"):
42
+ path = os.path.join(downloads_folder, file)
43
+ os.startfile(path)
44
+ return
45
+
46
+ time.sleep(0.5)
47
+ raise TimeoutError(f".SAP file not found in {downloads_folder}")
48
+
49
+ if __name__=="__main__":
50
+ user, password = os.environ['Opus Login'].split(';')
51
+ login(user, password)
52
+
53
+
@@ -1,16 +1,17 @@
1
- Metadata-Version: 2.1
2
- Name: ITK-dev-shared-components
3
- Version: 0.0.1
4
- Summary: Shared components to use in RPA projects
5
- Author-email: ITK Development <itk-rpa@mkb.aarhus.dk>
6
- Project-URL: Homepage, https://github.com/itk-dev-rpa/itk-dev-shared-components
7
- Project-URL: Bug Tracker, https://github.com/itk-dev-rpa/itk-dev-shared-components/issues
8
- Classifier: Programming Language :: Python :: 3
9
- Classifier: License :: OSI Approved :: MIT License
10
- Classifier: Operating System :: Microsoft :: Windows
11
- Requires-Python: >=3.7
12
- Description-Content-Type: text/markdown
13
-
14
- # itk-dev-shared-components
15
-
16
- Hej itk du er min ven
1
+ Metadata-Version: 2.1
2
+ Name: ITK-dev-shared-components
3
+ Version: 0.0.2
4
+ Summary: Shared components to use in RPA projects
5
+ Author-email: ITK Development <itk-rpa@mkb.aarhus.dk>
6
+ Project-URL: Homepage, https://github.com/itk-dev-rpa/itk-dev-shared-components
7
+ Project-URL: Bug Tracker, https://github.com/itk-dev-rpa/itk-dev-shared-components/issues
8
+ Classifier: Programming Language :: Python :: 3
9
+ Classifier: License :: OSI Approved :: MIT License
10
+ Classifier: Operating System :: Microsoft :: Windows
11
+ Requires-Python: >=3.7
12
+ Description-Content-Type: text/markdown
13
+ License-File: LICENSE
14
+
15
+ # itk-dev-shared-components
16
+
17
+ Version 0.0.2
@@ -1,3 +1,4 @@
1
+ LICENSE
1
2
  README.md
2
3
  pyproject.toml
3
4
  src/ITK_dev_shared_components/__init__.py
@@ -5,4 +6,5 @@ src/ITK_dev_shared_components.egg-info/PKG-INFO
5
6
  src/ITK_dev_shared_components.egg-info/SOURCES.txt
6
7
  src/ITK_dev_shared_components.egg-info/dependency_links.txt
7
8
  src/ITK_dev_shared_components.egg-info/top_level.txt
9
+ src/ITK_dev_shared_components/SAP/multi_session.py
8
10
  src/ITK_dev_shared_components/SAP/sap_login.py