Skip to content

Commit

Permalink
[IMP] oca_publish_modules: tool for publishing modules
Browse files Browse the repository at this point in the history
  • Loading branch information
alexey-pelykh committed Mar 1, 2019
1 parent e1d5bd6 commit ad4c185
Showing 1 changed file with 123 additions and 0 deletions.
123 changes: 123 additions & 0 deletions tools/oca_publish_modules.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
#!/usr/bin/env python
# Copyright 2019 Brainbean Apps (https://brainbeanapps.com)
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

import os
import logging
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

_logger = logging.getLogger(__name__)


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:
_logger.debug('Error: %s', ex)
print('Repository publishing failed!')


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:
_logger.debug('Scanning failed: %s', 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__':
main()

0 comments on commit ad4c185

Please sign in to comment.