Changeset View
Changeset View
Standalone View
Standalone View
add-bugzilla-versions/add-versions.py
- This file was copied to add-appstream-versions/add-versions.py.
Show All 10 Lines | |||||
11 | # This program is distributed in the hope that it will be useful, | 11 | # This program is distributed in the hope that it will be useful, | ||
12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
14 | # GNU General Public License for more details. | 14 | # GNU General Public License for more details. | ||
15 | # | 15 | # | ||
16 | # You should have received a copy of the GNU General Public License | 16 | # You should have received a copy of the GNU General Public License | ||
17 | # along with this program. If not, see <http://www.gnu.org/licenses/>. | 17 | # along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
18 | 18 | | |||
19 | import sys | ||||
20 | sys.path.append("..") | ||||
21 | | ||||
19 | import os | 22 | import os | ||
20 | from pathlib import Path | 23 | from pathlib import Path | ||
21 | import re | 24 | import re | ||
22 | from shutil import rmtree | 25 | from shutil import rmtree | ||
23 | from subprocess import run, DEVNULL, PIPE | 26 | from subprocess import run, DEVNULL, PIPE | ||
24 | from tempfile import mkdtemp | 27 | from tempfile import mkdtemp | ||
25 | 28 | | |||
26 | from bs4 import BeautifulSoup | 29 | from bs4 import BeautifulSoup | ||
27 | from click import command, echo, option, prompt | 30 | from click import command, echo, option, prompt | ||
28 | from git import GitCommandError, Repo | 31 | from git import GitCommandError, Repo | ||
29 | from git.exc import InvalidGitRepositoryError, NoSuchPathError | 32 | from git.exc import InvalidGitRepositoryError, NoSuchPathError | ||
30 | from requests import RequestException, Session | 33 | from requests import RequestException, Session | ||
31 | 34 | | |||
35 | import add_versions_lib | ||||
36 | | ||||
32 | 37 | | |||
33 | URL = 'https://bugs.kde.org' | 38 | URL = 'https://bugs.kde.org' | ||
34 | EDIT_VERSION_URL = '{}/editversions.cgi'.format(URL) | 39 | EDIT_VERSION_URL = '{}/editversions.cgi'.format(URL) | ||
35 | VERSION_RE = re.compile(r'(?i):\s+project\s*\(\s*\S+\s+' | | |||
36 | r'VERSION\s+(\d+(?:\.\d+(?:\.\d+(?:\.\d+)?)?)?)') | | |||
37 | 40 | | |||
38 | 41 | | |||
39 | def response_error(response): | 42 | def response_error(response): | ||
40 | html = response.text | 43 | html = response.text | ||
41 | soup = BeautifulSoup(html, 'html.parser') | 44 | soup = BeautifulSoup(html, 'html.parser') | ||
42 | error_message = soup.find('div', {'id': 'error_msg'}) | 45 | error_message = soup.find('div', {'id': 'error_msg'}) | ||
43 | if not error_message: | 46 | if not error_message: | ||
44 | return None | 47 | return None | ||
Show All 10 Lines | 57 | if error: | |||
55 | echo(error) | 58 | echo(error) | ||
56 | exit(1) | 59 | exit(1) | ||
57 | except RequestException: | 60 | except RequestException: | ||
58 | echo('Unexpected login error. Please, contact the maintainers of this ' | 61 | echo('Unexpected login error. Please, contact the maintainers of this ' | ||
59 | 'script.') | 62 | 'script.') | ||
60 | exit(1) | 63 | exit(1) | ||
61 | 64 | | |||
62 | 65 | | |||
63 | def products_and_branches(): | | |||
64 | modules_path = Path(__file__).resolve().parent.parent / 'modules.git' | | |||
65 | with modules_path.open() as modules_file: | | |||
66 | for line in modules_file: | | |||
67 | match = re.match(r'^(\S+)\s+(\S+)$', line) | | |||
68 | if match: | | |||
69 | yield match.group(1), match.group(2) | | |||
70 | | ||||
71 | | ||||
72 | def cmake_trace(folder): | | |||
73 | temp_folder = mkdtemp() | | |||
74 | try: | | |||
75 | cmake_command = ['cmake', '--trace-expand', folder] | | |||
76 | execution = run( | | |||
77 | cmake_command, cwd=temp_folder, stdout=DEVNULL, stderr=PIPE) | | |||
78 | return execution.stderr.decode(errors='ignore') | | |||
79 | finally: | | |||
80 | rmtree(temp_folder) | | |||
81 | | ||||
82 | | ||||
83 | def project_version(source_folder): | | |||
84 | match = None | | |||
85 | for match in VERSION_RE.finditer(cmake_trace(source_folder)): | | |||
86 | pass | | |||
87 | if not match: | | |||
88 | return None | | |||
89 | return match.group(1) | | |||
90 | | ||||
91 | | ||||
92 | def bugzilla_csrf_token(session, product): | 66 | def bugzilla_csrf_token(session, product): | ||
93 | params = {'action': 'add', 'product': product} | 67 | params = {'action': 'add', 'product': product} | ||
94 | response = session.get(EDIT_VERSION_URL, params=params) | 68 | response = session.get(EDIT_VERSION_URL, params=params) | ||
95 | soup = BeautifulSoup(response.text, 'html.parser') | 69 | soup = BeautifulSoup(response.text, 'html.parser') | ||
96 | try: | 70 | try: | ||
97 | return soup.find('input', {'name': 'token'})['value'] | 71 | return soup.find('input', {'name': 'token'})['value'] | ||
98 | except: | 72 | except: | ||
99 | raise RuntimeError('Could not parse token from \'{}\''.format( | 73 | raise RuntimeError('Could not parse token from \'{}\''.format( | ||
▲ Show 20 Lines • Show All 140 Lines • Show Last 20 Lines |