-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnextcloud_install.py
60 lines (50 loc) · 2.23 KB
/
nextcloud_install.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import sys
import signal
from time import time_ns
from playwright.sync_api import sync_playwright
from helpers.helper_functions import log_note, timeout_handler
def main(browser_name: str = "firefox", headless=False):
with sync_playwright() as playwright:
log_note(f"Launch browser {browser_name}")
signal.signal(signal.SIGALRM, timeout_handler)
signal.alarm(10)
if browser_name == "firefox":
browser = playwright.firefox.launch(headless=headless)
else:
browser = playwright.chromium.launch(headless=False, args=['--disable-gpu', '--disable-software-rasterizer', '--ozone-platform=wayland'])
context = browser.new_context(ignore_https_errors=True)
page = context.new_page()
signal.alarm(0) # remove timeout signal
try:
page.goto('https://ncs')
# 1. Create User
log_note("Create admin user")
page.locator('#adminlogin').fill('Crash')
page.locator('#adminpass').fill('Override')
page.locator('.primary').click()
# 2. Install all Apps
log_note("Install recommended apps")
install_selector = '.button-vue--vue-primary'
page.locator(install_selector).click()
# 3. Dashboard
page.locator('.app-dashboard').wait_for(timeout=240_000)
log_note("Installation complete")
browser.close()
except Exception as e:
if hasattr(e, 'message'): # only Playwright error class has this member
log_note(f"Exception occurred: {e.message}")
# set a timeout. Since the call to page.content() is blocking we need to defer it to the OS
signal.signal(signal.SIGALRM, timeout_handler)
signal.alarm(20)
log_note(f"Page content was: {page.content()}")
signal.alarm(0) # remove timeout signal
raise e
if __name__ == '__main__':
if len(sys.argv) > 1:
browser_name = sys.argv[1].lower()
if browser_name not in ["chromium", "firefox"]:
print("Invalid browser name. Please choose either 'chromium' or 'firefox'.")
sys.exit(1)
else:
browser_name = "firefox"
main(browser_name)