-
-
Notifications
You must be signed in to change notification settings - Fork 459
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[IMP] oca_publish_modules: tool for publishing modules
- Loading branch information
1 parent
e1d5bd6
commit 4d55001
Showing
1 changed file
with
119 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
#!/usr/bin/env python | ||
# Copyright 2019 Brainbean Apps (https://brainbeanapps.com) | ||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). | ||
|
||
import sys | ||
import os | ||
from getpass import getpass | ||
from selenium import webdriver | ||
from selenium.webdriver.support.ui import WebDriverWait | ||
from selenium.webdriver.chrome.options import Options | ||
|
||
from .oca_projects import get_repositories_and_branches, url | ||
|
||
|
||
def main(argv): | ||
chrome = os.getenv('CHROMEDRIVER') | ||
if not chrome: | ||
print( | ||
'Please specify CHROMEDRIVER environment variable pointing to' | ||
' valid Google Chrome Driver executable file and ensure its' | ||
' location is available via PATH environment variable.\n\n' | ||
'See http://chromedriver.chromium.org/downloads' | ||
) | ||
return | ||
|
||
login = input('Odoo.com publisher account:') | ||
password = getpass(prompt='Odoo.com account password:') | ||
|
||
for repository, branch in get_repositories_and_branches(): | ||
try: | ||
repository_url = url(repository) + '#' + branch | ||
print('Publishing %s#%s from %s...' % ( | ||
repository, | ||
branch, | ||
repository_url, | ||
)) | ||
publish_repository(chrome, login, password, repository_url) | ||
except Exception as ex: | ||
print('Repository publishing failed:', ex) | ||
|
||
|
||
def publish_repository(chrome, login, password, repository_url): | ||
options = Options() | ||
options.headless = True | ||
|
||
driver = webdriver.Chrome( | ||
executable_path=chrome, | ||
options=options, | ||
) | ||
|
||
login(driver, login, password) | ||
|
||
try: | ||
scan_repository(driver, repository_url) | ||
except Exception as ex: | ||
register_repository(driver, repository_url) | ||
scan_repository(driver, repository_url) | ||
|
||
|
||
def login(driver, login, password): | ||
wait = WebDriverWait(driver, 10) | ||
|
||
driver.get( | ||
'https://www.odoo.com/web/login?redirect=%2Foauth2%2Fauth%2F%3Fscope' | ||
'%3Duserinfo%26redirect_uri%3Dhttps%253A%252F%252Fapps.odoo.com%252F' | ||
'auth_oauth%252Fsignin%26state%3D%257B%2522p%2522%253A%2B1%252C%2B' | ||
'%2522r%2522%253A%2B%2522%25252F%25252Fapps.odoo.com%25252Fapps%25' | ||
'22%252C%2B%2522d%2522%253A%2B%2522apps%2522%257D%26response_type%3D' | ||
'token%26client_id%3Da0a30d16-6095-11e2-9c70-002590a17fd8&scope=user' | ||
'info&mode=login&redirect_hostname=https%3A%2F%2Fapps.odoo.com&login=' | ||
) | ||
login_field = driver.find_element_by_id('login') | ||
login_field.clear() | ||
login_field.send_keys(login) | ||
password_field = driver.find_element_by_id('password') | ||
password_field.clear() | ||
password_field.send_keys(password) | ||
login_button = driver.find_element_by_xpath( | ||
'.//form[@action="/web/login"]//button[@type="submit"]' | ||
) | ||
login_button.click() | ||
wait.until( | ||
lambda driver: driver.current_url == 'https://apps.odoo.com/apps' | ||
) | ||
|
||
|
||
def register_repository(driver, repository): | ||
wait = WebDriverWait(driver, 10) | ||
|
||
driver.get('https://apps.odoo.com/apps/upload') | ||
url_field = driver.find_element_by_id('url') | ||
url_field.clear() | ||
url_field.send_keys(repository) | ||
submit_button = driver.find_element_by_id('apps_submit_repo_button') | ||
submit_button.click() | ||
wait.until( | ||
lambda driver: driver.current_url | ||
== 'https://apps.odoo.com/apps/dashboard/repos' | ||
) | ||
|
||
|
||
def scan_repository(driver, repository): | ||
item_container = driver.find_element_by_xpath( | ||
'.//span[@id="repo_url" and text()="%s"]' | ||
'/ancestor::li[1]' % ( | ||
repository | ||
) | ||
) | ||
auto_scan_checkbox = item_container.find_element_by_xpath( | ||
'.//input[@name="auto_scan"]' | ||
) | ||
if not auto_scan_checkbox.is_selected(): | ||
auto_scan_checkbox.click() | ||
scan_link = item_container.find_element_by_class_name('js_repo_scan') | ||
scan_link.click_and_wait(5000) | ||
|
||
|
||
if __name__ == '__main__': | ||
sys.exit(main(sys.argv)) |